fix(background-agent): abort session on task completion to prevent zombie attach processes

This commit is contained in:
justsisyphus
2026-02-01 16:51:11 +09:00
parent e8cdab8871
commit 3e9a0ef9aa
2 changed files with 867 additions and 150 deletions

View File

@@ -982,6 +982,41 @@ describe("BackgroundManager.tryCompleteTask", () => {
expect(task.status).toBe("completed")
expect(concurrencyManager.getCount(concurrencyKey)).toBe(0)
})
test("should abort session on completion", async () => {
// #given
const abortedSessionIDs: string[] = []
const client = {
session: {
prompt: async () => ({}),
abort: async (args: { path: { id: string } }) => {
abortedSessionIDs.push(args.path.id)
return {}
},
},
}
manager.shutdown()
manager = new BackgroundManager({ client, directory: tmpdir() } as unknown as PluginInput)
stubNotifyParentSession(manager)
const task: BackgroundTask = {
id: "task-1",
sessionID: "session-1",
parentSessionID: "session-parent",
parentMessageID: "msg-1",
description: "test task",
prompt: "test",
agent: "explore",
status: "running",
startedAt: new Date(),
}
// #when
await tryCompleteTaskForTest(manager, task)
// #then
expect(abortedSessionIDs).toEqual(["session-1"])
})
})
describe("BackgroundManager.trackTask", () => {

File diff suppressed because it is too large Load Diff