Skip to content

v1.91.372.0 feat(flaky): gstack-flaky reruns a failed test command once and ledgers the flake (GSTA-158 P1) - #3612

Merged
capy-ai[bot] merged 9 commits into
mainfrom
gsta158-flaky-run
Oct 31, 2026
Merged

capy-ai[bot] merged 9 commits into
mainfrom
gsta158-flaky-run

Conversation

@garrytan

@garrytan garrytan commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3612,
  "head": "c86543f70b37fc9129b8c7e7d7b66a3fb7521c93",
  "version": "1.91.365.0",
  "base": "main",
  "gate": {
    "remote_gate": {
      "pass": 3270,
      "fail": 0,
      "skip": 0
    },
    "focused-local": {
      "pass": 98,
      "fail": 0,
      "skip": 0
    }
  },
  "spend_usd": 0.15,
  "session_kind": "unattended",
  "head_tree": "832e118cb442689f2ef2c0e55da917712c6e4420",
  "product_patch_id": "299699863e64e29c639036d567a9fbcfa8ba84a7",
  "gstack_version": "1.91.365.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 697,
    "rules": "150435b0a543019a",
    "base": "a305302963372231ce8db901b9515c30efa6dc1c",
    "registry": "a305302963372231ce8db901b9515c30efa6dc1c",
    "gate_scan": {
      "tagged": 4,
      "head": "c86543f70b37fc9129b8c7e7d7b66a3fb7521c93"
    },
    "reasons": [
      "gate-class",
      "runtime=697>50"
    ]
  },
  "pregate": "requires-remote cleared @832e118cb442 (1 checks, current for c86543f70b37)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/41201778330",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/41201778301",
    "pregate.json/remote_gate: remote-gate tree=832e118cb442 tests=3270"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "updated",
    "scope": "docs/, README.md, AGENTS.md, CLAUDE.md, CONTRIBUTING.md (base 319ef500)"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 11,
    "deferred": 0,
    "noted": 6,
    "fixed": 26,
    "scope": "frozen",
    "fix_checks": 3,
    "dispatches": {
      "specialist": 12,
      "red-team": 2
    }
  }
}

What changed

A test that fails once and passes on its rerun: bun alone turns the job red; gstack-flaky keeps it green and ledgers the flake

A test that fails once and passes on its rerun: bun test alone exits 1 and the job is red. Under gstack-flaky run the rerun's full green verdict keeps the job green, and the flake goes on the ledger.

Text before/after

Before (bun test … flaky.test.ts): (fail) flips once, exit 1.

After (gstack-flaky run --runner bun --junit r.xml -- bun test …):

FLAKY: flaky-pass flaky.test.ts::::flips once attempts=fail,pass
FLAKY_RERUN: scope=command (the default; --rerun-scope test reruns the failed test alone)
FLAKY_RESULT: tests=2 failed=0 flaky=1 reruns=1 command_exit=1 verdict=pass ledger=flake-ledger-junit.jsonl

exit 0.

Why

Garry's standing rule is "you can just run the failed test again and note that it is flaky". gstack's own free suite already does that per file, but other repositories had nothing. Truther's last five attempt-1 reds each failed one Playwright test, three of them cover-focus.spec.ts:144, and each cost a manual rerun of the whole job. Now a wrapped CI step reruns once, stays green only on the runner's own full green verdict, and leaves a ledger line for the daily flaky-fix pass.

Blast radius

The change adds a new bin, two new library modules, docs and tests. Nothing existing imports lib/flaky-run.ts or lib/junit.ts, and the only edit to an existing gate file is one fixture-map row in test/helpers/free-fixtures-data.ts (file read; the remote pregate ran 3270 selected tests with 0 failed at tree 832e118cb442). The free suite's file-level retry and its GSTACK_FLAKE_LEDGER are untouched, and the new ledger has its own path.

Approvals

Date Asked Exact words Outcome Covers Still pending
2026-10-29 Approve the plan "Flaky reruns with a ledger, a quarantine registry, and resumable Ubicloud verify (GSTA-158)" (autoplan run autoplan-20261029035729, 5 decisions) “Do it. Order priority by what saves money fastest” (Garry Tan (via GStack Minder), relayed by agent:gstack-minder) approved the reviewed plan (sha256 25e1f7fbe0f1), every recommendation taken none
2026-10-29 Approve the plan "Flaky reruns with a ledger, a quarantine registry, and resumable Ubicloud verify (GSTA-158)" (autoplan run autoplan-20261029035729, 2 decisions) “Do it. Order priority by what saves money fastest (Garry, 2026-10-29; GStack Minder relayed it as rec at full scope through READY with no further ask)” (Garry Tan (via GStack Minder), relayed by agent:gstack-minder) approved the reviewed plan (sha256 25e1f7fbe0f1), every recommendation taken none

Source: gstack-approvals record for gsta158-flaky-run (display only; not an approval citation).

Plan narrowed in the safe direction (GStack Minder, 2026-10-29). The approved plan reran only the failed test. Review found that a narrowed rerun cannot see every reason a run fails: with bun 1.4.4, a coverage threshold set in bunfig.toml with an lcov reporter turned a real red green. GStack Minder approved making the whole-command rerun the default for every runner, counting a rerun only on the runner's full green verdict, and keeping the targeted rerun as opt-in --rerun-scope test with its preconditions documented. The generic --rerun-arg templates from the plan were dropped. GStack Minder granted two rule-23 fix-check exceptions for this (on a4ea2f3 and on 12d5967), each one reviewer on the touched hunks.

Summary

CI jobs that fail on a one-off flake can now wrap their test step in gstack-flaky run --junit <file.xml> -- <command>. It reads the runner's JUnit report, and when at most three tests failed and the runner made no retries of its own, it runs the command once more. A test that failed and then passes is a flaky pass, so the job stays green with an Actions warning, a step-summary row and a redacted ledger line. Anything the rerun cannot prove stays red: a missing, stale or malformed report, a crash, a cancelled job (latched, nothing rerun), failures the runner counts outside its JUnit, a coverage threshold, or a test the first run never reached. Playwright, bun test, jest, vitest and pytest are supported, and gstack-flaky ids prints a report's test ids.

Test Coverage

Coverage audit (Step 7, at 0f8442c; the later commits added the default-scope, coverage and EACCES cases, taking test/flaky-run.test.ts from 38 to 41 tests):

CODE PATHS                                                         USER FLOWS
[+] lib/junit.ts                                                   [+] CI job wraps its runner in gstack-flaky run
  ├── parseXml()                                                     ├── [★★★ TESTED] flake once → rerun → exit 0 + ledger — :340
  │   ├── [★★  TESTED] tags/attrs/CDATA via captured fixtures;       ├── [★★★ TESTED] job cancelled → FLAKY_COMMAND_KILLED, no rerun — :374,:384
  │   │               unclosed tag → FLAKY_JUNIT_INVALID (:51)       ├── [★★★ TESTED] bad command / no report → exit 2|3 + fix: line — :358
  │   └── [★★  TESTED] entity decode (&amp;) — :61                   └── [GAP] [→E2E] flaky pass surfaces as ::warning + step summary in Actions
  ├── detectRunner()
  │   ├── [★★★ TESTED] bun / " › " playwright / generic — :22,:34,:61
  │   └── [GAP]        playwright heuristic (no " › " title, hostname+timestamp suites)
  ├── readCase() + testId() per runner — [★★★ TESTED] :22,:34,:61
  ├── attempts from flakyFailure/rerunFailure/skipped — [★★★ TESTED] :34,:207
  ├── retriesHidden ("Retry #" without retry data) — [★★★ TESTED] :46,:169
  ├── parseJunit() duplicate-id merge — [★★★ TESTED] :197,:207
  └── readJunit() missing/empty/zero-testcase — [★★★ TESTED] :51
