Public: anyone can read this; the crew can change it.
No flaky tests: ten green runs to join the gate, a nightly flake hunt in random order, mechanical quarantine #1323
Flaky tests now have a ten-run admission bar, a nightly hunt that runs in random order, and quarantine through an issue instead of by hand. This redoes #1268.
stopped closed without shipping deploy 9830f23
3 earlier comments
The flaky 50 ms check in test/spawn-first-boot.test.ts is fixed. The suite now refuses any test that limits a measured time to under 200 ms, and the nightly flake hunt names this as a sixth root cause. Both are pushed to this branch.
What changed
- The flaky test: "the child answers /healthz and / quickly once booted" now requires the median of five loopback fetches to be under 500 ms instead of 50 ms. It went red at 65.4 ms on the shared runner (trevato-apps/forge PR #36, shard 47). What it guards against is a boot on every request, which takes seconds, so 500 ms still catches that. This is the same bound used upstream.
- A new root cause:
scripts/flake.tsadds "a tight wall-clock bound" toROOT_CAUSES. The fix it gives is to compare against a baseline measured in the same run, or to set the bound atWALL_CLOCK_FLOOR_MS(200) or more. Every issue the hunt files now lists it. - A new guard:
tightBounds()sits next toretries(). It flagsexpect(<measured time>).toBeLessThan(N)(or…OrEqual) when N is a number under 200. "Measured time" means the expression mentionsnow,elapsed,took,ms,duration,latency,times,startedorbegan.test/flake.test.tsruns it over everytest/*.test.ts, gated or not, so an excluded file can't bring the pattern back when it rejoins. Counts, sizes and status codes are left alone, and its examples check this. - Docs: README and CLAUDE.md now list the sixth root cause and the 200 ms floor.
What I chose not to do
- I didn't rewrite the test as a relative assertion. Its point is "not a boot per request", and a generous fixed bound says exactly that.
- I didn't change bounds of 1 s and up elsewhere, such as
decide.test.tsandsnapshot-store.test.ts. They are above the floor, and if one flakes the hunt will name it. - The detector only reads numbers written in the assertion. A bound stored in a named constant, like
search.test.ts'sLIVE_BUDGET_MS + 1_500, isn't checked. A full-suite scan turned up no other bound under 200 ms.
How to try it
bun test test/flake.test.tspasses. With the old 50 ms line restored, it fails and namestest/spawn-first-boot.test.ts:245.- The type check is clean.
- The edited test itself could not run here: the sandbox blocks the unix socket the spawned child listens on (
EPERMonlisten), so the forge's check is the first real run of it.
🤖 Generated with Claude Code
The gate now hunts flaky test files instead of trusting them. To join the gate, a file has to pass ten runs in a row. A flaky file is quarantined against an issue number instead of being retried, and the hunt runs every night. The README explains how a file joins the gate and how it leaves.
What changed
scripts/gate.ts: addstest/flake.test.tsto the gate list, and holds the hunt, the quarantine-by-issue list and the ten-run admission rule.- Wall-clock bounds: any test file that asserts a timing bound under 200 ms is now refused, because tighter bounds fail on a busy machine for reasons unrelated to the code under test.
spawn-first-boot: its loopback median bound goes from 50 ms to 500 ms so it passes that rule. The old bound was too tight to hold on a loaded runner, so this is a test that was wrong, not a code change.- Merge with main: this branch and main had both added entries at the end of the
GATElist. The merge keeps both, soflake.test.tssits beside main's newly admittedssh-site,web-codeandweb-originstests. No file was dropped and none appears twice.
What to look at
The exclusion list in scripts/gate.ts and the 200 ms rule are where the policy lives. The type check is clean and bun test test/flake.test.ts passes (17 tests).
What I chose not to do
No test files were quarantined or rewritten beyond spawn-first-boot. A file that starts failing should get its own issue and go into quarantine by that issue number.
How to try it
Run bun test test/flake.test.ts, or run the hunt script against one file and watch it ask for ten green runs before admitting it.
🤖 Generated with Claude Code
A file can now join the test gate only with proof of ten green runs in random order under load. Removing one goes through a quarantine step tied to an issue, which a nightly flaky-test hunt opens.
scripts/flake.tsholds the rules: the run report, the text of the issue the hunt opens, and the edit that moves a file fromGATEtoEXCLUDED.scripts/flake-hunt.tsis the command line:admit <file>runs the file ten times and prints a report to paste into the pull, andquarantinemoves a flaky file out of the gate under its issue..forgejo/workflows/flake-hunt.ymlruns the hunt every night and opens aFlaky: test/…issue for any file that fails. The issue lists the usual causes and says a retry is not a fix.test/flake.test.tscovers all of this and is in the gate itself.scripts/gate.ts,README.mdandCLAUDE.mddescribe the new admission rule.
Merge with main:
test/spawn-first-boot.test.tsconflicted only in a comment: both branches had already raised the median bound to 500 ms, so I kept main's version.- Main had added
test/plan-route.test.tswithout listing it inGATEorEXCLUDED, which made the gate audit incheck-list.test.tsandflake.test.tsfail. That test timed out at 30 s on each of three runs here, far over the 1 s budget for a test. I listed it inEXCLUDEDas "not yet admitted" under #261. Making it fast is left to that issue.
flake.test.ts, check-list.test.ts and spawn-first-boot.test.ts pass after the merge. I couldn't fully run two other checks here:
- Type check: it stopped on a missing
buntype definition before checking any code. admitonplan-route.test.ts: it printed nothing before my 280 s limit cut it off.
To try it: bun scripts/flake-hunt.ts admit test/flake.test.ts, then bun test test/flake.test.ts test/check-list.test.ts.
🤖 Generated with Claude Code
Parked by the crew: the check stayed red through 2 automatic tries
Flaky tests now have a ten-run admission bar, a nightly hunt that runs in random order, and quarantine through an issue instead of by hand. This redoes #1268. That pull's red check came from its branch being cut before #1200: main's
--tier fastcommand ran against an oldscripts/test-shards.tsthat didn't know the flag. Its hunt also had a real bug. Outside a terminal,bun testprints only(fail)lines and never(pass), so it could never see a test pass and would have called every flake "broken". Here the verdict is each file's exit code, which is also what the gate judges and what quarantine moves. Failing test names and the text above them go into the issue.bun scripts/flake-hunt.ts admit test/x.test.tsruns the file ten times. Each run is its ownbun test --randomizewith a fresh seed, next to busy loops on half the cores. It prints the seeds as a record for the pull and exits non-zero unless all ten are green.test/flake.test.tsjoinsGATEin this pull, with its record:flake-hunt.ts hunt [--shard N/M] [--file-issues]runs every gate file five times. Each run gets a fresh seed that sets the file order (a seeded shuffle) and, through--randomize, the test order inside each file. It runs under the same load as admission and does not stop at the first failure. A file red in some runs and green in others is flaky. A file red in every run is reported as broken, not flaky. With--file-issuesit filesFlaky: test/x.test.tscarrying the failure text, the seed with a command to replay it, and the run's link. It skips files that already have an open issue.flake-hunt.ts quarantinereads the openFlaky:issues and moves each file still inGATEtoEXCLUDEDunder that issue's number. It editsscripts/gate.ts, so the issue is the record and nobody edits the list by hand..forgejo/workflows/flake-hunt.ymlruns at 02:17 UTC, split across 20 jobs because the runner cuts a job at about 30 minutes. A final job runsquarantineand opens aflake-hunt/<date>pull on the forge.test/flake.test.tsfails on--retry,--rerun-each, a bunfigretry =or a{ retry: N }. It checksforge.json,bunfig.toml,package.json, the workflows, the gate scripts and every file inGATE.What to look at: the file-level verdict in
scripts/flake.ts(readRunandfindFlakes), andquarantine(). The test loads the editedgate.tsand checks it withauditGate.Not done:
FORGE_TOKENsecret and aFORGE_URLvariable on the mirror.GATEfile was put through admission, and the known flaky ones (apps-ws,apps-idle,signin-throttle, …) are not fixed. The first hunt will quarantine whichever of them flake.src/crew/dispatch.ts,retriedChecks). That is a retry at the check level, not inside the gate. Removing it changes how the crew behaves and belongs in its own issue.Tests and checks:
tscis clean.flake,check-list,shardsandhollowpass.studioandreserved-namesfail locally with the same unix-socketEPERMfrom the sandbox, on main as well as this branch, so that failure is not caused by this change.quarantineagainst the live API listed the open issues and moved nothing.To try it:
bun test test/flake.test.tsbun scripts/flake-hunt.ts admit test/qr.test.tsbun scripts/flake-hunt.ts hunt --runs 2 --shard 58/60🤖 Generated with Claude Code
Closes #1243
Closes #1243