@devries-cameron20 / t3code-1 / commits / 694076dcf3
Fork 0

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

fix(server): show when Stop leaves a Claude steer unconfirmed (#23807)

Julius Marminge committed Nov 11, 2026 at 13:46 UTC 694076dcf34aac70f5d55feb6c15e7b895a5424a
2 files changed +223 -12
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+148
@@ -4958,6 +4958,154 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4958 ),
4959 );
4960
4961 + // regression: #15708 Stop must not silently drop a steer Claude queued behind a foreground task
4962 + it.effect.each([
4963 + {
4964 + readBy: "none",
4965 + echoes: true,
4966 + title: "warns that a steer Claude never read before Stop was not delivered",
4967 + },
4968 + {
4969 + readBy: "none",
4970 + echoes: false,
4971 + title: "does not warn about a steer on a CLI that never echoes prompt uuids",
4972 + },
4973 + {
4974 + readBy: "assistant",
4975 + echoes: true,
4976 + title: "does not warn about a steer Claude read before Stop",
4977 + },
4978 + ] as const)("$title", ({ readBy, echoes }) =>
4979 + Effect.gen(function* () {
4980 + const harness = yield* makeWakeHarnessWithOptions({
4981 + close: (sdkMessages) => Queue.shutdown(sdkMessages),
4982 + freshQueueOnReopen: true,
4983 + });
4984 + const idAllocator = yield* IdAllocator.IdAllocatorV2;
4985 + const firstInput = makeClaudeTestTurnInput({
4986 + threadId: harness.threadId,
4987 + providerThread: harness.providerThread,
4988 + now: yield* DateTime.now,
4989 + attemptId: RunAttemptId.make("attempt-claude-unread-steer-1"),
4990 + text: "Run the slow curl in the foreground.",
4991 + attachments: [],
4992 + });
4993 + yield* harness.runtime.startTurn(firstInput);
4994 + const providerTurnId = idAllocator.derive.providerTurn({
4995 + driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
4996 + nativeTurnId: `turn:${firstInput.attemptId}`,
4997 + });
4998 + yield* harness.offerAndWait(
4999 + claudeSdkFrame({
5000 + type: "assistant",
5001 + uuid: "00000000-0000-4000-8000-000000015701",
5002 + session_id: WAKE_NATIVE_SESSION,
5003 + parent_tool_use_id: null,
5004 + ...(echoes ? { user_message_uuids: [harness.promptUuid(0)] } : {}),
5005 + message: {
5006 + id: "msg_unread_steer_bash",
5007 + type: "message",
5008 + role: "assistant",
5009 + model: "claude-sonnet-4-6",
5010 + content: [
5011 + {
5012 + type: "tool_use",
5013 + id: "toolu-unread-steer-bash",
5014 + name: "Bash",
5015 + input: { command: "curl http://127.0.0.1:9/hang" },
5016 + },
5017 + ],
5018 + },
5019 + }),
5020 + );
5021 + // Past task_started the CLI queues a "now" steer until the call returns.
5022 + yield* harness.offerAndWait(
5023 + claudeSdkFrame({
5024 + type: "system",
5025 + subtype: "task_started",
5026 + task_id: "task-unread-steer-bash",
5027 + tool_use_id: "toolu-unread-steer-bash",
5028 + description: "Slow curl",
5029 + is_backgrounded: false,
5030 + task_type: "local_bash",
5031 + uuid: "00000000-0000-4000-8000-000000015702",
5032 + session_id: WAKE_NATIVE_SESSION,
5033 + }),
5034 + );
5035 + const steerText = "Codeword: PELICAN. Remember it, I will ask for it later.";
5036 + yield* harness.runtime.steerTurn({
5037 + threadId: harness.threadId,
5038 + runId: firstInput.runId,
5039 + providerThread: harness.providerThread,
5040 + providerTurnId,
5041 + message: {
5042 + createdBy: "user",
5043 + creationSource: "web",
5044 + messageId: MessageId.make("unread-steer"),
5045 + text: steerText,
5046 + attachments: [],
5047 + },
5048 + });
5049 + const steerUuid = harness.offeredMessages.at(-1)?.uuid;
5050 + assert.isDefined(steerUuid);
5051 + if (readBy === "assistant") {
5052 + yield* harness.offerAndWait(
5053 + claudeSdkFrame({
5054 + type: "assistant",
5055 + uuid: "00000000-0000-4000-8000-000000015703",
5056 + session_id: WAKE_NATIVE_SESSION,
5057 + parent_tool_use_id: null,
5058 + user_message_uuids: [steerUuid],
5059 + message: {
5060 + id: "msg_unread_steer_reply",
5061 + type: "message",
5062 + role: "assistant",
5063 + model: "claude-sonnet-4-6",
5064 + content: [{ type: "text", text: "Noted." }],
5065 + },
5066 + }),
5067 + );
5068 + }
5069 + const noticesBefore = harness.events.length;
5070 + yield* harness.runtime.interruptTurn({
5071 + providerThread: harness.providerThread,
5072 + providerTurnId,
5073 + });
5074 + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted");
5075 +
5076 + const notices = harness.events
5077 + .slice(noticesBefore)
5078 + .flatMap((event) =>
5079 + event.type === "turn_item.updated" && event.turnItem.type === "system_notice"
5080 + ? [event.turnItem.message]
5081 + : [],
5082 + );
5083 + const undelivered = notices.find((message) =>
5084 + /not (have )?(been )?delivered|never (reached|delivered)/i.test(message ?? ""),
5085 + );
5086 + if (readBy !== "none" || !echoes) {
5087 + assert.isUndefined(undelivered);
5088 + return;
5089 + }
5090 + assert.isDefined(
5091 + undelivered,
5092 + `expected an undelivered-steer notice, got ${JSON.stringify(notices)}`,
5093 + );
5094 + assert.match(undelivered ?? "", /resend|send it again|re-send/i);
5095 + assert.include(undelivered, "PELICAN");
5096 + }).pipe(
5097 + Effect.scoped,
5098 + Effect.provide(
5099 + Layer.mergeAll(
5100 + IdAllocator.layer,
5101 + McpProviderSessions.layer,
5102 + NodeServices.layer,
5103 + NodeCrypto.layer,
5104 + ),
5105 + ),
5106 + ),
5107 + );
5108 +
5109 // regression: #23948 Claude holds a steer behind a running foreground tool
5110 // call and goes silent, so each steer stays pending until Claude starts it.
5111 it.effect("keeps a steer pending until Claude starts it", () =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+75 -12
@@ -4453,6 +4453,9 @@ interface ActiveClaudeTurnContext {
4453 compactionFailure: { readonly message: string | undefined } | null;
4454 // Steers end segments whose usage is excluded from the final result; bill them too, oldest first.
4455 readonly steeredSegmentUsage: Array<SDKResultMessage["usage"]>;
4456 + // Set as finalization starts: a steer admitted later would stay pending
4457 + // forever, so it fails and the orchestrator follows up instead.
4458 + steersClosed: boolean;
4459 // Ledger growth of the steered segments; undefined once any segment's growth is unknown.
4460 steeredLedgerUsage: ClaudeLedgerUsage | undefined;
4461 readonly rootModels: Set<string>;
@@ -4465,8 +4468,16 @@ interface ActiveClaudeTurnContext {
4468 gatedFramesBeforeEcho: number;
4469 readonly heldRootFrames: Array<SDKMessage>;
4470 // Steers Claude has not started or echoed yet, by prompt uuid. Claude holds
4468 - // a steer behind a running foreground tool call without saying so.
4469 - readonly pendingSteers: Map<string, MessageId>;
4471 + // a steer behind a running foreground tool call without saying so, and Stop
4472 + // drops it unread.
4473 + readonly pendingSteers: Map<
4474 + string,
4475 + {
4476 + readonly messageId: MessageId;
4477 + readonly text: string;
4478 + readonly liveQuery: ClaudeLiveQueryContext;
4479 + }
4480 + >;
4481 // Claude may settle a turn with a result that echoes only a steer's uuid.
4482 readonly steerUuids: Set<string>;
4483 // Claude can run another model than requested, such as when an organization disallows it.
@@ -8124,10 +8135,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8135 ? [lifecycle.uuid]
8136 : [];
8137 for (const uuid of accepted) {
8127 - const messageId = context.pendingSteers.get(uuid);
8128 - if (messageId === undefined) continue;
8138 + const steer = context.pendingSteers.get(uuid);
8139 + if (steer === undefined) continue;
8140 context.pendingSteers.delete(uuid);
8130 - yield* emitSteerStatus(context, messageId, "completed");
8141 + yield* emitSteerStatus(context, steer.messageId, "completed");
8142 }
8143 });
8144
@@ -8142,16 +8153,18 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8153 readonly threadDisposition?: "reusable" | "broken";
8154 readonly result?: SDKResultMessage;
8155 }) {
8156 + input.context.steersClosed = true;
8157 yield* reasoningDeltas.flushTurn(input.context.nativeTurnId);
8158 // A turn that completes has taken in every steer; one that stops drops them unread.
8147 - for (const messageId of input.context.pendingSteers.values()) {
8159 + const droppedSteers = [...input.context.pendingSteers];
8160 + input.context.pendingSteers.clear();
8161 + for (const [, { messageId }] of droppedSteers) {
8162 yield* emitSteerStatus(
8163 input.context,
8164 messageId,
8165 input.status === "completed" ? "completed" : "cancelled",
8166 );
8167 }
8154 - input.context.pendingSteers.clear();
8168 if (input.context.compaction?.status === "running") {
8169 const reason = input.result?.subtype === "success" ? input.result.result.trim() : "";
8170 yield* emitProviderEvent({
@@ -8289,6 +8302,49 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8302 });
8303 }
8304
8305 + if (input.status === "interrupted") {
8306 + for (const [uuid, { text, liveQuery }] of droppedSteers) {
8307 + // Only a CLI proven to echo prompt uuids can leave a steer unconfirmed.
8308 + if (
8309 + liveQuery.promptEchoMode !== "early" &&
8310 + liveQuery.promptEchoMode !== "result_only"
8311 + ) {
8312 + continue;
8313 + }
8314 + const nativeItemId = `unread-steer:${uuid}`;
8315 + const notice = `Claude did not confirm reading your steer before Stop. It may not have been delivered. Resend it if needed: "${text}"`;
8316 + yield* emitProviderEvent({
8317 + type: "turn_item.updated",
8318 + driver: CLAUDE_PROVIDER,
8319 + turnItem: {
8320 + id: idAllocator.derive.turnItemFromProviderItem({
8321 + driver: CLAUDE_PROVIDER,
8322 + nativeItemId,
8323 + }),
8324 + threadId: input.context.input.threadId,
8325 + runId: input.context.input.runId,
8326 + nodeId: input.context.input.rootNodeId,
8327 + providerThreadId: input.context.input.providerThread.id,
8328 + providerTurnId: input.context.providerTurnId,
8329 + nativeItemRef: {
8330 + driver: CLAUDE_PROVIDER,
8331 + nativeId: nativeItemId,
8332 + strength: "weak",
8333 + },
8334 + parentItemId: null,
8335 + ordinal: yield* resolveItemOrdinal(input.context, nativeItemId),
8336 + type: "system_notice",
8337 + status: "completed",
8338 + title: "Steer delivery not confirmed",
8339 + message: notice,
8340 + startedAt: input.completedAt,
8341 + completedAt: input.completedAt,
8342 + updatedAt: input.completedAt,
8343 + },
8344 + });
8345 + }
8346 + }
8347 +
8348 const threadDisposition = input.threadDisposition ?? "reusable";
8349 const terminalEvent: ProviderAdapter.ProviderAdapterV2Event =
8350 input.status === "failed"
@@ -11538,6 +11594,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11594 latestAssistantRateLimit: null,
11595 compactionFailure: null,
11596 steeredSegmentUsage: [],
11597 + steersClosed: false,
11598 steeredLedgerUsage: { inputTokens: 0, outputTokens: 0 },
11599 rootModels: new Set(),
11600 subagentsByTaskId: new Map(),
@@ -11978,22 +12035,28 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
12035 // the steer fails and the orchestrator starts the follow-up turn.
12036 if (
12037 (yield* Ref.get(activeTurn))?.providerTurnId !== turnInput.providerTurnId ||
11981 - (yield* Ref.get(queryContext)) !== existing
12038 + (yield* Ref.get(queryContext)) !== existing ||
12039 + // No yield between this check and the set below.
12040 + currentTurn.steersClosed
12041 ) {
12042 return yield* new ProviderAdapter.ProviderAdapterProtocolError({
12043 driver: CLAUDE_PROVIDER,
12044 detail: `Claude provider turn ${turnInput.providerTurnId} ended before the steer was sent.`,
12045 });
12046 }
12047 + // Register before offering: Claude can start the steer and end the turn before offer returns.
12048 + const messageId = turnInput.message.messageId;
12049 + currentTurn.steerUuids.add(steerUuid);
12050 + currentTurn.pendingSteers.set(steerUuid, {
12051 + messageId,
12052 + text: turnInput.message.text,
12053 + liveQuery: existing,
12054 + });
12055 yield* Ref.update(steeredTurns, (current) => {
12056 const next = new Set(current);
12057 next.add(turnInput.providerTurnId);
12058 return next;
12059 });
11993 - // Register before offering: Claude can start the steer and end the turn before offer returns.
11994 - const messageId = turnInput.message.messageId;
11995 - currentTurn.steerUuids.add(steerUuid);
11996 - currentTurn.pendingSteers.set(steerUuid, messageId);
12060 yield* emitSteerStatus(currentTurn, messageId, "pending");
12061 yield* Effect.uninterruptibleMask((restore) =>
12062 restore(