fix(background-agent): improve parent session ID handling in task management
Enhance the BackgroundManager to properly clean up pending tasks when the parent session ID changes. This prevents stale entries in the pending notifications and ensures that the cleanup process is only executed when necessary, improving overall task management reliability.
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
"claude-code-hooks",
|
||||
"auto-slash-command",
|
||||
"edit-error-recovery",
|
||||
"sisyphus-task-retry",
|
||||
"prometheus-md-only",
|
||||
"start-work",
|
||||
"sisyphus-orchestrator"
|
||||
|
||||
@@ -262,7 +262,11 @@ export class BackgroundManager {
|
||||
}): Promise<BackgroundTask> {
|
||||
const existingTask = this.tasks.get(input.taskId)
|
||||
if (existingTask) {
|
||||
if (input.parentSessionID !== existingTask.parentSessionID) {
|
||||
// P2 fix: Clean up old parent's pending set BEFORE changing parent
|
||||
// Otherwise cleanupPendingByParent would use the new parent ID
|
||||
const parentChanged = input.parentSessionID !== existingTask.parentSessionID
|
||||
if (parentChanged) {
|
||||
this.cleanupPendingByParent(existingTask) // Clean from OLD parent
|
||||
existingTask.parentSessionID = input.parentSessionID
|
||||
}
|
||||
if (input.parentAgent !== undefined) {
|
||||
@@ -281,8 +285,8 @@ export class BackgroundManager {
|
||||
const pending = this.pendingByParent.get(input.parentSessionID) ?? new Set()
|
||||
pending.add(existingTask.id)
|
||||
this.pendingByParent.set(input.parentSessionID, pending)
|
||||
} else {
|
||||
// Don't re-add completed/cancelled tasks; clean any stale entry
|
||||
} else if (!parentChanged) {
|
||||
// Only clean up if parent didn't change (already cleaned above if it did)
|
||||
this.cleanupPendingByParent(existingTask)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user