Skip to content

fix(showcase): re-assert SSOT replica count on promote + skip probe-ineligible services locally - #5750

Closed
jpr5 wants to merge 2 commits into
mainfrom
fix/showcase-promote-replica-assert
Closed

jpr5 wants to merge 2 commits into
mainfrom
fix/showcase-promote-replica-assert

Conversation

@jpr5

@jpr5 jpr5 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Two related defects in showcase/bin/railway's promote path. Both are now fixed with red-green Ruby specs that drive the real methods (not stubs of the code under test).

Defect 1 (primary) — promote never re-asserts the SSOT replica count (the 6→1 trap)

Root cause. PromoteCommand.pin_and_verify (showcase/bin/railway) issued serviceInstanceUpdate(input: { source: { image } }) followed by serviceInstanceDeployV2 with no numReplicas. The authoritative count lives in showcase/scripts/railway-envs.ts as workerProvisioning.<env>.effectiveReplicas (=6 for harness-workers) and is exposed in the generated SSOT JSON, but no promote/deploy code path ever pushed it to Railway. Because serviceInstanceUpdate is a partial PATCH (omitted keys preserved), a promote didn't itself zero the override — but it never re-asserted it either, so once Railway's effective multiRegionConfig.us-west2.numReplicas drifted to 1 (manual edit / partial scale that only touched the top-level mirror / Railway-side reset), every subsequent promote left it at 1.

Fix. pin_and_verify now read-modify-writes multiRegionConfig.us-west2.numReplicas from the SSOT effectiveReplicas when the target service+env declares a worker count, mirroring the existing healthcheckPath self-heal. The serviceInstanceUpdate input/mutation is built dynamically (RestoreCommand.build_update_image_mutation) so any combination of {image, healthcheckPath, replicas} is a faithful partial PATCH.

Footgun handled (called out in code). serviceInstanceUpdate is a partial PATCH and multiRegionConfig is input-only / non-queryable — we cannot read-modify-write the live region object. So we set only the nested multiRegionConfig."us-west2".numReplicas key, add the region object only for services the SSOT declares a count for, and OMIT multiRegionConfig entirely otherwise — never null-clearing sibling region config and never forcing a count on a service that declares none. The top-level numReplicas mirror is deliberately not sent (touching the mirror alone is exactly the partial-scale footgun that caused the drift).

The promote call site sources effectiveReplicas from the generated SSOT record (workerProvisioning.prod.effectiveReplicas) and passes it as replicas:; nil for services with no declared count.

Red → Green (Defect 1)

showcase/bin/spec/test_promote_replicas_reassert.rb drives the real pin_and_verify and asserts the constructed serviceInstanceUpdate input/vars.

RED (origin/main bin/railway):

