Skip to content

Commit b6bcfae

Browse files
saphidclaude
andcommitted
fix(claude): workflow member tools running at Stop show as stopped
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1749f57 commit b6bcfae

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16924,6 +16924,79 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1692416924
),
1692516925
);
1692616926

16927+
it.effect("shows a workflow member's tool as stopped when Stop cancels the workflow", () =>
16928+
Effect.scoped(
16929+
Effect.gen(function* () {
16930+
const harness = yield* makeWorkflowHarness;
16931+
const transcriptPath = NodePath.join(harness.transcriptDir, "agent-a1.jsonl");
16932+
NodeFS.writeFileSync(
16933+
transcriptPath,
16934+
memberAssistantLine("line-bash", "msg_a1", [
16935+
{ type: "tool_use", id: "toolu_a1_ping", name: "Bash", input: { command: "ping" } },
16936+
]),
16937+
);
16938+
yield* harness.runtime.startTurn(
16939+
makeClaudeTestTurnInput({
16940+
threadId: harness.threadId,
16941+
providerThread: harness.providerThread,
16942+
now: yield* DateTime.now,
16943+
attemptId: RunAttemptId.make("attempt-claude-workflow-member-stopped"),
16944+
text: "Run the alpha workflow.",
16945+
attachments: [],
16946+
}),
16947+
);
16948+
yield* launchWorkflow({ harness, snapshotUuid: "00000000-0000-4000-8000-000000001375" });
16949+
const threadId = workflowMemberEvents(harness.events, 1)[0]?.subagent.childThreadId;
16950+
const errorLine = (uuid: string, toolUseId: string, output: string, denial?: object) =>
16951+
transcriptLine({
16952+
type: "user",
16953+
uuid,
16954+
message: {
16955+
role: "user",
16956+
content: [
16957+
{ tool_use_id: toolUseId, type: "tool_result", content: output, is_error: true },
16958+
],
16959+
},
16960+
...denial,
16961+
});
16962+
NodeFS.appendFileSync(
16963+
transcriptPath,
16964+
errorLine("line-ping-failed", "toolu_a1_ping", "Exit code 1") +
16965+
memberAssistantLine("line-sleep", "msg_a1_sleep", [
16966+
{ type: "tool_use", id: "toolu_a1_sleep", name: "Bash", input: { command: "sleep" } },
16967+
]) +
16968+
errorLine("line-sleep-stopped", "toolu_a1_sleep", "Rejected", {
16969+
toolUseResult: "User rejected tool use",
16970+
toolDenialKind: "user-rejected",
16971+
}),
16972+
);
16973+
yield* harness.offerAndWait(
16974+
workflowNotification({ uuid: "00000000-0000-4000-8000-000000001376", status: "stopped" }),
16975+
);
16976+
assert.equal(workflowMemberEvents(harness.events, 1).at(-1)?.subagent.status, "cancelled");
16977+
assert.deepEqual(latestMemberThreadItems(harness.events, threadId).map(describeItem), [
16978+
"user_message",
16979+
"command failed: Exit code 1",
16980+
"command interrupted: Rejected",
16981+
]);
16982+
yield* Queue.offer(
16983+
harness.sdkMessages,
16984+
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000001377", result: "Done." }),
16985+
);
16986+
yield* Queue.take(harness.terminalReceipts);
16987+
}).pipe(
16988+
Effect.provide(
16989+
Layer.mergeAll(
16990+
IdAllocator.layer,
16991+
McpProviderSessions.layer,
16992+
NodeServices.layer,
16993+
NodeCrypto.layer,
16994+
),
16995+
),
16996+
),
16997+
),
16998+
);
16999+
1692717000
it.effect("reads a settled workflow member's transcript to its end past the read cap", () =>
1692817001
Effect.scoped(
1692917002
Effect.gen(function* () {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,6 +4159,7 @@ interface ClaudeSubagentProjectionTarget {
41594159
readonly childRootNodeId: OrchestrationV2ExecutionNode["id"];
41604160
readonly nextOrdinal: () => number;
41614161
readonly toolCalls: Map<string, ActiveClaudeToolCall>;
4162+
readonly stopped?: boolean;
41624163
}
41634164

41644165
/** Claude writes blocks separately with stop_reason null until the last.
@@ -6131,6 +6132,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
61316132
childRootNodeId,
61326133
nextOrdinal: () => ++nextItemOrdinal,
61336134
toolCalls,
6135+
stopped: status === "cancelled",
61346136
};
61356137
const endOpenToolCalls = Effect.fnUntraced(function* () {
61366138
if (toolCalls.size === 0) return;
@@ -7040,6 +7042,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
70407042
readonly toolResult: ClaudeToolResultContentBlock;
70417043
readonly output: ClaudeNativeToolOutput;
70427044
readonly completedAt: DateTime.Utc;
7045+
readonly stopped?: boolean;
70437046
}) {
70447047
const { toolCall } = input;
70457048
const toolNonExecutionKind = claudeToolNonExecutionKind(
@@ -7048,8 +7051,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
70487051
);
70497052
// Stop makes Claude answer each running tool with an error result.
70507053
const stopped =
7051-
input.context !== null &&
7052-
(yield* Ref.get(interruptedTurns)).has(input.context.providerTurnId);
7054+
input.stopped === true ||
7055+
(input.context !== null &&
7056+
(yield* Ref.get(interruptedTurns)).has(input.context.providerTurnId));
70537057
yield* stopTaskOutputTail(toolCall.nativeItemId);
70547058
yield* emitToolCallArtifacts(
70557059
buildToolCallArtifacts({
@@ -7165,6 +7169,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
71657169
toolResult,
71667170
output,
71677171
completedAt: at,
7172+
// A genuine failure read late carries no denial kind.
7173+
stopped: target.stopped === true && field(line, "toolDenialKind") !== undefined,
71687174
});
71697175
}
71707176
if (line.type !== "assistant") return false;

0 commit comments

Comments
 (0)