Skip to content

Commit 718dbaa

Browse files
fix(server): read a forked skill's model from its transcript
A `context: fork` skill streams none of its own replies: the CLI sends task_started without a tool_use_id, task_notification, and only a prompt echo under `forked-command-<skill>`. No frame carries the fork's model, so mapping that parent id to the fork could never record it, and it caused a second run of the same skill to reopen the first. Drop that mapping. When the turn's result arrives, read the model of each finished subagent that had no Agent call and no model from its transcript, which the CLI writes only after reporting the fork done. AI-assisted; verified with the tests and tools listed above.
1 parent 0c78322 commit 718dbaa

4 files changed

Lines changed: 128 additions & 77 deletions

File tree

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

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ describe("ClaudeAdapterV2 Auto-accept edits", () => {
957957
}),
958958
forkSession: () => Effect.die("unused"),
959959
subagentLaunchToolUseId: () => Effect.succeed(null),
960+
subagentModel: () => Effect.succeed(null),
960961
assertComplete: Effect.void,
961962
},
962963
});
@@ -1083,6 +1084,7 @@ describe("ClaudeAdapterV2 append-system-prompt-file launch argument", () => {
10831084
}),
10841085
forkSession: () => Effect.die("unused"),
10851086
subagentLaunchToolUseId: () => Effect.succeed(null),
1087+
subagentModel: () => Effect.succeed(null),
10861088
assertComplete: Effect.void,
10871089
},
10881090
});
@@ -1349,6 +1351,7 @@ describe("ClaudeAdapterV2 provider installation gate", () => {
13491351
}),
13501352
forkSession: () => Effect.die("unused"),
13511353
subagentLaunchToolUseId: () => Effect.succeed(null),
1354+
subagentModel: () => Effect.succeed(null),
13521355
assertComplete: Effect.void,
13531356
},
13541357
});
@@ -1536,6 +1539,7 @@ const captureSdkExecutablePaths = Effect.fn("captureSdkExecutablePaths")(functio
15361539
}),
15371540
forkSession: () => Effect.die("unused"),
15381541
subagentLaunchToolUseId: () => Effect.succeed(null),
1542+
subagentModel: () => Effect.succeed(null),
15391543
assertComplete: Effect.void,
15401544
}),
15411545
);
@@ -1630,6 +1634,7 @@ describe("ClaudeAdapterV2 resumeThread", () => {
16301634
open: () => Effect.die("unused"),
16311635
forkSession: () => Effect.die("unused"),
16321636
subagentLaunchToolUseId: () => Effect.succeed(null),
1637+
subagentModel: () => Effect.succeed(null),
16331638
assertComplete: Effect.void,
16341639
},
16351640
});
@@ -1728,6 +1733,7 @@ describe("ClaudeAdapterV2 resume compaction", () => {
17281733
}),
17291734
forkSession: () => Effect.die("unused"),
17301735
subagentLaunchToolUseId: () => Effect.succeed(null),
1736+
subagentModel: () => Effect.succeed(null),
17311737
assertComplete: Effect.void,
17321738
},
17331739
});
@@ -2118,6 +2124,7 @@ describe("ClaudeAdapterV2 attachments", () => {
21182124
}),
21192125
forkSession: () => Effect.die("unused forkSession"),
21202126
subagentLaunchToolUseId: () => Effect.succeed(null),
2127+
subagentModel: () => Effect.succeed(null),
21212128
assertComplete: Effect.void,
21222129
},
21232130
});
@@ -2672,6 +2679,7 @@ describe("ClaudeAdapterV2 native fork", () => {
26722679
return yield* realRunner.forkSession(input);
26732680
}),
26742681
subagentLaunchToolUseId: () => Effect.succeed(null),
2682+
subagentModel: () => Effect.succeed(null),
26752683
assertComplete: Effect.void,
26762684
},
26772685
});
@@ -3016,6 +3024,7 @@ describe("ClaudeAdapterV2 native session identity", () => {
30163024
}),
30173025
forkSession: () => Effect.die("unused forkSession"),
30183026
subagentLaunchToolUseId: () => Effect.succeed(null),
3027+
subagentModel: () => Effect.succeed(null),
30193028
assertComplete: Effect.void,
30203029
},
30213030
});
@@ -3349,6 +3358,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
33493358
Partial<Pick<ClaudeAdapterV2.ClaudeAgentSdkQuerySession, "listPermissionRules">>;
33503359
readonly environment?: NodeJS.ProcessEnv;
33513360
readonly subagentLaunchToolUseId?: string;
3361+
readonly subagentModel?: string;
33523362
readonly nativeSessionId?: string;
33533363
readonly settings?: ClaudeSettings;
33543364
readonly modelCatalog?: Effect.Effect<ClaudeModelCatalog>;
@@ -3521,6 +3531,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
35213531
}),
35223532
forkSession: options?.forkSession ?? (() => Effect.die("unused forkSession")),
35233533
subagentLaunchToolUseId: () => Effect.succeed(options?.subagentLaunchToolUseId ?? null),
3534+
subagentModel: () => Effect.succeed(options?.subagentModel ?? null),
35243535
assertComplete: Effect.void,
35253536
},
35263537
});
@@ -12159,6 +12170,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1215912170
}),
1216012171
forkSession: () => Effect.die("unused forkSession"),
1216112172
subagentLaunchToolUseId: () => Effect.succeed(null),
12173+
subagentModel: () => Effect.succeed(null),
1216212174
assertComplete: Effect.void,
1216312175
},
1216412176
});
@@ -12352,6 +12364,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1235212364
}),
1235312365
forkSession: () => Effect.die("unused forkSession"),
1235412366
subagentLaunchToolUseId: () => Effect.succeed(null),
12367+
subagentModel: () => Effect.succeed(null),
1235512368
assertComplete: Effect.void,
1235612369
},
1235712370
});
@@ -12486,6 +12499,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1248612499
}),
1248712500
forkSession: () => Effect.die("unused forkSession"),
1248812501
subagentLaunchToolUseId: () => Effect.succeed(null),
12502+
subagentModel: () => Effect.succeed(null),
1248912503
assertComplete: Effect.void,
1249012504
},
1249112505
});
@@ -15765,6 +15779,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1576515779
}),
1576615780
forkSession: () => Effect.die("unused forkSession"),
1576715781
subagentLaunchToolUseId: () => Effect.succeed(null),
15782+
subagentModel: () => Effect.succeed(null),
1576815783
assertComplete: Effect.void,
1576915784
},
1577015785
});
@@ -17829,10 +17844,12 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1782917844
),
1783017845
);
1783117846

