Repository navigation
fix(showcase/harness): reap chromium zombies, alarm on PID saturation, stop saturated workers claiming - #6333
Merged
Merged
Conversation
Contributor
Production Digest-Pinning AuditAll 41 services digest-pinned. Run 2026-08-12 13:54:59 PDT — 0 finding(s). |
…ID 1 harness-workers leaked one cgroup PID slot per orphaned chromium grandchild. Node as PID 1 only waitpid()s processes it spawned, so every browser crash stranded ~5 <defunct> renderers permanently. Prod climbed to pids.current=1000/1000 with zombieCount=757 over 6d22h uptime, after which no browser could launch and ~295 d6 cells went abort fleet-wide. Install tini in the existing playwright apt layer and run it as PID 1 via exec-form ENTRYPOINT. No -g, so signal delivery to node is unchanged and orchestrator.ts's SIGTERM drain still runs; tini propagates the child's exit status so a crash still exits non-zero and Railway still restarts.
jpr5
force-pushed
the
fix/showcase-harness-pid-reaper
branch
from
August 12, 2026 20:21
6704379 to
e66fb1a
Compare
jpr5
marked this pull request as ready for review
August 12, 2026 20:21
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
August 12, 2026 20:21
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
Prod harness-workers replicas reach the platform-fixed pids.max=1000
ceiling roughly every 7 days and NOTHING alarmed. Measured 2026-08-10
20:09-20:10Z: pids=1000/1000 zombies=758, 1000/1000 zombies=761,
837/1000 zombies=744, with 320 `timeout after 600000ms` abort rows and
an e2e-smoke run 42 minutes into a 15-minute cadence with 3 jobs still
pending. The documented pool-unrecoverable alarm did not fire: it only
trips when the self-heal breaker gives up, which a PID-starved but
still-heartbeating worker never reaches.
The signal was already on the wire and read by nobody. The worker's
~75s heartbeat writes capacity_pids_current / capacity_pids_max onto
its `workers` row (worker/registration.ts), and fleet-health lists that
whole roster every 15s — its own comment said "the capacity gauges are
ignored here". Nothing in non-test source compared them.
Alarm control-plane-side rather than worker-side, because status-writer
documents `fleet-cp` as the only authoritative fleet writer ("workers
never write status directly"), and because fleet-health already holds
the roster read this needs.
- fleet-health raises a rising-edge alarm at pids.current/pids.max >=
0.75 (~36h of lead time at the observed leak rate), evaluated BEFORE
the online/stale branch since the failing worker is fully ONLINE.
- Latched per worker with a 0.65 hysteresis clear: the monitor ticks
every 15s, so an unlatched alarm would page ~8600 times across the
lead-time window. Construction fails loud on a ratio pair with no gap.
- Unmeasured gauges (null off-Linux, unbounded pids.max) never alarm --
pidUsageRatio returns null and null is never read as zero.
- Routed to a system:worker-pid-saturation status row plus #oss-alerts
via SLACK_WEBHOOK_OSS_ALERTS, the target family-silence and the
D0-gone monitor already post to. Deliberately NOT
SLACK_WEBHOOK_BROWSER_POOL_UNRECOVERABLE, which appears nowhere in
this repo outside its own definition and is unset everywhere -- an
alarm nobody receives is the gap being closed.
worker-loop's claim gate had exactly one conditional -- `if (budget.available <= 0)` -- and `available` is free Playwright browser-CONTEXT slots (maxContexts - liveContextCount), nothing else. A worker whose container has leaked PIDs to the cgroup ceiling therefore still advertises full capacity and keeps winning claims it cannot possibly run: the driver cannot fork, so each job burns its entire 600000ms lease and lands as an abort. Measured 2026-08-10: workers at pids=1000/1000 with 758-761 zombies, 320 `timeout after 600000ms` rows. Decline the claim above 0.90 of pids.max. Deliberately far above the control-plane's 0.75 saturation ALARM: the two thresholds do different jobs. 0.75 pages an operator while the worker is still perfectly able to run jobs; gating dispatch that early would convert a warning into ~36h of withheld fleet capacity. 0.90 leaves 100 free PIDs at the prod ceiling -- a chosen reserve, not a derived one (the per-job PID cost of a chromium context tree is not measured), hence the env override. The ordering that matters is that the alarm always fires before capacity is withdrawn. BLAST RADIUS -- reuses the SAME decline-and-idle path as the existing no-budget branch, which is what makes an all-workers-saturated fleet safe: the job is never claimed, so it is never dropped and never requeued; it simply stays `pending`. The loop then sleeps a full pollIntervalMs, so a fully-saturated fleet idles at the poll cadence instead of spinning. The queue stalls VISIBLY -- pending rows pile up, the rising-edge warn says why, and the control-plane's system:worker-pid-saturation alarm fired at 0.75 before this gate engaged at 0.90. A stalled, alarmed queue is recoverable by redeploy; claim-fail-repeat silently burned the whole cadence. The gate is INERT when the cgroup gauges are unreadable (pidUsageRatio -> null: off-Linux, every macOS dev box), so local workers claim exactly as before.
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.
CHANGE 1 — the leak (tini as PID 1)
The bug
harness-workershas no PID-1 zombie reaper, so it leaks cgroup PID slots until it cannot launch a browser.libuv's
SIGCHLDhandler onlywaitpid()s the pids Node itself spawned. Playwright spawns the chromium browser process (reaped fine), but that browser's zygote/renderer/GPU children are grandchildren. When a browser process dies — prod'sTarget crashedpath, or a pool self-heal relaunch — those grandchildren are re-parented onto PID 1 and exit. Node-as-PID-1 never waits on them, so each becomes a permanent<defunct>still holding a cgroup PID slot.Prod, on a single container up 6d22h:
zombieCount70 → 757,cgroupPidsCurrent286 → 1000/1000. Once saturated, probes could not launch browsers (Target crashed,browserContext.newPage: … has been closed,feature exceeded 300000ms wall-clock) and 295 of 414 red prod d6 cells wentabort, fleet-wide across ~20 slugs.This Dockerfile already documented the outage mode in a 40-line
FIX #3block — but both of its stated mitigations are demand-side (BROWSER_POOL_MAX_CONTEXTS40→24, resource-gauge warning logs). Those cap the peak ofpids.current. They cannot stop a monotonic leak, and prod died of a monotonic leak.resource-gauges.tsonly ever measured zombies (if (s.state === "Z") zombieCount += 1); nothing reaped them.The change
One file, +59/-3.
tinias PID 1.Why this form:
tinibaked into the image, not Docker--init—--initis a runtime flag and Railway does not expose it, the same reasonpids.maxisn't settable from here (already documented in this file).waitpidbinding, so an applicationSIGCHLDhandler would need a native addon. This is the platform's job.--with-depsjust ranapt-get update, so this costs one ~267KB package download instead of a second index refresh. Thetini --versioncall is a build-time assertion on the path baked intoENTRYPOINT: if a future Debian moves the binary, the build fails rather than the container failing to start in prod.-g— tini's process-group broadcast would signal the live chromium pool alongside node and pre-emptorchestrator.ts'sprocess.once("SIGTERM", drainAndExit). Without it, delivery is byte-identical to today: exactly one process gets the signal.execkept in CMD — tini really is PID 1 and really receives Railway's SIGTERM; node is tini's direct child with no bash lingering in the tree.No existing convention to match:
grepfortini/dumb-init/--initacross every Dockerfile in the repo returns zero hits. Nothing in the repo asserts on this image'sCMD/ENTRYPOINT, and nothing outside the CI build stepdocker runs it, so adding anENTRYPOINTbreaks no consumer.RED → GREEN
Real container, real chromium, real zombies. Identical argv for both; only the image differs, and the image supplies PID 1:
--pids-limit 1000mirrors Railway's platform-fixed ceiling. Each cycle launches chromium with the exact argsbrowser-pool.tsuses (headless,--no-sandbox,--disable-dev-shm-usage), opens a context+page, then SIGKILLs the browser process — prod'sTarget crashedpath, orphaning its children onto PID 1.Measurement is container-wide on purpose. The harness's own
sampleResourceGauges()walks the tree fromprocess.pid; under a real init the orphans re-parent to the init, not to node, so a node-rooted walk would report zero zombies whether or not they were reaped — a vacuous GREEN. Counting every state-Zprocess in/procplus the cgroup counter is blind to which process is PID 1, so it is honest in both directions.RED (unmodified
main,pid1=node)20 cycles — exactly +5 permanent zombies per crashed browser:
The leaked processes, verbatim from the final
/proctable — allppid=1, allZ:cgroupPidsCurrentafter each cycle never returns to 7 — it is7 + 5×cycles. A monotonic ratchet, the same curve prod walked over 7 days.RED, driven to saturation (started before the Dockerfile was touched)
The run wedged at cycle 185 with no output for >12 minutes:
chromium.launch()could not get PIDs and never returned — it did not even surface Playwright's 30s launch timeout, which is exactly why prod shows 300s feature timeouts and 1200s run aborts instead of a clean launch error.docker ps:Up 17 minutes (unhealthy).And the errno-11 signature this Dockerfile's own comment names — the container could no longer
fork()at all:That is the prod outage, end to end, in a local container.
GREEN (this PR's image,
pid1=tini) — same repro, same argv, 230 cyclesprocCountreturning to 2 (tini + node) after every single cycle is the reap actually happening: the browser's 6 processes appear pre-kill (procCount=8) and are fully gone post-kill.pid1=node)pid1=tini)pids.currentfloor at cycle 185chromium.launch()fork: Resource temporarily unavailablelaunchFailure=noneSignals and non-zero exit still work
The prober's container must still self-restart on crash, so this was proven, not assumed.
signal-child.mjsinstalls the sameprocess.once("SIGTERM", …)shapeorchestrator.tsuses; run on both images:pid=7, sodocker stop's SIGTERM was forwarded into the process that owns the graceful drain.orchestrator.ts'sdrainControlPlaneAndExit("SIGTERM")path is intact.exit(42)→ container42; a crash still exits non-zero, so Railway still restarts. The HEALTHCHECK restart-on-sustained-503 behaviour this Dockerfile calls "THE INTENDED OUTCOME" is untouched.Cross-arch check
Local images are arm64; prod builds amd64.
tiniavailability was verified on amd64 explicitly rather than assumed — same path the build-time assertion checks:Pre-push checks
docker buildx build -f showcase/harness/Dockerfile(== CI's build check)nx run @copilotkit/showcase-harness:typechecknx run @copilotkit/showcase-harness:test:cipre-commit+commit-msggit statusThe single failure is
d0-gone-predicate.test.ts > resolves the real generated registry.json…, failing onENOENT … showcase/shell/src/data/registry.json. That file is gitignored and generated at build time — this Dockerfile's own comment says so, which is why the image generates it viagenerate-registry.ts. Proven environmental rather than assumed: generated the file, re-ran that exact spec, 11/11 passed. A Dockerfile-only diff cannot affect a vitest run.No formatter/linter covers this file: lefthook's
lint-fixglob is*.{js,jsx,ts,tsx,mjs,cjs,md,css,yml,yaml,html,vue,py}, and there is no hadolint anywhere in CI.Not in this PR
conversation-errorand ~16goto-errorcells are almost certainly unrelated real bugs this will not fix; only theabort/feature-timeout/driver-errorpopulation is in scope.pool-unrecoverablealarm demonstrably never fired at 1000/1000, andcgroupPidsCurrent/cgroupPidsMax > 0.75would have given ~36h of warning before the flip.browser.close()path was not measured — irrelevant to the fix (tini reaps either way), but it means prod's exact 757 can't be attributed to crashes alone.RE-VERIFICATION 2026-08-12 — rebased onto
origin/main, red-green re-run from scratchThe proof above was produced 2026-08-03 against a base that predates
ced993447f("copy patches/ into harness build context"), which touches THISDockerfile. The branch has been rebased onto current
origin/mainand thewhole red-green was re-run on freshly built images so the numbers describe the
actual merge candidate.
Both images built locally from this repo, same machine, same context, ~3 min apart:
Identical driver, identical argv, 40 cycles each, runs 18 seconds apart:
RED —
showcase-harness:red-main,pid1=node(2026-08-12T20:19:28Z)All 200 leaked processes are
ppid=1, stateZ(tail of the final/proctable):GREEN —
showcase-harness:green-tini,pid1=tini(2026-08-12T20:19:46Z)grep -c defunctover the GREEN run: 0.procCountreturns to 2(tini + node) after every cycle — the browser's 6 processes appear pre-kill
(
procCount=8,threadCount76–79) and are fully gone post-kill.pid1=node)pid1=tini)b86686e9a06dd666b823f16bpids.currentbefore → after<defunct>rows in final tablelaunchFailureSignals / non-zero exit, both images, this run
SIGTERM reaches node (handler fires at
pid=7), non-zero exits survive(42 → 42; abort → 134 = 128+6), so Railway's restart-on-crash is intact.
The prod leak, measured live the same day
resource_snapshotsin prod PocketBase, immediately before the mitigationrestart on the unfixed digest
sha256:80a0c5c2…:and immediately after it (
initrows):pids=164–169/1000 zombies=0 procs=16.A new zombie was already recorded at
2026-08-12 20:12:27.182Z worker-de14c … zombies=1.Cross-arch
Local images are arm64 (
/usr/bin/tini68592 bytes); prod builds amd64.Measured on amd64 directly:
Package: tini / Architecture: amd64 / Version: 0.19.0-1+b3,/usr/bin/tini27792 bytes,tini version 0.19.0;package download 267,204 bytes, 749 kB on disk.
Deploy note
computePromoteClosure(["showcase-harness"])=pocketbase(0), harness(1), dashboard(1), harness-workers(1)— the workers are in the promote scope.Prod
startCommandisnulland no repo consumer overrides the entrypoint,so Railway uses the image's ENTRYPOINT+CMD. PR #5750 is CLOSED unmerged, so
promoting
harness-workersresetsmultiRegionConfig.us-west2.numReplicasto1 and it must be re-asserted to 6 and read back after the promote.
CHANGE 2 — nothing alarmed (worker PID-saturation alarm)
Commit
7f28e9bd39.The gap
The measured prod condition on 2026-08-12 20:09–20:10Z was
pids=1000/1000,1000/1000,837/1000across three workers, 320timeout after 600000msabort rows, an
e2e-smokerun 42 minutes into a 15-minute cadence with 3 jobsstill pending, prod d6 534/784 vs staging 744/788. No alarm fired, and this
was the second occurrence (2026-08-03, 2026-08-10).
The documented
pool-unrecoverablealarm did not fire by construction: it israised only when
BrowserPool's self-heal circuit-breaker exhaustsselfHealMaxHardRecoveries. A worker that is PID-starved but still heartbeatingnever reaches that state — it launches browsers fine, it just cannot fork the
process tree a probe needs.
The signal was already on the wire and read by nobody:
worker/registration.ts:192writescapacity_pids_current/capacity_pids_maxonto the worker'sworkersrow on its ~75s heartbeat(
DEFAULT_WORKER_HEARTBEAT_MS = 75_000).control-plane/fleet-health.tslists that entire roster every 15s(
DEFAULT_FLEET_HEALTH_INTERVAL_MS) — and its own comment on the row typesaid "the capacity gauges are ignored here."
pidsCurrenttopidsMax.Where the alarm goes, and why
Control-plane, not worker.
writers/status-writer.tsdocumentsfleet-cpas "the only authoritative fleet writer; workers never write status directly",
so a worker cannot raise a
system:health key.fleet-healthalready holdsthe roster read this needs, on a 15s cadence, so the alarm costs zero extra PB
traffic.
Routed to
#oss-alerts, not to the browser-pool webhook.SLACK_WEBHOOK_BROWSER_POOL_UNRECOVERABLEappears nowhere in this repooutside its own definition —
grepfinds it only inorchestrator.ts— so itis unset everywhere and that alarm has no receiver even when it does fire.
SLACK_WEBHOOK_OSS_ALERTSis a real wired secret that the family-silencemonitor and the D0-gone monitor already post through. Routing a new alarm to a
known-unwired webhook would reproduce the exact gap this closes.
Thresholds
pids.current / pids.max >= 0.75. At the observed leak rate(~1000 PIDs over ~7 days) that is roughly 36 hours of lead time — more than a
working day. A busy worker's context budget is nowhere near 750 PIDs.
unlatched alarm would page ~8600 times across that 36-hour window. An alarm
that fires constantly is worse than none, so
createFleetHealthMonitornowfails loud at construction on a ratio pair with no hysteresis gap.
fully
online— it heartbeats on time throughout.registration.tsmaps the pool's-1sentinel to
null;pidUsageRatioreturnsnullfor null/absent/negativecurrent or non-positive max, and null is never read as zero.
RED → GREEN (change 2)
Driver exercises the real chain end-to-end, faking only the OS cgroup read
(
BrowserPoolOptions.cgroupPidsReader, an existing injectable seam) and the PBtransport. The column names are whatever the real registration writer emits and
whatever the real fleet-health reader consumes, so a column drift fails this
driver:
Identical command both sides; only the source differs:
RED — unmodified source
The exact prod condition — a worker at the ceiling — produces zero alarms.
GREEN — with this change
The alarm must also stay QUIET — same run, same command
A4pins the boundary at 0.74.A5pins the off-Linux case: the-1sentinellands as
nullon the row and stays silent rather than reading as0.A6pins the latch — 5 saturated cycles, 1 alarm.
CHANGE 3 — saturated workers kept claiming (PID headroom claim gate)
Commit
63ef4081c2.The defect
fleet/worker/worker-loop.tshad exactly one conditional in the claim loop:and
availableis free Playwright browser-context slots and nothing else —browser-pool.ts:available: Math.max(0, this.maxContexts - this.liveContextCount).Context slots have no relationship to cgroup PIDs. A worker whose container has
leaked to
pids=1000/1000therefore still advertises full capacity, keepswinning claims, cannot fork the browser tree, and burns each job's entire
600000ms lease before aborting. That is the mechanism behind the 320 abort rows.
Blast radius — what happens when ALL workers are saturated
The gate deliberately reuses the same decline-and-idle path as the existing
no-budget branch, which is what makes total saturation safe:
stays
pendingfor a healthy worker, or for this one after a redeploy;pollIntervalMs, so a fully-saturated fleetidles at the poll cadence instead of spinning;
probe_jobsrows pile up pending, a rising-edgefleet.worker.pid-headroom-exhaustedwarn says why (warn → stderr → Sentry;steady state drops to debug so a multi-hour stall does not flood), and
change 2's
system:worker-pid-saturationalarm fired at 0.75 before thisgate engaged at 0.90.
A stalled, alarmed queue is recoverable by redeploy. Claim-fail-repeat silently
burned the whole cadence.
Why the gate is 0.90 and the alarm is 0.75
They do different jobs and must not be equal. 0.75 pages an operator while the
worker is still perfectly able to run jobs; gating dispatch that early would
convert a warning into ~36 hours of withheld fleet capacity. 0.90 is where we
stop trusting the worker to fork at all — 100 free PIDs at the prod ceiling.
That reserve is chosen, not derived: the per-job PID cost of a chromium
context tree is not measured, hence the
WORKER_PID_CLAIM_GATE_RATIOoverride. The invariant that matters is ordering — the alarm always fires before
capacity is withdrawn.
The gate is inert when the cgroup gauges are unreadable (
pidUsageRatio→null: off-Linux, every macOS dev box), so local workers claim exactly asbefore.
RED → GREEN (change 3)
Driver runs the real
startWorkerLoopagainst the realBrowserPoolbudget path, faking only the cgroup read and the queue transport. The queue fake
holds a real
pendinglist, so "was the job dropped / does it stay pending" isdirectly observed, not inferred.
budget()calls are counted as aloop-iteration proxy for the spin check.
Identical command both sides:
RED — unmodified source
A worker at the PID ceiling claims all three jobs. In prod each of those
becomes a 600000ms abort.
GREEN — with this change
claimNextis never called; all three jobs are still pending — not dropped,not requeued.
ALL workers saturated — the blast-radius case
Zero claims, 3 of 3 jobs still pending, and 36 iterations across 3 workers
over a 600ms window at a 50ms poll — i.e. 12 per worker, the poll cadence. No
spin, no loss.
The gate must NOT engage below threshold — same run, same command
B4is the load-bearing one: 0.89 is above change 2's 0.75 alarm and belowthis gate. The operator has been paged and the worker keeps working — which is
the whole reason the two thresholds differ.
B5pins the off-Linux case.Tests and gates (changes 2 and 3)
showcase/harness, on the pushed head63ef4081c2:npx tsc --noEmit -p tsconfig.jsonnpx oxlint src/fleet src/orchestrator.tsfleet-health.tsbefore and after)npx oxfmt --writevitest runThe single failure is
src/probes/frontend-matrix.test.ts— pre-existing.Verified by stashing this branch's changes and re-running it on the unmodified
tree, where it fails identically (
1 failed | 5 passed).14 tests are new (
3682 → 3696).Mutation-tested for vacuity. With the four source files reverted to
e66fb1af13and the new test files kept, 11 of the new tests fail:The three that pass on both sides are the sub-threshold controls (
still claims just BELOW the gate,claims normally on a healthy worker,stays INERT when the cgroup gauges are unreadable) — they are supposed to be unchanged by thefix, and they are.
New env knobs (all optional, all defaulted)
WORKER_PID_SATURATION_RATIO0.75WORKER_PID_SATURATION_CLEAR_RATIO0.65WORKER_PID_CLAIM_GATE_RATIO0.90An out-of-range override on the two alarm ratios falls back to the default
rather than tripping the fail-loud guard and taking the control-plane down over
a typo'd env var.
Not verified
staging PocketBase; both red-greens are local, on the real modules with the
cgroup read and PB/queue transport injected.
SLACK_WEBHOOK_OSS_ALERTSwas not set in thedriver, so the send leg was not exercised end-to-end — only that its failure
is swallowed without costing the durable status row.
0.90 gate's 100-PID reserve is a chosen value.