[+] lib/flaky-run.ts
  ├── rerunSelection() bun + playwright (escaped, --project) — [★★★ TESTED] :71,:76
  ├── defaultSpawn() stream / not-started / signal / cancel latch — [★★★ TESTED] :358,:374,:384
  ├── unreportedFailures()
  │   ├── [★★★ TESTED] bun errors, playwright outside-test + count mismatch, generic — :226,:234
  │   └── [★★  TESTED] bun "N fail" > JUnit count branch has no case (partial)
  ├── incompleteRun() bun/playwright/generic early-stop proofs — [★★★ TESTED] :83
  ├── provenance() tree/git_sha/branch/run_url — [GAP] no assertion on any ledger provenance field
  ├── safeText()/safeExcerpt() redaction — [★★★ TESTED] :307,:332
  ├── attempt() removes stale report; PLAYWRIGHT_JUNIT_INCLUDE_RETRIES set — [★★★ TESTED] :175,:215
  ├── rerunProblem()
  │   ├── [GAP]        targeted rerun exits 0 but its output counts unreported errors
  │   └── [★★★ TESTED] whole-command: failed / missing / killed / retried — :263
  ├── rerunVerdict() missing / killed / exit≠0 / problem / not-once / pass — [★★★ TESTED] :124,:137,:183,:191,:283
  ├── runFlaky() first-run refusals (killed, no report, hidden retries, crash, unreported) — [★★★ TESTED] :169,:175,:226,:289
  ├── runFlaky() eligibility (executions>1, runner retried, > --max-reruns) — [★★★ TESTED] :146,:157,:197
  ├── runFlaky() targeted vs whole rerun, already-red skip, interrupt stop — [★★★ TESTED] :242,:255,:275,:289
  ├── first report restored, rerun-N kept — [★★★ TESTED] :299
  ├── ledgerPath()/appendLedger() precedence + write-failure warning — [★★★ TESTED] :321
  └── renderResult()/stepSummary()/workflowEscape() — [★★★ TESTED] :124,:242,:307,:317
[+] bin/gstack-flaky
  ├── [★★  TESTED] missing --junit, non-.xml --junit kept on disk → exit 2 — :358
  ├── [GAP]        --max-reruns / --runner validation, unknown option, missing value
  ├── [GAP] [→E2E] GITHUB_STEP_SUMMARY append + ::warning annotation wiring (bin test blanks both env vars)
  ├── [★★  TESTED] ids prints one id per test — :416 (error path → exit 3 untested)
  └── [★★★ TESTED] every FLAKY_ code is in docs/flaky.md table; coded stderr fix: line — :358,:408
