From 57b4985424d77eb3268f5505a7b7639d5293defb Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 12 Mar 2026 02:24:42 +0900 Subject: [PATCH] fix(background-agent): delay session error task cleanup Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/features/background-agent/manager.ts | 3 +-- src/features/background-agent/task-history-cleanup.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index 75c8bc95b..536988f93 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -908,13 +908,12 @@ export class BackgroundManager { } this.cleanupPendingByParent(task) - this.tasks.delete(task.id) - this.clearTaskHistoryWhenParentTasksGone(task.parentSessionID) this.clearNotificationsForTask(task.id) const toastManager = getTaskToastManager() if (toastManager) { toastManager.removeTask(task.id) } + this.scheduleTaskRemoval(task.id) if (task.sessionID) { SessionCategoryRegistry.remove(task.sessionID) } diff --git a/src/features/background-agent/task-history-cleanup.test.ts b/src/features/background-agent/task-history-cleanup.test.ts index 1b585488d..f9dd72c56 100644 --- a/src/features/background-agent/task-history-cleanup.test.ts +++ b/src/features/background-agent/task-history-cleanup.test.ts @@ -112,7 +112,7 @@ describe("task history cleanup", () => { managerUnderTest = undefined }) - test("#given BackgroundManager with stale tasks for one parent #when pruneStaleTasksAndNotifications() runs #then only that parent's history is removed", () => { + test("#given BackgroundManager with stale tasks for one parent #when pruneStaleTasksAndNotifications() runs #then history is preserved until delayed cleanup", () => { // given const manager = createManager() managerUnderTest = manager @@ -136,7 +136,7 @@ describe("task history cleanup", () => { pruneStaleTasksAndNotificationsForTest(manager) // then - expect(manager.taskHistory.getByParentSession("parent-1")).toHaveLength(0) + expect(manager.taskHistory.getByParentSession("parent-1")).toHaveLength(1) expect(manager.taskHistory.getByParentSession("parent-2")).toHaveLength(1) }) })