Q57: quitting stops running sessions and waits for them to record their end

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 10:09:16 -04:00
1 parent d72333a04c
commit 3bc0d811cb
4 files changed
+71 -9

No files matched your search

+16 -2
View File
@@ -11,6 +11,9 @@ import { SkillService } from "./services/skill-service";
import { startProviderBackgroundWorker } from "./app/provider-background-worker";
import { recoverInterruptedWork } from "./app/startup-recovery";
import { startTaskQueueWorker } from "./app/task-queue-worker";
import { stopAllRunsAndWait } from "./services/run-control";
const QUIT_GRACE_MS = 10_000;
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -61,10 +64,21 @@ if (!app.requestSingleInstanceLock()) {
win.focus();
});
app.on("before-quit", () => {
let shutdown: "running" | "draining" | "drained" = "running";
app.on("before-quit", (event) => {
if (shutdown === "drained") return;
// Hold every exit request until running sessions are stopped and have recorded how they ended.
event.preventDefault();
if (shutdown === "draining") return;
shutdown = "draining";
stopProviderBackgroundWorker();
stopTaskQueueWorker();
connection.close();
void stopAllRunsAndWait("The app was closing.", QUIT_GRACE_MS).then((unsettled) => {
if (unsettled > 0) console.warn(`[quit] ${unsettled} run(s) did not settle within ${QUIT_GRACE_MS}ms; startup recovery will re-queue them.`);
connection.close();
shutdown = "drained";
app.quit();
});
});
});