Making a Flaky Test Suite Trustworthy Again
Measure flakiness with evidence, fix the confirmed offenders by root cause, and guard against their return.
3 milestones 16 sprints 41 agents
8 plan 18 execute 21 review 1 fix
140k peak context
77k median execute
4h 49m total 9m 26s per sprint
7m 16s plan 2h 11m execute 29m 36s review
80 edits 977 commands
codex harness
Gantry depends on its test suite as the arbiter of an autonomous build. A flaky test weakens that contract because a red result may be noise and a green result may be luck. This job treated flakiness as an evidence problem before it treated it as a repair problem.
The work built a repeatable stress command, turned its output into durable reports, used those reports to rank actual offenders, fixed the confirmed classes, and left fixture rules and guidance for future tests. Later reliability work has extended the same documentation and stress workflow, but the runner, snapshots, guardrail, and core fixes from this job are still visible in the current tree.
How this walkthrough is structured
Feature
What did the run build and ship?
The tree still contains the flake stress runner, report generator, analysis snapshots, fixture isolation helpers, guardrail test, reliability guide, and overlay readiness fix that came out of this job.
Build
How did Gantry structure the work?
The run was cut as measure, repair, and prevent, with the main adjustment coming when post-fix evidence showed that the repair and prevention boundaries had to be handled together.
Milestone 1
Flake Baseline
3 sprints 9 agents 50m 17s wall time 112k peak context
The lasting feature from this milestone is the measurement workflow. `bin/stress`, `scripts/analyze/stress-report.py`, the stress runner tests, and the first analysis snapshots remain in the tree. The initial baseline also survives as a document, though its own text says the broader suite ranking was limited and should not be overread.
This milestone was the measuring foundation. It was scoped so each worker could carry one part of the evidence chain: run the suite repeatedly, summarize raw outcomes, then preserve the first baseline. The child sprints stayed green, but the milestone review recorded a limit on the baseline scope. That note mattered because it kept later remediation tied to the offender class the samples actually confirmed.
Stress Test Runner
2 agents 7m 36s wall time 80k peak context
`bin/stress` still exists as an explicit analysis command. It can run default, integration, and closeout-oriented samples, select a runner, persist raw run metadata, and hand existing output to the report generator. The integration coverage for this command is still present under the current test layout.
The first sprint carried only the runner, not any interpretation of flakiness. Its brief asked for suite selection, repeated execution, concurrency settings, focused filters, fallback runner behavior, and raw result persistence. That was a bounded command-line and fixture problem a fresh worker could test without running expensive real stress loops. The gate did not send it back, so the later report layer received a stable input format.
Flake Reporting
2 agents 6m 12s wall time 81k peak context
`scripts/analyze/stress-report.py` still turns stress output into JSON and Markdown snapshots under the analysis directory. The current tests still cover ranked offenders, representative panic details, sampling context, and refusal to overwrite an existing snapshot. That reporting layer is the durable format all later reliability notes point at.
This sprint was sequenced after the runner because it needed raw run records to aggregate. The brief kept it to deterministic report generation over representative output, including both rich and fallback runner shapes. It did not need to diagnose a real flake, so the worker could focus on offender identity, representative failure text, snapshot naming, and non-clobbering writes. The cut held without repair.
Baseline Evidence
2 agents 28m 39s wall time 112k peak context
The baseline note and its generated snapshots are still present. They identify the driver-sprint re-enumeration class as the strongest target, carry overlay and driver-loop findings as weaker leads, and document the synced versus non-synced comparison. The old handover file was later archived, so this sprint's history is visible through the analysis note rather than a live handover document.
This was the bridge from tools to decisions. The sprint had to run enough current samples to separate confirmed targets from historical leads, compare synced and non-synced checkouts, and write the limits into the repository. It passed its own gate, but the milestone review narrowed the claim: the full-suite evidence was smoke-level, while the driver-sprint class was confirmed. That boundary prevented the next milestone from treating a thin ranking as a repair queue.
Milestone 2
Fix Confirmed Flakes
9 sprints 27 agents 2h 5m wall time 140k peak context
This milestone left most of the visible reliability machinery. The tree contains the expanded baseline, auth and fixture shared-state cleanup, overlay assertion cleanup, same-tag re-enumeration isolation, canonical temp helpers, the flaky-antipattern guardrail, and the reliability guide. Later work has extended the guide, but the resolved driver-sprint class and guardrail vocabulary still trace back to this milestone.
This milestone began as remediation over measured offenders, then expanded when the evidence showed a residual driver-sprint class after the first fixes. Its early units kept measurement, root cause, shared-state cleanup, and timing cleanup separate. The post-fix evidence sprint went red, ran a fix, and forced a re-plan that added verification, fixture standardization, a guardrail, and docs to the same milestone. The decomposition changed because prevention had become part of proving the fix.
Expanded Offender Baseline
2 agents 21m 41s wall time 60k peak context
The expanded baseline report is still present in `docs/analysis`. It keeps the driver-sprint class at the front, promotes the overlay ordered-log class from a lead to a confirmed timing offender, and leaves the driver-loop case as sample-limited. The snapshot files that support that report are still under the flake snapshot directory.
The first remediation sprint deliberately changed no production behavior. Its brief asked for a larger baseline so the milestone would not chase plausible but unconfirmed timing or ordering issues. That made it a self-contained measurement task on top of the runner and report generator. It stayed green and gave the following fix sprints a ranked, current target list.
Driver Root Cause
4 agents 17m 49s wall time 108k peak context
The broad review-stub matcher fix still appears in the driver-sprint tests as a regression for diff noise that must not trigger another re-plan. The handover and reliability docs still describe that as one real cause in the evidence sequence. It is not the whole current driver-sprint story, because a later sprint isolated same-tag stub executables as the residual cause.
This sprint took the strongest confirmed offender and investigated one class rather than the whole suite. The brief required a root cause and regression without broad serialization, ignored tests, or weaker assertions. The run facts show this sprint started more than once, but each recorded stage outcome was green. Its output was therefore useful but incomplete: it fixed one prompt-matching bug while later evidence showed a second fixture-isolation cause remained.
Shared State Sweep
2 agents 16m 15s wall time 140k peak context
The tree still carries the shared-state cleanup from this pass. Config auth is collected into explicit child-process environment state instead of mutating the parent environment during load, and overlay-player tests use guard and restore helpers for process-global mutation. Some of these changes were hazard reductions rather than fixes for a ranked offender, and the reports say that distinction plainly.
This sprint was a guided sweep, not a static audit of every suspicious call. The brief limited it to shared process-state hazards confirmed or implicated by the driver-sprint work. Its gate errored once before the sprint finished, locating stress at the boundary where process-global state and test isolation meet. The bounded scope kept the worker from serializing the suite as a blanket answer.
Timing Ordering Fixes
2 agents 5m 45s wall time 81k peak context
The overlay tests no longer assert a total order for independent process startup events. They keep strict checks for the events that matter and order only causal cleanup edges. That change is still present in the integration overlay coverage, although a later residual sprint found a different readiness failure in the same area.
This sprint took the confirmed overlay timing class after the shared-state work had narrowed the list. Its brief asked for deterministic readiness or causal ordering, not looser assertions. The boundary was small enough for one worker because it centered on the overlay recording tests and their process-log expectations. It finished without repair, so the later evidence sprint could evaluate it as a specific fixed class.
Post-Fix Evidence
4 agents 14m 40s wall time 112k peak context 1 fix 1 replan
The post-fix report is still in the analysis directory. It records the overlay ordered-log improvement, shared-state hazard reductions, and the still-confirmed driver-sprint residual at that point. Later reports supersede its driver-sprint status, but the document remains the evidence that caused fixture isolation and guardrails to move into this milestone.
This sprint tested whether the fixes actually held. Its brief was explicitly about comparison and bounded claims, not more repair. The gate failed, a fix ran, and review forced a re-plan after the report showed the driver-sprint class was still confirmed. That is the job's central boundary event: evidence closed the first remediation pass by changing the remaining work.
Driver-sprint duplicate execution - verify and lock the fix
4 agents 13m 41s wall time 75k peak context
`reenumeration_stubs_are_isolated_between_same_tag_fixtures` still asserts that same-tag fixtures get separate stub binaries and log paths. The reliability guide still names the residual cause as shared re-enumeration stubs leaking mutable paths across fixtures. The focused lock snapshot is also still present, supporting the resolved-and-guarded classification for that fixture class.
This sprint was added by the re-plan, and its brief sharply limited the work. It was not asked to invent a new root cause unless a real residual reproduced; it had to prove and lock the same-tag isolation fix. The sprint started more than once but its gates stayed green. The boundary was verification plus a deterministic regression, not another broad investigation.
Standardize flaky-test fixtures
2 agents 7m 41s wall time 72k peak context
`process::TempDir::new` and `unique_temp_name` still exist as the named safe fixture helpers. The build-engine and integration fixtures touched by this job use them where same-tag or concurrent scratch paths had mattered. The guardrail still treats older PID-only paths as a tracked legacy baseline rather than a reason to rewrite unrelated tests.
This was a propagation sprint over a proven pattern. The brief made it bounded: document and test the canonical helpers, then migrate fixtures already implicated by the milestone, without sweeping every temporary path in the repository. That made the work mechanical enough for a fresh worker and kept legacy safe patterns from becoming false blockers. It passed without a repair stage.
Flaky-test antipattern guardrail
2 agents 18m 20s wall time 77k peak context
`tests/integration/default/flaky_antipattern_guardrail.rs` still scans for the known flaky-test patterns. It rejects unguarded process-global mutation, sleep-before-assert readiness, brittle scratch names, reused same-tag stubs, and reused re-enumeration logs, while allowing documented exceptions. The guardrail remains part of the reliability workflow described in the guide.
This sprint converted the new fixture vocabulary into a normal verification check. The brief kept the guardrail heuristic and representative: catch known bad shapes and explain the accepted helper, without claiming to prove every possible flake. That boundary let the worker test good and bad examples instead of auditing the whole tree. The sprint stayed green.
Reliability docs and measurement workflow
2 agents 3m 9s wall time 60k peak context
`docs/analysis/test-reliability.md` still names the gate commands, accepted helpers, rejected antipatterns, guardrail command, stress workflow, and snapshot storage convention. The guide has since grown with later driver-loop evidence, but the driver-sprint incident history and helper guidance from this sprint remain part of it. README links into the reliability material are also still present.
This sprint closed the expanded remediation milestone by documenting the path a future contributor should follow. Its brief required bounded evidence language: resolved-and-guarded for the driver-sprint class, not a claim that flakes are permanently absent. It was a low-risk docs unit after the helper and guardrail code existed. The top-level milestone note then recorded that the planned prevention milestone had to reconsider its scope because this milestone had already built much of it.
Milestone 3
Test Guardrails
4 sprints 12 agents 31m 51s wall time 94k peak context
The final milestone left an audited guardrail, residual evidence snapshots, the overlay compositor-fallback readiness fix, and a closeout note tying the sequence together. Later reliability work added more driver-loop material to the same guide, but the overlay readiness classification and the snapshot sequence from this milestone still stand. The original prevention work is no longer isolated here because it had already moved into the prior milestone.
The final milestone became an audit and residual pass because the preceding milestone had already built the original fixture and guardrail deliverables. Its child sprints checked that guidance matched code, re-measured carried-forward leads, fixed only the reproduced residual, and closed the evidence trail. The residual evidence sprint forced a re-plan, which kept the next sprint tied to the observed overlay readiness signature. This milestone was therefore a narrow closeout rather than a second prevention build.
Reliability Audit
2 agents 3m 20s wall time 66k peak context
The guardrail still checks for repeated re-enumeration log tags, and the reliability guide still describes that hazard. This sprint's contribution is visible as alignment between the code scanner and the written guidance. It is a thin feature row because it mainly verified and adjusted already-built prevention work.
This sprint was an audit against the current tree, not a rebuild. Its brief asked whether the guardrail, representative coverage, and reliability guide still agreed after the previous milestone's re-plan. That made the scope small and checkable for a fresh worker. It passed cleanly and tightened the guardrail around repeated re-enumeration log tags.
Flake Evidence
3 agents 11m 12s wall time 57k peak context 1 replan
The residual evidence report and its snapshots are still present. They classify the guarded driver-sprint case as not reproduced in that sample, the driver-loop finalization lead as still sample-limited, and the overlay recording path as the only reproduced residual in this pass. The report is evidence, not a code change, and its feature value is the classification it preserved.
This sprint restored the job's data-before-edits rule after the audit. It sampled the guarded driver-sprint class, the overlay timing area, and the driver-loop finalization lead before any new fix claim. The sprint itself stayed green, but it ran a re-plan because the evidence identified one current residual signature. That re-plan narrowed the next sprint to the overlay compositor-fallback readiness failure.
Residual Fixes
2 agents 7m 17s wall time 94k peak context
`scripts/record-replay.sh` now launches the probe hold command through `/bin/sleep`, so a test PATH shim cannot shorten the probe lifetime. The integration test still covers compositor startup failure and delayed window discovery together. The post-fix overlay probe report and snapshot remain in the analysis directory.
The re-plan gave this sprint a single repair target: the overlay compositor-fallback recorder had to survive long enough to complete the ghostty cell-size probe. The brief ruled out ignoring the test, broad serialization, or longer timeouts as a disguise. Because the residual evidence already named the failure signature, the worker could focus on the readiness mechanism and regression. The sprint finished without a repair pass.
Reliability Closeout
2 agents 4m 8s wall time 73k peak context
The final closeout note still lists the baseline, expanded baseline, post-fix report, residual evidence, overlay probe fix, and durable snapshot directory as one sequence. The reliability guide now contains later additions too, but it still carries the fixture helpers, guardrail command, periodic stress workflow, and bounded language this sprint consolidated. Future readers can start from those classifications instead of reconstructing the incident from raw logs.
The last sprint was an evidence alignment task. It had to make the guide, analysis notes, and final classifications agree without overclaiming passing samples. That made it a documentation closeout over already-built code and measured snapshots. It stayed green, so the job ended with the measurement, remediation, and prevention story in one place.