Skip to content

Commit 4524eee

Browse files
only21milclaude
andauthored
fix(claude): no failed AskUserQuestion row after the resume dialog (#23481)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4ce9205 commit 4524eee

2 files changed

Lines changed: 81 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4953,6 +4953,69 @@ describe("ClaudeAdapterV2 background wake turns", () => {
49534953
),
49544954
);
49554955

4956+
it.effect("completes a turn after the resume dialog without a failed tool row", () =>
4957+
Effect.scoped(
4958+
Effect.gen(function* () {
4959+
const harness = yield* makeWakeHarness;
4960+
yield* harness.runtime.startTurn(
4961+
makeClaudeTestTurnInput({
4962+
threadId: harness.threadId,
4963+
providerThread: harness.providerThread,
4964+
now: yield* DateTime.now,
4965+
attemptId: RunAttemptId.make("attempt-resume-dialog"),
4966+
text: "continue",
4967+
attachments: [],
4968+
}),
4969+
);
4970+
const dialog = yield* Effect.promise(() =>
4971+
harness.getOpenedOptions()!.onUserDialog!(
4972+
{
4973+
dialogKind: "resume_return",
4974+
payload: { sessionAgeMinutes: 90, estimatedTokens: 120000 },
4975+
},
4976+
{ signal: new AbortController().signal, requestId: "dialog-resume" },
4977+
),
4978+
).pipe(Effect.forkScoped);
4979+
const request = yield* Queue.take(harness.runtimeRequestReceipts);
4980+
assert.deepEqual(
4981+
harness.events.flatMap((event) =>
4982+
event.type === "node.updated" && event.node.id === request.runtimeRequest.nodeId
4983+
? [event.node.parentNodeId]
4984+
: [],
4985+
),
4986+
[NodeId.make("node-attempt-resume-dialog")],
4987+
);
4988+
yield* harness.runtime.respondToRuntimeRequest({
4989+
requestId: request.runtimeRequest.id,
4990+
answers: {
4991+
[formatClaudeResumeCompactionQuestion({ ageMinutes: 90, estimatedTokens: 120000 })]:
4992+
"Keep full history",
4993+
},
4994+
});
4995+
assert.deepEqual(yield* Fiber.join(dialog), { behavior: "completed", result: "continue" });
4996+
yield* Queue.offer(
4997+
harness.sdkMessages,
4998+
makeResultFrame({ uuid: "result-resume-dialog", result: "Done" }),
4999+
);
5000+
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
5001+
assert.deepEqual(
5002+
harness.events.flatMap((event) =>
5003+
event.type === "turn_item.updated" &&
5004+
event.turnItem.type === "dynamic_tool" &&
5005+
event.turnItem.nativeItemRef?.nativeId === "dialog-resume"
5006+
? [event.turnItem.status]
5007+
: [],
5008+
),
5009+
[],
5010+
);
5011+
}).pipe(
5012+
Effect.provide(
5013+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5014+
),
5015+
),
5016+
),
5017+
);
5018+
49565019
it.effect.each(
49575020
(["aborted_tools", "aborted_streaming"] as const).flatMap((terminalReason) =>
49585021
[true, false].map((steered) => ({ terminalReason, steered })),

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7081,6 +7081,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
70817081
readonly context: ActiveClaudeTurnContext;
70827082
readonly nativeItemId: string;
70837083
readonly nativeRequestId: string;
7084+
readonly parentNodeId?: OrchestrationV2ExecutionNode["id"];
70847085
readonly requestKind: OrchestrationV2RuntimeRequest["kind"];
70857086
readonly prompt?: string;
70867087
readonly appName?: string;
@@ -7116,10 +7117,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
71167117
id: nodeId,
71177118
threadId: input.context.input.threadId,
71187119
runId: input.context.input.runId,
7119-
parentNodeId: idAllocator.derive.nodeFromProviderItem({
7120-
driver: CLAUDE_PROVIDER,
7121-
nativeItemId: input.nativeItemId,
7122-
}),
7120+
parentNodeId:
7121+
input.parentNodeId ??
7122+
idAllocator.derive.nodeFromProviderItem({
7123+
driver: CLAUDE_PROVIDER,
7124+
nativeItemId: input.nativeItemId,
7125+
}),
71237126
rootNodeId: input.context.input.rootNodeId,
71247127
kind: input.questions === undefined ? "approval_request" : "user_input_request",
71257128
status: "waiting",
@@ -9556,6 +9559,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
95569559
toolName: Parameters<CanUseTool>[0],
95579560
toolInput: Parameters<CanUseTool>[1],
95589561
callbackOptions: Parameters<CanUseTool>[2],
9562+
options?: { readonly startToolCall?: boolean },
95599563
) {
95609564
const context = yield* Ref.get(activeTurn);
95619565
if (context === null) {
@@ -9569,6 +9573,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
95699573
const nativeRequestId = callbackOptions.toolUseID;
95709574
const nativeToolInput = claudeNativeToolInputFromRecord(toolInput);
95719575
const heldForEcho = context.heldRootFrames.length > 0;
9576+
const startToolCall = toolName !== "Agent" && options?.startToolCall !== false;
95729577
if (toolName === "Agent") {
95739578
rememberClaudeSubagentLaunch(
95749579
subagentModelCatalog,
@@ -9578,7 +9583,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
95789583
nativeToolInput,
95799584
null,
95809585
);
9581-
} else if (!heldForEcho) {
9586+
} else if (startToolCall && !heldForEcho) {
95829587
yield* ensureToolCallStarted({
95839588
context,
95849589
nativeItemId: nativeRequestId,
@@ -9595,7 +9600,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
95959600
) {
95969601
// The SDK blocks prompt echoes on permission answers; release held output except for ExitPlanMode.
95979602
yield* releaseHeldRootFrames(context);
9598-
if (toolName !== "Agent") {
9603+
if (startToolCall) {
95999604
yield* ensureToolCallStarted({
96009605
context,
96019606
nativeItemId: nativeRequestId,
@@ -9612,6 +9617,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
96129617
context,
96139618
nativeItemId: nativeRequestId,
96149619
nativeRequestId,
9620+
// No tool node exists for a control request to hang under.
9621+
...(options?.startToolCall === false
9622+
? { parentNodeId: context.input.rootNodeId }
9623+
: {}),
96159624
requestKind: "user_input",
96169625
questions,
96179626
});
@@ -9973,6 +9982,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
99739982
requestId: callbackOptions.requestId,
99749983
toolUseID: request.toolUseID ?? callbackOptions.requestId,
99759984
},
9985+
// The dialog is a control request, not a tool call, so no
9986+
// tool_result would ever settle a tool row started for it.
9987+
{ startToolCall: false },
99769988
);
99779989
if (result.behavior !== "allow") return { behavior: "cancelled" as const };
99789990
const answers =

0 commit comments

Comments
 (0)