17832-
it.effect("records a forked skill's model from its frames instead of the parent's", () =>
17847+
it.effect("records a forked skill's model from its transcript instead of the parent's", () =>
1783317848
Effect.scoped(
1783417849
Effect.gen(function* () {
17835-
const harness = yield* makeWakeHarness;
17850+
const harness = yield* makeWakeHarnessWithOptions({
17851+
subagentModel: "claude-haiku-4-5-20251001",
17852+
});
1783617853
const now = yield* DateTime.now;
1783717854
const parentModel = "claude-opus-4-6";
1783817855
yield* harness.runtime.startTurn(
@@ -17846,76 +17863,51 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1784617863
modelSelection: { ...CLAUDE_TEST_MODEL_SELECTION, model: parentModel },
1784717864
}),
1784817865
);
17849-
// A `context: fork` skill has no Agent call: task_started carries no tool_use_id,
17850-
// and every run's frames name `forked-command-<skill>` as their parent.
17851-
const forkFrames = (taskId: string, text: string, uuidBase: number) => [
17866+
// A `context: fork` skill has no Agent call and streams none of its own replies:
17867+
// task_started carries no tool_use_id, and only its prompt echo names the fork.
17868+
for (const frame of [
1785217869
claudeSdkFrame({
1785317870
type: "system",
1785417871
subtype: "task_started",
17855-
task_id: taskId,
17872+
task_id: "task-forked-skill",
1785617873
description: "/fork-probe",
1785717874
prompt: "go",
1785817875
subagent_type: "general-purpose",
1785917876
task_type: "local_agent",
17860-
uuid: `00000000-0000-4000-8000-000000000${uuidBase}`,
17861-
session_id: WAKE_NATIVE_SESSION,
17862-
}),
17863-
claudeSdkFrame({
17864-
type: "assistant",
17865-
parent_tool_use_id: "forked-command-fork-probe",
17866-
message: {
17867-
model: "claude-haiku-4-5-20251001",
17868-
id: `msg_${taskId}`,
17869-
type: "message",
17870-
role: "assistant",
17871-
content: [{ type: "text", text }],
17872-
},
17873-
uuid: `00000000-0000-4000-8000-000000000${uuidBase + 1}`,
17877+
skip_transcript: true,
17878+
ambient: true,
17879+
uuid: "00000000-0000-4000-8000-000000000231",
1787417880
session_id: WAKE_NATIVE_SESSION,
1787517881
}),
1787617882
claudeSdkFrame({
1787717883
type: "system",
1787817884
subtype: "task_notification",
17879-
task_id: taskId,
17885+
task_id: "task-forked-skill",
1788017886
status: "completed",
1788117887
summary: "/fork-probe",
1788217888
output_file: "",
17883-
uuid: `00000000-0000-4000-8000-000000000${uuidBase + 2}`,
17889+
uuid: "00000000-0000-4000-8000-000000000232",
1788417890
session_id: WAKE_NATIVE_SESSION,
1788517891
}),
17886-
];
17887-
for (const frame of [
17888-
...forkFrames("task-fork-a", "first", 231),
17889-
...forkFrames("task-fork-b", "second", 241),
17890-
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000251", result: "OK" }),
17892+
claudeSdkFrame({
17893+
type: "user",
17894+
parent_tool_use_id: "forked-command-fork-probe",
17895+
message: { role: "user", content: [{ type: "text", text: "go" }] },
17896+
uuid: "00000000-0000-4000-8000-000000000233",
17897+
session_id: WAKE_NATIVE_SESSION,
17898+
}),
17899+
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000234", result: "OK" }),
1789117900
]) {
1789217901
yield* Queue.offer(harness.sdkMessages, frame);
1789317902
}
1789417903
yield* Queue.take(harness.terminalReceipts);
1789517904

17896-
const latestByTask = new Map(
17897-
harness.events.flatMap((event) =>
17898-
event.type === "subagent.updated"
17899-
? [[event.subagent.nativeTaskRef?.nativeId, event.subagent] as const]
17900-
: [],
17901-
),
17902-
);
17903-
const repliesIn = (threadId: string | null | undefined) =>
17904-
harness.events.flatMap((event) =>
17905-
event.type === "message.updated" && event.message.threadId === threadId
17906-
? [event.message.text]
17907-
: [],
17908-
);
17909-
assert.deepEqual(
17910-
["task-fork-a", "task-fork-b"].map((taskId) => {
17911-
const fork = latestByTask.get(taskId);
17912-
return [fork?.model, fork?.modelSelection?.model, repliesIn(fork?.childThreadId)];
17913-
}),
17914-
[
17915-
["claude-haiku-4-5", "claude-haiku-4-5", ["go", "first", "/fork-probe"]],
17916-
["claude-haiku-4-5", "claude-haiku-4-5", ["go", "second", "/fork-probe"]],
17917-
],
17918-
);
17905+
const fork = harness.events
17906+
.filter((event) => event.type === "subagent.updated")
17907+
.at(-1)?.subagent;
17908+
assert.equal(fork?.status, "completed");
17909+
assert.equal(fork?.model, "claude-haiku-4-5");
17910+
assert.equal(fork?.modelSelection?.model, "claude-haiku-4-5");
1791917911
}).pipe(
1792017912
Effect.provide(
1792117913
Layer.mergeAll(
@@ -18803,6 +18795,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1880318795
}),
1880418796
forkSession: () => Effect.die("unused forkSession"),
1880518797
subagentLaunchToolUseId: () => Effect.succeed(null),
18798+
subagentModel: () => Effect.succeed(null),
1880618799
assertComplete: Effect.void,
1880718800
},
1880818801
});
@@ -18981,6 +18974,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1898118974
}),
1898218975
forkSession: () => Effect.die("unused forkSession"),
1898318976
subagentLaunchToolUseId: () => Effect.succeed(null),
18977+
subagentModel: () => Effect.succeed(null),
1898418978
assertComplete: Effect.void,
1898518979
},
1898618980
});
@@ -19162,6 +19156,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1916219156
}),
1916319157
forkSession: () => Effect.die("unused forkSession"),
1916419158
subagentLaunchToolUseId: () => Effect.succeed(null),
19159+
subagentModel: () => Effect.succeed(null),
1916519160
assertComplete: Effect.void,
1916619161
},
1916719162
});
@@ -19363,6 +19358,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1936319358
}),
1936419359
forkSession: () => Effect.die("unused forkSession"),
1936519360
subagentLaunchToolUseId: () => Effect.succeed(null),
19361+
subagentModel: () => Effect.succeed(null),
1936619362
assertComplete: Effect.void,
1936719363
},
1936819364
});
@@ -19509,6 +19505,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1950919505
},
1951019506
forkSession: () => Effect.die("unused forkSession"),
1951119507
subagentLaunchToolUseId: () => Effect.succeed(null),
19508+
subagentModel: () => Effect.succeed(null),
1951219509
assertComplete: Effect.void,
1951319510
},
1951419511
});
@@ -19631,6 +19628,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1963119628
}),
1963219629
forkSession: () => Effect.die("unused forkSession"),
1963319630
subagentLaunchToolUseId: () => Effect.succeed(null),
19631+
subagentModel: () => Effect.succeed(null),
1963419632
assertComplete: Effect.void,
1963519633
},
1963619634
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ function replayQueryRunnerService(
943943
open: (input) => replay(() => queryRunner.open(input)),
944944
forkSession: (input) => replay(() => queryRunner.forkSession(input)),
945945
subagentLaunchToolUseId: (input) => replay(() => queryRunner.subagentLaunchToolUseId(input)),
946+
subagentModel: () => Effect.succeed(null),
946947
assertComplete: replay(() => queryRunner.assertComplete()),
947948
});
948949
}

0 commit comments

Comments
 (0)