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)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user