Skip to content

Commit f2dee1e

Browse files
only21milclaude
andcommitted
fix(claude): no failed AskUserQuestion row after the resume dialog
Claude's resume_return dialog is answered through canUseToolEffect, which started a dynamic tool row keyed by the control request id. No tool_result ever settles that id, so the row stayed running for the turn and finalizeActiveTurn ended it as failed when the turn completed. The dialog now asks canUseToolEffect not to start a tool row, the same way Agent requests already skip it. The question card is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bd6940b commit f2dee1e

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,6 +3460,61 @@ describe("ClaudeAdapterV2 background wake turns", () => {
34603460
),
34613461
);
34623462

3463+
it.effect("completes a turn after the resume dialog without a failed tool row", () =>
3464+
Effect.scoped(
3465+
Effect.gen(function* () {
3466+
const harness = yield* makeWakeHarness;
3467+
yield* harness.runtime.startTurn(
3468+
makeClaudeTestTurnInput({
3469+
threadId: harness.threadId,
3470+
providerThread: harness.providerThread,
3471+
now: yield* DateTime.now,
3472+
attemptId: RunAttemptId.make("attempt-resume-dialog"),
3473+
text: "continue",
3474+
attachments: [],
3475+
}),
3476+
);
3477+
const dialog = yield* Effect.promise(() =>
3478+
harness.getOpenedOptions()!.onUserDialog!(
3479+
{
3480+
dialogKind: "resume_return",
3481+
payload: { sessionAgeMinutes: 90, estimatedTokens: 120000 },
3482+
},
3483+
{ signal: new AbortController().signal, requestId: "dialog-resume" },
3484+
),
3485+
).pipe(Effect.forkScoped);
3486+
const request = yield* Queue.take(harness.runtimeRequestReceipts);
3487+
yield* harness.runtime.respondToRuntimeRequest({
3488+
requestId: request.runtimeRequest.id,
3489+
answers: {
3490+
[formatClaudeResumeCompactionQuestion({ ageMinutes: 90, estimatedTokens: 120000 })]:
3491+
"Keep full history",
3492+
},
3493+
});
3494+
assert.deepEqual(yield* Fiber.join(dialog), { behavior: "completed", result: "continue" });
3495+
yield* Queue.offer(
3496+
harness.sdkMessages,
3497+
makeResultFrame({ uuid: "result-resume-dialog", result: "Done" }),
3498+
);
3499+
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
3500+
assert.deepEqual(
3501+
harness.events.flatMap((event) =>
3502+
event.type === "turn_item.updated" &&
3503+
event.turnItem.type === "dynamic_tool" &&
3504+
event.turnItem.nativeItemRef?.nativeId === "dialog-resume"
3505+
? [event.turnItem.status]
3506+
: [],
3507+
),
3508+
[],
3509+
);
3510+
}).pipe(
3511+
Effect.provide(
3512+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3513+
),
3514+
),
3515+
),
3516+
);
3517+
34633518
it.effect.each(
34643519
(["aborted_tools", "aborted_streaming"] as const).flatMap((terminalReason) =>
34653520
[true, false].map((steered) => ({ terminalReason, steered })),

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8793,6 +8793,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
87938793
toolName: Parameters<CanUseTool>[0],
87948794
toolInput: Parameters<CanUseTool>[1],
87958795
callbackOptions: Parameters<CanUseTool>[2],
8796+
options?: { readonly startToolCall?: boolean },
87968797
) {
87978798
const context = yield* Ref.get(activeTurn);
87988799
if (context === null) {
@@ -8806,6 +8807,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88068807
const nativeRequestId = callbackOptions.toolUseID;
88078808
const nativeToolInput = claudeNativeToolInputFromRecord(toolInput);
88088809
const heldForEcho = context.heldRootFrames.length > 0;
8810+
const startToolCall = toolName !== "Agent" && options?.startToolCall !== false;
88098811
if (toolName === "Agent") {
88108812
rememberClaudeSubagentLaunch(
88118813
subagentModelCatalog,
@@ -8815,7 +8817,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88158817
nativeToolInput,
88168818
null,
88178819
);
8818-
} else if (!heldForEcho) {
8820+
} else if (startToolCall && !heldForEcho) {
88198821
yield* ensureToolCallStarted({
88208822
context,
88218823
nativeItemId: nativeRequestId,
@@ -8836,7 +8838,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88368838
// did before this turn was held. ExitPlanMode is answered at once
88378839
// below, so its frames stay held.
88388840
yield* releaseHeldRootFrames(context);
8839-
if (toolName !== "Agent") {
8841+
if (startToolCall) {
88408842
yield* ensureToolCallStarted({
88418843
context,
88428844
nativeItemId: nativeRequestId,
@@ -9094,6 +9096,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
90949096
requestId: callbackOptions.requestId,
90959097
toolUseID: request.toolUseID ?? callbackOptions.requestId,
90969098
},
9099+
// The dialog is a control request, not a tool call, so no
9100+
// tool_result would ever settle a tool row started for it.
9101+
{ startToolCall: false },
90979102
);
90989103
if (result.behavior !== "allow") return { behavior: "cancelled" as const };
90999104
const answers =

0 commit comments

Comments
 (0)