[+] test/helpers/free-fixtures-data.ts junit/** mapping — [★★ TESTED] checked by test/free-fixtures.test.ts (not run here)
[+] docs/TESTING_INTERNALS.md, docs/flaky.md — docs only, no code paths
Line refs are test/flaky-run.test.ts.

COVERAGE: 25/30 paths tested (83%)  |  value-weighted 25/30 (83%)
QUALITY: ★★★:19 ★★:6 ★:0  |  GAPS: 5 (1 E2E, 0 eval)
User flows map onto the code paths above (bin run, defaultSpawn, CI wiring) and are not counted separately.

Proposed tests for remaining gaps (audit-only; none written):
1. bin arg validation — Value: protects=run rejects --max-reruns -1/1.5/abc and an unknown --runner with exit 2; fails_when=validation dropped so NaN max makes every failure eligible; why_new=:358 covers only missing --junit and non-.xml; seam=none; no_claim=none beyond protects. Extend the usage test with rows.
2. rerunProblem targeted unreported — Value: protects=a targeted rerun that exits 0 but prints "1 error" stays rerun-fail; fails_when=the unreportedFailures check in rerunProblem is removed; why_new=:226 covers the first run only; seam=none; no_claim=real bun load-error output (canned summary). Add one fakeRun case.
3. provenance on ledger lines — Value: protects=ledger carries tree, git_sha and run_url built from GITHUB_* incl. /attempts/N; fails_when=run_url format or tree lookup regresses (CREW rule 16 needs the tree); why_new=no test reads these fields; seam=none; no_claim=GitHub's real env (synthetic env, temp git repo).
4. Actions wiring in bin — Value: protects=GITHUB_ACTIONS=true prints an escaped ::warning per flaky pass and GITHUB_STEP_SUMMARY gets the table; fails_when=bin stops emitting or escaping them; why_new=bin test blanks both vars; seam=none; no_claim=GitHub rendering of annotations (fake runner, temp summary file).
5. detectRunner heuristic — Value: protects=a Playwright report with no describe titles is detected as playwright with per-project ids; fails_when=heuristic removed, so projects merge into one duplicate id and nothing reruns; why_new=all captured fixtures carry " › "; seam=none; no_claim=other Playwright versions' JUnit shape (one synthetic report).

Tests: 1534 → 1534 (+0 new) test files counted at 0f8442c; test/flaky-run.test.ts is new on this branch.
Coverage: 83% value-weighted (83% including 0 weakly covered paths)
Tests ran: remote_gate 3270

Pre-Landing Review

Pass 1 found 8 blocking findings and pass 2 found 2; all were fixed (a44dda6, 0f8442c). The final native adversarial pass found a CRITICAL false green (bun coverage threshold under a targeted rerun), fixed in a4ea2f3 and then by the whole-command default in 12d5967. Fix-check 3 on 12d5967 found nothing at the blocking floor in the default rerun-verdict logic.

REVIEW_LOOP: passes=2 blocking_found=11 deferred=0 noted=6 fixed=26 scope=frozen fix_checks=3 dispatches=14

Gate edits: 1 listed (test/helpers/free-fixtures-data.ts: registers test/fixtures/junit/** to test/flaky-run.test.ts), kept; no assertion, threshold or skip changed.

Outside review: openai/gpt-6.1-sol adversarial pass ran (logged d5be5d78); its findings were folded into pass 2.

Base merge (2026-10-31). Merged main a305302 under GStack Minder's rule 19 grant. Every added line in the product files is byte-identical to the reviewed head c668d58; the CHANGELOG entry moved to changelog.d/gsta158-flaky-run.md (main now uses fragments). gstack-ship-receipt carry refused (RECEIPT_CARRY_PRODUCT_CHANGED) only because the context around the docs/standalone-binaries.md row changed on main, so the receipt was rewritten at this head with the same review loop (CREW rule 30b).

Review notes

Informational, not looped (CREW rule 30a):

  • lib/flaky-run.ts:316 (inside the default logic, verdict correct): when a whole-command rerun fails because of a different test, the originally failed test is ledgered as rerun-fail with attempts=[fail,pass], and the test that failed in the rerun gets no ledger line. The run is red either way, but the daily pass sees the wrong id.
  • bin/gstack-flaky:103: a --junit path whose parent directory is unreadable or is a file throws EACCES/ENOTDIR and exits 1 with a stack trace instead of usage exit 2. Fails closed.
  • test/flaky-run.test.ts:213: three tests written for the targeted path now run the default whole-command path. The opt-in scope's rerun-missing, non-zero-exit and retried cases have no test, and the title at 213 still says targeted.
  • Cancelling during a rerun records rerun-fail and exits 1 rather than FLAKY_COMMAND_KILLED exit 3 (still red).
  • A Playwright rerun rewrites test-results/ and the HTML report; --junit and <name>.rerun-<n>.xml are the record (documented).
  • Opt-in --rerun-scope test with Playwright widens selection to every test matching the grep title in that file and project.

Exploratory QA

Rerun at the final code (c668d58) on a bun fixture with the default scope. A flaky test gives verdict=pass, exit 0 and one flaky-pass ledger line. An always-red test gives rerun-fail, exit 1. A file that fails to load beside a flaky test gives FLAKY_UNREPORTED_FAILURES, nothing rerun, exit 1. Earlier at 12d5967: a Playwright 1.64.1 flaky run with the default scope passes, and bun with coverageThreshold = 0.9, an lcov reporter and a flaky test stays red (verdict=fail, exit 1) by default.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped.

Plan Completion

Plan /home/user/.capy/work/gstack/GSTA-158/plan-v2.md (P1 only): the implementation, docs and test items are DONE or CHANGED as approved above. The two handoff notes it named (Truther, gbrain) are now written in the crew drive. The quarantine registry (P2) and the Ubicloud reattach (P3, #3615) are separate PRs.

Documentation

Status: updated. One factual table row added; no blockers.

Scope: base 319ef50 to head 12d5967 (6 commits, 11 files) plus unstaged CHANGELOG.md. The change adds bin/gstack-flaky with lib/flaky-run.ts and lib/junit.ts, JUnit fixtures and tests. docs/flaky.md and the docs/TESTING_INTERNALS.md#flake-ledger paragraph were checked against the code. README.md, AGENTS.md, CONTRIBUTING.md, CLAUDE.md and docs/troubleshooting.md were searched for bin lists and flaky handling.

Documentation health:

  • docs/standalone-binaries.md: Updated (added a gstack-flaky row to the standalone CLI table, linking to docs/flaky.md)
  • docs/flaky.md: Current (rerun scope, rules, ids, ledger path, output and exit codes match the code)
  • docs/TESTING_INTERNALS.md: Current (the flake-ledger paragraph matches the default whole-command rerun and the ledger path)
  • README.md: Current (now reaches gstack-flaky through the Standalone binaries row)
  • AGENTS.md: Current (lists skills, not bins)
  • CONTRIBUTING.md: Current (its flaky text covers the free-suite file retry)
  • docs/troubleshooting.md: Current (error codes are documented in docs/flaky.md)
  • CHANGELOG.md: not audited in ship-owned mode (parent-owned)
  • TODOS.md: not audited in ship-owned mode (parent-owned)

Coverage debt: gstack-flaky has reference (docs/standalone-binaries.md, docs/flaky.md) and how-to (docs/flaky.md GitHub Actions setup) coverage. It has no tutorial or explanation. docs/captain.md and docs/recommended-harness.md describe the daily flaky pass without pointing at the JUnit ledger (flake-ledger-junit.jsonl); /document-generate could fill these gaps.

Diagram drift: none; no diagrams reference the changed modules.

Test plan

  • gstack-pregate --stage tests --remote --spend-cap 2 --timeout 2700 --allow-repo-commands: remote_gate cleared at tree 832e118cb442, 3270 selected tests, 0 failed, $0.04; macOS and Windows lanes cleared from CI runs 41201778330 and 41201778301
  • bun test test/flaky-run.test.ts plus the free-fixtures, module-size, bun-entry-isolation, spawnsync-timeout and state-root guards: 98 pass, 0 fail (with the changelog-fragments and version-gate-fragments tests)
  • bun run typecheck: clean; bun run gen:skill-docs: no diff

@trunk-io

trunk-io Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits October 29, 2026 16:24
…gers the flake (GSTA-158)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…closed duplicates and nonzero reruns

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan and others added 5 commits October 29, 2026 16:54
gstack-flaky never greens an incomplete run: a targeted rerun needs the
runner's summary proving the first run complete, otherwise (and always for
generic runners) the rerun repeats the whole command. A rerun clears a test
only when it exits 0 and the test passes once on its first attempt. Killed
runners exit 3 (FLAKY_COMMAND_KILLED) and signals are forwarded. The first
report is restored at --junit with reruns kept beside it; ids are redacted at
every output; the ledger gets its own GSTACK_FLAKE_LEDGER_JUNIT; fixtures are
registered in FREE_FIXTURES.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
A cancel forwarded to a runner that traps the signal now counts as killed for
every later attempt, so a cancelled job is never rerun or greened. A
whole-command rerun clears nothing when its report has a failed test, misses a
first-run test, or its runner counted failures outside the report.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… the run

A coverage threshold or a fail-on-flaky policy fails a run for a reason a
narrowed rerun cannot reproduce, so either forces a whole-command rerun.
--junit refuses an existing file that is not a JUnit report instead of
deleting it.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…t-in

A rerun counts only on the runner's own full green verdict: exit 0, no failed
or missing test, nothing counted outside the report. That covers every way a
run can fail, which a narrowed rerun cannot (a coverage threshold with an lcov
reporter, a fail-on-flaky policy, a test never reached). --rerun-scope test
reruns the failed test alone, with its preconditions documented and the
complete-run checks kept as a safety net. An unreadable existing --junit file
is a usage error, not a crash.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…158)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai capy-ai Bot changed the title feat(flaky): gstack-flaky reruns a failed JUnit test once and ledgers the flake feat(flaky): gstack-flaky reruns a failed test command once and ledgers the flake (GSTA-158 P1) Oct 29, 2026
@capy-ai
capy-ai Bot marked this pull request as ready for review October 29, 2026 17:56
garrytan and others added 2 commits October 31, 2026 12:34
…ntry moves to changelog.d

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@github-actions github-actions Bot changed the title feat(flaky): gstack-flaky reruns a failed test command once and ledgers the flake (GSTA-158 P1) v1.91.372.0 feat(flaky): gstack-flaky reruns a failed test command once and ledgers the flake (GSTA-158 P1) Oct 31, 2026
@capy-ai
capy-ai Bot merged commit 44eeeb3 into main Oct 31, 2026
62 checks passed
garrytan added a commit that referenced this pull request Oct 31, 2026
…; retarget to main

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
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