PromoteReplicasReassertTest:
  ArgumentError: unknown keyword: :replicas
    bin/railway:1154:in `pin_and_verify'
3 runs, 0 assertions, 0 failures, 3 errors, 0 skips

GREEN (with fix):

3 runs, 20 assertions, 0 failures, 0 errors, 0 skips

The generated mutation (replicas + healthcheck case):

input: { source: { image: $image }, healthcheckPath: $healthcheckPath, multiRegionConfig: { "us-west2": { numReplicas: $numReplicas } } }

and OMITs multiRegionConfig entirely when no count is declared.

Post-merge live check (not runnable pre-merge): the next prod promote of harness-workers must preserve 6 replicas (confirm via Railway's effective multiRegionConfig.us-west2.numReplicas, since the top-level mirror is non-authoritative for this single-region service).

Defect 2 (secondary) — local bin/railway refuses probe:false services

Root cause. check_p3_staging_live_green → run_staging_probe (showcase/bin/railway) shelled to verify-deploy.ts without --skip-ineligible, so harness-workers (probe.staging=false, domainless queue worker) went red and P3 emitted REFUSE: P3: staging is not green. CI already fixed this in merged commit 160ba5a4aa (showcase_promote.yml passes --skip-ineligible); the local CLI was missed, which is why the workaround had been --no-require-staging-green.

Fix. Plumb --skip-ineligible into the local run_staging_probe invocation — a faithful 1-line port of the merged CI behavior. The flag does not relax green for eligible services, and an unknown/typo name is still a hard error inside verify-deploy.ts.

Red → Green (Defect 2)

showcase/bin/spec/test_promote_staging_probe_skip_ineligible.rb drives the real run_staging_probe, intercepts the spawn, and asserts the constructed argv.

RED (origin/main bin/railway):

Expected ["npx", "--yes", "tsx", ".../verify-deploy.ts", "--env", "staging", "--services", "harness-workers", {:err=>[:child, :out]}] to include "--skip-ineligible".
1 runs, 4 assertions, 1 failures, 0 errors, 0 skips

GREEN (with fix):

1 runs, 12 assertions, 0 failures, 0 errors, 0 skips

Files changed

  • showcase/bin/railway — build_update_image_mutation helper + replicas: param on pin_and_verify; --skip-ineligible in run_staging_probe; replica sourcing at the promote call site. Removed the now-unused UPDATE_IMAGE_AND_HEALTHCHECK_MUTATION constant (superseded by the dynamic builder).
  • showcase/bin/spec/test_promote_replicas_reassert.rb — new (Defect 1).
  • showcase/bin/spec/test_promote_staging_probe_skip_ineligible.rb — new (Defect 2).
  • showcase/bin/spec/test_snapshot_ivar_lint.rb — renumbered the line-pinned allowlist to track the shifted lines (no behavior change).

Full suite: ruby showcase/bin/spec/all_tests.rb → 179 runs, 709 assertions, 0 failures, 0 errors, 0 skips.

…-ineligible services locally

Two defects in showcase/bin/railway's promote path:

Defect 1 — promote never re-asserted the declared replica count (the 6->1
trap). PromoteCommand.pin_and_verify sent serviceInstanceUpdate(source.image)
+ serviceInstanceDeployV2 with no numReplicas, so the SSOT
workerProvisioning.<env>.effectiveReplicas (6 for harness-workers) was never
pushed to Railway. Once the effective multiRegionConfig.us-west2 override
drifted to 1, every subsequent promote left it at 1. Fix: pin_and_verify now
read-modify-writes multiRegionConfig.us-west2.numReplicas from the SSOT
effectiveReplicas when the service+env declares a worker count, mirroring the
healthcheckPath self-heal. serviceInstanceUpdate is a partial PATCH and
multiRegionConfig is input-only/non-queryable, so we set ONLY the nested
numReplicas key and OMIT multiRegionConfig entirely for services that declare
no count — never null-clearing sibling region config.

Defect 2 — local bin/railway refused probe:false services. run_staging_probe
shelled to verify-deploy.ts without --skip-ineligible, so harness-workers
(probe:false, domainless) went red and P3 REFUSEd. CI already fixed this
(160ba5a); the local CLI was missed. Fix: plumb --skip-ineligible into the
local probe invocation, a faithful port of the merged CI behavior.

Both defects covered by red-green Ruby specs driving the real methods.
@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@github-actions

github-actions Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Production Digest-Pinning Audit

All 41 services digest-pinned.

Run 2026-06-28 09:26:02 PDT — 0 finding(s).

…iable, verify it applied, reconcile SSOT contract

The promote replica re-assert had four coupled defects (CR bucket-(a)):

A1 (CRITICAL) — malformed GraphQL. build_update_image_mutation emitted
`multiRegionConfig: { "us-west2": { numReplicas: $numReplicas } }`. A
quoted/hyphenated key in a GraphQL *literal* is invalid query syntax, so
Railway's parser rejects the whole mutation and the replica re-assert
could never work against real Railway. Now pass multiRegionConfig as a
typed GraphQL variable (`$multiRegionConfig: JSON!`) and build the
`{ "us-west2" => { "numReplicas" => n } }` object in Ruby
(build_multi_region_config), carried in the variables hash — no
hyphenated key ever appears as a GraphQL field name. The image +
healthcheckPath path is unchanged and no sibling region keys are cleared.

A2 — the test was false-green. test_promote_replicas_reassert only
asserted /multiRegionConfig/ and /us-west2/ against the query string, so
it passed against the malformed mutation. It now asserts the GraphQL
document is well-formed (no quoted/hyphenated key in the body, region key
absent from the document) and that multiRegionConfig is sent as a JSON
variable with the correct {us-west2:{numReplicas:N}} structure. Verified
red against the old quoted-key mutation, green against the fix.

A3 — success gate did not verify replicas applied. pin_and_verify now
asserts the accepted mutation actually carried the SSOT count under
multiRegionConfig.<region>.numReplicas and fails loud otherwise.
multiRegionConfig is input-only / non-queryable, so carrying the target
is the strongest available proof; a true result that never carried the
count is no longer declared a successful self-heal.

A4 — SSOT contract contradiction. railway-envs.ts and RAILWAY.md
documented bin/railway as verify-only / never-writes-replicas. Updated to
state promote now RE-ASSERTS the SSOT-declared count on pin (verify-only
now applies to the emitter only, and still to overlap/draining seconds).
@jpr5

jpr5 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing as obsolete. Both defects already landed on main the same day via separate PRs: the SSOT replica re-assert by #5756 (using a replica_config region→count hash API) and the skip-ineligible behavior by #5752 (filtering STAGING_PROBE_INELIGIBLE services out before run_staging_probe, rather than an argv flag). This PR's parameter shapes and test assertions diverged from what shipped — rebasing would be a full rewrite with no net value over current main.

@jpr5 jpr5 closed this Jul 7, 2026
jpr5 added a commit that referenced this pull request Aug 12, 2026
…, stop saturated workers claiming (#6333)

> **This PR carries three changes to the same prod incident.** Change 1
fixes
> the PID leak itself; changes 2 and 3 fix the two reasons the leak was
able to
> starve the fleet unannounced. Each has its own RED → GREEN below.
>
> | # | Commit | What it fixes |
> |---|---|---|
> | 1 | `e66fb1af13` | **The leak.** No PID-1 reaper, so crashed
chromium grandchildren become permanent zombies holding cgroup PID
slots. |
> | 2 | `7f28e9bd39` | **Nothing alarmed.** The worker heartbeats its
cgroup PID gauges and no non-test code read them. |
> | 3 | `63ef4081c2` | **Saturated workers kept claiming.** The claim
gate only checked free browser-context slots, so a worker at 1000/1000
PIDs won jobs it could not run and burned each to a 600000ms abort. |

---

# CHANGE 1 — the leak (tini as PID 1)

## The bug

`harness-workers` has **no PID-1 zombie reaper**, so it leaks cgroup PID
slots until it cannot launch a browser.

libuv's `SIGCHLD` handler only `waitpid()`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's `Target crashed`
path, 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: `zombieCount` 70 → **757**,
`cgroupPidsCurrent` 286 → **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 went `abort`, fleet-wide across ~20 slugs.**

This Dockerfile already documented the outage mode in a 40-line `FIX #3`
block — but **both of its stated mitigations are demand-side**
(`BROWSER_POOL_MAX_CONTEXTS` 40→24, resource-gauge warning logs). Those
cap the *peak* of `pids.current`. They cannot stop a *monotonic* leak,
and prod died of a monotonic leak. `resource-gauges.ts` only ever
**measured** zombies (`if (s.state === "Z") zombieCount += 1`); nothing
reaped them.

