@devries-cameron20 / t3code Mirror · read-only / commits / a50ebef78b
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 23:30 UTC

fix(server): show when a Claude steer is waiting for acceptance (#24785)

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

Julius Marminge committed Nov 11, 2026 at 11:55 UTC a50ebef78bf65843b3dd8c52e23b313fdb7b0efd
2 files changed +267 -2
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+179 -1
@@ -3210,6 +3210,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3210 readonly freshQueueOnReopen?: boolean;
3211 readonly forkSession?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["forkSession"];
3212 readonly allocateSessionId?: Effect.Effect<string>;
3213 + readonly offer?: (message: SDKUserMessage) => Effect.Effect<void>;
3214 readonly promptSuggestions?: boolean;
3215 }) =>
3216 Effect.gen(function* () {
@@ -3342,7 +3343,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3343 offer: (message) =>
3344 Effect.sync(() => {
3345 offeredMessages.push(message);
3345 - }).pipe(Effect.andThen(changes.notify)),
3346 + }).pipe(
3347 + Effect.andThen(changes.notify),
3348 + Effect.andThen(options?.offer?.(message) ?? Effect.void),
3349 + ),
3350 setModel: (model) =>
3351 Effect.sync(() => {
3352 liveSelectionChanges.push({ model });
@@ -4909,6 +4913,180 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4913 ),
4914 );
4915
4916 + // regression: #23948 Claude holds a steer behind a running foreground tool
4917 + // call and goes silent, so each steer stays pending until Claude starts it.
4918 + it.effect("keeps a steer pending until Claude starts it", () =>
4919 + Effect.gen(function* () {
4920 + const harness = yield* makeWakeHarness;
4921 + const idAllocator = yield* IdAllocator.IdAllocatorV2;
4922 + const attemptId = RunAttemptId.make("attempt-steer-waiting");
4923 + const input = makeClaudeTestTurnInput({
4924 + threadId: harness.threadId,
4925 + providerThread: harness.providerThread,
4926 + now: yield* DateTime.now,
4927 + attemptId,
4928 + text: "Run the slow build.",
4929 + attachments: [],
4930 + });
4931 + yield* harness.runtime.startTurn(input);
4932 + const steer = (id: string) =>
4933 + harness.runtime.steerTurn({
4934 + threadId: harness.threadId,
4935 + runId: input.runId,
4936 + providerThread: harness.providerThread,
4937 + providerTurnId: idAllocator.derive.providerTurn({
4938 + driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
4939 + nativeTurnId: `turn:${attemptId}`,
4940 + }),
4941 + message: {
4942 + createdBy: "user",
4943 + creationSource: "web",
4944 + messageId: MessageId.make(id),
4945 + text: `Steer ${id}`,
4946 + attachments: [],
4947 + },
4948 + });
4949 + yield* steer("message-steer-read");
4950 + yield* steer("message-steer-unread");
4951 + const steerStatuses = () => {
4952 + const latest = new Map<string, string>();
4953 + for (const event of harness.events) {
4954 + if (event.type === "steer.updated") latest.set(event.messageId, event.status);
4955 + }
4956 + return Object.fromEntries(latest);
4957 + };
4958 + const expectSteers = (expected: Record<string, string>) =>
4959 + harness
4960 + .until(() => JSON.stringify(steerStatuses()) === JSON.stringify(expected))
4961 + .pipe(Effect.andThen(Effect.sync(() => assert.deepEqual(steerStatuses(), expected))));
4962 +
4963 + // Claude keeps streaming the foreground tool's turn; once its text is
4964 + // recorded, anything the steers emitted before it is recorded too.
4965 + yield* harness.offerAndWait(
4966 + makeAssistantTextFrame({
4967 + uuid: "00000000-0000-4000-8000-000000002392",
4968 + text: "Still building.",
4969 + }),
4970 + );
4971 + yield* harness.until(() =>
4972 + harness.events.some(
4973 + (event) => event.type === "message.updated" && event.message.text === "Still building.",
4974 + ),
4975 + );
4976 + assert.deepEqual(steerStatuses(), {
4977 + "message-steer-read": "pending",
4978 + "message-steer-unread": "pending",
4979 + });
4980 +
4981 + const lifecycle = (index: number, state: string, uuid: string) =>
4982 + harness.offerAndWait(
4983 + claudeSdkFrame({
4984 + type: "command_lifecycle",
4985 + command_uuid: harness.promptUuid(index),
4986 + state,
4987 + uuid,
4988 + session_id: WAKE_NATIVE_SESSION,
4989 + }),
4990 + );
4991 + // Claude completes prompts it never started, so completed alone is not
4992 + // proof it read one.
4993 + yield* lifecycle(2, "completed", "00000000-0000-4000-8000-000000002393");
4994 + yield* lifecycle(1, "started", "00000000-0000-4000-8000-000000002394");
4995 + yield* expectSteers({
4996 + "message-steer-read": "completed",
4997 + "message-steer-unread": "pending",
4998 + });
4999 +
5000 + yield* harness.offerAndWait(
5001 + claudeSdkFrame({
5002 + ...makeResultFrame({ uuid: "00000000-0000-4000-8000-000000002395", result: "Built." }),
5003 + user_message_uuid: harness.promptUuid(0),
5004 + }),
5005 + );
5006 + yield* harness.awaitTerminal(1);
5007 + yield* expectSteers({
5008 + "message-steer-read": "completed",
5009 + "message-steer-unread": "completed",
5010 + });
5011 + }).pipe(
5012 + Effect.scoped,
5013 + Effect.provide(
5014 + Layer.mergeAll(
5015 + IdAllocator.layer,
5016 + McpProviderSessions.layer,
5017 + NodeServices.layer,
5018 + NodeCrypto.layer,
5019 + ),
5020 + ),
5021 + ),
5022 + );
5023 +
5024 + // Claude can answer a steer while its offer is still being logged.
5025 + it.effect("settles a turn whose result echoes only a steer before the offer returns", () =>
5026 + Effect.gen(function* () {
5027 + let settleDuringOffer: (message: SDKUserMessage) => Effect.Effect<void> = () => Effect.void;
5028 + const harness = yield* makeWakeHarnessWithOptions({
5029 + offer: (message) =>
5030 + message.priority === "now"
5031 + ? Effect.suspend(() => settleDuringOffer(message))
5032 + : Effect.void,
5033 + });
5034 + settleDuringOffer = (message) =>
5035 + harness
5036 + .offerAndWait(
5037 + claudeSdkFrame({
5038 + ...makeResultFrame({
5039 + uuid: "00000000-0000-4000-8000-000000002396",
5040 + result: "Built.",
5041 + }),
5042 + user_message_uuid: message.uuid,
5043 + }),
5044 + )
5045 + .pipe(Effect.andThen(harness.awaitTerminal(1)));
5046 + const idAllocator = yield* IdAllocator.IdAllocatorV2;
5047 + const attemptId = RunAttemptId.make("attempt-steer-result");
5048 + const input = makeClaudeTestTurnInput({
5049 + threadId: harness.threadId,
5050 + providerThread: harness.providerThread,
5051 + now: yield* DateTime.now,
5052 + attemptId,
5053 + text: "Run the slow build.",
5054 + attachments: [],
5055 + });
5056 + yield* harness.runtime.startTurn(input);
5057 + yield* harness.runtime.steerTurn({
5058 + threadId: harness.threadId,
5059 + runId: input.runId,
5060 + providerThread: harness.providerThread,
5061 + providerTurnId: idAllocator.derive.providerTurn({
5062 + driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
5063 + nativeTurnId: `turn:${attemptId}`,
5064 + }),
5065 + message: {
5066 + createdBy: "user",
5067 + creationSource: "web",
5068 + messageId: MessageId.make("message-steer-result"),
5069 + text: "Steer",
5070 + attachments: [],
5071 + },
5072 + });
5073 + assert.deepEqual(
5074 + harness.events.flatMap((event) => (event.type === "steer.updated" ? [event.status] : [])),
5075 + ["pending", "completed"],
5076 + );
5077 + }).pipe(
5078 + Effect.scoped,
5079 + Effect.provide(
5080 + Layer.mergeAll(
5081 + IdAllocator.layer,
5082 + McpProviderSessions.layer,
5083 + NodeServices.layer,
5084 + NodeCrypto.layer,
5085 + ),
5086 + ),
5087 + ),
5088 + );
5089 +
5090 // regression: #15475 MCP title arriving after the tool starts must survive to completion
5091 it.effect.each([
5092 { isError: false, title: "Check weather" },
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+88 -1
@@ -97,6 +97,7 @@ import {
97 TrimmedNonEmptyString,
98 defaultInstanceIdForDriver,
99 isCompactionCommandMessage,
100 + type MessageId,
101 type ModelSelection,
102 type OrchestrationV2ConversationMessage,
103 type OrchestrationV2ExecutionNode,
@@ -4052,10 +4053,13 @@ function claudePromptLifecycle(
4053 function isClaudeResultForOtherTurn(input: {
4054 readonly message: SDKResultMessage;
4055 readonly promptUuid: string;
4056 + readonly steerUuids: ReadonlySet<string>;
4057 readonly promptEchoMode: ClaudeLiveQueryContext["promptEchoMode"];
4058 }): boolean {
4059 const echoed = claudeEchoedPromptUuids(input.message);
4058 - if (echoed.length > 0) return !echoed.includes(input.promptUuid);
4060 + if (echoed.length > 0) {
4061 + return !echoed.some((uuid) => uuid === input.promptUuid || input.steerUuids.has(uuid));
4062 + }
4063 return (
4064 input.promptEchoMode !== "unknown" &&
4065 input.message.origin !== undefined &&
@@ -4422,6 +4426,11 @@ interface ActiveClaudeTurnContext {
4426 nativeWakeStarted: boolean;
4427 gatedFramesBeforeEcho: number;
4428 readonly heldRootFrames: Array<SDKMessage>;
4429 + // Steers Claude has not started or echoed yet, by prompt uuid. Claude holds
4430 + // a steer behind a running foreground tool call without saying so.
4431 + readonly pendingSteers: Map<string, MessageId>;
4432 + // Claude may settle a turn with a result that echoes only a steer's uuid.
4433 + readonly steerUuids: Set<string>;
4434 // Claude can run another model than requested, such as when an organization disallows it.
4435 executedModel: string | undefined;
4436 }
@@ -7974,6 +7983,41 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7983 subagentToolCalls.clear();
7984 });
7985
7986 + const emitSteerStatus = (
7987 + context: ActiveClaudeTurnContext,
7988 + messageId: MessageId,
7989 + status: "pending" | "completed" | "cancelled",
7990 + ) =>
7991 + emitProviderEvent({
7992 + type: "steer.updated",
7993 + driver: CLAUDE_PROVIDER,
7994 + threadId: context.input.threadId,
7995 + runId: context.input.runId,
7996 + messageId,
7997 + status,
7998 + });
7999 +
8000 + const markSteersAccepted = Effect.fnUntraced(function* (
8001 + context: ActiveClaudeTurnContext,
8002 + message: SDKMessage,
8003 + ) {
8004 + // Completed alone is not proof of acceptance: Claude also completes
8005 + // prompts it never started.
8006 + const lifecycle = claudePromptLifecycle(message);
8007 + const accepted =
8008 + lifecycle === null
8009 + ? claudeEchoedPromptUuids(message)
8010 + : lifecycle.state === "started"
8011 + ? [lifecycle.uuid]
8012 + : [];
8013 + for (const uuid of accepted) {
8014 + const messageId = context.pendingSteers.get(uuid);
8015 + if (messageId === undefined) continue;
8016 + context.pendingSteers.delete(uuid);
8017 + yield* emitSteerStatus(context, messageId, "completed");
8018 + }
8019 + });
8020 +
8021 const finalizeActiveTurn = Effect.fnUntraced(function* (input: {
8022 readonly context: ActiveClaudeTurnContext;
8023 readonly status: Extract<
@@ -7986,6 +8030,15 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8030 readonly result?: SDKResultMessage;
8031 }) {
8032 yield* reasoningDeltas.flushTurn(input.context.nativeTurnId);
8033 + // A turn that completes has taken in every steer; one that stops drops them unread.
8034 + for (const messageId of input.context.pendingSteers.values()) {
8035 + yield* emitSteerStatus(
8036 + input.context,
8037 + messageId,
8038 + input.status === "completed" ? "completed" : "cancelled",
8039 + );
8040 + }
8041 + input.context.pendingSteers.clear();
8042 if (input.context.compaction?.status === "running") {
8043 const reason = input.result?.subtype === "success" ? input.result.result.trim() : "";
8044 yield* emitProviderEvent({
@@ -10256,6 +10309,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10309 const message = input.message;
10310 const context = yield* Ref.get(activeTurn);
10311 const liveQuery = yield* Ref.get(queryContext);
10312 + if (
10313 + context !== null &&
10314 + context.pendingSteers.size > 0 &&
10315 + liveQuery?.query === input.query
10316 + ) {
10317 + yield* markSteersAccepted(context, message);
10318 + }
10319 if (
10320 context?.promptUuid === null &&
10321 liveQuery?.query === input.query &&
@@ -10329,6 +10389,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10389 isClaudeResultForOtherTurn({
10390 message,
10391 promptUuid: context.promptUuid,
10392 + steerUuids: context.steerUuids,
10393 promptEchoMode: liveQuery.promptEchoMode,
10394 })
10395 ) {
@@ -11356,6 +11417,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11417 nativeWakeStarted: false,
11418 gatedFramesBeforeEcho: 0,
11419 heldRootFrames: [],
11420 + pendingSteers: new Map(),
11421 + steerUuids: new Set(),
11422 executedModel: undefined,
11423 };
11424 const attachTurn = Effect.gen(function* () {
@@ -11741,6 +11804,18 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11804 detail: `Claude provider turn ${turnInput.providerTurnId} is not the active turn.`,
11805 });
11806 }
11807 + // Claude echoes this uuid once it accepts the steer.
11808 + const steerUuid = yield* random.uuidV4().pipe(
11809 + Effect.filterOrFail(isClaudePromptUuid),
11810 + Effect.mapError(
11811 + (cause) =>
11812 + new ProviderAdapter.ProviderAdapterProtocolError({
11813 + driver: CLAUDE_PROVIDER,
11814 + detail: "Failed to allocate a Claude prompt uuid.",
11815 + payload: cause,
11816 + }),
11817 + ),
11818 + );
11819 const pdfReservation = yield* reserveClaudePdfBudget(
11820 pdfBudgets.get(existing.nativeThreadId) ??
11821 makeClaudeAttachmentBudget({
@@ -11757,6 +11832,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11832 ),
11833 attachments: turnInput.message.attachments,
11834 priority: "now",
11835 + uuid: steerUuid,
11836 attachmentsDir,
11837 fileSystem,
11838 pdfReservation,
@@ -11783,6 +11859,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11859 next.add(turnInput.providerTurnId);
11860 return next;
11861 });
11862 + // Register before offering: Claude can start the steer and end the turn before offer returns.
11863 + const messageId = turnInput.message.messageId;
11864 + currentTurn.steerUuids.add(steerUuid);
11865 + currentTurn.pendingSteers.set(steerUuid, messageId);
11866 + yield* emitSteerStatus(currentTurn, messageId, "pending");
11867 yield* Effect.uninterruptibleMask((restore) =>
11868 restore(
11869 existing.query.offer(userMessage, () => {
@@ -11795,6 +11876,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11876 }),
11877 ),
11878 ),
11879 + ).pipe(
11880 + Effect.onError(() =>
11881 + currentTurn.pendingSteers.delete(steerUuid)
11882 + ? emitSteerStatus(currentTurn, messageId, "completed")
11883 + : Effect.void,
11884 + ),
11885 );
11886 },
11887 (effect, turnInput) =>