From b5bd837025c718ab3ab9d40363ca756a7b5958cd Mon Sep 17 00:00:00 2001 From: Jeremy Gollehon Date: Thu, 15 Jan 2026 00:16:35 -0800 Subject: [PATCH] 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. --- assets/oh-my-opencode.schema.json | 1 + src/features/background-agent/manager.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/oh-my-opencode.schema.json b/assets/oh-my-opencode.schema.json index b215a7c8..308b177c 100644 --- a/assets/oh-my-opencode.schema.json +++ b/assets/oh-my-opencode.schema.json @@ -77,6 +77,7 @@ "claude-code-hooks", "auto-slash-command", "edit-error-recovery", + "sisyphus-task-retry", "prometheus-md-only", "start-work", "sisyphus-orchestrator" diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index f166b476..40870190 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -262,7 +262,11 @@ export class BackgroundManager { }): Promise { 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) }