fix(background-agent): prevent memory leak - completed tasks now removed from Map (#302)

- Add finally block in notifyParentSession() to ensure task cleanup
- Call tasks.delete(taskId) after notification sent or on error
- Prevents memory accumulation when tasks complete or fail
- taskId captured before setTimeout to ensure proper cleanup in async context

🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-28 14:59:06 +09:00
committed by GitHub
parent 092718f82d
commit 18d134fa57

View File

@@ -325,6 +325,7 @@ export class BackgroundManager {
log("[background-agent] Sending notification to parent session:", { parentSessionID: task.parentSessionID })
const taskId = task.id
setTimeout(async () => {
try {
const messageDir = getMessageDir(task.parentSessionID)
@@ -344,10 +345,13 @@ export class BackgroundManager {
},
query: { directory: this.directory },
})
this.clearNotificationsForTask(task.id)
this.clearNotificationsForTask(taskId)
log("[background-agent] Successfully sent prompt to parent session:", { parentSessionID: task.parentSessionID })
} catch (error) {
log("[background-agent] prompt failed:", String(error))
} finally {
this.tasks.delete(taskId)
log("[background-agent] Removed completed task from memory:", taskId)
}
}, 200)
}