From 8b098ea8ebba3a1862a093e3b82ad8de0a11fd93 Mon Sep 17 00:00:00 2001 From: Omar <76748259+omar9848492@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:37:15 -0500 Subject: [PATCH] feat(server): Claude questions can stay open while the agent keeps working With T3CODE_CLAUDE_ASYNC_QUESTIONS=1, Claude's AskUserQuestion posts its question card as a message-capability request and returns at once instead of blocking the turn. The thread shows Input needed while the run continues, and the answer is delivered as a user message through the existing async question path that Codex already uses. The resume-compaction dialog stays blocking. Off by default. Co-Authored-By: Claude Fable 5.2 --- .../Adapters/ClaudeAdapterV2.test.ts | 71 +++++++++++++++++++ .../Adapters/ClaudeAdapterV2.ts | 40 +++++++++++ 2 files changed, 111 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index d0dda62b1ff20..ced2e5635fa87 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -15247,6 +15247,77 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + it.effect("posts a question without blocking the turn when async questions are on", () => + Effect.gen(function* () { + const harness = yield* makeWakeHarnessWithOptions({ + environment: { [ClaudeAdapterV2.CLAUDE_ASYNC_QUESTIONS_ENV]: "1" }, + }); + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-async-question"), + text: "Deploy it.", + attachments: [], + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "full-access", + interactionMode: "default", + cwd: "/workspace", + }), + }), + ); + // Not forked: the callback must return without an answer. + const result = yield* Effect.promise(() => + harness.getOpenedOptions()!.canUseTool!( + "AskUserQuestion", + { + questions: [ + { + header: "Target", + question: "Where should this deploy?", + options: [ + { label: "Production", description: "Deploy to production." }, + { label: "Staging", description: "Deploy to staging." }, + ], + multiSelect: false, + }, + ], + }, + { + // @effect-diagnostics-next-line abortControllerInEffect:off - the SDK callback takes a signal. + signal: new AbortController().signal, + toolUseID: "toolu_01AsyncQuestion", + requestId: "request-async-question", + }, + ), + ); + assert.equal(result?.behavior, "deny"); + assert.include(result?.behavior === "deny" ? result.message : "", "stays open"); + const pending = (yield* Queue.take(harness.runtimeRequestReceipts)).runtimeRequest; + assert.equal(pending.kind, "user_input"); + assert.equal(pending.status, "pending"); + assert.deepEqual(pending.responseCapability, { type: "message" }); + const card = harness.events.flatMap((event) => + event.type === "turn_item.updated" && event.turnItem.type === "user_input_request" + ? [event.turnItem] + : [], + ); + assert.equal(card.length, 1); + assert.equal(card[0]?.responseMode, "message"); + assert.equal(card[0]?.status, "waiting"); + }).pipe( + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ); + it.effect.each([ { card: "an approval", toolName: "Bash", toolInput: { command: "echo probe" } }, { diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index edb8ef01301a9..dd7ac399538d7 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -2469,6 +2469,10 @@ export const CLAUDE_READ_ONLY_T3_MCP_ALLOWED_TOOLS: ReadonlyArray = [ "mcp__t3-code__send_to_user", ]; +export const CLAUDE_ASYNC_QUESTIONS_ENV = "T3CODE_CLAUDE_ASYNC_QUESTIONS"; +const CLAUDE_ASYNC_QUESTION_NOTE = + "The user now sees this question as a card, and it stays open; this is not a rejection. Do not wait for it or ask it again. Keep doing the work that does not depend on the answer. The answer arrives later as a user message. If nothing else can be done, end your turn and say you are waiting on this question."; + // request_secret can wait an hour; exceed Claude's default 60 s timeout. export const CLAUDE_T3_MCP_TOOL_TIMEOUT_MS = 65 * 60 * 1_000; @@ -12138,6 +12142,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( yield* handleRoutedSdkMessage(input); }); + // Opt-in: a question shows its card and the agent keeps working; the answer arrives as a message. + const asyncQuestions = adapterOptions.environment[CLAUDE_ASYNC_QUESTIONS_ENV] === "1"; const canUseToolEffect = Effect.fn("ClaudeAdapterV2.canUseTool")(function* ( toolName: Parameters[0], toolInput: Parameters[1], @@ -12207,6 +12213,40 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( requestKind: "user_input", questions, }); + // The compaction dialog (startToolCall false) is a control request that needs its answer. + if (asyncQuestions && options?.startToolCall !== false) { + yield* Effect.all( + [ + emitProviderEvent({ + type: "node.updated", + driver: CLAUDE_PROVIDER, + node: artifacts.node, + }), + emitProviderEvent({ + type: "runtime_request.updated", + driver: CLAUDE_PROVIDER, + runtimeRequest: { + ...artifacts.request, + responseCapability: { type: "message" }, + }, + }), + emitProviderEvent({ + type: "turn_item.updated", + driver: CLAUDE_PROVIDER, + turnItem: + artifacts.turnItem.type === "user_input_request" + ? { ...artifacts.turnItem, responseMode: "message" } + : artifacts.turnItem, + }), + ], + { concurrency: 1 }, + ); + return { + behavior: "deny", + message: CLAUDE_ASYNC_QUESTION_NOTE, + toolUseID: callbackOptions.toolUseID, + } satisfies PermissionResult; + } const answers = yield* Deferred.make(); yield* Ref.update(pendingRuntimeRequests, (current) => { const updated = new Map(current);