Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
{
Expand Down
40 changes: 40 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,10 @@ export const CLAUDE_READ_ONLY_T3_MCP_ALLOWED_TOOLS: ReadonlyArray<string> = [
"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;

Expand Down Expand Up @@ -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<CanUseTool>[0],
toolInput: Parameters<CanUseTool>[1],
Expand Down Expand Up @@ -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<ProviderUserInputAnswers, never>();
yield* Ref.update(pendingRuntimeRequests, (current) => {
const updated = new Map(current);
Expand Down
Loading