Repository navigation
fix(server): forked Claude skills show their work in the subagent thread #43023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d0a4d2e
646c4c7
b203753
110abc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22241,6 +22241,310 @@ describe("ClaudeAdapterV2 background wake turns", () => { | |
| ), | ||
| ); | ||
|
|
||
| // Frame order captured from Claude Code 2.1.332: the fork's work arrives only after task_notification. | ||
| it.effect("shows a forked skill's commands and reply in its subagent thread", () => | ||
| Effect.gen(function* () { | ||
| const harness = yield* makeWakeHarness; | ||
| yield* harness.runtime.startTurn( | ||
| makeClaudeTestTurnInput({ | ||
| threadId: harness.threadId, | ||
| providerThread: harness.providerThread, | ||
| now: yield* DateTime.now, | ||
| attemptId: RunAttemptId.make("attempt-forked-skill-activity"), | ||
| text: "/fork-probe go", | ||
| attachments: [], | ||
| }), | ||
| ); | ||
| const forkParent = "forked-command-fork-probe"; | ||
| for (const frame of [ | ||
| claudeSdkFrame({ | ||
| type: "system", | ||
| subtype: "task_started", | ||
| task_id: "task-forked-activity", | ||
| description: "/fork-probe", | ||
| prompt: "go", | ||
| subagent_type: "general-purpose", | ||
| task_type: "local_agent", | ||
| skip_transcript: true, | ||
| ambient: true, | ||
| uuid: "00000000-0000-4000-8000-000000000a01", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "system", | ||
| subtype: "task_notification", | ||
| task_id: "task-forked-activity", | ||
| status: "completed", | ||
| summary: "/fork-probe", | ||
| output_file: "", | ||
| uuid: "00000000-0000-4000-8000-000000000a02", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "user", | ||
| parent_tool_use_id: forkParent, | ||
| message: { role: "user", content: [{ type: "text", text: "go" }] }, | ||
| uuid: "00000000-0000-4000-8000-000000000a03", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "assistant", | ||
| parent_tool_use_id: forkParent, | ||
| message: { | ||
| model: "claude-haiku-5-5", | ||
| id: "msg_fork_bash", | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [ | ||
| { | ||
| type: "tool_use", | ||
| id: "toolu-fork-bash", | ||
| name: "Bash", | ||
| input: { command: "cat hello.txt", description: "Read hello.txt" }, | ||
| }, | ||
| ], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000a04", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "user", | ||
| parent_tool_use_id: forkParent, | ||
| message: { | ||
| role: "user", | ||
| content: [ | ||
| { type: "tool_result", tool_use_id: "toolu-fork-bash", content: "greetings" }, | ||
| ], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000a05", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "assistant", | ||
| parent_tool_use_id: forkParent, | ||
| message: { | ||
| model: "claude-haiku-5-5", | ||
| id: "msg_fork_reply", | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [{ type: "text", text: "FORK-REPORT greetings" }], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000a06", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| makeResultFrame({ | ||
| uuid: "00000000-0000-4000-8000-000000000a07", | ||
| result: "FORK-REPORT greetings", | ||
| }), | ||
| ]) { | ||
| yield* Queue.offer(harness.sdkMessages, frame); | ||
| } | ||
| yield* Queue.take(harness.terminalReceipts); | ||
|
|
||
| const routing = subagentRouting(harness.events, ["toolu-fork-bash"]); | ||
| assert.isDefined(routing.childThreadId); | ||
| assert.deepEqual( | ||
| [...(routing.toolThreadIds.get("toolu-fork-bash") ?? [])], | ||
| [routing.childThreadId], | ||
| "the fork's Bash call never reached its subagent thread", | ||
| ); | ||
| assert.include(routing.assistantTexts(routing.childThreadId), "FORK-REPORT greetings"); | ||
| const subagent = harness.events | ||
| .filter((event) => event.type === "subagent.updated") | ||
| .at(-1)?.subagent; | ||
| assert.notEqual(subagent?.result, "/fork-probe", "the skill's name became its result"); | ||
| }).pipe( | ||
| Effect.provide( | ||
| Layer.mergeAll( | ||
| IdAllocator.layer, | ||
| McpProviderSessions.layer, | ||
| NodeServices.layer, | ||
| NodeCrypto.layer, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| it.effect("shows a forked skill's work from its transcript while it runs, once", () => | ||
| Effect.gen(function* () { | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const configDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-fork-" }); | ||
| const subagentsDir = NodePath.join( | ||
| configDir, | ||
| "projects", | ||
| "-workspace", | ||
| WAKE_NATIVE_SESSION, | ||
| "subagents", | ||
| ); | ||
| yield* fileSystem.makeDirectory(subagentsDir, { recursive: true }); | ||
| const forkParent = "forked-command-fork-probe"; | ||
| const bashCall = { | ||
| type: "assistant" as const, | ||
| parent_tool_use_id: forkParent, | ||
| message: { | ||
| model: "claude-haiku-5-5", | ||
| id: "msg_fork_live_bash", | ||
| type: "message", | ||
| role: "assistant", | ||
| stop_reason: "tool_use", | ||
| content: [ | ||
| { | ||
| type: "tool_use", | ||
| id: "toolu-fork-live-bash", | ||
| name: "Bash", | ||
| input: { command: "cat hello.txt", description: "Read hello.txt" }, | ||
| }, | ||
| ], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000b04", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }; | ||
| yield* fileSystem.writeFileString( | ||
| NodePath.join(subagentsDir, "agent-task-forked-live.jsonl"), | ||
| `${JSON.stringify(bashCall)}\n`, | ||
| ); | ||
| const harness = yield* makeWakeHarnessWithOptions({ | ||
| environment: { CLAUDE_CONFIG_DIR: configDir }, | ||
| }); | ||
| yield* harness.runtime.startTurn( | ||
| makeClaudeTestTurnInput({ | ||
| threadId: harness.threadId, | ||
| providerThread: harness.providerThread, | ||
| now: yield* DateTime.now, | ||
| attemptId: RunAttemptId.make("attempt-forked-skill-live"), | ||
| text: "/fork-probe go", | ||
| attachments: [], | ||
| }), | ||
| ); | ||
| yield* harness.offerAndWait( | ||
| claudeSdkFrame({ | ||
| type: "system", | ||
| subtype: "task_started", | ||
| task_id: "task-forked-live", | ||
| description: "/fork-probe", | ||
| prompt: "go", | ||
| subagent_type: "general-purpose", | ||
| task_type: "local_agent", | ||
| uuid: "00000000-0000-4000-8000-000000000b01", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| ); | ||
| yield* TestClock.adjust("1 second"); | ||
| yield* harness.until( | ||
| () => subagentRouting(harness.events, ["toolu-fork-live-bash"]).toolThreadIds.size > 0, | ||
| ); | ||
| const running = harness.events | ||
| .filter((event) => event.type === "subagent.updated") | ||
| .at(-1)?.subagent; | ||
| assert.equal(running?.status, "running", "the fork's command appeared only after it ended"); | ||
|
|
||
| // As captured from Claude Code 2.1.332: the fork's report is written to its transcript | ||
| // just before task_notification and never sent on the stream. | ||
| yield* fileSystem.writeFileString( | ||
| NodePath.join(subagentsDir, "agent-task-forked-live.jsonl"), | ||
| `${JSON.stringify(bashCall)}\n${JSON.stringify({ | ||
| type: "assistant", | ||
| parent_tool_use_id: forkParent, | ||
| message: { | ||
| model: "claude-haiku-5-5", | ||
| id: "msg_fork_live_reply", | ||
| type: "message", | ||
| role: "assistant", | ||
| stop_reason: "end_turn", | ||
| content: [{ type: "text", text: "FORK-REPORT greetings" }], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000b06", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| })}\n`, | ||
| ); | ||
| for (const frame of [ | ||
| claudeSdkFrame({ | ||
| type: "system", | ||
| subtype: "task_notification", | ||
| task_id: "task-forked-live", | ||
| status: "completed", | ||
| summary: "/fork-probe", | ||
| output_file: "", | ||
| uuid: "00000000-0000-4000-8000-000000000b02", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "system", | ||
| subtype: "init", | ||
| uuid: "00000000-0000-4000-8000-000000000b09", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame(bashCall), | ||
| claudeSdkFrame({ | ||
| type: "user", | ||
| parent_tool_use_id: forkParent, | ||
| message: { | ||
| role: "user", | ||
| content: [ | ||
| { type: "tool_result", tool_use_id: "toolu-fork-live-bash", content: "greetings" }, | ||
| ], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000b05", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| claudeSdkFrame({ | ||
| type: "assistant", | ||
| parent_tool_use_id: null, | ||
| message: { | ||
| model: "claude-haiku-5-5", | ||
| id: "msg_root_live_reply", | ||
| type: "message", | ||
| role: "assistant", | ||
| content: [{ type: "text", text: "FORK-REPORT greetings" }], | ||
| }, | ||
| uuid: "00000000-0000-4000-8000-000000000b08", | ||
| session_id: WAKE_NATIVE_SESSION, | ||
| }), | ||
| makeResultFrame({ | ||
| uuid: "00000000-0000-4000-8000-000000000b07", | ||
| result: "FORK-REPORT greetings", | ||
| }), | ||
| ]) { | ||
| yield* Queue.offer(harness.sdkMessages, frame); | ||
| } | ||
| yield* Queue.take(harness.terminalReceipts); | ||
|
|
||
| const routing = subagentRouting(harness.events, ["toolu-fork-live-bash"]); | ||
| const toolItemIds = new Set( | ||
| harness.events.flatMap((event) => | ||
| event.type === "turn_item.updated" && | ||
| event.turnItem.nativeItemRef?.nativeId === "toolu-fork-live-bash" | ||
| ? [event.turnItem.id] | ||
| : [], | ||
| ), | ||
| ); | ||
| assert.equal(toolItemIds.size, 1, "the fork's command was shown twice"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "shown twice" assertion cannot fail.
The test also writes only the Bash call to the transcript. The reply The observable effect of a missing dedupe is a doubled Fix this in two steps:
That assertion then fails when dedupe is removed. Drop the Proposed fix
As per path instructions, hold changed tests to docs/internals/15_testing.md, which requires tests at the lowest layer that would fail on the base branch.
|
||
| const completedCall = harness.events.findLast( | ||
| (event) => | ||
| event.type === "turn_item.updated" && | ||
| event.turnItem.nativeItemRef?.nativeId === "toolu-fork-live-bash", | ||
| ); | ||
| assert.equal( | ||
| completedCall?.type === "turn_item.updated" ? completedCall.turnItem.status : undefined, | ||
| "completed", | ||
| ); | ||
| assert.deepEqual(routing.assistantTexts(routing.childThreadId), ["FORK-REPORT greetings"]); | ||
| const subagent = harness.events | ||
| .filter((event) => event.type === "subagent.updated") | ||
| .at(-1)?.subagent; | ||
| assert.equal(subagent?.result, "FORK-REPORT greetings"); | ||
| }).pipe( | ||
| Effect.provide( | ||
| Layer.mergeAll( | ||
| IdAllocator.layer, | ||
| McpProviderSessions.layer, | ||
| NodeServices.layer, | ||
| NodeCrypto.layer, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| it.effect.each([ | ||
| { | ||
| source: "custom model", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion accepts a missing result.
assert.notEqual(subagent?.result, "/fork-probe", ...)also passes whenresultisnullorundefined. That is the failure whenlastAssistantTextis not captured or the notification is released early.The test title and the PR objective say the fork's final reply is the result. Assert
assert.equal(subagent?.result, "FORK-REPORT greetings").As per path instructions, hold changed tests to docs/internals/15_testing.md.
Source: Path instructions