diff --git a/packages/server/src/server/agent/providers/claude/agent.sub-agent-replay.test.ts b/packages/server/src/server/agent/providers/claude/agent.sub-agent-replay.test.ts index 91007aa7ce..d943b210f6 100644 --- a/packages/server/src/server/agent/providers/claude/agent.sub-agent-replay.test.ts +++ b/packages/server/src/server/agent/providers/claude/agent.sub-agent-replay.test.ts @@ -648,6 +648,23 @@ describe("ClaudeAgentSession persisted subagent replay", () => { ); } + test("cancels a background child from a task-id-only stopped notification on reopen", async () => { + const text = `\n${AGENT_ID}\nstopped\nBackground agent didn't finish before the previous session ended\n`; + writeSession({ + parentLines: [ + ...backgroundLaunch(), + JSON.stringify({ type: "queue-operation", operation: "enqueue", content: text }), + JSON.stringify({ type: "user", message: { role: "user", content: text } }), + ], + meta: JSON.stringify({ toolUseId: TOOL_USE_ID }), + sidechainLines: [sidechainEntry({ stopReason: "tool_use" })], + }); + expect(upserts(await replayDescriptors()).at(-1)).toMatchObject({ + id: TOOL_USE_ID, + status: "canceled", + }); + }); + test("prefers a stopped notification over the child's end_turn", async () => { writeSession({ parentLines: [...backgroundLaunch(), taskNotification("stopped")],