@@ -10436,16 +10436,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio |
10436 | 10436 | Effect.gen(function* () { |
10437 | 10437 | const childControls = yield* projectionStore.getThreadRecords( |
10438 | 10438 | childThreadId, |
10439 | | - [ |
10440 | | - "runs", |
10441 | | - "messages", |
10442 | | - "subagents", |
10443 | | - "providerThreads", |
10444 | | - "providerTurns", |
10445 | | - "attempts", |
10446 | | - "runtimeRequests", |
10447 | | - "nodes", |
10448 | | - ], |
| 10439 | + ["runs", "messages", "subagents", "providerThreads", "providerTurns", "attempts"], |
10449 | 10440 | { messageRoles: ["user"] }, |
10450 | 10441 | ); |
10451 | 10442 | const parentThreadId = childControls.thread.lineage.parentThreadId; |
@@ -10492,15 +10483,34 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio |
10492 | 10483 | ) |
10493 | 10484 | ) |
10494 | 10485 | return; |
10495 | | - // Completed or failed tasks keep async questions: answering resumes the child. |
| 10486 | + // Cancelled or interrupted tasks must not leave async questions that resume the child. |
10496 | 10487 | // Callers hold the parent lock; dismiss takes the child lock, as follow-up intake does. |
10497 | | - for (const request of childControls.runtimeRequests) { |
10498 | | - if ( |
| 10488 | + const { runtimeRequests } = yield* projectionStore.getThreadRecords(childThreadId, [ |
| 10489 | + "runtimeRequests", |
| 10490 | + ]); |
| 10491 | + const pendingQuestions = runtimeRequests.filter( |
| 10492 | + (request) => |
10499 | 10493 | request.status === "pending" && |
10500 | 10494 | request.kind === "user_input" && |
10501 | | - request.responseCapability.type === "message" && |
10502 | | - childControls.nodes.some( |
10503 | | - (node) => node.id === request.nodeId && node.runId === resultRun.id, |
| 10495 | + request.responseCapability.type === "message", |
| 10496 | + ); |
| 10497 | + if (pendingQuestions.length === 0) return; |
| 10498 | + const { nodes } = yield* projectionStore.getThreadRecords(childThreadId, ["nodes"]); |
| 10499 | + const resultRunIds = new Set<RunId>(); |
| 10500 | + let run: OrchestrationV2Run | undefined = resultRun; |
| 10501 | + while (run !== undefined && !resultRunIds.has(run.id)) { |
| 10502 | + resultRunIds.add(run.id); |
| 10503 | + const previousRunId: RunId | undefined = run.restartContinuationOfRunId; |
| 10504 | + run = |
| 10505 | + previousRunId === undefined |
| 10506 | + ? undefined |
| 10507 | + : childControls.runs.find((candidate) => candidate.id === previousRunId); |
| 10508 | + } |
| 10509 | + for (const request of pendingQuestions) { |
| 10510 | + if ( |
| 10511 | + nodes.some( |
| 10512 | + (node) => |
| 10513 | + node.id === request.nodeId && node.runId !== null && resultRunIds.has(node.runId), |
10504 | 10514 | ) |
10505 | 10515 | ) { |
10506 | 10516 | yield* dispatchWithReceipt({ |
|