@devries-cameron20 / t3code-1 / commits / e2bb9e63e1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): subagent questions reach a busy parent agent (#29909)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Nov 2, 2026 at 22:58 UTC e2bb9e63e129001aa37fa1f9f51cb334d1a3db42
4 files changed +132 -25
apps/server/src/orchestration-v2/EffectWorker.ts
+5 -4
@@ -278,6 +278,10 @@ export const layerExecutor: Layer.Layer<
278 const message = projection.messages.find((item) => item.id === messageId);
279 const run = projection.runs.find((item) => item.id === message?.runId);
280 if (message === undefined || run === undefined) return yield* error;
281 + // Notifications must be queued messages.
282 + const queued =
283 + message.delegatedCompletion !== undefined ||
284 + message.notification !== undefined;
285 // Reuse message ids and receipts so retries cannot duplicate messages or follow-ups.
286 yield* threads
287 .dispatch({
@@ -292,10 +296,7 @@ export const layerExecutor: Layer.Layer<
296 ? {}
297 : { modelSelection: run.modelSelection }),
298 dispatchMode: {
295 - type:
296 - message.delegatedCompletion === undefined
297 - ? "start_immediately"
298 - : "queue_after_active",
299 + type: queued ? "queue_after_active" : "start_immediately",
300 },
301 createdBy: message.createdBy,
302 creationSource: message.creationSource,
apps/server/src/orchestration-v2/Orchestrator.ts
+17 -8
@@ -4685,6 +4685,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4685 readonly senderThreadId?: OrchestrationV2ConversationMessage["senderThreadId"];
4686 readonly idleCompaction?: OrchestrationV2ConversationMessage["idleCompaction"];
4687 readonly delegatedCompletion?: OrchestrationV2ConversationMessage["delegatedCompletion"];
4688 + readonly notification?: OrchestrationV2ConversationMessage["notification"];
4689 readonly forceRestart: boolean;
4690 }) {
4691 const targetRun = input.projection.runs.find((candidate) => candidate.id === input.targetRunId);
@@ -4838,6 +4839,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4839 ...(input.delegatedCompletion === undefined
4840 ? {}
4841 : { delegatedCompletion: input.delegatedCompletion }),
4842 + ...(input.notification === undefined ? {} : { notification: input.notification }),
4843 ...(input.scheduledTaskId === undefined
4844 ? {}
4845 : { scheduledTaskId: input.scheduledTaskId }),
@@ -4939,6 +4941,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4941 input.projection.thread.providerInstanceId !== input.modelSelection.instanceId;
4942 if (
4943 input.delegatedCompletion === undefined &&
4944 + input.notification === undefined &&
4945 (instanceChanged ||
4946 !modelSelectionsEqual(input.projection.thread.modelSelection, input.modelSelection))
4947 ) {
@@ -5729,13 +5732,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5732 taskIds: delivery.taskIds,
5733 };
5734 }
5732 - // Route durable mailbox deliveries under the thread lock, using the live
5733 - // session's capabilities. Never interrupt/restart a turn for a notification.
5735 + // Route durable mailbox deliveries and delegated task questions under the
5736 + // thread lock, using the live session's capabilities. A question queued
5737 + // behind a long parent turn is never seen. Never interrupt/restart a turn
5738 + // for a notification.
5739 if (
5735 - delegatedCompletion !== undefined &&
5736 - delegatedCompletion.taskIds.every(
5737 - (id) => projection.subagents.find((task) => task.id === id)?.completionWake === "always",
5738 - )
5740 + delegatedCompletion !== undefined
5741 + ? delegatedCompletion.taskIds.every(
5742 + (id) =>
5743 + projection.subagents.find((task) => task.id === id)?.completionWake === "always",
5744 + )
5745 + : command.notification?.source.kind === "delegated_task"
5746 ) {
5747 const active = projection.runs.find((run) => run.status === "running");
5748 const providerThread = projection.providerThreads.find(
@@ -5759,7 +5766,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5766 if (
5767 Option.isSome(session) &&
5768 session.value.providerSession.capabilities.turns.supportsActiveSteering &&
5762 - session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools !== true
5769 + session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools !== true &&
5770 + !(yield* stopReachedRun(command, command.threadId, active.id))
5771 ) {
5772 dispatchMode = { type: "steer_active", targetRunId: active.id };
5773 }
@@ -5826,11 +5834,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5834 effects,
5835 projection,
5836 modelSelection:
5829 - delegatedCompletion === undefined
5837 + delegatedCompletion === undefined && command.notification === undefined
5838 ? modelSelection
5839 : (projection.runs.find((run) => run.id === dispatchMode.targetRunId)?.modelSelection ??
5840 modelSelection),
5841 delegatedCompletion,
5842 + ...(command.notification === undefined ? {} : { notification: command.notification }),
5843 targetRunId: dispatchMode.targetRunId,
5844 messageId: command.messageId,
5845 text: dispatchText,
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+104 -11
@@ -44,13 +44,16 @@ it.effect.each(
44 [true, "with interrupting native steering"],
45 [true, "settled only"],
46 [false, "during continuation"],
47 + ["question", "during delivery"],
48 ] as const
48 - ).map(([mailbox, timing]) => ({
49 - mailbox,
49 + ).map(([kind, timing]) => ({
50 + mailbox: kind === true,
51 + question: kind === "question",
52 timing,
51 - label: mailbox ? "mailbox notification" : "steering",
53 + label:
54 + kind === "question" ? "delegated task question" : kind ? "mailbox notification" : "steering",
55 })),
53 -)("delivers $label when completion wins $timing", ({ mailbox, timing }) =>
56 +)("delivers $label when completion wins $timing", ({ mailbox, question, timing }) =>
57 Effect.scoped(
58 Effect.gen(function* () {
59 const cwd = yield* checkpointWorkspace(`steering-completion-${timing.replaceAll(" ", "-")}`);
@@ -255,6 +258,21 @@ it.effect.each(
258 ],
259 });
260 }
261 + if (question) {
262 + const { thread } = yield* orchestrator.getThreadProjection(threadId);
263 + yield* (yield* EventSink.EventSinkV2).write({
264 + events: [
265 + {
266 + id: EventId.make("event:composer-selection"),
267 + type: "thread.model-selection-updated",
268 + threadId,
269 + providerInstanceId: instanceId,
270 + occurredAt: yield* DateTime.now,
271 + payload: { ...thread, modelSelection: composerSelection },
272 + },
273 + ],
274 + });
275 + }
276 const dispatchSteer = orchestrator.dispatch({
277 type: "message.dispatch",
278 commandId: CommandId.make("steer"),
@@ -270,11 +288,21 @@ it.effect.each(
288 sizeBytes: 10,
289 },
290 ],
273 - dispatchMode: mailbox
274 - ? { type: "queue_after_active" }
275 - : { type: "steer_active", targetRunId: first.runId },
276 - createdBy: mailbox ? "agent" : "user",
277 - creationSource: mailbox ? "server" : "web",
291 + dispatchMode:
292 + mailbox || question
293 + ? { type: "queue_after_active" }
294 + : { type: "steer_active", targetRunId: first.runId },
295 + createdBy: mailbox || question ? "agent" : "user",
296 + creationSource: mailbox || question ? "server" : "web",
297 + ...(question
298 + ? {
299 + notification: {
300 + source: { kind: "delegated_task", taskIds: [taskId] },
301 + outcome: "updated",
302 + summary: "Delegated task has a question",
303 + },
304 + }
305 + : {}),
306 ...(mailbox
307 ? {
308 delegatedCompletion: {
@@ -340,6 +368,8 @@ it.effect.each(
368 if (delivery !== null) {
369 yield* Deferred.succeed(rejectSteer, undefined);
370 yield* Fiber.join(delivery);
371 + }
372 + if (delivery !== null && !question) {
373 const requeued = yield* orchestrator.getThreadProjection(threadId);
374 const item = requeued.turnItems.find(
375 (item) => item.type === "user_message" && item.messageId === messageId,
@@ -399,7 +429,11 @@ it.effect.each(
429 ]);
430 assert.equal(steerCalls, timing === "during delivery" ? 1 : 0);
431 const final = yield* orchestrator.getThreadProjection(threadId);
402 - if (!mailbox) {
432 + if (question) {
433 + assert.deepEqual(final.thread.modelSelection, composerSelection);
434 + assert.deepEqual(started[1]?.modelSelection, composerSelection);
435 + }
436 + if (!mailbox && !question) {
437 assert.equal(
438 final.turnItems.find(
439 (item) => item.type === "user_message" && item.messageId === messageId,
@@ -414,7 +448,7 @@ it.effect.each(
448 );
449 assert.equal(
450 final.turnItems.filter((item) =>
417 - mailbox
451 + mailbox || question
452 ? item.type === "notification"
453 : item.type === "user_message" && item.messageId === messageId,
454 ).length,
@@ -617,6 +651,65 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
651 return { cwd, events, started, steered, interrupted, layer, startFirstTurn };
652 });
653
654 +it.effect("steers a delegated task question notice into the running parent turn", () =>
655 + Effect.scoped(
656 + Effect.gen(function* () {
657 + const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
658 + "delegated-question-steer",
659 + );
660 + yield* Effect.gen(function* () {
661 + const orchestrator = yield* Orchestrator.OrchestratorV2;
662 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
663 + const threadId = yield* startFirstTurn;
664 + const { thread } = yield* orchestrator.getThreadProjection(threadId);
665 + yield* (yield* EventSink.EventSinkV2).write({
666 + events: [
667 + {
668 + id: EventId.make("event:composer-selection"),
669 + type: "thread.model-selection-updated",
670 + threadId,
671 + providerInstanceId: instanceId,
672 + occurredAt: yield* DateTime.now,
673 + payload: { ...thread, modelSelection: composerSelection },
674 + },
675 + ],
676 + });
677 + const messageId = MessageId.make("message:delegated-task-question:child-question");
678 + const notification = {
679 + source: {
680 + kind: "delegated_task" as const,
681 + taskIds: [NodeId.make("task:question")],
682 + childThreadId: ThreadId.make("thread:question-child"),
683 + },
684 + outcome: "updated" as const,
685 + summary: "Delegated task has a question",
686 + };
687 + yield* orchestrator.dispatch({
688 + type: "message.dispatch",
689 + commandId: CommandId.make("question-wake"),
690 + threadId,
691 + messageId,
692 + text: "Delegated task asked a question",
693 + notification,
694 + attachments: [],
695 + dispatchMode: { type: "queue_after_active" },
696 + createdBy: "agent",
697 + creationSource: "server",
698 + });
699 + yield* worker.drain();
700 + const after = yield* orchestrator.getThreadProjection(threadId);
701 + assert.deepEqual(steered, ["Delegated task asked a question"]);
702 + assert.lengthOf(started, 1);
703 + assert.isFalse(after.runs.some((run) => run.status === "queued"));
704 + const message = after.messages.find((candidate) => candidate.id === messageId);
705 + assert.equal(message?.runId, started[0]?.runId);
706 + assert.deepEqual(message?.notification, notification);
707 + assert.deepEqual(after.thread.modelSelection, composerSelection);
708 + }).pipe(Effect.provide(layer));
709 + }),
710 + ),
711 +);
712 +
713 it.effect("sends a selected held message once and preserves the remaining queue order", () =>
714 Effect.scoped(
715 Effect.gen(function* () {
docs/orchestration-v2/orchestrator-mcp-server.md
+6 -2
@@ -515,8 +515,12 @@ Users rarely watch child threads, so a child question would otherwise go
515 unanswered. When a child opens a pending `user_input` request, the parent gets
516 a notification message telling it to answer with the pending request tools or
517 ask the user. The message says whether the child is blocked or, for a Codex
518 -async question, still working. If the question is answered or dismissed before
519 -the notification starts a turn, that queued turn is cancelled. Approvals are not
518 +async question, still working. If the parent's turn is running and its provider
519 +can steer without interrupting tools, the notification steers into that turn,
520 +like a background task's completion. A queued notice would wait behind a
521 +long-running orchestrator turn that may never end. Otherwise it queues. If the
522 +question is answered or dismissed before a queued notification starts a turn,
523 +that queued turn is cancelled. Approvals are not
524 routed, because those tools cannot answer them.
525 A parent still blocked in a `delegate_task` wait gets the blocking question
526 through that wait instead.