diff --git a/packages/core/src/services/shellExecutionService.ts b/packages/core/src/services/shellExecutionService.ts index 95b3f2d17b..ffc714b375 100644 --- a/packages/core/src/services/shellExecutionService.ts +++ b/packages/core/src/services/shellExecutionService.ts @@ -1341,6 +1341,11 @@ export class ShellExecutionService { const activePty = this.activePtys.get(pid); const activeChild = this.activeChildProcesses.get(pid); + // If the process has already exited, there is no need to background it. + if (!activePty && !activeChild) { + return; + } + const resolvedSessionId = sessionId ?? activePty?.sessionId ?? activeChild?.sessionId; const resolvedCommand = diff --git a/packages/core/src/tools/shell.ts b/packages/core/src/tools/shell.ts index 0407cb99bf..053cc4b00d 100644 --- a/packages/core/src/tools/shell.ts +++ b/packages/core/src/tools/shell.ts @@ -515,7 +515,13 @@ export class ShellToolInvocation extends BaseToolInvocation< if (shouldAutoPromote && currentPid) { if (this._autoPromoteTimer) clearTimeout(this._autoPromoteTimer); this._autoPromoteTimer = setTimeout(() => { - ShellExecutionService.background(currentPid!); + const sessionId = + this.context.config?.getSessionId?.() ?? 'default'; + ShellExecutionService.background( + currentPid!, + sessionId, + strippedCommand, + ); }, waitMs); } };