Merge pull request #2156 from code-yeongyu/fix/background-pending-notif-leak
fix(background-agent): clean pendingNotifications on session.deleted
This commit is contained in:
@@ -2987,6 +2987,28 @@ describe("BackgroundManager.handleEvent - session.deleted cascade", () => {
|
||||
manager.shutdown()
|
||||
resetToastManager()
|
||||
})
|
||||
|
||||
test("should clean pending notifications for deleted sessions", () => {
|
||||
//#given
|
||||
const manager = createBackgroundManager()
|
||||
const sessionID = "session-pending-notifications"
|
||||
|
||||
manager.queuePendingNotification(sessionID, "<system-reminder>queued</system-reminder>")
|
||||
expect(getPendingNotifications(manager).get(sessionID)).toEqual([
|
||||
"<system-reminder>queued</system-reminder>",
|
||||
])
|
||||
|
||||
//#when
|
||||
manager.handleEvent({
|
||||
type: "session.deleted",
|
||||
properties: { info: { id: sessionID } },
|
||||
})
|
||||
|
||||
//#then
|
||||
expect(getPendingNotifications(manager).has(sessionID)).toBe(false)
|
||||
|
||||
manager.shutdown()
|
||||
})
|
||||
})
|
||||
|
||||
describe("BackgroundManager.handleEvent - session.error", () => {
|
||||
|
||||
@@ -830,6 +830,8 @@ export class BackgroundManager {
|
||||
tasksToCancel.set(descendant.id, descendant)
|
||||
}
|
||||
|
||||
this.pendingNotifications.delete(sessionID)
|
||||
|
||||
if (tasksToCancel.size === 0) return
|
||||
|
||||
for (const task of tasksToCancel.values()) {
|
||||
@@ -866,6 +868,13 @@ export class BackgroundManager {
|
||||
subagentSessions.delete(task.sessionID)
|
||||
}
|
||||
}
|
||||
|
||||
for (const task of tasksToCancel.values()) {
|
||||
if (task.parentSessionID) {
|
||||
this.pendingNotifications.delete(task.parentSessionID)
|
||||
}
|
||||
}
|
||||
|
||||
SessionCategoryRegistry.remove(sessionID)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user