fix(server): an unread Claude steer no longer hangs the turn or gets lost #39018
MergedAlb11747(GitHub profile, opens in a new tab)merged 8 commits into
main fromrefs/pull/39018/headmerged by juliusmarminge View on GitHubPushed22a4d3c
- @@ -12001,3 +12019,18 @@1200112019 resultFailure?.class === "usage_limit"1200212020 ? { ...resultFailure, resetAt }1200312021 : resultFailure;12022+ const status = interrupted12023+ ? "interrupted"12024+ : limitedCompaction !== null12025+ ? "failed"12026+ : terminalStatusFromResult(message, failureHint);12027+ // Claude answers a steer it has not read yet as the next native turn, which echoes12028+ // the steer. A result without echoes cannot prove that turn will come.12029+ if (12030+ status === "completed" &&12031+ terminalFailure === null &&12032+ context.pendingSteers.size > 0 &&12033+ claudeEchoedPromptUuids(message).length > 012034+ ) {12035+ context.heldResult = message;12036+ return;@@ -3375,0 +3428,21 @@3428+ providerTurnId: item.providerTurnId ?? null,3429+ nativeItemRef: null,3430+ parentItemId: null,3431+ ordinal: item.ordinal,3432+ type: "system_notice" as const,3433+ status: "completed" as const,3434+ title: "Steer delivery not confirmed",3435+ message: `The agent did not confirm reading your steer before Stop. It may not have been delivered. Resend it if needed: "${message.text}"`,3436+ startedAt: now,3437+ completedAt: now,3438+ updatedAt: now,3439+ },3440+ },3441+ ]);3442+ continue;3443+ }3444+ // The message's first steer effect recorded which runs were queued before it was sent; a3445+ // queued message that was promoted also stays behind only the runs queued before its own.3446+ const steer = Option.getOrUndefined(3447+ yield* effectOutbox.firstSteer(threadId, message.id),3448+ )?.request;
- @@ -5758,0 +5777,21 @@5777+ ["user", "web"],5778+ ["agent", "mcp"],5779+ ] as const) {5780+ yield* harness.runtime.steerTurn({5781+ threadId: harness.threadId,5782+ runId: input.runId,5783+ providerThread: harness.providerThread,5784+ providerTurnId,5785+ message: {5786+ createdBy,5787+ creationSource,5788+ messageId: MessageId.make(`steer-priority-${createdBy}`),5789+ text: "Progress note, nothing to change.",5790+ attachments: [],5791+ },5792+ });5793+ }5794+ // Claude Code aborts in-flight and waiting tool calls for a "now" input and5795+ // reports the waiting ones as "The user doesn't want to take this action".5796+ assert.notEqual(harness.offeredMessages[1]?.priority, "now");5797+ assert.notEqual(harness.offeredMessages[2]?.priority, "now");@@ -9257,5 +9250,15 @@92579250 const steer = context.pendingSteers.get(uuid);92589251 if (steer === undefined) continue;92599252 context.pendingSteers.delete(uuid);9253+ // Claude now answers this steer, and that answer's result ends the turn.9254+ absorbHeldResult(context);92609255 yield* emitSteerStatus(context, steer.messageId, "completed");92619256 }9257+ // Claude removed the steer before reading it. Its item stays pending, so the orchestrator9258+ // sends it as the next turn once this run ends.9259+ if (9260+ lifecycle !== null &&9261+ (lifecycle.state === "cancelled" ||9262+ lifecycle.state === "discarded" ||9263+ lifecycle.state === "refused") &&9264+ context.pendingSteers.delete(lifecycle.uuid) &&@@ -9260,2 +9253,21 @@9253+ // Claude now answers this steer, and that answer's result ends the turn.9254+ absorbHeldResult(context);92609255 yield* emitSteerStatus(context, steer.messageId, "completed");92619256 }9257+ // Claude removed the steer before reading it. Its item stays pending, so the orchestrator9258+ // sends it as the next turn once this run ends.9259+ if (9260+ lifecycle !== null &&9261+ (lifecycle.state === "cancelled" ||9262+ lifecycle.state === "discarded" ||9263+ lifecycle.state === "refused") &&9264+ context.pendingSteers.delete(lifecycle.uuid) &&9265+ context.pendingSteers.size === 0 &&9266+ context.heldResult !== undefined9267+ ) {9268+ yield* finalizeActiveTurn({9269+ context,9270+ status: "completed",9271+ completedAt: yield* DateTime.now,9272+ result: context.heldResult,9273+ });@@ -9288,7 +9301,11 @@92889301 if (input.status === "completed" && input.context.appContextOffered !== undefined) {92899302 deliveredAppContext.set(input.context.nativeThreadId, input.context.appContextOffered);92909303 }9291- // A turn that completes has taken in every steer; one that stops drops them unread.9304+ // A live Claude still runs a steer queued at a completed result, and Stop drops them unread9305+ // with a notice below. A steer whose process exited stays pending: nothing can read it now,9306+ // so the orchestrator sends it as the next turn.92929307 const droppedSteers = [...input.context.pendingSteers];92939308 input.context.pendingSteers.clear();9294- for (const [, { messageId }] of droppedSteers) {9309+ const currentQuery = yield* Ref.get(queryContext);9310+ for (const [, { messageId, liveQuery }] of droppedSteers) {9311+ if (input.status !== "interrupted" && liveQuery !== currentQuery) continue;@@ -12001,3 +12019,14 @@1200112019 resultFailure?.class === "usage_limit"1200212020 ? { ...resultFailure, resetAt }1200312021 : resultFailure;12022+ const status = interrupted12023+ ? "interrupted"12024+ : limitedCompaction !== null12025+ ? "failed"12026+ : terminalStatusFromResult(message, failureHint);12027+ // Claude answers a steer it has not read yet as the next native turn, which echoes12028+ // the steer. A result without echoes cannot prove that turn will come.12029+ if (12030+ status === "completed" &&12031+ terminalFailure === null &&12032+ context.pendingSteers.size > 0 &&@@ -12001,3 +12019,17 @@1200112019 resultFailure?.class === "usage_limit"1200212020 ? { ...resultFailure, resetAt }1200312021 : resultFailure;12022+ const status = interrupted12023+ ? "interrupted"12024+ : limitedCompaction !== null12025+ ? "failed"12026+ : terminalStatusFromResult(message, failureHint);12027+ // Claude answers a steer it has not read yet as the next native turn, which echoes12028+ // the steer. A result without echoes cannot prove that turn will come.12029+ if (12030+ status === "completed" &&12031+ terminalFailure === null &&12032+ context.pendingSteers.size > 0 &&12033+ claudeEchoedPromptUuids(message).length > 012034+ ) {12035+ context.heldResult = message;@@ -1036,0 +1238,21 @@1238+ const requeued = yield* watch(1239+ (event) =>1240+ event.type === "run.updated" &&1241+ event.payload.userMessageId === steerId &&1242+ event.payload.status === "queued",1243+ );1244+ yield* Queue.shutdown(sdkMessages);1245+ yield* Fiber.join(requeued);1246+ yield* worker.drain();1247+ // The provider failure holds the queue, the follow-up included, until someone resumes it.1248+ assert.deepEqual(yield* queuedOrder, [1249+ [MessageId.make("before"), true],1250+ [steerId, true],1251+ [MessageId.make("after"), true],1252+ ]);1253+ assert.equal(offers.length, 2);1254+ return;1255+ }1256+1257+ if (outcome === "Claude cancels it and the user stops") {1258+ yield* cancel(offers[1]!);@@ -3373,3 +3365,21 @@33733365 );33743366 });337533673368+ // A steer still pending after its run ended was never read: the provider marks one it read3369+ // completed, and one Stop dropped cancelled. It runs next, in its place among waiting messages.3370+ const requeueUnreadSteers = Effect.fn("Orchestrator.requeueUnreadSteers")(function* (3371+ threadId: ThreadId,3372+ runIds?: ReadonlyArray<RunId>,3373+ ) {3374+ const { turnItems } = yield* projectionStore.getThreadRecords(threadId, ["turnItems"], {3375+ turnItemTypes: ["user_message"],3376+ turnItemStatuses: ["pending"],3377+ ...(runIds === undefined ? {} : { turnItemRunIds: runIds }),3378+ });3379+ const unread = turnItems3380+ .filter(3381+ (item) =>3382+ item.type === "user_message" &&3383+ (item.inputIntent === "steer" || item.inputIntent === "promoted_queued_to_steer"),3384+ )3385+ .toSorted((left, right) => left.ordinal - right.ordinal);@@ -3375,0 +3431,21 @@3431+ ordinal: item.ordinal,3432+ type: "system_notice" as const,3433+ status: "completed" as const,3434+ title: "Steer delivery not confirmed",3435+ message: `The agent did not confirm reading your steer before Stop. It may not have been delivered. Resend it if needed: "${message.text}"`,3436+ startedAt: now,3437+ completedAt: now,3438+ updatedAt: now,3439+ },3440+ },3441+ ]);3442+ continue;3443+ }3444+ // The message's first steer effect recorded which runs were queued before it was sent; a3445+ // queued message that was promoted also stays behind only the runs queued before its own.3446+ const steer = Option.getOrUndefined(3447+ yield* effectOutbox.firstSteer(threadId, message.id),3448+ )?.request;3449+ const steeredAfter =3450+ steer?.type === "provider-turn.steer" ? steer.steerFollowUpAfterRunOrdinal : undefined;3451+ yield* dispatchWithReceiptEffect({@@ -3375,0 +3433,21 @@3433+ status: "completed" as const,3434+ title: "Steer delivery not confirmed",3435+ message: `The agent did not confirm reading your steer before Stop. It may not have been delivered. Resend it if needed: "${message.text}"`,3436+ startedAt: now,3437+ completedAt: now,3438+ updatedAt: now,3439+ },3440+ },3441+ ]);3442+ continue;3443+ }3444+ // The message's first steer effect recorded which runs were queued before it was sent; a3445+ // queued message that was promoted also stays behind only the runs queued before its own.3446+ const steer = Option.getOrUndefined(3447+ yield* effectOutbox.firstSteer(threadId, message.id),3448+ )?.request;3449+ const steeredAfter =3450+ steer?.type === "provider-turn.steer" ? steer.steerFollowUpAfterRunOrdinal : undefined;3451+ yield* dispatchWithReceiptEffect({3452+ type: "message.dispatch",3453+ commandId: CommandId.make(`command:unread-steer:${run.id}:${message.id}`),
Pusheda1eea3e
- @@ -3038,3 +3042,9 @@30383042 budget.committed.pages += this.pages;30393043 budget.committed.bytes += this.bytes;30403044 },3045+ // Claude dropped the message unread, so its files never entered the session.3046+ refund() {3047+ if (!this.delivered || this.refunded) return;3048+ this.refunded = true;3049+ budget.committed.pages -= this.pages;3050+ budget.committed.bytes -= this.bytes;@@ -9261,0 +9304,21 @@9304+ const dropped =9305+ lifecycle !== null &&9306+ (lifecycle.state === "cancelled" ||9307+ lifecycle.state === "discarded" ||9308+ lifecycle.state === "refused")9309+ ? context.pendingSteers.get(lifecycle.uuid)9310+ : undefined;9311+ if (dropped === undefined || lifecycle === null) return;9312+ context.pendingSteers.delete(lifecycle.uuid);9313+ // The follow-up turn sends the same files and notes again.9314+ if (9315+ dropped.appContextOffered !== undefined &&9316+ context.appContextOffered === dropped.appContextOffered9317+ ) {9318+ context.appContextOffered = dropped.appContextBefore;9319+ }9320+ if (dropped.pdfReservation.delivered && !dropped.pdfReservation.refunded) {9321+ dropped.pdfReservation.refund();9322+ yield* persistAttachmentBudget(context.nativeThreadId);9323+ }9324+ if (context.pendingSteers.size === 0 && context.heldResult !== undefined) {
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged thise8c4824
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.




chatgpt-codex-connector[bot](GitHub profile, opens in a new tab) reviewed
💡 Codex Review#
Here are some automated review suggestions for this pull request.
Reviewed commit:
5d961dfafcℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".