## The change

One file, +59/-3. `tini` as PID 1.

```dockerfile
RUN node ./node_modules/playwright/cli.js install --with-deps chromium \
 && apt-get install -y --no-install-recommends tini \
 && /usr/bin/tini --version \
 && rm -rf /var/lib/apt/lists/*
…
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/bin/bash", "-c", "ulimit -u $(ulimit -Hu) 2>/dev/null || true; exec node dist/orchestrator.js"]
```

Why this form:

- **`tini` baked into the image, not Docker `--init`** — `--init` is a
*runtime* flag and Railway does not expose it, the same reason
`pids.max` isn't settable from here (already documented in this file).
- **Not an in-process reaper** — Node has no `waitpid` binding, so an
application `SIGCHLD` handler would need a native addon. This is the
platform's job.
- **Rides the existing apt layer** — playwright's `--with-deps` just ran
`apt-get update`, so this costs one ~267KB package download instead of a
second index refresh. The `tini --version` call is a build-time
assertion on the path baked into `ENTRYPOINT`: if a future Debian moves
the binary, the **build** fails rather than the container failing to
start in prod.
- **No `-g`** — tini's process-group broadcast would signal the live
chromium pool alongside node and pre-empt `orchestrator.ts`'s
`process.once("SIGTERM", drainAndExit)`. Without it, delivery is
byte-identical to today: exactly one process gets the signal.
- **Exec form, `exec` kept 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: `grep` for `tini`/`dumb-init`/`--init`
across every Dockerfile in the repo returns zero hits. Nothing in the
repo asserts on this image's `CMD`/`ENTRYPOINT`, and nothing outside the
CI build step `docker run`s it, so adding an `ENTRYPOINT` breaks no
consumer.

---

# RED → GREEN

Real container, real chromium, real zombies. **Identical argv for
both**; only the image differs, and the image supplies PID 1:

```
docker run --rm --pids-limit 1000 -e REPRO_CYCLES=230 \
  -v <repro>:/repro:ro <image> /bin/bash -c "exec node /repro/zombie-repro.mjs"
```

`--pids-limit 1000` mirrors Railway's platform-fixed ceiling. Each cycle
launches chromium with the exact args `browser-pool.ts` uses
(`headless`, `--no-sandbox`, `--disable-dev-shm-usage`), opens a
context+page, then **SIGKILLs the browser process** — prod's `Target
crashed` path, orphaning its children onto PID 1.

**Measurement is container-wide on purpose.** The harness's own
`sampleResourceGauges()` walks the tree from `process.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-`Z` process in `/proc` plus 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**:

```
baseline zombieCount=0 procCount=1 threadCount=7 cgroupPidsCurrent=7 cgroupPidsMax=1000 selfPid=1 pid1=node
  PID  PPID S THR COMMAND
    1     0 R   7 node
cycle=1 pre-kill zombieCount=0 procCount=7 threadCount=76 cgroupPidsCurrent=76 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=1 zombieCount=5 procCount=6 threadCount=16 cgroupPidsCurrent=16 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=2 zombieCount=10 procCount=11 threadCount=21 cgroupPidsCurrent=21 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=3 zombieCount=15 procCount=16 threadCount=26 cgroupPidsCurrent=26 cgroupPidsMax=1000 selfPid=1 pid1=node
…
cycle=20 zombieCount=100 procCount=101 threadCount=111 cgroupPidsCurrent=111 cgroupPidsMax=1000 selfPid=1 pid1=node
final    zombieCount=100 procCount=101 threadCount=111 cgroupPidsCurrent=111 cgroupPidsMax=1000 selfPid=1 pid1=node
SUMMARY cycles=20 zombiesBefore=0 zombiesAfter=100 pidsBefore=7 pidsAfter=111 launchFailure=none
```

The leaked processes, verbatim from the final `/proc` table — all
`ppid=1`, all `Z`:

```
   21     1 Z   1 headless_shell <defunct>
   22     1 Z   1 headless_shell <defunct>
   36     1 Z   1 headless_shell <defunct>
   61     1 Z   1 headless_shell <defunct>
   77     1 Z   1 headless_shell <defunct>
   87     1 Z   1 headless_shell <defunct>
   88     1 Z   1 headless_shell <defunct>
  104     1 Z   1 headless_shell <defunct>
```

`cgroupPidsCurrent` after each cycle never returns to 7 — it is `7 +
5×cycles`. A monotonic ratchet, the same curve prod walked over 7 days.

### RED, driven to saturation (started before the Dockerfile was
touched)

