Repository navigation
fix(app): no-output watchdog replaces fixed timeouts; graceful kills; cold floor everywhere; orphan serve reaping - #1096
Merged
Merged
Conversation
… cold floor everywhere; orphan serve reaping The desktop app capped every read at 45s of TOTAL runtime, so a slow machine's warm `optimize` (52.5s on 0.9.20, 39.6s on main) was SIGKILLed mid-parse and the panel painted a red "timed out" that a 60s poll then reproduced forever. - cli.ts: the read timeout is now a no-output watchdog. The window restarts on every byte the child writes (serve: every frame carrying that request's id), so only a genuinely silent child times out. A 15-minute absolute ceiling still reaps a livelocked child. Every read spawn sets CODEBURN_PROGRESS=1 so a long parse heartbeats through it; progress lines are stripped from any surfaced stderr so they can never become the error message. - cli.ts: a timed-out child gets SIGTERM first and SIGKILL only after a 5s grace, on both the spawn and the serve branch. That lets the CLI's signal cleanup publish its partial parse and release the cross-process refresh lock instead of leaving both stale. - main.ts: the 10-minute cold floor now covers EVERY read while the first hydration is still running, not just the overview. Sections start polling the moment `ready` flips (which an overview error also does), and a 45s section spawn queued behind the cold parse was killed on arrival. - main.ts/renderer: a timeout raised while the hydration is still running is flagged `cold`, and the renderer keeps its indexing splash (and keeps the sections gated) instead of latching ready and painting CliErrorPanel. Only timeouts are flagged; a permission or nonzero failure still surfaces. - cli.ts/main.ts: the resident serve child's pid is recorded under userData and a serve orphaned by a previous crash is reaped at launch, after `ps` confirms the pid still belongs to a codeburn serve. - src/main.ts: `codeburn serve` exits explicitly once its stdin closes, so a handle outliving the transport cannot keep the child alive as an orphan.
…M grace A settings mutation replaces the resident serve child, which may be mid-write: the same lock hazard a timed-out read has, so it gets the same treatment. restartAfterMutation and destroy now go through killGracefully instead of SIGKILL. reapAll's one-shot loop stays a hard kill and now says why - quit has a 1.5s flush budget, shorter than the grace, so waiting one out would wedge the quit, and a one-shot read holds no lock worth releasing.
F1 - `codeburn serve` lost an in-flight request's response when stdin closed mid-flight: runStdioServe returned before its queue drained, and the explicit process.exit(0) then hit runCaptured's monkeypatched exit, throwing ExitSignal and exiting 1 with the frame never written. The finally now awaits the queue. F2 - the SIGTERM rationale was false. armSignalCleanup unlinks the refresh lock and re-raises; it publishes no partial cache, and a lock left by SIGKILL already self-heals through the stale-pid takeover. SIGTERM-first is kept for the real (smaller) benefit - a clean lock release instead of a takeover - and every comment plus the CHANGELOG now says only that. F3 - the cold gate had no exit. overviewWarmed only flips on success, so an install that can never hydrate sat behind an indexing splash forever with no error and no route to the CLI recovery. The cold claim now expires with the cold window itself. F4 - the real CLI does not heartbeat the way the demo did: a cold parse's inter-provider cache save measured 31.6s of total silence, which a 45s window survives only until the machine is 1.5x slower. Under CODEBURN_PROGRESS a running parse now emits a keepalive every 10s regardless of phase, so silence genuinely means stopped. Consumers that do not know the event ignore it. F5 - the orphan-reap identity check matched any `cli.js` running `serve`. The pidfile now records the exact argv and `ps -ww` must match it exactly. F6 - bump() re-armed the watchdog after settle, leaving a timer finish() never clears when a killed child's buffered output landed. F7 - kill paths dropped the child from activeChildren before SIGTERM and the SIGKILL backstop was unref'd, so a quit inside the 5s grace orphaned a child that ignores SIGTERM. It now stays registered until it actually dies. N8 - the silence test wrote its only byte at t~0, so it passed without the re-arm. The byte now lands mid-window and the kill is asserted from it. N9 - documented why mutations keep a plain total cap.
… grace test G1a - the stdin-EOF drain is now bounded (Promise.race against 45s, overridable via CODEBURN_SERVE_DRAIN_MS for the test). Generous enough that no legitimate request answered at EOF comes near it, and an async-wedged one releases the child instead of turning it into the orphan the drain was added to prevent. The comment names the ceiling: a SYNCHRONOUSLY wedged parse never yields to this timer or to any other JS path, and only a signal can end that process. G1b - Windows is the majority of the desktop fleet and had no orphan escape at all: no ps, and no stdin-close recourse once the app has crashed. The reap now works there. tasklist cannot report argv (image name and window title only) and wmic is gone from current Windows, so the command line comes from Get-CimInstance Win32_Process. Match discipline is unchanged - exact argv - with quoting normalized on both sides, because we record a plain space-joined argv while Windows reports the real quoted command line; a path with spaces still round-trips. serveCommandMatches is extracted and tested directly. G2 - the grace test raced node's cold boot (a 300ms window). The child now emits one byte the moment it is ready, so the watchdog window is measured from READINESS, not from spawn: boot cost cannot eat it at any machine speed. Timeout raised on top of that. 6/6 green under 8 busy loops. G3 - a served request heartbeats for its whole duration now, not just its parse: the wrap moved to the one seam (runCaptured) that also covers aggregation and payload serialization, whose ~8s tail lands back-to-back with the parse's own quiet stretches. The one-shot path keeps the parse-only wrap, where an 8s tail is comfortably inside the window on its own, and the CHANGELOG now says exactly that instead of claiming every phase. G4 - stillCold() anchors to coldStartBegan ?? bootedAt. Text: the cold-timeout bound no longer claims to restore the "locate the CLI" recovery (that is a not-found state, never cold-flagged), and the CHANGELOG states the >15min case honestly - the ceiling still ends it, but partial cache saves mean successive polls converge rather than each rescanning from nothing.
This was referenced Aug 22, 2026
Closed
pull Bot
pushed a commit
to TheTechOddBug/codeburn
that referenced
this pull request
Aug 24, 2026
…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 getagentseal#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 getagentseal#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.
The failure class
Desktop-app telemetry across 386 installs plus a local repro established a
timeout failure class that is not a slow-machine annoyance but a permanent
broken state.
app/electron/cli.tscapped every read atDEFAULT_TIMEOUT_MS = 45_000oftotal runtime, so any section command —
optimize,yield,models,sessions,spend,audit,act report,plan— that ran longer than 45swas SIGKILLed mid-parse. On the repro machine a warm
optimizemeasures52.5s on 0.9.20 and 39.6s on main: over the cliff, and near it. The kill
surfaced as a red
CliErrorPanel"timed out",usePolledre-polled 60s later,and the whole thing repeated forever — the cache never persisted, so every retry
restarted the same doomed scan.
Three compounding pieces:
WARMUP_TIMEOUT_MS(10 min) covered only the overview status while cold.The moment
readyflipped — which an overview error also does — everysection spawned with the plain 45s cap, straight into the queue behind the
still-running cold parse.
SIGKILL, so a lock-holding parser's cache refreshlock was only ever reclaimed through the next parse's stale-pid takeover
rather than released by the process that took it.
codeburn serve --stdiochildren survive app crashes — 4 found aliveon the dev machine, up to 4 days old.
What changed
The parse heartbeats (
src/parser.ts). A watchdog is only as good as thesignal it watches, and the real CLI is not as chatty as it looks: a cold parse's
inter-provider cache save (
src/parser.ts:4165) was measured at 31.6s of totalsilence, plus an ~8s tail. A 45s silence window survives that only until the
machine is 1.5x slower. So under
CODEBURN_PROGRESS=1a running parse now emits akeepaliveevent every 10s regardless of phase, started and stopped aroundrunParseso it covers the throwing paths too, and — for served requests — aroundrunCaptured, the one seam that also covers the ~8s aggregation-and-serializationtail landing right after the parse's own quiet stretches. (A one-shot spawn keeps
the parse-only wrap; an 8s tail alone sits comfortably inside the window.) Silence
now genuinely means stopped. The event carries nothing; the Splash reducer ignores it, and gained a
defaultarm so any future event kind from a newer CLI is ignored rather thancrashing an older app.
codeburn servedrains before exiting, but not forever (src/serve.ts).runStdioServereturned as soon as the transport closed, so a request still inflight lost its response frame — and because
runCapturedmonkeypatchesprocess.exitinto a thrownExitSignal, the new explicit exit turned that intoexit 1. The
finallynow awaits the request queue, bounded at 45s: generousenough that nothing legitimate is truncated, short enough that an async-wedged
request releases the child rather than making it the orphan this whole section is
about. The ceiling is documented in place — a synchronously wedged parse never
yields to that timer, or to any other JS path; only a signal ends it.
No-output watchdog (
app/electron/cli.ts).timeoutMsnow bounds silence,not total runtime: the window restarts on every byte the child writes on
stdout/stderr, and on every serve frame carrying that request's id. A 15-minute
absolute ceiling still reaps a livelocked child. Every read spawn sets
CODEBURN_PROGRESS=1(the env already exists on main —src/parser.ts:2937) soa multi-minute parse heartbeats instead of going silent; those heartbeat lines
are stripped from any stderr that becomes an error message.
Cold floor everywhere (
app/electron/main.ts). While the first hydration isstill running, every read gets the 10-minute floor, not just the overview.
Graceful kill. SIGTERM first, SIGKILL after a 5s grace, on the spawn branch,
the serve branch, and the mutation-restart/destroy paths. To be precise about the
benefit: SIGTERM is catchable, so
armSignalCleanup(src/session-cache.ts:1549)unlinks the child's own cache refresh lock before it dies. Under SIGKILL that lock
is merely left behind and self-heals via the stale-pid takeover. Neither signal
publishes a partial cache — nothing does. The grace is a clean release in place
of a takeover, not data preservation. Quit stays a hard kill: its flush budget is
1.5s, shorter than the grace, and a lock left there still self-heals.
No red panel during provable cold — and it always ends. A timeout raised while
hydration is running is flagged
coldon the error envelope (add-only, optionalfield); the renderer keeps its indexing splash and keeps the sections gated rather
than latching
ready. Only timeouts are flagged — a permission or nonzerofailure still surfaces normally. The claim is bounded by the cold window
itself:
overviewWarmedonly flips on success, so without a bound an installthat can never hydrate would sit behind the splash forever, with no error and no
route to the "Locate the CLI" recovery. Past 10 minutes, a timeout is an error.
Orphan reaping, Windows included. The serve child's pid and full command
line are recorded under
userData; on boot a serve orphaned by a previous crashis SIGTERMed, but only after the OS reports that pid running that exact argv.
A keyword sniff ("a
cli.jsrunningserve") matches plenty of unrelated tools,and pids recycle.
Windows is the majority of the desktop fleet and previously had no orphan escape
— no
ps, and no stdin-close recourse once the app has crashed — so it is coverednow. On the command-line lookup:
tasklistnever reports argv (image name andwindow title only) and
wmicis removed from current Windows, so this readsWin32_Process.CommandLineviaGet-CimInstance. Quoting is normalized on bothsides — we record a plain space-joined argv while Windows reports the real quoted
line — so
C:\Program Files\…round-trips without loosening the match.src/serve.tsalreadyexits on stdin EOF and the app never detaches, so the remaining gap was a handle
outliving the transport —
src/main.tsnow exits explicitly oncerunStdioServereturns.
Before / after, at production timings
Real
spawnClifromorigin/mainvs this branch, productionDEFAULT_TIMEOUT_MS(45s), against a CLI that heartbeats every 5s and answers at 60s — the 0.9.20
warm-
optimizeshape with margin:And the lock half, against a silent child holding a lock it releases on SIGTERM
the way
armSignalCleanupdoes:Read that as the modest thing it is: the lock is released by its owner instead of
being reclaimed later by a stale-pid takeover. Nothing is rescued from the parse.
Detection of a genuinely stuck child is unchanged: still 45s, still a
timeout—what changed is that a working child no longer looks stuck, on both sides (the
app resets on output, and the CLI now produces some).
Tests
app/electrongains coverage for each rule; the two watchdog tests were verifiedto fail against the old fixed-timeout logic (reset removed → both red), and
the renderer gating test fails when
readylatches on a cold error.mid-window, so a fixed-cap implementation fails this)
keeps beating until the outermost parse finishes, and stays quiet for a plain
CLI run
codeburn serveanswers an in-flight request in full and exits 0 when stdincloses on the same tick, and gives up on an async-wedged one at the drain bound
(a fixture supplies its own never-settling
buildProgramto the realrunStdioServe, so no test hook exists in shipped code)conventions and a path with spaces, and refuses a recycled pid, an unavailable
PowerShell, and an empty CommandLine
(the child signals readiness with a byte, so the window is measured from that
rather than from spawn — node's boot cost cannot flake it; 6/6 under 8 busy loops)
CODEBURN_PROGRESS=1child handling it exits without waiting the grace out
act report/plan/optimizewhile cold, andreverts once the overview lands
is never signalled — including the lookalike shapes (
cli.js serve --stdio, abinary literally named
codeburn); missing/garbage/incomplete pidfiles are no-opsreleases them on a real failure
(The root run also reports 26 collection errors from a missing
jsdomin thissandbox's borrowed
node_modules; they are identical on the branch point andunrelated to this change.)
Shipping
CODEBURN_PROGRESSand the newkeepaliveevent exist in no shipped release —both are post-0.9.20. Packaged builds spawn their own bundled, version-matched CLI,
so app and CLI ship together and this is a non-issue there. A dev repo build or a
pinned/persisted external
codeburnthat predates them simply emits no heartbeats,and a long silent parse degrades to the old behaviour (a timeout at the window)
rather than misbehaving. The renderer's
defaultreducer arm covers the oppositeskew, a newer CLI against an older app.
Contract
Payload shapes are add-only: the error envelope gains an optional
cold?: true,absent on older mains, and the renderer reads it defensively. No new CLI flag or
env —
CODEBURN_PROGRESSalready exists on main. The CLI-side changes (src/main.tsexiting afterrunStdioServe,src/serve.tsdraining first, thesrc/parser.tskeepalive) allship in this PR and are invisible to an older app.