Skip to content

fix(desktop): make quit bounded and re-entrancy safe so SIGTERM and Cmd+Q always exit - #4787

Merged
yomgui merged 2 commits into
devfrom
fix/desktop-quit-path
Sep 10, 2026
Merged

yomgui merged 2 commits into
devfrom
fix/desktop-quit-path

Conversation

@yomgui

@yomgui yomgui commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Symbolicated cause

Five OpenWork Enterprise-*.ips reports (0.18.42–0.18.45, Electron 43.2.0 arm64, dSYM UUID 4C4C44E7-5555-3144-A15C-8DC0CC013F82 matched) all fault at

electron::ElectronBrowserClient::AppendExtraCommandLineSwitches  electron_browser_client.cc:522
  CHECK_EQ(program, child_path) << "Aborted from launching unexpected helper executable";

program = base::MakeAbsoluteFilePath(GetProgram()) is realpath(): it returns empty once the helper binary no longer exists on disk. Two field triggers, both a Chromium relaunch of a dead helper while the main loop was still running:

pids frame 1 → entry
71727, 72968, 67054 GpuProcessHost::LaunchGpuProcess ← VizProcessTransportFactory::OnGpuProcessLost ← HostFrameSinkManager::OnConnectionLost
74183, 57033 UtilityProcessHost::Start ← ServiceProcessHost::Launch<NetworkService> ← NetworkConnectionTracker::Initialize (Mojo pipe error)

Controls on a packaged build from this branch: bundle intact + SIGKILL GPU helper → relaunch succeeds, no crash; bundle removed + SIGKILL GPU helper → SIGTRAP at the same CHECK (variant A reproduced); bundle removed + SIGTERM → SIGTRAP at the same CHECK via a third trigger, our own showShutdownScreen() → loadURL("data:…") → RenderFrameHostManager::CreateSpeculativeRenderFrameHost. The crashed processes were leaked eval launches (started 15:17–15:22, killed 16:54) whose cp -Rc bundle copies had already been removed by world disposal. The security CHECK is Electron's and stays; this PR removes the one child launch our quit path itself started and makes the quit finish so nothing lingers past the bundle.

Why the app did not exit (three bugs in our code)

  1. Re-entrant app.quit(). On an install with nothing running, the before-quit teardown settled without leaving the microtask queue, so app.quit() ran inside Emit("before-quit") of the signal-driven Browser::Quit(). The nested Quit() set is_quitting_ = true and closed the windows; the outer one returned prevent_default = true and overwrote it with false. OnWindowAllClosed then took the non-quitting branch → window-all-closed → macOS kept a windowless process forever (released 0.18.46: fresh --blank-slate + SIGTERM never exits). Deferring the quit to a macrotask on the same build exits in ~160 ms.
  2. Startup modal during quit. A quit that arrives while app.whenReady().then(async …) still awaits mainWindow.loadFile() aborts the load (ERR_FAILED (-2)), the chain rejects, and its .catch called dialog.showErrorBox — a synchronous -[NSAlert runModal] that blocked the main thread (sampled) before reaching its own app.quit(). No JS failsafe can run behind a modal.
  3. Shutdown screen spawned a renderer (data: navigation) — the third trigger above.