```
baseline  zombieCount=0    cgroupPidsCurrent=7    /1000
cycle=25  zombieCount=125  cgroupPidsCurrent=136  /1000
cycle=50  zombieCount=250  cgroupPidsCurrent=261  /1000
cycle=75  zombieCount=375  cgroupPidsCurrent=386  /1000
cycle=100 zombieCount=500  cgroupPidsCurrent=511  /1000
cycle=125 zombieCount=625  cgroupPidsCurrent=636  /1000
cycle=150 zombieCount=750  cgroupPidsCurrent=761  /1000     ← prod's ~757 reproduced
cycle=175 zombieCount=875  cgroupPidsCurrent=886  /1000
cycle=184 pre-kill  zombieCount=915  cgroupPidsCurrent=993  /1000
cycle=185 pre-kill  zombieCount=920  cgroupPidsCurrent=996  /1000
cycle=185           zombieCount=925  cgroupPidsCurrent=936  /1000
   ← no further output. Cycle 186 never completed.
```

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)`.

```
$ docker exec red-sat cat /sys/fs/cgroup/pids.current /sys/fs/cgroup/pids.max
1000
1000
```

And the errno-11 signature this Dockerfile's own comment names — the
container could no longer `fork()` at all:

```
$ docker exec red-sat /bin/bash -c 'for i in 1 2 3; do cat /proc/uptime; done'
/bin/bash: fork: retry: Resource temporarily unavailable
/bin/bash: fork: retry: Resource temporarily unavailable
/bin/bash: fork: retry: Resource temporarily unavailable
/bin/bash: fork: retry: Resource temporarily unavailable
/bin/bash: fork: Resource temporarily unavailable
```

That is the prod outage, end to end, in a local container.

## GREEN (this PR's image, `pid1=tini`) — same repro, same argv, 230
cycles

```
baseline zombieCount=0 procCount=2 threadCount=8 cgroupPidsCurrent=8 cgroupPidsMax=1000 selfPid=7 pid1=tini
  PID  PPID S THR COMMAND
    1     0 S   1 tini
    7     1 R   7 node
cycle=1   pre-kill zombieCount=0 procCount=8 threadCount=76 cgroupPidsCurrent=76 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=1            zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=50           zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=100          zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=150          zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=200          zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=230 pre-kill zombieCount=0 procCount=8 threadCount=77 cgroupPidsCurrent=77 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=230          zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
final              zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
SUMMARY cycles=230 zombiesBefore=0 zombiesAfter=0 pidsBefore=8 pidsAfter=12 launchFailure=none
```

`procCount` returning 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.

|  | RED (`pid1=node`) | GREEN (`pid1=tini`) |
| --- | --- | --- |
| zombies after 20 cycles | 100 | **0** |
| zombies at cycle 185 | 925 | **0** |
| `pids.current` floor at cycle 185 | 936, peaking 996/1000 | **12** |
| reached cycle 230? | **no — wedged at 185** | yes |
| `chromium.launch()` | hangs; `fork: Resource temporarily unavailable`
| fine, `launchFailure=none` |
| leak per crashed browser | **+5** | **0** |

---

## Signals and non-zero exit still work

The prober's container must still self-restart on crash, so this was
proven, not assumed. `signal-child.mjs` installs the same
`process.once("SIGTERM", …)` shape `orchestrator.ts` uses; run on
**both** images:

```
--- GREEN (ENTRYPOINT tini, pid1=tini) ---
[showcase-harness:green MODE=term-graceful] exitCode=0
    CHILD mode=term-graceful pid=7 ppid=1
    CHILD ready — idling until signalled
    CHILD received SIGTERM at pid=7 — draining        ← tini FORWARDED it to node
[showcase-harness:green MODE=exit-42] exitCode=42     ← non-zero preserved
[showcase-harness:green MODE=abort]   exitCode=134    ← 128+6 (SIGABRT), non-zero
--- RED (no ENTRYPOINT, pid1=node) — baseline ---
[showcase-harness:red MODE=term-graceful] exitCode=0
    CHILD received SIGTERM at pid=1 — draining
[showcase-harness:red MODE=exit-42] exitCode=42
[showcase-harness:red MODE=abort]   exitCode=133
```

- **SIGTERM reaches node, not just tini** — the handler fires at
`pid=7`, so `docker stop`'s SIGTERM was forwarded into the process that
owns the graceful drain. `orchestrator.ts`'s
`drainControlPlaneAndExit("SIGTERM")` path is intact.
- **Non-zero exits survive** — `exit(42)` → container `42`; 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.
- **tini is strictly *more* correct here**: note RED's abort → **133**
vs GREEN's → **134**. A process running as PID 1 in a namespace has
default signal actions *ignored* by the kernel, so node-as-PID-1 was
distorting its own fatal-signal exit code (128+SIGTRAP instead of
128+SIGABRT). Both non-zero, so no regression — but the fixed image
reports crashes accurately.

## Cross-arch check

Local images are arm64; prod builds amd64. `tini` availability was
verified on amd64 explicitly rather than assumed — same path the
build-time assertion checks:

```
Package: tini
Architecture: amd64
Version: 0.19.0-1+b3
-rwxr-xr-x 1 root root 27792 Jun  6  2025 /usr/bin/tini
tini version 0.19.0
```

## Pre-push checks

| Check | Result |
| --- | --- |
| `docker buildx build -f showcase/harness/Dockerfile` (== CI's build
check) | **PASS**, both images |
| `nx run @copilotkit/showcase-harness:typecheck` | **PASS** |
| `nx run @copilotkit/showcase-harness:test:ci` | 3677 passed, 18
skipped, 1 failed — **environmental**, see below |
| commitlint | **PASS** |
| lefthook `pre-commit` + `commit-msg` | **PASS** |
| `git status` | clean |

The single failure is `d0-gone-predicate.test.ts > resolves the real
generated registry.json…`, failing on `ENOENT …
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 via `generate-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-fix` glob 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

