From a52e416ad5217023275f7a889773191f84ad5f09 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Tue, 17 Nov 2026 09:34:04 +0800 Subject: [PATCH] fix(run): a run closed or restarted while starting does not leave its process behind (#3862) Closing a Java run tab while the plugin list for remote Java agents was loading still started the process, and nothing owned it afterwards. The start is now abandoned when the session was stopped, closed or started again meanwhile, and a process that started anyway is stopped. --- src/features/run/store.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/features/run/store.ts b/src/features/run/store.ts index b8426f261..0d6800a00 100644 --- a/src/features/run/store.ts +++ b/src/features/run/store.ts @@ -1017,6 +1017,8 @@ async function startRunIn( } if (runtimes.get(sessionId)?.generation !== generation) return getSession(sessionId) ?? null; const agentNote = await remoteJavaAgentNote(started); + if (runtimes.get(sessionId)?.generation !== generation || getSession(sessionId)?.stopped) + return getSession(sessionId) ?? null; if (agentNote) enqueue(sessionId, { kind: "system", text: agentNote }); const processStarted = performance.now(); const request = { id: nextRequestId(), controller: new AbortController() }; @@ -1027,12 +1029,17 @@ async function startRunIn( }).finally(() => { if (rt.resolveRequest === request) delete rt.resolveRequest; }); - if (request.controller.signal.aborted || getSession(sessionId)?.stopped) { + // Stopped, closed or started again meanwhile: nothing would own this process. + if ( + request.controller.signal.aborted || + !getSession(sessionId) || + getSession(sessionId)?.stopped || + runtimes.get(sessionId)?.generation !== generation + ) { await call(commands.runStop(info.id)).catch(() => undefined); return getSession(sessionId) ?? null; } console.info("Run process started", { name: config.name, ms: performance.now() - processStarted }); - if (runtimes.get(sessionId)?.generation !== generation) return getSession(sessionId) ?? null; if (info.pty && rt.terminalSize) void commands.runResize(info.id, rt.terminalSize.cols, rt.terminalSize.rows); // The process may already have exited (fast commands) before we got its id. const exited = pendingExits.get(info.id);