From 1749f5759739af35a2a369c5df951c9aaa177302 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:56:45 +1100 Subject: [PATCH 1/6] fix(claude): tools running at Stop show as stopped, not failed Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 78 ++++++++++++++++--- .../Adapters/ClaudeAdapterV2.ts | 8 +- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 1972009683779..44cce413d056f 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -9354,15 +9354,41 @@ describe("ClaudeAdapterV2 background wake turns", () => { attachments: [], }), ); - acknowledge = harness.offerAndWait( - makeResultFrame({ - uuid: "00000000-0000-4000-8000-000000000620", - result: "", - subtype: "error_during_execution", - errors: ["Error: Request was aborted."], - terminalReason: "aborted_streaming", - }), - ); + // Real Claude answers Stop with an error result for the running tool, then the result. + acknowledge = harness + .offerAndWait( + claudeSdkFrame({ + type: "user", + uuid: "00000000-0000-4000-8000-000000000619", + session_id: WAKE_NATIVE_SESSION, + parent_tool_use_id: null, + message: { + role: "user", + content: [ + { + type: "tool_result", + tool_use_id: "tool-running-bash", + is_error: true, + content: "The user doesn't want to proceed with this tool use.", + }, + ], + }, + tool_result_meta: [{ id: "tool-running-bash", non_execution_kind: "user-rejected" }], + }), + ) + .pipe( + Effect.andThen( + harness.offerAndWait( + makeResultFrame({ + uuid: "00000000-0000-4000-8000-000000000620", + result: "", + subtype: "error_during_execution", + errors: ["Error: Request was aborted."], + terminalReason: "aborted_tools", + }), + ), + ), + ); yield* harness.until(() => harness.events.some( (event) => @@ -9375,6 +9401,31 @@ describe("ClaudeAdapterV2 background wake turns", () => { ); if (active?.type !== "provider_turn.updated") return yield* Effect.die("Missing running native turn"); + yield* harness.offerAndWait( + claudeSdkFrame({ + type: "assistant", + uuid: "00000000-0000-4000-8000-000000000618", + session_id: WAKE_NATIVE_SESSION, + parent_tool_use_id: null, + message: { + id: "msg_running_bash", + model: "claude-sonnet-4-6", + type: "message", + role: "assistant", + content: [ + { + type: "tool_use", + id: "tool-running-bash", + name: "Bash", + input: { command: "sleep 60" }, + }, + ], + stop_reason: "tool_use", + stop_sequence: null, + usage: { input_tokens: 1, output_tokens: 1 }, + }, + }), + ); yield* harness.runtime.interruptTurn({ providerThread: harness.providerThread, providerTurnId: active.providerTurn.id, @@ -9383,6 +9434,15 @@ describe("ClaudeAdapterV2 background wake turns", () => { assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted"); assert.equal(closes, 1); assert.lengthOf(harness.terminalEvents(), 1); + const stoppedTool = harness.events.findLast( + (event) => + event.type === "turn_item.updated" && + event.turnItem.nativeItemRef?.nativeId === "tool-running-bash", + ); + assert.equal( + stoppedTool?.type === "turn_item.updated" ? stoppedTool.turnItem.status : undefined, + "interrupted", + ); }).pipe( Effect.provide( Layer.mergeAll( diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index add71bfd16532..cab8f0fb38667 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -7046,6 +7046,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( input.message, input.toolResult.tool_use_id, ); + // Stop makes Claude answer each running tool with an error result. + const stopped = + input.context !== null && + (yield* Ref.get(interruptedTurns)).has(input.context.providerTurnId); yield* stopTaskOutputTail(toolCall.nativeItemId); yield* emitToolCallArtifacts( buildToolCallArtifacts({ @@ -7064,7 +7068,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( toolNonExecutionKind === "cancelled" ? "cancelled" : isClaudeToolResultError(input.toolResult) - ? "failed" + ? stopped + ? "interrupted" + : "failed" : "completed", ...(toolNonExecutionKind === undefined ? {} : { toolNonExecutionKind }), startedAt: toolCall.startedAt, From b6bcfae4d48b4fdfa653321a379ff3515d0460b6 Mon Sep 17 00:00:00 2001 From: Alex Southwell <4596216+saphid@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:17:55 +1100 Subject: [PATCH 2/6] fix(claude): workflow member tools running at Stop show as stopped Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 73 +++++++++++++++++++ .../Adapters/ClaudeAdapterV2.ts | 10 ++- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 44cce413d056f..59d03104c016a 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -16924,6 +16924,79 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + it.effect("shows a workflow member's tool as stopped when Stop cancels the workflow", () => + Effect.scoped( + Effect.gen(function* () { + const harness = yield* makeWorkflowHarness; + const transcriptPath = NodePath.join(harness.transcriptDir, "agent-a1.jsonl"); + NodeFS.writeFileSync( + transcriptPath, + memberAssistantLine("line-bash", "msg_a1", [ + { type: "tool_use", id: "toolu_a1_ping", name: "Bash", input: { command: "ping" } }, + ]), + ); + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-workflow-member-stopped"), + text: "Run the alpha workflow.", + attachments: [], + }), + ); + yield* launchWorkflow({ harness, snapshotUuid: "00000000-0000-4000-8000-000000001375" }); + const threadId = workflowMemberEvents(harness.events, 1)[0]?.subagent.childThreadId; + const errorLine = (uuid: string, toolUseId: string, output: string, denial?: object) => + transcriptLine({ + type: "user", + uuid, + message: { + role: "user", + content: [ + { tool_use_id: toolUseId, type: "tool_result", content: output, is_error: true }, + ], + }, + ...denial, + }); + NodeFS.appendFileSync( + transcriptPath, + errorLine("line-ping-failed", "toolu_a1_ping", "Exit code 1") + + memberAssistantLine("line-sleep", "msg_a1_sleep", [ + { type: "tool_use", id: "toolu_a1_sleep", name: "Bash", input: { command: "sleep" } }, + ]) + + errorLine("line-sleep-stopped", "toolu_a1_sleep", "Rejected", { + toolUseResult: "User rejected tool use", + toolDenialKind: "user-rejected", + }), + ); + yield* harness.offerAndWait( + workflowNotification({ uuid: "00000000-0000-4000-8000-000000001376", status: "stopped" }), + ); + assert.equal(workflowMemberEvents(harness.events, 1).at(-1)?.subagent.status, "cancelled"); + assert.deepEqual(latestMemberThreadItems(harness.events, threadId).map(describeItem), [ + "user_message", + "command failed: Exit code 1", + "command interrupted: Rejected", + ]); + yield* Queue.offer( + harness.sdkMessages, + makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001377", result: "Done." }), + ); + yield* Queue.take(harness.terminalReceipts); + }).pipe( + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ), + ); + it.effect("reads a settled workflow member's transcript to its end past the read cap", () => Effect.scoped( Effect.gen(function* () { diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index cab8f0fb38667..4378ee533f932 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -4159,6 +4159,7 @@ interface ClaudeSubagentProjectionTarget { readonly childRootNodeId: OrchestrationV2ExecutionNode["id"]; readonly nextOrdinal: () => number; readonly toolCalls: Map; + readonly stopped?: boolean; } /** Claude writes blocks separately with stop_reason null until the last. @@ -6131,6 +6132,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( childRootNodeId, nextOrdinal: () => ++nextItemOrdinal, toolCalls, + stopped: status === "cancelled", }; const endOpenToolCalls = Effect.fnUntraced(function* () { if (toolCalls.size === 0) return; @@ -7040,6 +7042,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( readonly toolResult: ClaudeToolResultContentBlock; readonly output: ClaudeNativeToolOutput; readonly completedAt: DateTime.Utc; + readonly stopped?: boolean; }) { const { toolCall } = input; const toolNonExecutionKind = claudeToolNonExecutionKind( @@ -7048,8 +7051,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( ); // Stop makes Claude answer each running tool with an error result. const stopped = - input.context !== null && - (yield* Ref.get(interruptedTurns)).has(input.context.providerTurnId); + input.stopped === true || + (input.context !== null && + (yield* Ref.get(interruptedTurns)).has(input.context.providerTurnId)); yield* stopTaskOutputTail(toolCall.nativeItemId); yield* emitToolCallArtifacts( buildToolCallArtifacts({ @@ -7165,6 +7169,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( toolResult, output, completedAt: at, + // A genuine failure read late carries no denial kind. + stopped: target.stopped === true && field(line, "toolDenialKind") !== undefined, }); } if (line.type !== "assistant") return false; From b4eac6d112f825e1b10314b48e7455ffe59b3c2d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 15:26:13 +0000 Subject: [PATCH 3/6] fix(claude): workflow Stop shows its member and tool as stopped Claude reports a member of a stopped workflow as `error`, and writes the Stop rejection to the member transcript while the member still reads as running. The member was therefore projected failed, and its rejected tool settled before any cancelled status existed. Record when a workflow Stop is requested and use it: a member that fails after it is cancelled, and a member tool result with a denial kind after it is interrupted. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 31 ++++++++++++++----- .../Adapters/ClaudeAdapterV2.ts | 12 +++++-- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 62d2d50006c52..549cf2f9735cb 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -20911,8 +20911,8 @@ describe("ClaudeAdapterV2 background wake turns", () => { }); const workflowSnapshot = (input: { readonly uuid: string; - readonly state: "queued" | "start" | "done"; - readonly secondState?: "queued" | "start" | "done"; + readonly state: "queued" | "start" | "done" | "error"; + readonly secondState?: "queued" | "start" | "done" | "error"; readonly startedAt?: number; readonly lastProgressAt?: number; readonly durationMs?: number; @@ -22730,11 +22730,28 @@ describe("ClaudeAdapterV2 background wake turns", () => { errorLine("line-ping-failed", "toolu_a1_ping", "Exit code 1") + memberAssistantLine("line-sleep", "msg_a1_sleep", [ { type: "tool_use", id: "toolu_a1_sleep", name: "Bash", input: { command: "sleep" } }, - ]) + - errorLine("line-sleep-stopped", "toolu_a1_sleep", "Rejected", { - toolUseResult: "User rejected tool use", - toolDenialKind: "user-rejected", - }), + ]), + ); + yield* harness.offerAndWait( + workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001378", state: "start" }), + ); + yield* harness.runtime.stopTask!({ + providerThread: harness.providerThread, + taskId: WORKFLOW_TASK_ID, + }); + // Claude writes the Stop rejection while the member still reads as running, then reports it as an error. + NodeFS.appendFileSync( + transcriptPath, + errorLine("line-sleep-stopped", "toolu_a1_sleep", "Rejected", { + toolUseResult: "User rejected tool use", + toolDenialKind: "user-rejected", + }), + ); + yield* harness.offerAndWait( + workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001379", state: "start" }), + ); + yield* harness.offerAndWait( + workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001380", state: "error" }), ); yield* harness.offerAndWait( workflowNotification({ uuid: "00000000-0000-4000-8000-000000001376", status: "stopped" }), diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index bdb4477d6ab8d..60d72a2913821 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -5793,6 +5793,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( string, Deferred.Deferred >(); + // Claude reports a stopped workflow's members as failed; this is the only evidence it was Stop. + const workflowStopRequestedAt = new Map(); // Buffered idle outcomes must not settle a resumed child again. const appliedSubagentOutcomes = new WeakSet(); // Subagent frames can precede the task_started that registers their owner. @@ -7140,13 +7142,18 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( return; const memberKey = `${input.coordinator.childThreadId}:agent:${member.index}`; const previous = seen.get(memberKey); + const stopRequestedAt = workflowStopRequestedAt.get(taskId); const status = (member.state === "queued" || member.state === "running") && input.coordinator.task.status !== "running" ? input.coordinator.task.status : member.state === "queued" ? "pending" - : member.state; + : member.state === "failed" && + stopRequestedAt !== undefined && + (member.completedAt ?? stopRequestedAt) >= stopRequestedAt + ? "cancelled" + : member.state; const settled = status !== "pending" && status !== "running"; const prompt = member.prompt ?? member.label; const model = member.model ?? parentThread.modelSelection.model; @@ -7304,7 +7311,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( childRootNodeId, nextOrdinal: () => ++nextItemOrdinal, toolCalls, - stopped: status === "cancelled", + stopped: status === "cancelled" || stopRequestedAt !== undefined, }; const endOpenToolCalls = Effect.fnUntraced(function* () { if (toolCalls.size === 0) return; @@ -13731,6 +13738,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( detail: "No running workflow task belongs to this provider thread", }); } + workflowStopRequestedAt.set(taskId, DateTime.toEpochMillis(yield* DateTime.now)); yield* liveQuery.query.stopTask(taskId).pipe( Effect.mapError( (cause) => From 45c8abd6d3a41d704f63768b7fd9a835bf800b7b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 15:36:33 +0000 Subject: [PATCH 4/6] fix(claude): workflow Stop keeps genuine member failures failed A member already projected failed stays failed after a Stop, even when its snapshot has no completion time. A Stop request that fails or is interrupted no longer leaves its marker behind to relabel later failures. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 70 +++++++++++++++++++ .../Adapters/ClaudeAdapterV2.ts | 2 + 2 files changed, 72 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 549cf2f9735cb..9b718fb7c9cb4 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -22780,6 +22780,76 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + it.effect("keeps genuine member failures failed around a workflow Stop", () => + Effect.gen(function* () { + let stopCalls = 0; + const harness = yield* makeWorkflowHarnessWithOptions({ + stopTask: () => + ++stopCalls === 1 + ? Effect.fail( + new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({ + method: "stopTask", + cause: new Error("rejected"), + }), + ) + : Effect.void, + }); + yield* harness.runtime.startTurn( + makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-workflow-stop-failures"), + text: "Run the alpha workflow.", + attachments: [], + }), + ); + yield* launchWorkflow({ harness, snapshotUuid: "00000000-0000-4000-8000-000000001390" }); + const memberStatus = (index: number) => + workflowMemberEvents(harness.events, index).at(-1)?.subagent.status; + const stop = harness.runtime.stopTask!({ + providerThread: harness.providerThread, + taskId: WORKFLOW_TASK_ID, + }).pipe(Effect.exit); + yield* harness.offerAndWait( + workflowSnapshot({ + uuid: "00000000-0000-4000-8000-000000001391", + state: "error", + secondState: "start", + }), + ); + assert.equal(memberStatus(1), "failed"); + assert.isTrue(Exit.isFailure(yield* stop)); + yield* harness.offerAndWait( + workflowSnapshot({ + uuid: "00000000-0000-4000-8000-000000001392", + state: "error", + secondState: "error", + }), + ); + assert.equal(memberStatus(2), "failed"); + assert.isTrue(Exit.isSuccess(yield* stop)); + yield* harness.offerAndWait( + workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001393", state: "error" }), + ); + assert.deepEqual([memberStatus(1), memberStatus(2)], ["failed", "failed"]); + yield* Queue.offer( + harness.sdkMessages, + makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001394", result: "Done." }), + ); + yield* Queue.take(harness.terminalReceipts); + }).pipe( + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ); + it.effect("reads a settled workflow member's transcript to its end past the read cap", () => Effect.gen(function* () { const harness = yield* makeWorkflowHarness; diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 60d72a2913821..1de7ad018a84c 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -7151,6 +7151,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( ? "pending" : member.state === "failed" && stopRequestedAt !== undefined && + previous?.status !== "failed" && (member.completedAt ?? stopRequestedAt) >= stopRequestedAt ? "cancelled" : member.state; @@ -13748,6 +13749,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( cause, }), ), + Effect.onError(() => Effect.sync(() => workflowStopRequestedAt.delete(taskId))), ); }), awaitBackgroundTasks: Effect.fn("ClaudeAdapterV2.awaitBackgroundTasks")( From d038ba77b94be54f5837862e42cfdecd94dbf798 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 15:49:55 +0000 Subject: [PATCH 5/6] fix(claude): only a denial written after workflow Stop reads as stopped A member's denied tool counted as interrupted whenever its workflow had a Stop request, so a declined approval written before Stop but read after it showed as stopped. The transcript line's timestamp now has to be at or after the Stop request. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/ClaudeAdapterV2.test.ts | 26 ++++++++++++++----- .../Adapters/ClaudeAdapterV2.ts | 11 +++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 9b718fb7c9cb4..e23862752e3bd 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -22725,16 +22725,29 @@ describe("ClaudeAdapterV2 background wake turns", () => { }, ...denial, }); + const denial = { + toolUseResult: "User rejected tool use", + toolDenialKind: "user-rejected", + }; NodeFS.appendFileSync( transcriptPath, - errorLine("line-ping-failed", "toolu_a1_ping", "Exit code 1") + - memberAssistantLine("line-sleep", "msg_a1_sleep", [ - { type: "tool_use", id: "toolu_a1_sleep", name: "Bash", input: { command: "sleep" } }, - ]), + errorLine("line-ping-failed", "toolu_a1_ping", "Exit code 1"), ); yield* harness.offerAndWait( workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001378", state: "start" }), ); + // A declined approval written before Stop but first read after it stays a failure. + NodeFS.appendFileSync( + transcriptPath, + memberAssistantLine("line-rm", "msg_a1_rm", [ + { type: "tool_use", id: "toolu_a1_rm", name: "Bash", input: { command: "rm" } }, + ]) + + errorLine("line-rm-declined", "toolu_a1_rm", "Declined", denial) + + memberAssistantLine("line-sleep", "msg_a1_sleep", [ + { type: "tool_use", id: "toolu_a1_sleep", name: "Bash", input: { command: "sleep" } }, + ]), + ); + yield* TestClock.setTime(Date.parse("2026-10-17T06:00:00.000Z")); yield* harness.runtime.stopTask!({ providerThread: harness.providerThread, taskId: WORKFLOW_TASK_ID, @@ -22743,8 +22756,8 @@ describe("ClaudeAdapterV2 background wake turns", () => { NodeFS.appendFileSync( transcriptPath, errorLine("line-sleep-stopped", "toolu_a1_sleep", "Rejected", { - toolUseResult: "User rejected tool use", - toolDenialKind: "user-rejected", + ...denial, + timestamp: "2026-10-17T06:00:01.000Z", }), ); yield* harness.offerAndWait( @@ -22760,6 +22773,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { assert.deepEqual(latestMemberThreadItems(harness.events, threadId).map(describeItem), [ "user_message", "command failed: Exit code 1", + "command failed: Declined", "command interrupted: Rejected", ]); yield* Queue.offer( diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 1de7ad018a84c..f7042715f1f43 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -4997,7 +4997,7 @@ interface ClaudeSubagentProjectionTarget { readonly childRootNodeId: OrchestrationV2ExecutionNode["id"]; readonly nextOrdinal: () => number; readonly toolCalls: Map; - readonly stopped?: boolean; + readonly stopRequestedAt?: number | undefined; } /** Claude writes blocks separately with stop_reason null until the last. @@ -7312,7 +7312,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( childRootNodeId, nextOrdinal: () => ++nextItemOrdinal, toolCalls, - stopped: status === "cancelled" || stopRequestedAt !== undefined, + stopRequestedAt, }; const endOpenToolCalls = Effect.fnUntraced(function* () { if (toolCalls.size === 0) return; @@ -8522,8 +8522,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( toolResult, output, completedAt: at, - // A genuine failure read late carries no denial kind. - stopped: target.stopped === true && field(line, "toolDenialKind") !== undefined, + // A denial written before Stop (a declined approval) is not the Stop's. + stopped: + target.stopRequestedAt !== undefined && + field(line, "toolDenialKind") !== undefined && + DateTime.toEpochMillis(at) >= target.stopRequestedAt, }); } if (line.type !== "assistant") return false; From 0bc7b87e62e732c0c2cbc4396b014d62cf11bf8d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 16:16:22 +0000 Subject: [PATCH 6/6] fix(claude): a stopped workflow member reads cancelled, not failed Claude's terminal member progress carries lastProgressAt, the member's last progress tick. A member blocked in one foreground tool last progressed when that tool started, before Stop, so the completedAt comparison kept it failed while its tool already showed as stopped. A failure already shown before Stop still stays failed, and a failed Stop request still clears its marker. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts | 7 ++++++- .../src/orchestration-v2/Adapters/ClaudeAdapterV2.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index e23862752e3bd..a66bb07150f63 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -22764,7 +22764,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001379", state: "start" }), ); yield* harness.offerAndWait( - workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001380", state: "error" }), + workflowSnapshot({ + uuid: "00000000-0000-4000-8000-000000001380", + state: "error", + // Claude's last progress tick for a member blocked in one tool predates the Stop. + lastProgressAt: Date.parse("2026-10-17T05:59:00.000Z"), + }), ); yield* harness.offerAndWait( workflowNotification({ uuid: "00000000-0000-4000-8000-000000001376", status: "stopped" }), diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index f7042715f1f43..894d7c78c3a64 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -7151,8 +7151,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( ? "pending" : member.state === "failed" && stopRequestedAt !== undefined && - previous?.status !== "failed" && - (member.completedAt ?? stopRequestedAt) >= stopRequestedAt + // lastProgressAt (completedAt) is the last tick, often before Stop for a blocked tool. + previous?.status !== "failed" ? "cancelled" : member.state; const settled = status !== "pending" && status !== "running";