Fix (smallest diff)

  • apps/desktop/electron/quit-sequence.mjs: single-shot sequencer — always resumes app.quit() from a fresh macrotask, caps the service stop at 10 s, quits on rejection/throw, falls back to app.exit(0) 5 s after a quit that never reaches will-quit.
  • main.mjs: sequencer wired to before-quit/will-quit; shutdown screen replaces the document in place (document.open/write, same renderer); startup .catch and render-process-gone recovery stand down while a quit is in progress.
  • Evals: SurfaceHandle.exit (local host resolves the spawned process's exit code/signal), world desktop-quit-path.ts, journey desktop-quit-path.e2e.test.ts (placement local), new desktop-quit-enterprise phase in packaged-smoke.mjs.

Repro matrix (packaged enterprise build, macOS 26.6.2 arm64, settle 20 s)

case before (origin/dev) after (this PR)
fresh + SIGTERM alive after 20 s exit 0 in 139 ms
fresh + Browser.close (Cmd+Q path) alive after 20 s exit 0 in 158 ms
activated + SIGTERM exit 0 in 198 ms exit 0 in 160 ms
activated + Browser.close exit 0 in 211 ms exit 0 in 176 ms
bundle removed + SIGTERM (fresh / activated) SIGTRAP (CHECK, renderer spawn) exit 0 in 2.1 s / 1.8 s
bundle removed + SIGKILL GPU helper SIGTRAP (CHECK, GPU relaunch) SIGTRAP — Chromium's own relaunch; upstream (Electron electron_browser_client.cc:522, by design), not reachable from app code
journey, quit ~5 s after CDP up (startup load still pending) 0/4 pass 4/4 pass

Proof

check command lane result
unit pnpm --dir apps/desktop test local 405 tests, 404 pass, 0 fail, 1 skip (pre-existing is a no-op off macOS, same on origin/dev); 7 new in quit-sequence.test.mjs
journey red OPENWORK_EVAL_ELECTRON_BINARY=<before build> pnpm evals:e2e desktop-quit-path --local local exit 1, 0 passed / 4 failed (still running after 15002ms)
journey green OPENWORK_EVAL_ELECTRON_BINARY=<this build> pnpm evals:e2e desktop-quit-path --local local exit 0, 4 passed / 0 failed
Linux CI packaged-smoke → desktop-quit-enterprise phase (run 34451642113) CI 4 passed / 0 failed, exit 0 in 22–38 ms each; crash-report half recorded skipped — needs: macOS DiagnosticReports (linux has none)
typecheck pnpm --filter @openwork/desktop typecheck:electron local + CI pass (second commit typed the sequencer's timer handles)

Journey runs on the PR head 73e45c959 are published in the test-evidence comment (four sections). Lane: local. The journey is placement: 'local' like its packaged siblings — it needs the macOS packaged binary and reads ~/Library/Logs/DiagnosticReports; on Linux the crash-report half records skipped — needs: macOS DiagnosticReports and the exit signal is the witness.

Not done here: no .github/ changes; no host updater/ShipIt/defaults changes (eval launches run with a redirected HOME).

…md+Q always exit

before-quit resumed the quit with app.quit() from a microtask inside the
before-quit emit; Electron's Browser::Quit() then overwrote is_quitting_ and a
never-activated install stayed alive with no window after SIGTERM. A quit that
arrived mid-startup rejected the whenReady chain and its showErrorBox modal
blocked the main thread forever. The shutdown screen navigated to a data: URL,
which spawns a renderer and trips CHECK_EQ(program, child_path) once the app
bundle is gone from disk.

The quit sequencer always resumes from a fresh macrotask, caps the service
teardown at 10 s, quits on rejection, and falls back to app.exit() when will-quit
never arrives. The shutdown screen replaces the document in place. Startup and
renderer-crash dialogs stand down while a quit is in progress.
@vercel

vercel Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
openwork-app Skipped Skipped Sep 10, 2026 7:46am UTC
openwork-den Skipped Skipped Sep 10, 2026 7:46am UTC
openwork-diagnostics Skipped Skipped Sep 10, 2026 7:46am UTC
openwork-landing Skipped Skipped Sep 10, 2026 7:46am UTC

@yomgui

yomgui commented Sep 10, 2026 •

Copy link
Copy Markdown
Member Author

Composed from four publisher renders (--dry-run) for PR head 73e45c959; the composed review-app path was unavailable locally (public blob store), and this spec records no screenshots.

Test evidence — a fresh enterprise install exits within 15s of SIGTERM without crashing — ✅ passed

SHA 73e45c9 · engine v1

✅ passed · 2 expectations passed · 0 failed · 0 pending

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. A fresh enterprise install exits with code 0 within 15000ms of SIGTERM

exit code 0 signal null after 170ms

  • ✅ PASS A fresh enterprise install exits with code 0 within 15000ms of SIGTERM — exit code 0 signal null after 170ms

ℹ️ ASSERTION — 2. No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the fresh install after SIGTERM

no new OpenWork*.ips

  • ✅ PASS No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the fresh install after SIGTERM — no new OpenWork*.ips

Test run created 2026-09-10T07:50:39.085Z · Source: evals/results/test-runs/2026-09-10T07-50-39-084Z-a-fresh-enterprise-install-exits-within-15s-of-sigterm-without-crashing/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4787 --test-run 2026-09-10T07-50-39-084Z-a-fresh-enterprise-install-exits-within-15s-of-sigterm-without-crashing


Test evidence — a fresh enterprise install exits within 15s of normal quit without crashing — ✅ passed

SHA 73e45c9 · engine v1

✅ passed · 2 expectations passed · 0 failed · 0 pending

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. A fresh enterprise install exits with code 0 within 15000ms of normal quit

exit code 0 signal null after 82ms

  • ✅ PASS A fresh enterprise install exits with code 0 within 15000ms of normal quit — exit code 0 signal null after 82ms

ℹ️ ASSERTION — 2. No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the fresh install after normal quit

no new OpenWork*.ips

  • ✅ PASS No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the fresh install after normal quit — no new OpenWork*.ips

Test run created 2026-09-10T07:50:46.123Z · Source: evals/results/test-runs/2026-09-10T07-50-46-123Z-a-fresh-enterprise-install-exits-within-15s-of-normal-quit-without-crashing/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4787 --test-run 2026-09-10T07-50-46-123Z-a-fresh-enterprise-install-exits-within-15s-of-normal-quit-without-crashing


Test evidence — a activated enterprise install exits within 15s of SIGTERM without crashing — ✅ passed

SHA 73e45c9 · engine v1

✅ passed · 2 expectations passed · 0 failed · 0 pending

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. A activated enterprise install exits with code 0 within 15000ms of SIGTERM

exit code 0 signal null after 158ms

  • ✅ PASS A activated enterprise install exits with code 0 within 15000ms of SIGTERM — exit code 0 signal null after 158ms

ℹ️ ASSERTION — 2. No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the activated install after SIGTERM

no new OpenWork*.ips

  • ✅ PASS No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the activated install after SIGTERM — no new OpenWork*.ips

Test run created 2026-09-10T07:50:50.724Z · Source: evals/results/test-runs/2026-09-10T07-50-50-724Z-a-activated-enterprise-install-exits-within-15s-of-sigterm-without-crashing/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4787 --test-run 2026-09-10T07-50-50-724Z-a-activated-enterprise-install-exits-within-15s-of-sigterm-without-crashing


Test evidence — a activated enterprise install exits within 15s of normal quit without crashing — ✅ passed

SHA 73e45c9 · engine v1

✅ passed · 2 expectations passed · 0 failed · 0 pending

verdict passed · 0 user observations · 0 probes · steps 0/0

ℹ️ ASSERTION — 1. A activated enterprise install exits with code 0 within 15000ms of normal quit

exit code 0 signal null after 143ms

  • ✅ PASS A activated enterprise install exits with code 0 within 15000ms of normal quit — exit code 0 signal null after 143ms

ℹ️ ASSERTION — 2. No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the activated install after normal quit

no new OpenWork*.ips

  • ✅ PASS No crash report appears in /Users/guillaume/Library/Logs/DiagnosticReports for the activated install after normal quit — no new OpenWork*.ips

Test run created 2026-09-10T07:50:55.488Z · Source: evals/results/test-runs/2026-09-10T07-50-55-488Z-a-activated-enterprise-install-exits-within-15s-of-normal-quit-without-crashing/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4787 --test-run 2026-09-10T07-50-55-488Z-a-activated-enterprise-install-exits-within-15s-of-normal-quit-without-crashing


@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Warden review summary — Clear

Native findings: 0. Blocking policy matches before consolidation: 0. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run

Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (80006 ms), confidentiality-review (107970 ms), spec-provenance-review (129901 ms), desktop-den-sync-review (124046 ms).

Blockers

  • None.

Advisories

  • None.

Needs recheck

  • None.

Observed review-thread metrics

  • Unique observed run attempts in retained window: 2
  • Distinct heads in retained window: 2
  • Current unresolved Warden threads: 0 of 0 observed
  • Observed resolved/unresolved transitions in retained snapshots: 0 / 0
  • First observed resolved/unresolved (state at first collection, not event time): 0 / 0
  • Precision: unavailable (no adjudications; no TP/FP values are inferred)
  • Observation window: 2/20 run attempts retained; truncated: false
  • Transition snapshot: 0/0 current attributed threads retained (limit 500); truncated: false

Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority.

diff-warden[bot]
diff-warden Bot previously approved these changes Sep 10, 2026

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (ad3d5b91ecd849beec96c14b99e1cf872475966a). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@vercel
vercel Bot temporarily deployed to Preview – openwork-den September 10, 2026 07:46 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 10, 2026 07:46 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 10, 2026 07:46 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 10, 2026 07:46 Inactive

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (73e45c95906f78e65f93ddf7ad928181bc04befb). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

This branch was previously deployed

4 inactive deployments
Preview – openwork-diagnostics — 73e45c95 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-landing — 73e45c95 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-app — 73e45c95 Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-den — 73e45c95 Deployed Sep 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant