feat(ci): rerun a red PR's failed Actions jobs once before a fix round (#487) - #504
Merged
Merged
Conversation
#487) On a failing rollup the CI reconcile now runs `gh run rerun <id> --failed` for each failing GitHub Actions run, stamps the bead `ci-rerun:<sha>:<n>` and spends nothing. Green after the rerun logs one flake line and clears the stamp; red again at the same head bounces as before; a new head gets a fresh allowance. No Actions run ids, a gh refusal, or `ci_rerun_max: 0` bounces at once. The new seam is REAL against the pinned failed fixture run (PB_GH_FIXTURE_FAILED_RUN); the stamp is REAL through `br`. Fixes #487 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
QA panel review — PASS
code-review-structural · head bd28dcc3351e · formal
No findings were raised, so there was nothing to verify. The panel (correctness, removed-behavior, cross-file, conventions, and protoPatch structural) reviewed the CI-rerun state machine, allowance tracking, cross-file references, and hygiene conventions across all changed files and found no defects. The one protoPatch nit (falsy timeout=0 in dispatch_coder) targets pre-existing code outside this PR's scope and was dropped. No coverage gaps noted.
No findings — the review came back clean.
findings JSON (machine-readable)
[]
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #487
What
A red PR used to spend a coder fix round (and a
ci_fix_maxunit) right away, even when the red was a flaky job. Now the CI reconcile reruns the failed GitHub Actions jobs first, once per PR head, and bounces only if they fail again.Design
worktree.rerun_failed_ci(pr_url="", *, cwd, run_ids=None, slug=""). It reads the PR'sstatusCheckRollupand uses the purefailed_ci_run_ids(checks)to get(owner/repo, run_id)for each Actions run behind a failed blocking check. It parses the run fromdetailsUrl/actions/runs/<id>and dedupes per run. It then runsgh run rerun <id> --failed -R <slug>for each and returns the ids GitHub accepted. Passingrun_ids=skips the rollup read, which is how the real tier points it at the pinned fixture run. It is best-effort: a gh error, timeout or refusal is logged, that run is left out, and the function never raises.[]means "bounce as before"._reconcile_ci. Onfailing,_rerun_ci_onceruns first:ci-rerun:<sha12>:<n>stamp. If there is a stamp, it readspr_head_sha. A different head gets a fresh allowance. The same head withn >= ci_rerun_maxbounces as today. An unreadable head also bounces as today.CI red at <head> — rerunning failed jobs once before a fix round: <run ids>, and returns. There is no requeue, noci-fixspend and no feedback injection.passingwith a stamp,_settle_ci_rerunlogs oneCI flakeline naming the checks that failed, if the head is still the one that was rerun. It then clears the stamp. A green new head clears it silently.store.record_ci_rerun(fid, head="", n=1). This is the single-label-replaced pattern viareplace_prefixed_label_args, plusci_rerun_from_labels. The label is at most 23 chars, well under beads' 50-char cap. It lives on the bead, so a restart never reruns a head twice. The format is:<n>rather than a bare sha soci_rerun_max > 1works.ci_rerun_max. Default 1; 0 turns it off. It is read likeci_fix_maxinloop/core.pyand documented indocs/configuration.md(row + paragraph; the YAML-only count is now 29 of 80). It is also in the manifestconfig:block besideci_fix_maxand in the Settings fields. The README has noci_fix_maxentry, so the manifest's commented config is the matching place. Rerunning needsactions: writeon the board's gh token.Fixture and real tier
rerun_failed_ciis REAL, so the worktree contract goes from 42 to 43 REAL. The new store seamrecord_ci_rerunis REAL too; the store UNCOVERED count stays 16.tests/test_publish_gate_real.py::test_rerun_failed_ci_reruns_the_pinned_failed_fixture_runcallsworktree.rerun_failed_ci(run_ids=[PB_GH_FIXTURE_FAILED_RUN], slug=...)on the pinnedci-fixture-fails.ymlrun.completed, so another CI run's rerun can't collide. If a collision still wins, the seam returns[], and the test accepts that as long asrun_attemptstill rose.run_attemptincreases, polling for up to 60s. It does not wait for the new attempt to finish.PB_GH_ALLOW_WRITES. With writes allowed underPB_REQUIRE_GH, a missing run id fails rather than skips.[]without raising.ci.yml'stest (real gh)job now hasactions: writeandPB_GH_FIXTURE_FAILED_RUN: ${{ vars.PB_GH_FIXTURE_FAILED_RUN }}. The ratchet asserts both.conftest.py: an autouse stub makesrerun_failed_cireturn[]in the unit tier, so every existing CI-bounce test bounces unchanged. The real seam goes intoREAL_SEAMSand is restored by the tier'sreal_seamsfixture.Unit tests (
tests/test_ci_rerun_487.py)These use a mocked gh in the
_stub_ci_worktreestyle:ci_rerun_max: 0is the old behavior;ci_rerun_max: 2reruns a head twice;ci-rerun:stamp through realbr: it stamps, re-stamps idempotently, is replaced rather than accumulated, fits the 50-char cap, and clears.Verification
ruff check .is clean andruff format --checkpasses on the changed files.PB_REQUIRE_GH=1 PB_GH_FIXTURE_PR=…/pull/370 PB_GH_FIXTURE_FAILED_RUN=36520566451 PB_GH_ALLOW_WRITES=1: both rerun tests passed. Fixture run 36520566451 went from attempt 1 to attempt 2.🤖 Generated with Claude Code