- **This does not fix prod by itself.** Prod is digest-pinned and still
running the leaking container; it needs the live mitigation restart
(owned by a separate worker — **prod was not touched here**) and then a
promote to pick this image up.
- **The ≥3-cell value test is not done and cannot be done from this PR**
— confirming red cells flip requires the prod restart plus a fleet
sweep. Note the ~20 `conversation-error` and ~16 `goto-error` cells are
almost certainly unrelated real bugs this will **not** fix; only the
`abort`/`feature-timeout`/`driver-error` population is in scope.
- **Alerting / scheduled recycle is deliberately out of scope** (one
concern per change). Still worth doing: the documented
`pool-unrecoverable` alarm demonstrably never fired at 1000/1000, and
`cgroupPidsCurrent/cgroupPidsMax > 0.75` would have given ~36h of
warning before the flip.
- Leak rate on the **graceful** `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 scratch

The proof above was produced 2026-08-03 against a base that predates
`ced993447f` ("copy patches/ into harness build context"), which touches
THIS
Dockerfile. The branch has been rebased onto current `origin/main` and
the
whole 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:**

```
showcase-harness:red-main    sha256:b86686e9a06d51f884d5e59e9d15d667fd298284efe7a15622ff3bf2575a3ffd created=2026-08-12T20:15:50Z  (origin/main Dockerfile, /usr/bin/tini ABSENT, Entrypoint=["docker-entrypoint.sh"])
showcase-harness:green-tini  sha256:d666b823f16bda07bf62d35f1d72ef099d13406a61e2f0cd51c99bf51eb14df4 created=2026-08-12T20:18:54Z  (this branch,          /usr/bin/tini present, Entrypoint=["/usr/bin/tini","--"])
```

Identical driver, identical argv, 40 cycles each, runs 18 seconds apart:

```
docker run --rm --pids-limit 1000 -e REPRO_CYCLES=40 -v <repro>:/repro:ro <image> \
  /bin/bash -c "exec node /repro/zombie-repro.mjs"
```

## RED — `showcase-harness:red-main`, `pid1=node` (2026-08-12T20:19:28Z)

```
baseline zombieCount=0 procCount=1 threadCount=7 cgroupPidsCurrent=7 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=1 pre-kill zombieCount=0 procCount=7 threadCount=76 cgroupPidsCurrent=76 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=1 zombieCount=5 procCount=6 threadCount=16 cgroupPidsCurrent=16 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=2 pre-kill zombieCount=5 procCount=12 threadCount=83 cgroupPidsCurrent=83 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=2 zombieCount=10 procCount=11 threadCount=21 cgroupPidsCurrent=21 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=10 pre-kill zombieCount=45 procCount=52 threadCount=120 cgroupPidsCurrent=120 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=10 zombieCount=50 procCount=51 threadCount=61 cgroupPidsCurrent=61 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=20 pre-kill zombieCount=95 procCount=102 threadCount=174 cgroupPidsCurrent=174 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=20 zombieCount=100 procCount=101 threadCount=111 cgroupPidsCurrent=111 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=30 pre-kill zombieCount=145 procCount=152 threadCount=219 cgroupPidsCurrent=219 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=30 zombieCount=150 procCount=151 threadCount=161 cgroupPidsCurrent=161 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=40 pre-kill zombieCount=195 procCount=202 threadCount=271 cgroupPidsCurrent=271 cgroupPidsMax=1000 selfPid=1 pid1=node
cycle=40 zombieCount=200 procCount=201 threadCount=211 cgroupPidsCurrent=211 cgroupPidsMax=1000 selfPid=1 pid1=node
final zombieCount=200 procCount=201 threadCount=211 cgroupPidsCurrent=211 cgroupPidsMax=1000 selfPid=1 pid1=node
SUMMARY cycles=40 zombiesBefore=0 zombiesAfter=200 pidsBefore=7 pidsAfter=211 launchFailure=none
```

All 200 leaked processes are `ppid=1`, state `Z` (tail of the final
`/proc` table):

```
 2610     1 Z   1 headless_shell <defunct>
 2612     1 Z   1 headless_shell <defunct>
 2646     1 Z   1 headless_shell <defunct>
 2661     1 Z   1 headless_shell <defunct>
 2662     1 Z   1 headless_shell <defunct>
 2678     1 Z   1 headless_shell <defunct>
 2680     1 Z   1 headless_shell <defunct>
 2717     1 Z   1 headless_shell <defunct>
```

## GREEN — `showcase-harness:green-tini`, `pid1=tini`
(2026-08-12T20:19:46Z)

```
baseline zombieCount=0 procCount=2 threadCount=8 cgroupPidsCurrent=8 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=1 pre-kill zombieCount=0 procCount=8 threadCount=76 cgroupPidsCurrent=76 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=1 zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=2 pre-kill zombieCount=0 procCount=8 threadCount=78 cgroupPidsCurrent=78 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=2 zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=10 pre-kill zombieCount=0 procCount=8 threadCount=79 cgroupPidsCurrent=79 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=10 zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=20 pre-kill zombieCount=0 procCount=8 threadCount=76 cgroupPidsCurrent=76 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=20 zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=30 pre-kill zombieCount=0 procCount=8 threadCount=77 cgroupPidsCurrent=77 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=30 zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=40 pre-kill zombieCount=0 procCount=8 threadCount=79 cgroupPidsCurrent=79 cgroupPidsMax=1000 selfPid=7 pid1=tini
cycle=40 zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
final zombieCount=0 procCount=2 threadCount=12 cgroupPidsCurrent=12 cgroupPidsMax=1000 selfPid=7 pid1=tini
SUMMARY cycles=40 zombiesBefore=0 zombiesAfter=0 pidsBefore=8 pidsAfter=12 launchFailure=none
```

`grep -c defunct` over the GREEN run: **0**. `procCount` returns to
**2**
(tini + node) after every cycle — the browser's 6 processes appear
pre-kill
(`procCount=8`, `threadCount` 76–79) and are fully gone post-kill.

|  | RED (`pid1=node`) | GREEN (`pid1=tini`) |
| --- | --- | --- |
| image id | `b86686e9a06d` | `d666b823f16b` |
| cycles | 40 | 40 |
| zombies after | **200** | **0** |
| zombies per crashed browser | **+5** | **0** |
| `pids.current` before → after | 7 → **211** | 8 → **12** |
| `<defunct>` rows in final table | **200** | **0** |
| `launchFailure` | none | none |

## Signals / non-zero exit, both images, this run

```
[showcase-harness:RED   MODE=term-graceful] exitCode=0
    CHILD mode=term-graceful pid=1 ppid=0
    CHILD received SIGTERM at pid=1 — draining
[showcase-harness:RED   MODE=exit-42]   exitCode=42
[showcase-harness:RED   MODE=abort]     exitCode=133
    RED  /proc/1/comm = bash

[showcase-harness:GREEN MODE=term-graceful] exitCode=0
    CHILD mode=term-graceful pid=7 ppid=1
    CHILD received SIGTERM at pid=7 — draining     <- tini FORWARDED it to node
[showcase-harness:GREEN MODE=exit-42]   exitCode=42
[showcase-harness:GREEN MODE=abort]     exitCode=134
    GREEN /proc/1/comm = tini, child self=7
```

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_snapshots` in prod PocketBase, immediately before the
mitigation
restart on the unfixed digest `sha256:80a0c5c2…`:

```
2026-08-12 20:10:00.674Z worker-7abf6 heartbeat pids=1000/1000 zombies=758 procs=778 threads=1000
2026-08-12 20:09:59.783Z worker-5a213 heartbeat pids=1000/1000 zombies=761 procs=781 threads=1000
2026-08-12 20:09:54.868Z worker-de14c heartbeat pids=837/1000  zombies=744 procs=753 threads=837
```

and immediately after it (`init` rows): `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/tini` 68592 bytes); prod builds amd64.
Measured on amd64 directly: `Package: tini / Architecture: amd64 /
Version: 0.19.0-1+b3`, `/usr/bin/tini` 27792 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 `startCommand` is `null` and no repo consumer overrides the
entrypoint,
so Railway uses the image's ENTRYPOINT+CMD. **PR #5750 is CLOSED
unmerged**, so
promoting `harness-workers` resets
`multiRegionConfig.us-west2.numReplicas` to
1 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/1000` across three workers, 320 `timeout after
600000ms`
abort rows, an `e2e-smoke` run 42 minutes into a 15-minute cadence with
3 jobs
still 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-unrecoverable` alarm did not fire *by
construction*: it is
raised only when `BrowserPool`'s self-heal circuit-breaker exhausts
`selfHealMaxHardRecoveries`. A worker that is PID-starved but still
heartbeating
never 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:192` writes `capacity_pids_current` /
`capacity_pids_max` onto the worker's `workers` row on its ~75s
heartbeat
  (`DEFAULT_WORKER_HEARTBEAT_MS = 75_000`).
- `control-plane/fleet-health.ts` lists that entire roster every 15s
(`DEFAULT_FLEET_HEALTH_INTERVAL_MS`) — and its own comment on the row
type
  said *"the capacity gauges are ignored here."*
- Nothing in non-test source compared `pidsCurrent` to `pidsMax`.

## Where the alarm goes, and why

**Control-plane, not worker.** `writers/status-writer.ts` documents
`fleet-cp`
as *"the only authoritative fleet writer; workers never write status
directly"*,
so a worker cannot raise a `system:` health key. `fleet-health` already
holds
the 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_UNRECOVERABLE` appears **nowhere in this
repo
outside its own definition** — `grep` finds it only in `orchestrator.ts`
— so it
is unset everywhere and that alarm has no receiver even when it does
fire.
`SLACK_WEBHOOK_OSS_ALERTS` is a real wired secret that the
family-silence
monitor 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

- **Alarm at `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.
- **Latched per worker, clearing at 0.65.** The monitor ticks every 15s;
an
unlatched alarm would page ~8600 times across that 36-hour window. An
alarm
that fires constantly is worse than none, so `createFleetHealthMonitor`
now
  **fails loud at construction** on a ratio pair with no hysteresis gap.
- **Evaluated before the online/stale branch**, because the failing
worker is
  fully `online` — it heartbeats on time throughout.
- **Unmeasured gauges never alarm.** `registration.ts` maps the pool's
`-1`
sentinel to `null`; `pidUsageRatio` returns `null` for
null/absent/negative
  current 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 PB
transport. 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:

```
BrowserPool.budget()            [real, probes/helpers/browser-pool.ts]
  -> workerCapacityFromBudget   [real, fleet/contracts.ts]
  -> registerWorker()           [real, fleet/worker/registration.ts]
  -> workers row
  -> createFleetHealthMonitor().checkOnce()
                                [real, fleet/control-plane/fleet-health.ts]
  -> alarm sink
```

Identical command both sides; only the source differs:

```
./node_modules/.bin/tsx <scratch>/drive-alarm.mts
```

### RED — unmodified source

```
=== A1 SATURATED 900/1000 (ratio 0.90) ===
  pool.budget() pids      : 900/1000
  workers row gauges      : capacity_pids_current=900 capacity_pids_max=1000
  fleet-health cycles run : 1
  ALARM HOOK CALLS        : 0
  result.pidSaturated     : <field does not exist>
  error-level log events  : <none>

=== A2 CEILING   1000/1000 (ratio 1.00) ===
  pool.budget() pids      : 1000/1000
  workers row gauges      : capacity_pids_current=1000 capacity_pids_max=1000
  fleet-health cycles run : 1
  ALARM HOOK CALLS        : 0
  result.pidSaturated     : <field does not exist>
  error-level log events  : <none>

=== A6 LATCH     900/1000 over 5 cycles ===
  fleet-health cycles run : 5
  ALARM HOOK CALLS        : 0
  result.pidSaturated     : <field does not exist>
  error-level log events  : <none>
```

The exact prod condition — a worker at the ceiling — produces **zero**
alarms.

### GREEN — with this change

```
=== A1 SATURATED 900/1000 (ratio 0.90) ===
  pool.budget() pids      : 900/1000
  workers row gauges      : capacity_pids_current=900 capacity_pids_max=1000
  fleet-health cycles run : 1
  ALARM HOOK CALLS        : 1
  result.pidSaturated     : 1
  error-level log events  : ["fleet.health.worker-pid-saturated"]
  ALARM PAYLOAD           : {"workerId":"worker-drv","pidsCurrent":900,"pidsMax":1000,"ratio":0.9,"threshold":0.75,"lastHeartbeatAt":"2026-08-12T20:44:54.244Z","observedAt":"2026-08-12T20:44:54.244Z"}

=== A2 CEILING   1000/1000 (ratio 1.00) ===
  ALARM HOOK CALLS        : 1
  result.pidSaturated     : 1
  error-level log events  : ["fleet.health.worker-pid-saturated"]
  ALARM PAYLOAD           : {"workerId":"worker-drv","pidsCurrent":1000,"pidsMax":1000,"ratio":1,"threshold":0.75,"lastHeartbeatAt":"2026-08-12T20:44:54.253Z","observedAt":"2026-08-12T20:44:54.253Z"}
```

### The alarm must also stay QUIET — same run, same command

```
=== A3 QUIET     500/1000 (ratio 0.50) ===
  ALARM HOOK CALLS        : 0
  result.pidSaturated     : 0
  error-level log events  : <none>

=== A4 QUIET     740/1000 (ratio 0.74, just under) ===
  ALARM HOOK CALLS        : 0
  result.pidSaturated     : 0
  error-level log events  : <none>

=== A5 QUIET     -1/-1 (cgroup unreadable) ===
  pool.budget() pids      : -1/-1
  workers row gauges      : capacity_pids_current=null capacity_pids_max=null
  ALARM HOOK CALLS        : 0
  result.pidSaturated     : 0
  error-level log events  : <none>

=== A6 LATCH     900/1000 over 5 cycles ===
  fleet-health cycles run : 5
  ALARM HOOK CALLS        : 1        <- once, not five times
```

`A4` pins the boundary at 0.74. `A5` pins the off-Linux case: the `-1`
sentinel
lands as `null` on the row and stays silent rather than reading as `0`.
`A6`
pins 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.ts` had exactly one conditional in the claim
loop:

```ts
if (budget.available <= 0) { … idle … }
```

and `available` is 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/1000` therefore still advertises **full** capacity,
keeps
winning 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:

- the job is **never claimed**, so it is never dropped and never
requeued — it
stays `pending` for a healthy worker, or for this one after a redeploy;
- the loop then sleeps a full `pollIntervalMs`, so a fully-saturated
fleet
  **idles at the poll cadence** instead of spinning;
- the queue **stalls visibly**: `probe_jobs` rows pile up pending, a
rising-edge
`fleet.worker.pid-headroom-exhausted` warn 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-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.

## 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_RATIO`
override. 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
as
before.

---

## RED → GREEN (change 3)

Driver runs the **real `startWorkerLoop`** against the **real
`BrowserPool`**
budget path, faking only the cgroup read and the queue transport. The
queue fake
holds a real `pending` list, so *"was the job dropped / does it stay
pending"* is
directly observed, not inferred. `budget()` calls are counted as a
loop-iteration proxy for the spin check.

Identical command both sides:

```
./node_modules/.bin/tsx <scratch>/drive-gate.mts
```

### RED — unmodified source

```
=== B1 SATURATED  1 worker @ 1000/1000, 3 jobs pending ===
  workers=1  cgroup pids=1000/1000  contexts available=24
  window                  : 600ms @ poll 50ms
  queue.claimNext CALLS   : 15
  jobs CLAIMED            : 3 ["job-1","job-2","job-3"]
  jobs STILL PENDING      : 0 []
  jobs REPORTED           : 3
  loop iterations         : 15

=== B2 ALL-SATURATED  3 workers @ 1000/1000, 3 jobs pending ===
  workers=3  cgroup pids=1000/1000  contexts available=24
  queue.claimNext CALLS   : 39
  jobs CLAIMED            : 3 ["job-1","job-2","job-3"]
  jobs STILL PENDING      : 0 []
  jobs REPORTED           : 3
  loop iterations         : 39
```

