From dd95d5940241ebf14c108ad5845e29eab1db1fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=AF=E6=9D=A8?= Date: Thu, 16 Apr 2026 12:02:43 +0800 Subject: [PATCH] fix(cli-run): cover all terminal paths for background task marker cleanup Address review feedback: add updateBackgroundTaskMarker() calls to three additional terminal paths in BackgroundManager that were missing marker cleanup, which could leave stale "active" markers and prevent CLI run mode from exiting: - processKey() startTask error handler - handleEvent() session error (non-retryable) - pruneStaleTasksAndNotifications() stale task cleanup Closes #3452 --- src/features/background-agent/manager.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index 2350d0dbc..e50e8f468 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -433,6 +433,9 @@ export class BackgroundManager { await this.abortSessionWithLogging(item.task.sessionID, "startTask error cleanup") } + // Update continuation marker for CLI run mode + this.updateBackgroundTaskMarker(item.task.parentSessionID) + this.markForNotification(item.task) this.enqueueNotificationForParent(item.task.parentSessionID, () => this.notifyParentSession(item.task)).catch(err => { log("[background-agent] Failed to notify on startTask error:", err) @@ -1329,6 +1332,11 @@ export class BackgroundManager { SessionCategoryRegistry.remove(task.sessionID) } + // Update continuation marker for CLI run mode + if (task.parentSessionID) { + this.updateBackgroundTaskMarker(task.parentSessionID) + } + this.markForNotification(task) this.enqueueNotificationForParent(task.parentSessionID, () => this.notifyParentSession(task)).catch(err => { log("[background-agent] Error in notifyParentSession for errored task:", { taskId: task.id, error: err }) @@ -1964,6 +1972,10 @@ export class BackgroundManager { } } this.cleanupPendingByParent(task) + // Update continuation marker for CLI run mode + if (task.parentSessionID) { + this.updateBackgroundTaskMarker(task.parentSessionID) + } this.markForNotification(task) this.enqueueNotificationForParent(task.parentSessionID, () => this.notifyParentSession(task)).catch(err => { log("[background-agent] Error in notifyParentSession for stale-pruned task:", { taskId: task.id, error: err })