Skip to content

Commit 4d8f783

Browse files
henrychu04claude
andcommitted
fix(server): foreground Claude forks no longer show as finished the moment they start
Claude Code opens a foreground fork's stream with a placeholder result ("Fork started — that fork is you.") for the fork's own launch call, tagged with that call as parent_tool_use_id. The adapter read it as the subagent's final result and settled the fork as completed while it was still running. A subagent's stream never carries the real result of its own launch, so skip a tool result whose id matches its message's parent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1abf368 commit 4d8f783

2 files changed

Lines changed: 75 additions & 0 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
@@ -11529,6 +11529,79 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1152911529
),
1153011530
);
1153111531

11532+
it.effect("keeps a foreground fork running past the placeholder result for its own launch", () =>
11533+
Effect.scoped(
11534+
Effect.gen(function* () {
11535+
const harness = yield* makeWakeHarness;
11536+
yield* harness.runtime.startTurn(
11537+
makeClaudeTestTurnInput({
11538+
threadId: harness.threadId,
11539+
providerThread: harness.providerThread,
11540+
now: yield* DateTime.now,
11541+
attemptId: RunAttemptId.make("attempt-claude-foreground-fork"),
11542+
text: "Fork this.",
11543+
attachments: [],
11544+
}),
11545+
);
11546+
yield* harness.offerAndWait(
11547+
claudeSdkFrame({
11548+
type: "system",
11549+
subtype: "task_started",
11550+
task_id: "agent-fork",
11551+
tool_use_id: "toolu-fork",
11552+
description: "Probe",
11553+
subagent_type: "fork",
11554+
is_backgrounded: false,
11555+
task_type: "local_agent",
11556+
prompt: "Reply with exactly FORK-DONE.",
11557+
uuid: "00000000-0000-4000-8000-000000000901",
11558+
session_id: WAKE_NATIVE_SESSION,
11559+
}),
11560+
);
11561+
assert.equal((yield* Queue.take(harness.subagentReceipts)).subagent.status, "running");
11562+
// Claude Code opens a foreground fork's own stream with a placeholder result for its launch.
11563+
yield* harness.offerAndWait(
11564+
claudeSdkFrame({
11565+
type: "user",
11566+
message: {
11567+
role: "user",
11568+
content: [
11569+
{
11570+
type: "tool_result",
11571+
tool_use_id: "toolu-fork",
11572+
content: [{ type: "text", text: "Fork started — that fork is you." }],
11573+
},
11574+
],
11575+
},
11576+
parent_tool_use_id: "toolu-fork",
11577+
agent_id: "agent-fork",
11578+
subagent_type: "fork",
11579+
uuid: "00000000-0000-4000-8000-000000000902",
11580+
session_id: WAKE_NATIVE_SESSION,
11581+
}),
11582+
);
11583+
yield* harness.offerAndWait(
11584+
makeSubagentNotificationFrame({
11585+
taskId: "agent-fork",
11586+
toolUseId: "toolu-fork",
11587+
summary: "FORK-DONE",
11588+
uuid: "00000000-0000-4000-8000-000000000903",
11589+
}),
11590+
);
11591+
let settled = yield* Queue.take(harness.subagentReceipts);
11592+
while (settled.subagent.status === "running") {
11593+
settled = yield* Queue.take(harness.subagentReceipts);
11594+
}
11595+
assert.equal(settled.subagent.status, "completed");
11596+
assert.equal(settled.subagent.result, "FORK-DONE");
11597+
}).pipe(
11598+
Effect.provide(
11599+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
11600+
),
11601+
),
11602+
),
11603+
);
11604+
1153211605
it.effect("releases the idle pin when a post-settle subagent stops without completing", () =>
1153311606
Effect.scoped(
1153411607
Effect.gen(function* () {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8819,6 +8819,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88198819
}
88208820

88218821
for (const { toolResult, output } of claudeToolResultEntriesFromMessage(message)) {
8822+
// A foreground fork's stream opens with a placeholder result for its own launch call.
8823+
if (parentToolUseIdFromSdkMessage(message) === toolResult.tool_use_id) continue;
88228824
const subagent = yield* resolveSubagentByToolUseId(context, toolResult.tool_use_id);
88238825
const runHandles = parseClaudeWorkflowRunHandles(claudeNativeToolOutputValue(output));
88248826
if (subagent !== undefined && runHandles !== undefined) {

0 commit comments

Comments
 (0)