Repository navigation
fix(menubar): no-output watchdog, lock signal cleanup, dead-pid takeover, serve orphan reaping - #1120
Merged
Merged
Conversation
…ver, serve orphan reaping The 0.9.20 menubar never completed a fetch on a large corpus: the cache version bump forced a full rehydration, DataClient's fixed 45s kill ended it mid-transaction, cache-refresh-lock had no signal cleanup so the dead holder's lock survived, and DEFAULT_WAIT_MS (30s) < DEFAULT_STALE_MS (90s) meant no waiter could ever recover it. A. Swift port of #1096's watchdog. CLIWatchdog holds the constants and the pure verdict; spawns and the resident serve child set CODEBURN_PROGRESS=1; the window restarts on any stdout/stderr byte; 45s silence, 10min cold floor until the first payload, 15min ceiling, SIGTERM then SIGKILL after 5s. ServeConnection's fixed 60s warm cap becomes the same silence window, re-armed by each progress frame, and a spent death budget is now a 5-minute cooldown instead of disabling the resident for the app run. B. cache-refresh-lock arms SIGINT/SIGTERM cleanup the way session-cache does for hydrating.lock, so a SIGTERMed holder unlinks its own lock. C. Staleness also opens on a dead holder pid, and the waiter budget derives from staleMs so it can never expire before the gate it waits for. A live holder - fresh heartbeat, pid answers signal 0 - is never taken from. parser.ts heartbeats through the lock wait, the one silent stretch left. D. The app closes its end of a retired child's stdin (dropping the handle left the pipe alive inside the Process), reaps every serve child synchronously at quit, and records pid+argv so a crash-orphaned child is reaped next launch. serve's final exit no longer runs through a monkeypatched process.exit, and its post-drain cleanup is bounded. Closes #1117
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1117 — the 0.9.20 menubar refresh livelock (fixed 45s kill × leaked refresh lock × waiter-gives-up-before-stale-gate), diagnosed live on a 21k-file corpus where the menubar had not completed a single fetch since upgrade.
A — Swift watchdog (port of #1096's electron semantics, same constants)
CLIWatchdog.swift: pure verdict type — 45s silence window (warm), 10min cold floor (raises the silence window, still finite: a child that never emits a byte dies at 10min), 15min hard ceiling, SIGTERM→5s→SIGKILL. Spawns setCODEBURN_PROGRESS=1and any stdout/stderr activity re-arms the window; progress frames filtered out of error text. ServeConnection warm-up loses its fixed 60s cap (keepalive-driven + ceiling), andensureStarted()gets a re-entry path: the death budget resets after a 300s cooldown, so a transient triple-death no longer kills the resident serve for the app's lifetime.B — Lock signal cleanup
cache-refresh-lock.tsarms SIGINT/SIGTERM cleanup exactly as session-cache does for hydrating.lock (unlink-if-ours, re-raise, armed once, cleared on release).C — Waiter can outlive an abandoned lock
Abandoned = heartbeat mtime older than staleMs OR recorded pid dead (kill(pid,0)/EPERM probe, win32-safe). Applied to the wait loop, takeover, and the takeover-guard file.
DEFAULT_WAIT_MSdeleted — the default wait is nowstaleMs + 30sso the two can never drift out of order again. Live holders are safe by construction: heartbeat inside staleMs AND live pid; takeover still requires an unchanged observation under the exclusive guard. The lock wait itself now emits keepalives (it was the one legitimately-silent stretch that would have tripped the new window).D — Serve orphan prevention (root causes found in code)
applicationWillTerminate'sTask { await shutdown() }almost certainly never ran before exit — quit-time cleanup was effectively absent. Now a synchronous lock-guardedServeChildRegistryreap.reapOrphanServe(suffix argv match — the shebang rewrite makes exact match impossible; documented).process.exitbound beforerunStdioServe(an in-flight request past the drain bound left a monkeypatched exit that threw), post-drain watcher await bounded.Verification (re-run after rebasing onto clean main)
swift build clean, 193 Swift tests / 28 suites (+10 new incl. cold-floor-still-kills and stderr-keepalive cases) · tsc clean ·
test:locks31/31 (agent ran it 3× during development, no flakes; 3 of 4 new lock tests fail with the fix reverted — proven non-vacuous) · full CLI suite 3200 green · app suite untouched and green.Ships in 0.9.21: this is the mac-app half; the CLI half (#1097 partial saves + the perf stack) is already on main. All three surfaces (CLI, desktop, menubar) release together.