Skip to content

chore(ci): scale test watchdogs under the determinism gate and stop flagging raised timeouts (#4191) - #4193

Merged
schlessera merged 5 commits into
mainfrom
chore/4191-watchdog-catch-all
Nov 17, 2026
Merged

schlessera merged 5 commits into
mainfrom
chore/4191-watchdog-catch-all

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #4191

What changed

A test watchdog (a timeout that exists to stop a hang and clean up) is now handled as a catch-all for the worst case, in the tooling and in the written rules.

  • The determinism job multiplies test deadlines by a fixed factor of 8. One owner holds it, beside the job's other numbers (DETERMINISM_PARTITIONS.deadlineFactor, scripts/proof-shards.ts). Inside the repetition run three things scale: Bun's per-test cap (240 s for the root script's 30 s, through a later --timeout), every explicit test and hook timeout (through a preload that replaces bun:test with a scaling copy), and in-test watchdogs written as watchdogMs(n) (through BRAIN_TEST_DEADLINE_FACTOR). No other job scales anything, and no existing test is edited except the one below.
  • The 27-second watchdog in tests/integration-command.test.ts reads the helper.
  • bun scripts/proof-system.ts classify no longer flags a timeout or deadline that is only raised. A lowered, removed or added one stays a proof-system change, and so does a change whose direction it cannot read.
  • The policy is written down: a decision-record section that says what it supersedes, the two kinds of number (watchdog and product timing) with a test for telling them apart, how to size a watchdog and what to do when one trips (docs/decisions/ci-utility.md, docs/process/testing.md, docs/process/test-authoring.md rule C4, docs/process/test-waits.md, AGENTS.md, and the test-health skill's two rules that said the opposite).

Why this shape

The factor. 8 is the smallest whole number at least 15% above 6.84, the largest slowdown measured under the job's own load (elapsed seconds per weighted second, run 44039499653, the highest of the five calibration runs of #4117). Per test the slowdown is smaller: across the determinism jobs of 33 hosted runs on 2026-11-17, 140 test cases that take at least one second in the unit job of main run 44107659969 ran 1,137 times, with a median of 1.94 times their unit duration, a 99th percentile of 3.40 and a maximum of 3.83. The test that prompted the ruling ran 3.3 times slower (8.3 s in unit, 26.9 s and 27.2 s in run 44104941268). A test asserts that the factor covers the measured ratio with its margin, and that a full capacity at that ratio plus one hung test under the scaled cap still fits the 40-minute step (2,052 s + 240 s). --bail=1 means at most one test waits out its cap.

Explicit timeouts. Bun 1.4.2 has no flag for them. Verified on the pinned version: the last --timeout wins, and neither --timeout nor setDefaultTimeout changes a timeout a test names itself. About 650 explicit timeouts in the Bun test files are exactly the long tests most likely to trip under load, so leaving them unscaled would have kept most of the friction. Two mechanisms were tried:

  • Assigning scaled registrars to the object require("bun:test") returns. Declined: it only works until something imports bun:test, and the offline preload already has. The first real run through the wrapper showed this, caught by the preload's own check.
  • mock.module("bun:test", …) from a second preload, loaded only by the repetition command. Taken: on 1.4.2 and 1.4.4 the replacement reaches every later import and the runner's globals, in every file and every repetition, and a test's mock.restore() does not undo it. The preload checks that the replacement took and stops the run if it did not.

The preload is passed on the command line by scripts/test-determinism.ts instead of being imported by the shared offline preload, so unit and every other command are untouched and the ten fixtures that copy the offline preload need no change.

The classifier. A raise is read only where a value is rewritten in place (same hunk) to the same or a larger number, or to the same expression with no number made smaller. A duration inside watchdogMs(...) is read as that duration, so adopting the helper is not a change, and leaving it is a lowering. Adding a timeout to an existing test stays flagged: the check does not know which default applied before, so it cannot tell a raise from a lowering. That is narrower than the ruling allows and is named under "Anything left open".

What stays unscaled is listed in the decision record: waits a test bounds without the helper, timeouts inside the product and inside child processes, product timings, the job's own limits, every other job, and Vitest specs (#4192).

Proof

bun run check:pr --base origin/main

All runs below are on Bun 1.4.2, the version CI pins.

Failing first, for the reason claimed

Tests added first Red before the change Reason shown
tests/proof-system.test.ts, raise/lower/remove cases 11 of 31 failed RAISED_WATCHDOG_IS_NOT_FLAGGED, ADOPTING_THE_HELPER_IS_A_RAISE, SAME_SHAPE_LARGER_NUMBER_IS_A_RAISE: the old check reported every raise
tests/test-determinism.test.ts, "watchdogs scale under the gate" (helper modules and the --deadline-factor argument present, nothing passed to the wrapper yet) 3 of 7 failed the slow fixture: this test timed out after 500ms; the hang: AT_THE_SCALED_CAP (it timed out after 250 ms, not 2000); WAITED_THE_SCALED_WATCHDOG

The two receipts the issue asks for are permanent tests in tests/test-determinism.test.ts, run through the real command and the real offline wrapper in a scratch checkout:

  • Passes with the scaling: three fixtures, one per watchdog kind (the runner's cap, the test's own timeout, an in-test watchdogMs timer), each taking half its 500 ms watchdog in calm water and three times that under ODYSSEUS_HEADWIND=3, pass two repetitions at the gate's factor (SLOW_TESTS_PASS_UNDER_THE_SCALED_WATCHDOGS).
  • Fails without it: the same fixtures with --deadline-factor 1 each fail in repetition 1 on their own watchdog (UNSCALED_WATCHDOG_TRIPS, TRIPPED_BY_ITS_OWN_WATCHDOG).

The slowdown in those fixtures is simulated by sleeping, so the receipts are certain on any host and need no real burn. The run at the gate's real load is this PR's own hosted determinism job, linked below.

A true hang still fails, within the scaled watchdog, with its child gone: a fixture that waits for a sleep 300 child fails at exactly the scaled cap (this test timed out after 2000ms) and its PID is gone (HUNG_CHILD_CLEANED_UP); the same hang under an in-test watchdogMs(200) timer is stopped by that timer after at least 1,600 ms.

Mutations, each restored afterwards

Mutation Killed by Assertion
raisedOrEqual always false (every change flagged, the old behaviour) 10 cases in tests/proof-system.test.ts RAISED_WATCHDOG_IS_NOT_FLAGGED
raisedOrEqual always true (no change flagged) 8 cases LOWERED_STAYS_FLAGGED
a raise accepted across hunks "only a rewrite in place is a raise" MOVED_TIMEOUT_IS_NOT_A_RAISE
leaving watchdogMs not read as a lowering "starts reading the scaling helper" LEAVING_THE_HELPER_IS_A_LOWERING_UNDER_LOAD
scaled --timeout not passed cap fixture and the hang case this test timed out after 500ms
scaling preload not passed explicit-timeout fixture the explicit case times out
factor not set in the environment in-test watchdog hang WAITED_THE_SCALED_WATCHDOG
watchdogMs returns the written duration tests/test-deadlines.test.ts WATCHDOG_SCALES_WITH_THE_RUN
registrar proxy passes itself as receiver tests/test-deadlines.test.ts RECEIVER_IS_THE_REAL_REGISTRAR
deadlineFactor: 7 owner test FACTOR_COVERS_THE_MEASURED_SLOWDOWN_WITH_MARGIN
deadlineFactor: 12 owner test STEP_LIMIT_STILL_BOUNDS_A_SCALED_RUN

Focused runs on the final tree: tests/proof-system.test.ts, tests/test-deadlines.test.ts, tests/test-determinism.test.ts, tests/hosted-proof.test.ts, tests/ci-workflows.test.ts, tests/integration-command.test.ts, tests/integration-proof.test.ts, tests/red-main.test.ts, tests/ci-plan.test.ts, tests/local-checks.test.ts, tests/check-receipt.test.ts, tests/ci-epochs.test.ts, tests/refresh-browser-costs.test.ts, tests/docs-paths.test.ts, tests/release-manifest.test.ts and scripts/skill-tests/test-health-batch.test.ts pass; tsc --noEmit and bun run lint are clean. The real command, in this checkout, with one burner for 15 seconds: bun scripts/test-determinism.ts --burners 1 --repetitions 2 tests/proof-system.test.ts tests/test-deadlines.test.ts passed with deadlines: { factor: 8, testCapMs: 240000 } in its report.

Acceptance criteria

Criterion Evidence
Half-its-watchdog fixture passes under the command, fails without the scaling The two receipts above; hosted run below
A true hang still fails within the scaled watchdog, children cleaned up The two hang cases above
classify reports a raise as not a proof-system change, a lowering or removal as one, with a mutation tests/proof-system.test.ts (the command case and the cases around it); first two mutations
The 27-second deadline reads the helper and passes the hosted job watchdogMs(27_000); hosted run below
The decision record states the factor, the runs and what stays unscaled "Test watchdogs are a worst-case catch-all" in docs/decisions/ci-utility.md
The docs say how to size a watchdog and that a tripped one is raised or scaled "Watchdogs and product timings" in docs/process/testing.md, rule C4 in docs/process/test-authoring.md, AGENTS.md

Off-main qualification

After merging main, which now carries the browser repetition job (#4163): https://github.com/schlessera/brain-kit/actions/runs/44124983219 (draft, head 74a58fb0552aebf67817d3f79c628faac0305871). Its determinism (1) job repeats this PR's changed Bun test files with the deadline scaling in effect.
Run https://github.com/schlessera/brain-kit/actions/runs/44121413796 on head 93fcb661490d4d500dbd42dffdf5621a20396878 (this draft's own ci.yml run).

What it establishes: the draft changes four Bun test files (tests/integration-command.test.ts, tests/proof-system.test.ts, tests/test-deadlines.test.ts, tests/test-determinism.test.ts), so its determinism job repeats them under four burners on four CPUs with the scaling in effect: about 61 weighted seconds per pass, four repetitions. The comparison is run 44104941268, where the same job, unscaled, failed tests/integration-command.test.ts at 27.2 s against its 27-second watchdog. A pass here shows that file clearing the gate with its watchdog at 216 s and Bun's cap at 240 s, and the job's report records deadlines: { factor: 8, testCapMs: 240000 }. The nested fixtures in tests/test-determinism.test.ts and tests/test-deadlines.test.ts run inside the same loaded job, including the controls that must still fail with the factor at one.

{"version":1,"kind":"brain-check-pr-receipt","head":"74a58fb0552aebf67817d3f79c628faac0305871","base":"origin/main","mode":"focused","startedAt":"2026-11-17T16:19:48.180Z","finishedAt":"2026-11-17T16:21:19.644Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":14329.656328},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":132.4550139999992},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":72.5485800000024},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":21.879912999997032},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":76891.014368}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • A PR touching packages/ui-react/, packages/ui-kit/, packages/ui-server/ or packages/core/ carries a recorded independent review of its head (bun scripts/review-receipt.ts check <pr>), or it touches none of them.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

The one guard added is the scaling preload's check (scripts/test-deadline-preload.ts).

  • Trigger: after replacing bun:test, a fresh import does not return the scaled test and beforeEach. It does not cover a wait a test bounds without a test timeout or watchdogMs.
  • What it restricts: the one bun test invocation of the repetition command. Nothing narrower exists: the replacement is per process.
  • Restricted mode considered: running on with explicit timeouts unscaled and a warning. Declined, because the result would be slow tests failing on their own timeouts and reading as test faults, which is the failure this change removes. The same choice applies to a malformed factor, which is refused instead of being read as one.
  • How it clears: by itself, on the next run with a Bun on which the replacement works. It can only start failing on a Bun version change, and tests/test-deadlines.test.ts and tests/test-determinism.test.ts run the preload under real bun test in the unit job, so that change goes red before it merges.
  • Where the cause is recorded: the error names the preload and the consequence, in the job log; the report names the factor and the scaled cap.
  • Another scope stays usable: tests/test-deadlines.test.ts, "with the factor unset the preload does nothing": every command other than the repetition command never loads the preload, and with a factor of one it changes nothing.

Anything left open

🤖 Generated with Claude Code

schlessera and others added 3 commits November 17, 2026 16:00
…ge (#4191)

A watchdog is a catch-all for the worst case, so raising one cannot make a
passing test fail. The timeout check now reads the direction of a value
rewritten in place: the same or a larger number, or the same expression with
no number made smaller, is not reported. A lowered, removed or added value is
still a proof-system change, and so is one whose direction cannot be read or
that moved between hunks. A duration inside watchdogMs() is read as that
duration, so adopting the scaling helper is not a change and leaving it is a
lowering.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The gate applies CPU load on purpose, and a timeout that exists to stop a hang
is a catch-all for the worst case. The repetition command now multiplies test
deadlines by one factor, owned by DETERMINISM_PARTITIONS.deadlineFactor: Bun's
per-test cap through a later --timeout, explicit test and hook timeouts
through a preload that replaces bun:test with a scaling copy, and in-test
watchdogs that read watchdogMs() through the environment. The 27-second
watchdog in tests/integration-command.test.ts reads the helper.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Records the 2026-11-17 ruling and what it supersedes: the practice of treating
every test deadline as proof that must not move. The decision record states
the two kinds of number, the gate's factor of eight with the hosted runs
behind it, what stays unscaled, and what the proof-system check still flags.
The process docs say how to size a watchdog and what to do when one trips.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 17, 2026
@schlessera schlessera added type: chore Tooling, CI, release plumbing, dependencies. area: ci CI workflows, the gates they run, release scripts, packaging. labels Nov 17, 2026
@schlessera
schlessera marked this pull request as ready for review November 17, 2026 17:16
@schlessera
schlessera merged commit 0babede into main Nov 17, 2026
49 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci CI workflows, the gates they run, release scripts, packaging. type: chore Tooling, CI, release plumbing, dependencies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: test watchdogs are a worst-case catch-all: scale them under the determinism gate and stop treating them as proof

1 participant