The best way to control Claude Code, Codex and more from any computer or phone
fix(claude): tools running at Stop show as stopped, not failed (#29801)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 03:41 UTC
7bc474667de6a38b5dd3d8fb10c6f2a8a1597d40
2 files changed
+300
-13
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+271
-11
@@ -12941,15 +12941,47 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12941
attachments: [],
12942
}),
12943
);
12944
- acknowledge = harness.offerAndWait(
12945
- makeResultFrame({
12946
- uuid: "00000000-0000-4000-8000-000000000620",
12947
- result: "",
12948
- subtype: "error_during_execution",
12949
- errors: ["Error: Request was aborted."],
12950
- terminalReason: "aborted_streaming",
12951
- }),
12952
- );
12944
+ // Real Claude answers Stop with an error result for the running tool, then the result.
12945
+ acknowledge = harness
12946
+ .offerAndWait(
12947
+ claudeSdkFrame({
12948
+ type: "user",
12949
+ uuid: "00000000-0000-4000-8000-000000000619",
12950
+ session_id: WAKE_NATIVE_SESSION,
12951
+ parent_tool_use_id: null,
12952
+ message: {
12953
+ role: "user",
12954
+ content: [
12955
+ {
12956
+ type: "tool_result",
12957
+ tool_use_id: "tool-running-bash",
12958
+ is_error: true,
12959
+ content: "The user doesn't want to proceed with this tool use.",
12960
+ },
12961
+ {
12962
+ type: "tool_result",
12963
+ tool_use_id: "tool-failed-bash",
12964
+ is_error: true,
12965
+ content: "Process exited with code 1",
12966
+ },
12967
+ ],
12968
+ },
12969
+ tool_result_meta: [{ id: "tool-running-bash", non_execution_kind: "user-rejected" }],
12970
+ }),
12971
+ )
12972
+ .pipe(
12973
+ Effect.andThen(
12974
+ harness.offerAndWait(
12975
+ makeResultFrame({
12976
+ uuid: "00000000-0000-4000-8000-000000000620",
12977
+ result: "",
12978
+ subtype: "error_during_execution",
12979
+ errors: ["Error: Request was aborted."],
12980
+ terminalReason: "aborted_tools",
12981
+ }),
12982
+ ),
12983
+ ),
12984
+ );
12985
yield* harness.until(() =>
12986
harness.events.some(
12987
(event) =>
@@ -12962,6 +12994,37 @@ describe("ClaudeAdapterV2 background wake turns", () => {
12994
);
12995
if (active?.type !== "provider_turn.updated")
12996
return yield* Effect.die("Missing running native turn");
12997
+ yield* harness.offerAndWait(
12998
+ claudeSdkFrame({
12999
+ type: "assistant",
13000
+ uuid: "00000000-0000-4000-8000-000000000618",
13001
+ session_id: WAKE_NATIVE_SESSION,
13002
+ parent_tool_use_id: null,
13003
+ message: {
13004
+ id: "msg_running_bash",
13005
+ model: "claude-sonnet-4-6",
13006
+ type: "message",
13007
+ role: "assistant",
13008
+ content: [
13009
+ {
13010
+ type: "tool_use",
13011
+ id: "tool-running-bash",
13012
+ name: "Bash",
13013
+ input: { command: "sleep 60" },
13014
+ },
13015
+ {
13016
+ type: "tool_use",
13017
+ id: "tool-failed-bash",
13018
+ name: "Bash",
13019
+ input: { command: "exit 1" },
13020
+ },
13021
+ ],
13022
+ stop_reason: "tool_use",
13023
+ stop_sequence: null,
13024
+ usage: { input_tokens: 1, output_tokens: 1 },
13025
+ },
13026
+ }),
13027
+ );
13028
yield* harness.runtime.interruptTurn({
13029
providerThread: harness.providerThread,
13030
providerTurnId: active.providerTurn.id,
@@ -12970,6 +13033,24 @@ describe("ClaudeAdapterV2 background wake turns", () => {
13033
assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted");
13034
assert.equal(closes, 1);
13035
assert.lengthOf(harness.terminalEvents(), 1);
13036
+ const stoppedTool = harness.events.findLast(
13037
+ (event) =>
13038
+ event.type === "turn_item.updated" &&
13039
+ event.turnItem.nativeItemRef?.nativeId === "tool-running-bash",
13040
+ );
13041
+ const failedTool = harness.events.findLast(
13042
+ (event) =>
13043
+ event.type === "turn_item.updated" &&
13044
+ event.turnItem.nativeItemRef?.nativeId === "tool-failed-bash",
13045
+ );
13046
+ assert.equal(
13047
+ failedTool?.type === "turn_item.updated" ? failedTool.turnItem.status : undefined,
13048
+ "failed",
13049
+ );
13050
+ assert.equal(
13051
+ stoppedTool?.type === "turn_item.updated" ? stoppedTool.turnItem.status : undefined,
13052
+ "interrupted",
13053
+ );
13054
}).pipe(
13055
Effect.provide(
13056
Layer.mergeAll(
@@ -20998,8 +21079,8 @@ describe("ClaudeAdapterV2 background wake turns", () => {
21079
});
21080
const workflowSnapshot = (input: {
21081
readonly uuid: string;
21001
- readonly state: "queued" | "start" | "done";
21002
- readonly secondState?: "queued" | "start" | "done";
21082
+ readonly state: "queued" | "start" | "done" | "error";
21083
+ readonly secondState?: "queued" | "start" | "done" | "error";
21084
readonly startedAt?: number;
21085
readonly lastProgressAt?: number;
21086
readonly durationMs?: number;
@@ -22777,6 +22858,185 @@ describe("ClaudeAdapterV2 background wake turns", () => {
22858
),
22859
);
22860
22861
+ it.effect("shows a workflow member's tool as stopped when Stop cancels the workflow", () =>
22862
+ Effect.scoped(
22863
+ Effect.gen(function* () {
22864
+ const harness = yield* makeWorkflowHarness;
22865
+ const transcriptPath = NodePath.join(harness.transcriptDir, "agent-a1.jsonl");
22866
+ NodeFS.writeFileSync(
22867
+ transcriptPath,
22868
+ memberAssistantLine("line-bash", "msg_a1", [
22869
+ { type: "tool_use", id: "toolu_a1_ping", name: "Bash", input: { command: "ping" } },
22870
+ ]),
22871
+ );
22872
+ yield* harness.runtime.startTurn(
22873
+ makeClaudeTestTurnInput({
22874
+ threadId: harness.threadId,
22875
+ providerThread: harness.providerThread,
22876
+ now: yield* DateTime.now,
22877
+ attemptId: RunAttemptId.make("attempt-claude-workflow-member-stopped"),
22878
+ text: "Run the alpha workflow.",
22879
+ attachments: [],
22880
+ }),
22881
+ );
22882
+ yield* launchWorkflow({ harness, snapshotUuid: "00000000-0000-4000-8000-000000001375" });
22883
+ const threadId = workflowMemberEvents(harness.events, 1)[0]?.subagent.childThreadId;
22884
+ const errorLine = (uuid: string, toolUseId: string, output: string, denial?: object) =>
22885
+ transcriptLine({
22886
+ type: "user",
22887
+ uuid,
22888
+ message: {
22889
+ role: "user",
22890
+ content: [
22891
+ { tool_use_id: toolUseId, type: "tool_result", content: output, is_error: true },
22892
+ ],
22893
+ },
22894
+ ...denial,
22895
+ });
22896
+ const denial = {
22897
+ toolUseResult: "User rejected tool use",
22898
+ toolDenialKind: "user-rejected",
22899
+ };
22900
+ NodeFS.appendFileSync(
22901
+ transcriptPath,
22902
+ errorLine("line-ping-failed", "toolu_a1_ping", "Exit code 1"),
22903
+ );
22904
+ yield* harness.offerAndWait(
22905
+ workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001378", state: "start" }),
22906
+ );
22907
+ // A declined approval written before Stop but first read after it stays a failure.
22908
+ NodeFS.appendFileSync(
22909
+ transcriptPath,
22910
+ memberAssistantLine("line-rm", "msg_a1_rm", [
22911
+ { type: "tool_use", id: "toolu_a1_rm", name: "Bash", input: { command: "rm" } },
22912
+ ]) +
22913
+ errorLine("line-rm-declined", "toolu_a1_rm", "Declined", denial) +
22914
+ memberAssistantLine("line-sleep", "msg_a1_sleep", [
22915
+ { type: "tool_use", id: "toolu_a1_sleep", name: "Bash", input: { command: "sleep" } },
22916
+ ]),
22917
+ );
22918
+ yield* TestClock.setTime(Date.parse("2026-10-17T06:00:00.000Z"));
22919
+ yield* harness.runtime.stopTask!({
22920
+ providerThread: harness.providerThread,
22921
+ taskId: WORKFLOW_TASK_ID,
22922
+ });
22923
+ // Claude writes the Stop rejection while the member still reads as running, then reports it as an error.
22924
+ NodeFS.appendFileSync(
22925
+ transcriptPath,
22926
+ errorLine("line-sleep-stopped", "toolu_a1_sleep", "Rejected", {
22927
+ ...denial,
22928
+ timestamp: "2026-10-17T06:00:01.000Z",
22929
+ }),
22930
+ );
22931
+ yield* harness.offerAndWait(
22932
+ workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001379", state: "start" }),
22933
+ );
22934
+ yield* harness.offerAndWait(
22935
+ workflowSnapshot({
22936
+ uuid: "00000000-0000-4000-8000-000000001380",
22937
+ state: "error",
22938
+ // Claude's last progress tick for a member blocked in one tool predates the Stop.
22939
+ lastProgressAt: Date.parse("2026-10-17T05:59:00.000Z"),
22940
+ }),
22941
+ );
22942
+ yield* harness.offerAndWait(
22943
+ workflowNotification({ uuid: "00000000-0000-4000-8000-000000001376", status: "stopped" }),
22944
+ );
22945
+ assert.equal(workflowMemberEvents(harness.events, 1).at(-1)?.subagent.status, "cancelled");
22946
+ assert.deepEqual(latestMemberThreadItems(harness.events, threadId).map(describeItem), [
22947
+ "user_message",
22948
+ "command failed: Exit code 1",
22949
+ "command failed: Declined",
22950
+ "command interrupted: Rejected",
22951
+ ]);
22952
+ yield* Queue.offer(
22953
+ harness.sdkMessages,
22954
+ makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001377", result: "Done." }),
22955
+ );
22956
+ yield* Queue.take(harness.terminalReceipts);
22957
+ }).pipe(
22958
+ Effect.provide(
22959
+ Layer.mergeAll(
22960
+ IdAllocator.layer,
22961
+ McpProviderSessions.layer,
22962
+ NodeServices.layer,
22963
+ NodeCrypto.layer,
22964
+ ),
22965
+ ),
22966
+ ),
22967
+ ),
22968
+ );
22969
+
22970
+ it.effect("keeps genuine member failures failed around a workflow Stop", () =>
22971
+ Effect.gen(function* () {
22972
+ let stopCalls = 0;
22973
+ const harness = yield* makeWorkflowHarnessWithOptions({
22974
+ stopTask: () =>
22975
+ ++stopCalls === 1
22976
+ ? Effect.fail(
22977
+ new ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerError({
22978
+ method: "stopTask",
22979
+ cause: new Error("rejected"),
22980
+ }),
22981
+ )
22982
+ : Effect.void,
22983
+ });
22984
+ yield* harness.runtime.startTurn(
22985
+ makeClaudeTestTurnInput({
22986
+ threadId: harness.threadId,
22987
+ providerThread: harness.providerThread,
22988
+ now: yield* DateTime.now,
22989
+ attemptId: RunAttemptId.make("attempt-claude-workflow-stop-failures"),
22990
+ text: "Run the alpha workflow.",
22991
+ attachments: [],
22992
+ }),
22993
+ );
22994
+ yield* launchWorkflow({ harness, snapshotUuid: "00000000-0000-4000-8000-000000001390" });
22995
+ const memberStatus = (index: number) =>
22996
+ workflowMemberEvents(harness.events, index).at(-1)?.subagent.status;
22997
+ const stop = harness.runtime.stopTask!({
22998
+ providerThread: harness.providerThread,
22999
+ taskId: WORKFLOW_TASK_ID,
23000
+ }).pipe(Effect.exit);
23001
+ yield* harness.offerAndWait(
23002
+ workflowSnapshot({
23003
+ uuid: "00000000-0000-4000-8000-000000001391",
23004
+ state: "error",
23005
+ secondState: "start",
23006
+ }),
23007
+ );
23008
+ assert.equal(memberStatus(1), "failed");
23009
+ assert.isTrue(Exit.isFailure(yield* stop));
23010
+ yield* harness.offerAndWait(
23011
+ workflowSnapshot({
23012
+ uuid: "00000000-0000-4000-8000-000000001392",
23013
+ state: "error",
23014
+ secondState: "error",
23015
+ }),
23016
+ );
23017
+ assert.equal(memberStatus(2), "failed");
23018
+ assert.isTrue(Exit.isSuccess(yield* stop));
23019
+ yield* harness.offerAndWait(
23020
+ workflowSnapshot({ uuid: "00000000-0000-4000-8000-000000001393", state: "error" }),
23021
+ );
23022
+ assert.deepEqual([memberStatus(1), memberStatus(2)], ["failed", "failed"]);
23023
+ yield* Queue.offer(
23024
+ harness.sdkMessages,
23025
+ makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001394", result: "Done." }),
23026
+ );
23027
+ yield* Queue.take(harness.terminalReceipts);
23028
+ }).pipe(
23029
+ Effect.provide(
23030
+ Layer.mergeAll(
23031
+ IdAllocator.layer,
23032
+ McpProviderSessions.layer,
23033
+ NodeServices.layer,
23034
+ NodeCrypto.layer,
23035
+ ),
23036
+ ),
23037
+ ),
23038
+ );
23039
+
23040
it.effect("reads a settled workflow member's transcript to its end past the read cap", () =>
23041
Effect.gen(function* () {
23042
const harness = yield* makeWorkflowHarness;
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+29
-2
@@ -4999,6 +4999,7 @@ interface ClaudeSubagentProjectionTarget {
4999
readonly childRootNodeId: OrchestrationV2ExecutionNode["id"];
5000
readonly nextOrdinal: () => number;
5001
readonly toolCalls: Map<string, ActiveClaudeToolCall>;
5002
+ readonly stopRequestedAt?: number | undefined;
5003
}
5004
5005
/** Claude writes blocks separately with stop_reason null until the last.
@@ -5794,6 +5795,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
5795
string,
5796
Deferred.Deferred<ProviderAdapter.ProviderAdapterV2SubagentOutcome>
5797
>();
5798
+ // Claude reports a stopped workflow's members as failed; this is the only evidence it was Stop.
5799
+ const workflowStopRequestedAt = new Map<string, number>();
5800
// Buffered idle outcomes must not settle a resumed child again.
5801
const appliedSubagentOutcomes = new WeakSet<SDKMessage>();
5802
// Subagent frames can precede the task_started that registers their owner.
@@ -7186,13 +7189,19 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7189
return;
7190
const memberKey = `${input.coordinator.childThreadId}:agent:${member.index}`;
7191
const previous = seen.get(memberKey);
7192
+ const stopRequestedAt = workflowStopRequestedAt.get(taskId);
7193
const status =
7194
(member.state === "queued" || member.state === "running") &&
7195
input.coordinator.task.status !== "running"
7196
? input.coordinator.task.status
7197
: member.state === "queued"
7198
? "pending"
7195
- : member.state;
7199
+ : member.state === "failed" &&
7200
+ stopRequestedAt !== undefined &&
7201
+ // lastProgressAt (completedAt) is the last tick, often before Stop for a blocked tool.
7202
+ previous?.status !== "failed"
7203
+ ? "cancelled"
7204
+ : member.state;
7205
const settled = status !== "pending" && status !== "running";
7206
const prompt = member.prompt ?? member.label;
7207
const model = member.model ?? parentThread.modelSelection.model;
@@ -7350,6 +7359,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7359
childRootNodeId,
7360
nextOrdinal: () => ++nextItemOrdinal,
7361
toolCalls,
7362
+ stopRequestedAt,
7363
};
7364
const endOpenToolCalls = Effect.fnUntraced(function* () {
7365
if (toolCalls.size === 0) return;
@@ -8430,12 +8440,20 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8440
readonly toolResult: ClaudeToolResultContentBlock;
8441
readonly output: ClaudeNativeToolOutput;
8442
readonly completedAt: DateTime.Utc;
8443
+ readonly stopped?: boolean;
8444
}) {
8445
const { toolCall } = input;
8446
const toolNonExecutionKind = claudeToolNonExecutionKind(
8447
input.message,
8448
input.toolResult.tool_use_id,
8449
);
8450
+ // Stop denial metadata distinguishes cancelled work from a real error
8451
+ // that happens to arrive after the turn was interrupted.
8452
+ const stopped =
8453
+ input.stopped === true ||
8454
+ (toolNonExecutionKind === "user-rejected" &&
8455
+ input.context !== null &&
8456
+ (yield* Ref.get(interruptedTurns)).has(input.context.providerTurnId));
8457
yield* stopTaskOutputTail(toolCall.nativeItemId);
8458
yield* emitToolCallArtifacts(
8459
buildToolCallArtifacts({
@@ -8454,7 +8472,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8472
toolNonExecutionKind === "cancelled" || toolNonExecutionKind === "interrupted"
8473
? toolNonExecutionKind
8474
: isClaudeToolResultError(input.toolResult)
8457
- ? "failed"
8475
+ ? stopped
8476
+ ? "interrupted"
8477
+ : "failed"
8478
: "completed",
8479
...(toolNonExecutionKind === undefined ? {} : { toolNonExecutionKind }),
8480
startedAt: toolCall.startedAt,
@@ -8549,6 +8569,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8569
toolResult,
8570
output,
8571
completedAt: at,
8572
+ // A denial written before Stop (a declined approval) is not the Stop's.
8573
+ stopped:
8574
+ target.stopRequestedAt !== undefined &&
8575
+ field(line, "toolDenialKind") !== undefined &&
8576
+ DateTime.toEpochMillis(at) >= target.stopRequestedAt,
8577
});
8578
}
8579
if (line.type !== "assistant") return false;
@@ -13778,6 +13803,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
13803
detail: "No running workflow task belongs to this provider thread",
13804
});
13805
}
13806
+ workflowStopRequestedAt.set(taskId, DateTime.toEpochMillis(yield* DateTime.now));
13807
yield* liveQuery.query.stopTask(taskId).pipe(
13808
Effect.mapError(
13809
(cause) =>
@@ -13787,6 +13813,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
13813
cause,
13814
}),
13815
),
13816
+ Effect.onError(() => Effect.sync(() => workflowStopRequestedAt.delete(taskId))),
13817
);
13818
}),
13819
awaitBackgroundTasks: Effect.fn("ClaudeAdapterV2.awaitBackgroundTasks")(