Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(update): cancelling the quit warning un-sticks restart to update

Chaitanya Girif184a9a682f4
diff --git a/src/main/index.ts b/src/main/index.ts
index c3a97530..872a40b3 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -11,7 +11,7 @@ import { homedir } from 'node:os';
import { request as httpsRequest } from 'node:https';
import { PtyManager, type SpawnOptions } from './pty';
import { resolveCommand as resolveCliCommand } from './shellEnv';
-import { initAutoUpdater } from './updater';
+import { initAutoUpdater, abortPendingRestart } from './updater';
import { RealtimeFloorWatcher } from './realtimeFloorWatcher';
import {
readConfig, writeConfig, setAgentTokenCap, resetConfig, ensureHarnessHome, ensureClaudePermissionsAccepted,
@@ -3581,7 +3581,11 @@ ipcMain.handle('app:confirmClose', () => {
teardownAndQuit();
});
ipcMain.handle('app:cancelClose', () => {
- // no-op — modal will close on the renderer side
+ // The modal closes on the renderer side. The one thing main owes anybody here
+ // is the truth about a restart-to-install: if this quit was one, it has just
+ // been called off, and whoever is waiting on it needs to hear that rather than
+ // sit disabled forever waiting for a process that is not going to die.
+ abortPendingRestart();
});
// Open a new floor (independent office window). Gated by the multiWindow flag
diff --git a/src/main/updater.ts b/src/main/updater.ts
index 4041ca81..164fa784 100644
--- a/src/main/updater.ts
+++ b/src/main/updater.ts
@@ -55,6 +55,38 @@ let started = false;
let lastFallbackCheck = 0;
/** Remembered so a status survives a renderer reload and can be re-served. */
let lastStatus: UpdateStatus | null = null;
+/**
+ * Resolved when a restart-to-install is CALLED OFF.
+ *
+ * `quitAndInstall()` does not report an outcome. It asks the app to quit, and
+ * the app may refuse: with agents running, the quit warning goes up and the user
+ * can cancel it. The handler used to return `{ ok: true }` the instant it made
+ * that request, so the renderer was told the restart succeeded while the app was
+ * still sitting there. Every surface that had disabled its button waiting for a
+ * process that was never going to die then had nothing to wait for, and the
+ * button stayed "restarting…" with no way back.
+ *
+ * So the handler now waits on this instead. Exactly one of two things happens:
+ * the app really quits and this never settles (the process is gone, nothing is
+ * left to tell), or the user cancels and `abortPendingRestart()` settles it and
+ * the handler reports the truth.
+ */
+let pendingRestart: (() => void) | null = null;
+
+/**
+ * The user backed out of the quit that a restart-to-install asked for.
+ *
+ * Called from the cancel path of the quit warning, which is the only place that
+ * knows a requested quit was refused. Safe to call when no restart is pending —
+ * an ordinary quit the user cancels is not our business.
+ */
+export function abortPendingRestart(): void {
+ if (!pendingRestart) return;
+ const resolve = pendingRestart;
+ pendingRestart = null;
+ logLine('quitAndInstall cancelled by the user at the quit warning');
+ resolve();
+}
/** Append-only breadcrumb trail in userData. The whole point of this file's
* existence is that the last failure left no trace anywhere. */
@@ -263,9 +295,17 @@ export function initAutoUpdater(getWebContents: () => WebContents | null): void
try {
const autoUpdater = await loadAutoUpdater();
logLine('quitAndInstall requested by the user');
+ // A restart already in flight is superseded rather than left dangling, so
+ // its caller is released instead of waiting on a resolve that never comes.
+ abortPendingRestart();
+ const cancelled = new Promise<void>((resolve) => { pendingRestart = resolve; });
autoUpdater.quitAndInstall();
- return { ok: true };
+ // Settles ONLY if the quit was called off. If the app is really going, the
+ // process exits here and the renderer's promise dies with the window.
+ await cancelled;
+ return { ok: false, error: 'cancelled' };
} catch (e) {
+ pendingRestart = null;
const error = errText(e);
logLine(`quitAndInstall failed: ${error}`);
emit({ state: 'error', message: error });
diff --git a/test/restart-cancel.test.cjs b/test/restart-cancel.test.cjs
new file mode 100644
index 00000000..5a536fea
--- /dev/null
+++ b/test/restart-cancel.test.cjs
@@ -0,0 +1,55 @@
+/**
+ * Cancelling the quit warning must un-stick restart-to-install.
+ *
+ * The bug: `quitAndInstall()` reports nothing. It ASKS the app to quit, and with
+ * agents running the app refuses and puts up the quit warning. The IPC handler
+ * returned `{ ok: true }` at that moment, so every surface that had disabled its
+ * button was told the restart had succeeded — and then the user cancelled, the
+ * app carried on living, and the button sat on "restarting…" forever with
+ * nothing left to resolve it.
+ *
+ * The fix is a wiring one and lives across two files, which is exactly why it is
+ * worth pinning: the handler waits for an outcome, and the cancel path is the
+ * thing that supplies it. Delete either half and the bug returns silently, with
+ * every unit test still green, because nothing pure is involved.
+ */
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const { readFileSync } = require('node:fs');
+const { join } = require('node:path');
+
+const read = (rel) => readFileSync(join(__dirname, '..', rel), 'utf8');
+
+test('the restart handler waits for an outcome instead of assuming one', () => {
+ const src = read('src/main/updater.ts');
+ const handler = src.slice(src.indexOf("ipcMain.handle('update:restartAndInstall'"));
+ const body = handler.slice(0, handler.indexOf('\n });'));
+
+ assert.ok(body.includes('await cancelled'),
+ 'the handler must await the cancellation signal — returning straight after '
+ + 'quitAndInstall() is what told the renderer a refused quit had succeeded');
+ assert.ok(!/return \{ ok: true \}/.test(body),
+ 'there is no success to report here: either the process dies, or the quit was called off');
+ assert.ok(/export function abortPendingRestart\(\): void/.test(src),
+ 'the cancel path needs a way in');
+});
+
+test('cancelling the quit warning is wired to the restart handler', () => {
+ const src = read('src/main/index.ts');
+ assert.ok(src.includes("import { initAutoUpdater, abortPendingRestart } from './updater';"),
+ 'index.ts must import the abort');
+ const handler = src.slice(src.indexOf("ipcMain.handle('app:cancelClose'"));
+ const body = handler.slice(0, handler.indexOf('\n});'));
+ assert.ok(body.includes('abortPendingRestart()'),
+ 'app:cancelClose is the ONLY place that knows a requested quit was refused; '
+ + 'if it stops calling this, the restart button goes back to hanging');
+});
+
+test('the renderer restores its notice when the restart reports a cancel', () => {
+ const src = read('src/renderer/src/components/UpdateToast.tsx');
+ const fn = src.slice(src.indexOf('const restart = async'));
+ const body = fn.slice(0, fn.indexOf('\n };'));
+ assert.ok(/if \(!res\.ok\) \{ setStatus\(prev\); setBusy\(false\); \}/.test(body),
+ 'a cancelled restart has to put the notice back AND clear busy — clearing one '
+ + 'without the other leaves either a dead button or no way to retry');
+});