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.
This commit is contained in:
l0ng-ai
2026-11-17 09:34:04 +08:00
committed by GitHub
parent a7464bf631
commit a52e416ad5
+9 -2
View File
@@ -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);