A worker at the PID ceiling claims **all three jobs**. In prod each of
those
becomes a 600000ms abort.

### GREEN — with this change

```
=== B1 SATURATED  1 worker @ 1000/1000, 3 jobs pending ===
  workers=1  cgroup pids=1000/1000  contexts available=24
  window                  : 600ms @ poll 50ms
  queue.claimNext CALLS   : 0
  jobs CLAIMED            : 0 []
  jobs STILL PENDING      : 3 ["job-1","job-2","job-3"]
  jobs REPORTED           : 0
  loop iterations         : 12 (spin check: bounded by window/poll)
```

`claimNext` is never called; all three jobs are **still pending** — not
dropped,
not requeued.

### ALL workers saturated — the blast-radius case

```
=== B2 ALL-SATURATED  3 workers @ 1000/1000, 3 jobs pending ===
  workers=3  cgroup pids=1000/1000  contexts available=24
  window                  : 600ms @ poll 50ms
  queue.claimNext CALLS   : 0
  jobs CLAIMED            : 0 []
  jobs STILL PENDING      : 3 ["job-1","job-2","job-3"]
  jobs REPORTED           : 0
  loop iterations         : 36 (spin check: bounded by window/poll)
```

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

```
=== B3 HEALTHY  1 worker @ 100/1000, 3 jobs pending ===
  queue.claimNext CALLS   : 15
  jobs CLAIMED            : 3   jobs STILL PENDING : 0   jobs REPORTED : 3

=== B4 UNDER-GATE  1 worker @ 890/1000, 3 jobs pending ===
  queue.claimNext CALLS   : 15
  jobs CLAIMED            : 3   jobs STILL PENDING : 0   jobs REPORTED : 3

=== B5 UNMEASURED  1 worker @ -1/-1, 3 jobs pending ===
  queue.claimNext CALLS   : 15
  jobs CLAIMED            : 3   jobs STILL PENDING : 0   jobs REPORTED : 3
```

`B4` is the load-bearing one: 0.89 is **above** change 2's 0.75 alarm
and below
this gate. The operator has been paged and the worker keeps working —
which is
the whole reason the two thresholds differ. `B5` pins the off-Linux
case.

---

# Tests and gates (changes 2 and 3)

`showcase/harness`, on the pushed head `63ef4081c2`:

| Gate | Command | Result |
|---|---|---|
| Typecheck | `npx tsc --noEmit -p tsconfig.json` | exit 0 |
| Lint | `npx oxlint src/fleet src/orchestrator.ts` | 0 errors; warning
count unchanged vs base (2 on `fleet-health.ts` before and after) |
| Format | `npx oxfmt --write` | clean |
| Unit suite | `vitest run` | **3696 passed, 18 skipped, 1 failed** —
175/178 files pass |

The 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
`e66fb1af13` and the new test files kept, **11 of the new tests fail**:

```
Test Files  2 failed (2)
     Tests  11 failed | 80 passed (91)

FAIL fleet-health.test.ts > PID saturation > alarms on an ONLINE worker whose PID gauges cross the threshold
FAIL fleet-health.test.ts > PID saturation > stays silent below the threshold, including just under it
FAIL fleet-health.test.ts > PID saturation > stays silent when the gauges are UNMEASURED (null / unbounded max)
FAIL fleet-health.test.ts > PID saturation > is EDGE-triggered: a sustained saturation alarms once, not every cycle
FAIL fleet-health.test.ts > PID saturation > re-arms only after the worker drops below the CLEAR ratio
FAIL fleet-health.test.ts > PID saturation > never lets a throwing alarm hook abort the cycle
FAIL fleet-health.test.ts > PID saturation > fails loud on a ratio config that would alarm every cycle
FAIL worker-loop.test.ts  > PID headroom gate > declines to claim at the PID ceiling — the job is never claimed, so it stays pending
FAIL worker-loop.test.ts  > PID headroom gate > declines at the gate ratio boundary (0.90)
FAIL worker-loop.test.ts  > PID headroom gate > honours an injected gate ratio
FAIL fleet-health.test.ts > checkOnce > never throws when the roster read fails — returns an empty cycle
```

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 the
fix, and they are.

# New env knobs (all optional, all defaulted)

| Var | Default | Effect |
|---|---|---|
| `WORKER_PID_SATURATION_RATIO` | `0.75` | Control-plane alarm
threshold. |
| `WORKER_PID_SATURATION_CLEAR_RATIO` | `0.65` | Alarm latch hysteresis
clear. |
| `WORKER_PID_CLAIM_GATE_RATIO` | `0.90` | Worker claim-gate threshold.
|

An 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

- Neither change 2 nor change 3 has been exercised against **live prod
or
staging PocketBase**; both red-greens are local, on the real modules
with the
  cgroup read and PB/queue transport injected.
- **No Slack post was sent.** `SLACK_WEBHOOK_OSS_ALERTS` was not set in
the
driver, so the send leg was not exercised end-to-end — only that its
failure
  is swallowed without costing the durable status row.
- The per-job PID cost of a chromium context tree is **not measured**,
so the
  0.90 gate's 100-PID reserve is a chosen value.
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