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 #1504

Closed opened this in answer to
Closed without merging

Flaky tests now have a ten-run bar to join the gate, a nightly hunt that runs in random order, and quarantine through an issue instead of by hand. This redoes #1323.

Notes

stopped closed without shipping deploy 714c4a7

opened this

Flaky tests now have a ten-run bar to join the gate, a nightly hunt that runs in random order, and quarantine through an issue instead of by hand. This redoes #1323. That pull's check was red only on the gate's list test ("every test/*.test.ts is in exactly one list"): test/plan-route.test.ts was in EXCLUDED twice, once from main (#1468) and once from this branch. This push merges current main and removes the duplicate. Locally the list test, test/flake.test.ts and tsc --noEmit pass.

  • Admission: bun scripts/flake-hunt.ts admit test/x.test.ts runs the file ten times, each a separate bun test --randomize with a fresh seed, while busy loops run on half the cores. It prints the seeds for the admitting pull and exits non-zero unless all ten runs are green. test/flake.test.ts joins GATE in this pull, with its record:
    admission: test/flake.test.ts — 10/10 green, random order, under load
      seeds 2265455907 773010353 277401282 … — all green
  • Hunt: flake-hunt.ts hunt [--shard N/M] [--file-issues] runs every gate file five times under the same load:
    • Each run's seed shuffles the file order and, through --randomize, the test order inside each file.
    • A file that fails in some runs and passes in others is flaky. A file that fails in every run is reported as broken, not flaky.
    • The verdict is each file's exit code, the same thing the gate judges.
    • With --file-issues it files Flaky: test/x.test.ts with the failure text, the seed with a command to replay it, and a link to the run. It skips files that already have an open issue.
  • Quarantine: flake-hunt.ts quarantine reads the open Flaky: issues and moves each file still in GATE to EXCLUDED under that issue's number, so nobody edits scripts/gate.ts by hand.
  • Nightly: .forgejo/workflows/flake-hunt.yml runs at 02:17 UTC, split across 20 jobs because the runner cuts a job at about 30 minutes. A final job runs quarantine and opens a flake-hunt/<date> pull.
  • Root causes: the hunt's issue body lists shared port, real clock, order dependence, leaked server, and a timeout near the real duration, as tickboxes with the fix for each, and says a retry is not a fix.
  • No retry: test/flake.test.ts fails on any --retry, --rerun-each, bunfig retry = or { retry: N } in forge.json, bunfig.toml, package.json, the workflows, the gate scripts and every file in GATE.
  • Short wall-clock bounds: the same test also fails on any time limit under 200 ms in a test file. Because of that, test/spawn-first-boot.test.ts now bounds its loopback median at 500 ms instead of 50 ms; it went red at 65 ms on a busy shared runner.

Worth a look: scripts/flake.ts (the seeded shuffle, the flaky-or-broken verdict, the issue body and the edit to GATE), and the workflow's last job, which is the only thing that writes scripts/gate.ts.

To try it: bun scripts/flake-hunt.ts admit test/flake.test.ts, then bun scripts/flake-hunt.ts hunt --shard 1/20.

🤖 Generated with Claude Code

Closes #1243

Changes requested

The machinery is tidy and well tested, but it has one security hole and one workflow bug. Neither is visible in the preview, which this change does not touch.

Fix first: quarantine trusts any open issue whose title starts with Flaky: test/…. openFlakyIssues reads only title and number, so anyone who can open an issue can pull a gate file out of the check by naming it. The result is a pull from the workflow's own token that weakens the gate. Keep only issues authored by the hunt's identity (the token's user), and ignore anything flagged untrusted. Add a test with a foreign-authored issue that is not quarantined.

Second: the quarantine job clones ${FORGE_URL}/${FORGE_REPO}.git with no credentials, while the hunt job and check.yml clone through the internal REGISTRY with a token. If the mirror is private, the job fails every night and nothing is ever quarantined. Clone the way the hunt job does.

Also: test/flake.test.ts is in GATE and spawns two bun test runs under busy loops with the default 5s test timeout. That is the timeout-near-real-duration shape this pull bans. Give that test an explicit generous timeout, or run it with --runs 1. The pull should also show ten admission runs for flake.test.ts, as the new rule requires.

commented

Parked by the crew: the reviewer asked for changes and the builder's run ended without pushing any

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs