fix(server): Claude follow-ups no longer interrupt tools #21158
main fromrefs/pull/21158/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
- apps/server/src/orchestration-v2/Orchestrator.ts line 4739OutdatedResolvedby Alb11747(GitHub profile, opens in a new tab)@@ -4721,3 +4721,19 @@47214721 turn.status === "completed"))47224722 ) {47234723 dispatchMode = { type: "start_immediately" };4724+ } else if (command.createdBy === "agent") {4725+ const providerThread = projection.providerThreads.find(4726+ (candidate) => candidate.id === target?.providerThreadId,4727+ );4728+ if (providerThread?.providerSessionId != null) {4729+ const session = yield* providerSessions4730+ .get(providerThread.providerSessionId)4731+ .pipe(mapDispatchError(command));4732+ if (4733+ Option.isSome(session) &&4734+ session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools ===4735+ true4736+ ) {4737+ // Claude steering cancels pending tools, which appear as user refusals.4738+ // Agent updates can wait for the durable queue's next-turn boundary.4739+ dispatchMode = { type: "queue_after_active" };
juliusmarminge assignedjuliusmarminge
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts lines 8698 to 8704OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -8646,0 +8684,21 @@8684+ if (8685+ options.signal.aborted ||8686+ hookInput.agent_id !== undefined ||8687+ context === null ||8688+ live?.query !== boundaryQuery ||8689+ live?.stopping ||8690+ context.nativeThreadId !== hookInput.session_id ||8691+ (yield* Ref.get(interruptedTurns)).has(context.providerTurnId) ||8692+ (hookInput.hook_event_name !== "PostToolBatch" &&8693+ hookInput.hook_event_name !== "Stop")8694+ ) {8695+ return {};8696+ }8697+ // Resolve before claiming so an aborted hook consumes no partial batch.8698+ const pendingSteers = yield* Effect.forEach(8699+ Array.from(context.pendingAgentSteers),8700+ ([id, pending]) =>8701+ (pending.resolveMessageText ?? Effect.succeed(pending.text)).pipe(8702+ Effect.map((text) => ({ id, pending, text })),8703+ ),8704+ );apps/server/src/orchestration-v2/ProviderTurnControlService.ts lines 453 to 460OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -384,8 +443,18 @@384443 operation: "steer",385444 providerTurnId: input.providerTurnId,386445 turnCompleted: current.providerTurn?.status === "completed",446+ deferToQueue:447+ cause._tag === "ProviderAdapterSteerRunError" && cause.deferToQueue === true,387448 cause,388449 });389450 }),390451 ),391452 );453+ if (input.isCurrent !== undefined && !(yield* input.isCurrent)) {454+ return yield* new ProviderTurnControlError({455+ threadId: input.threadId,456+ operation: "steer",457+ providerTurnId: input.providerTurnId,458+ deliveryCancelled: true,459+ });460+ }
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -9152,0 +9245,21 @@9245+ // `priority: next` also folds after tools, but can start an unowned9246+ // native turn if the answer ends first. Hooks keep delivery owned9247+ // by this turn. Allow ordinary commands to finish before falling9248+ // back to T3's queue.9249+ if (turnInput.message.attachments.length > 0) {9250+ return yield* new ProviderAdapter.ProviderAdapterSteerRunDeferredError({9251+ driver: CLAUDE_PROVIDER,9252+ providerThreadId: turnInput.providerThread.id,9253+ providerTurnId: turnInput.providerTurnId,9254+ });9255+ }9256+ const pending: PendingClaudeAgentSteer = {9257+ text: turnInput.message.text,9258+ completion: yield* Deferred.make<ClaudeAgentSteerOutcome>(),9259+ ...(turnInput.resolveMessageText === undefined9260+ ? {}9261+ : { resolveMessageText: turnInput.resolveMessageText }),9262+ };9263+ currentTurn.pendingAgentSteers.set(turnInput.message.messageId, pending);9264+ yield* Deferred.await(pending.completion).pipe(9265+ Effect.timeoutOption("1 minute"),@@ -9152,0 +9245,21 @@9245+ // `priority: next` also folds after tools, but can start an unowned9246+ // native turn if the answer ends first. Hooks keep delivery owned9247+ // by this turn. Allow ordinary commands to finish before falling9248+ // back to T3's queue.9249+ if (turnInput.message.attachments.length > 0) {9250+ return yield* new ProviderAdapter.ProviderAdapterSteerRunDeferredError({9251+ driver: CLAUDE_PROVIDER,9252+ providerThreadId: turnInput.providerThread.id,9253+ providerTurnId: turnInput.providerTurnId,9254+ });9255+ }9256+ const pending: PendingClaudeAgentSteer = {9257+ text: turnInput.message.text,9258+ completion: yield* Deferred.make<ClaudeAgentSteerOutcome>(),9259+ ...(turnInput.resolveMessageText === undefined9260+ ? {}9261+ : { resolveMessageText: turnInput.resolveMessageText }),9262+ };9263+ currentTurn.pendingAgentSteers.set(turnInput.message.messageId, pending);9264+ yield* Deferred.await(pending.completion).pipe(9265+ Effect.timeoutOption("1 minute"),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -242,3 +244,19 @@242244 },243245 );244246247+ // The provider waits on this from a tool-batch or stop hook, so each update248+ // joins its running turn before the hook returns the text. An update that249+ // cannot join (edited away, held by Stop, turn no longer running) stays250+ // queued for the next turn.251+ const claimAgentMessages: ProviderContinuationRequests.ClaimAgentMessages = (input) =>252+ Effect.gen(function* () {253+ const queued = yield* threads.getThreadRecords(input.threadId, ["runs", "messages"], {254+ messageRoles: ["user"],255+ });256+ const texts: Array<string> = [];257+ for (const run of queuedRunsInDeliveryOrder(queued)) {258+ const message = queued.messages.find((row) => row.id === run.userMessageId);259+ if (message?.atToolBoundary !== true) continue;260+ const result = yield* threads261+ .dispatch({262+ type: "queued-message.promote-to-steer",
- @@ -244,0 +253,21 @@253+ const queued = yield* threads.getThreadRecords(input.threadId, ["runs", "messages"], {254+ messageRoles: ["user"],255+ });256+ const texts: Array<string> = [];257+ for (const run of queuedRunsInDeliveryOrder(queued)) {258+ const message = queued.messages.find((row) => row.id === run.userMessageId);259+ if (message?.atToolBoundary !== true) continue;260+ const result = yield* threads261+ .dispatch({262+ type: "queued-message.promote-to-steer",263+ // Fresh per try: a refusal now must not be replayed at a later boundary.264+ commandId: yield* ids.allocate.command({265+ fixtureName: "tool-boundary",266+ commandName: "promote",267+ }),268+ threadId: input.threadId,269+ queuedRunId: run.id,270+ targetRunId: input.runId,271+ atToolBoundary: true,272+ })273+ .pipe(Effect.catchCause(() => Effect.succeed(undefined)));@@ -242,3 +244,12 @@242244 },243245 );244246247+ // The provider waits on this from a tool-batch or stop hook, so each update248+ // joins its running turn before the hook returns the text. An update that249+ // cannot join (edited away, held by Stop, turn no longer running) stays250+ // queued for the next turn.251+ const claimAgentMessages: ProviderContinuationRequests.ClaimAgentMessages = (input) =>252+ Effect.gen(function* () {253+ const queued = yield* threads.getThreadRecords(input.threadId, ["runs", "messages"], {254+ messageRoles: ["user"],255+ });@@ -234,4 +234,4 @@234234235235 const ThreadSendTool = Tool.make("t3_thread_send", {236236 description:237- "Send a message to any T3 thread in this environment. The target cannot have broader permission modes than the caller. Use delegate_task with the full review context and a new clientRequestId for independent review rounds. For a follow-up that needs the same child's conversation, send to its childThreadId. After the original task completes, a requested follow-up creates a fresh task in that child thread and returns taskId when it starts a turn or restarts a turn without its own task; its completion notifies the parent, and the original result stays unchanged. A steer that joins a running turn returns that turn's task, if it has one. mode='auto' starts an idle thread, steers a fully active turn, or queues behind a turn that is not yet steerable. Use queue for a separate follow-up turn, steer for an in-flight update, or restart to interrupt-and-restart the active turn. clientRequestId makes retries idempotent.",237+ "Send a message to any T3 thread in this environment. The target cannot have broader permission modes than the caller. Use delegate_task with the full review context and a new clientRequestId for independent review rounds. For a follow-up that needs the same child's conversation, send to its childThreadId. After the original task completes, a requested follow-up creates a fresh task in that child thread and returns taskId when it starts a turn or restarts a turn without its own task; its completion notifies the parent, and the original result stays unchanged. A steer that joins a running turn returns that turn's task, if it has one. mode='auto' starts an idle thread, safely steers a fully active turn, or queues behind a turn that is not yet steerable. When the target session's steering interrupts tools (including Claude), both auto and explicit steer queue a separate turn instead; delivery='queued' confirms this fallback. Use queue for a separate follow-up turn, steer for an in-fli@@ -3138,0 +3158,21 @@3158+ attemptId: RunAttemptId.make("attempt-agent-boundary"),3159+ text: "Run the slow build.",3160+ attachments: [],3161+ });3162+ yield* harness.runtime.startTurn(input);3163+ const hooks = harness.getOpenedOptions()?.hooks;3164+ const signal = new AbortController().signal;3165+ const base = {3166+ session_id: WAKE_NATIVE_SESSION,3167+ transcript_path: "",3168+ cwd: "",3169+ };3170+ const batch = yield* Effect.promise(() =>3171+ hooks!.PostToolBatch![0]!.hooks[0]!(3172+ { ...base, hook_event_name: "PostToolBatch", tool_calls: [] },3173+ undefined,3174+ { signal },3175+ ),3176+ );3177+ const stop = yield* Effect.promise(() =>3178+ hooks!.Stop![0]!.hooks[0]!(
- @@ -244,0 +248,21 @@248+ // joins its running turn before the hook returns the text. An update that249+ // cannot join (edited away, held by Stop, turn no longer running) stays250+ // queued for the next turn.251+ const claimAgentMessages: ProviderContinuationRequests.ClaimAgentMessages = (input) =>252+ Effect.gen(function* () {253+ // This runs at every tool batch: read only queued runs and their messages.254+ const { runs } = yield* threads.getThreadRecords(input.threadId, ["runs"], {255+ runStatuses: ["queued"],256+ });257+ if (runs.length === 0) return [];258+ const { messages } = yield* threads.getThreadRecords(input.threadId, ["messages"], {259+ messageIds: runs.map((run) => run.userMessageId),260+ });261+ const queued = { runs, messages };262+ const texts: Array<string> = [];263+ for (const run of queuedRunsInDeliveryOrder(queued)) {264+ const message = queued.messages.find((row) => row.id === run.userMessageId);265+ if (message?.atToolBoundary !== true) continue;266+ const result = yield* threads267+ .dispatch({268+ type: "queued-message.promote-to-steer",
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge added labelstakeover
juliusmarminge added labelspr:in-progress
juliusmarminge added labelspr:needs-julius
juliusmarminge removed labelspr:in-progress
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
Alb11747(GitHub profile, opens in a new tab) changed the title
- @@ -5848,3 +5878,21 @@58485878 turn.status === "completed"))58495879 ) {58505880 dispatchMode = { type: "start_immediately" };5881+ } else if (5882+ // After Stop the steer must still fail below; queueing it instead would5883+ // start the update on its own once the provider stops.5884+ !(yield* stopReachedRun(command, command.threadId, targetRunId))5885+ ) {5886+ const providerThread = projection.providerThreads.find(5887+ (candidate) => candidate.id === target?.providerThreadId,5888+ );5889+ if (providerThread?.providerSessionId != null) {5890+ const session = yield* providerSessions5891+ .get(providerThread.providerSessionId)5892+ .pipe(mapDispatchError(command));5893+ if (5894+ Option.isSome(session) &&5895+ session.value.providerSession.capabilities.turns.activeSteeringInterruptsTools === true5896+ ) {5897+ dispatchMode = { type: "queue_after_active" };5898+ atToolBoundary = true;
- @@ -9963,3 +10246,7 @@996310246 : { idleCompaction: queuedMessage.idleCompaction }),996410247 forceRestart: false,996510248 });10249+ if (receipt !== undefined && queuedMessage.delegatedCompletion !== undefined) {10250+ // Accept in the same commit: the cancelled queued run would otherwise10251+ // read as a failed delivery and reserve a duplicate notification.10252+ yield* dispatchNotificationAccepted(@@ -9963,3 +10246,7 @@996310246 : { idleCompaction: queuedMessage.idleCompaction }),996410247 forceRestart: false,996510248 });10249+ if (receipt !== undefined && queuedMessage.delegatedCompletion !== undefined) {10250+ // Accept in the same commit: the cancelled queued run would otherwise10251+ // read as a failed delivery and reserve a duplicate notification.10252+ yield* dispatchNotificationAccepted(
- @@ -270,4 +270,4 @@270270271271 const ThreadSendTool = Tool.make("t3_thread_send", {272272 description:273- "Send a message to any thread. The target cannot run with broader modes than yours. `mode:'auto'` starts an idle thread, steers a running turn, or queues. `queue`: new turn. `steer`: mid-turn update. `restart`: interrupt and restart. A send to a finished child thread starts a fresh task and returns its `taskId`. In your reply, name it as its `link` verbatim.",273+ "Send within your modes. `auto`: start idle, steer running, or queue. Claude auto/steer follows its tool batch, or waits for the next turn after its last batch. `queue`: next turn. `steer`: mid-turn. `restart`: interrupt/restart. Sending to a finished child starts a new task and returns `taskId`. Use its `link` verbatim in your reply.",
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Codex Review Summary: ❌ Failed
This comment shows the latest Codex review activity on this pull request.
We couldn’t complete this review. Comment
@codex reviewto try again.3e0e70bℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.