@devries-cameron20 / t3code Mirror · read-only / commits / 4524eeeaa3
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 22, 12:00 UTC

fix(claude): no failed AskUserQuestion row after the resume dialog (#23481)

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

Victor Vogel committed Oct 30, 2026 at 15:51 UTC 4524eeeaa3fbcfde64b207c553b42357e3542433
2 files changed +81 -6
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+63
@@ -4953,6 +4953,69 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4953 ),
4954 );
4955
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 +
5019 it.effect.each(
5020 (["aborted_tools", "aborted_streaming"] as const).flatMap((terminalReason) =>
5021 [true, false].map((steered) => ({ terminalReason, steered })),
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+18 -6
@@ -7081,6 +7081,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7081 readonly context: ActiveClaudeTurnContext;
7082 readonly nativeItemId: string;
7083 readonly nativeRequestId: string;
7084 + readonly parentNodeId?: OrchestrationV2ExecutionNode["id"];
7085 readonly requestKind: OrchestrationV2RuntimeRequest["kind"];
7086 readonly prompt?: string;
7087 readonly appName?: string;
@@ -7116,10 +7117,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7117 id: nodeId,
7118 threadId: input.context.input.threadId,
7119 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 + }),
7126 rootNodeId: input.context.input.rootNodeId,
7127 kind: input.questions === undefined ? "approval_request" : "user_input_request",
7128 status: "waiting",
@@ -9556,6 +9559,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9559 toolName: Parameters<CanUseTool>[0],
9560 toolInput: Parameters<CanUseTool>[1],
9561 callbackOptions: Parameters<CanUseTool>[2],
9562 + options?: { readonly startToolCall?: boolean },
9563 ) {
9564 const context = yield* Ref.get(activeTurn);
9565 if (context === null) {
@@ -9569,6 +9573,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9573 const nativeRequestId = callbackOptions.toolUseID;
9574 const nativeToolInput = claudeNativeToolInputFromRecord(toolInput);
9575 const heldForEcho = context.heldRootFrames.length > 0;
9576 + const startToolCall = toolName !== "Agent" && options?.startToolCall !== false;
9577 if (toolName === "Agent") {
9578 rememberClaudeSubagentLaunch(
9579 subagentModelCatalog,
@@ -9578,7 +9583,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9583 nativeToolInput,
9584 null,
9585 );
9581 - } else if (!heldForEcho) {
9586 + } else if (startToolCall && !heldForEcho) {
9587 yield* ensureToolCallStarted({
9588 context,
9589 nativeItemId: nativeRequestId,
@@ -9595,7 +9600,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9600 ) {
9601 // The SDK blocks prompt echoes on permission answers; release held output except for ExitPlanMode.
9602 yield* releaseHeldRootFrames(context);
9598 - if (toolName !== "Agent") {
9603 + if (startToolCall) {
9604 yield* ensureToolCallStarted({
9605 context,
9606 nativeItemId: nativeRequestId,
@@ -9612,6 +9617,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9617 context,
9618 nativeItemId: nativeRequestId,
9619 nativeRequestId,
9620 + // No tool node exists for a control request to hang under.
9621 + ...(options?.startToolCall === false
9622 + ? { parentNodeId: context.input.rootNodeId }
9623 + : {}),
9624 requestKind: "user_input",
9625 questions,
9626 });
@@ -9973,6 +9982,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9982 requestId: callbackOptions.requestId,
9983 toolUseID: request.toolUseID ?? callbackOptions.requestId,
9984 },
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 },
9988 );
9989 if (result.behavior !== "allow") return { behavior: "cancelled" as const };
9990 const answers =