From 5d99e9ab64dc66ec522a758a52d37aa30c0bba9b Mon Sep 17 00:00:00 2001 From: Gladdonilli Date: Tue, 13 Jan 2026 14:48:43 +0800 Subject: [PATCH] fix: address remaining PR review feedback - Add pendingByParent cleanup in pruneStaleTasksAndNotifications - Add double-release guard in launch error handler (L170) - Add concurrency release in resume error handler (L326) --- src/features/background-agent/manager.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index c2ad078f..369ee15d 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -183,6 +183,7 @@ export class BackgroundManager { existingTask.completedAt = new Date() if (existingTask.concurrencyKey) { this.concurrencyManager.release(existingTask.concurrencyKey) + existingTask.concurrencyKey = undefined // Prevent double-release } this.markForNotification(existingTask) this.notifyParentSession(existingTask).catch(err => { @@ -340,6 +341,11 @@ export class BackgroundManager { const errorMessage = error instanceof Error ? error.message : String(error) existingTask.error = errorMessage existingTask.completedAt = new Date() + // Release concurrency on resume error (matches launch error handler) + if (existingTask.concurrencyKey) { + this.concurrencyManager.release(existingTask.concurrencyKey) + existingTask.concurrencyKey = undefined // Prevent double-release + } this.markForNotification(existingTask) this.notifyParentSession(existingTask).catch(err => { log("[background-agent] Failed to notify on resume error:", err) @@ -732,6 +738,16 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea this.concurrencyManager.release(task.concurrencyKey) task.concurrencyKey = undefined // Prevent double-release } + // Clean up pendingByParent to prevent stale entries + if (task.parentSessionID) { + const pending = this.pendingByParent.get(task.parentSessionID) + if (pending) { + pending.delete(task.id) + if (pending.size === 0) { + this.pendingByParent.delete(task.parentSessionID) + } + } + } this.clearNotificationsForTask(taskId) this.tasks.delete(taskId) subagentSessions.delete(task.sessionID)