Skip to content

fix(pr-pipeline): re-run a dispatched in-set post-merge red once before demotion - #9132

Merged
kyle-sexton merged 5 commits into
mainfrom
feat/postmerge-red-one-rerun
Oct 22, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
feat/postmerge-red-one-rerun

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #9126

Summary

Owner decision (Issue Triage, 2026-10-22): a red post-merge full run that pr-merge dispatched,
with a failing suite inside the merges' affected set, gets one re-run before demotion, chosen by
pr-merge's --lane-merges-only selector.

Before this change, the selector marked a re-run only for a red run inside a lane merge's
attribution window. Two kinds of red got no re-run. One was a red with no lane merge since the
floor (the early return in check()). The other was a red after every lane merge it contains was
verified (in_window). Each waited out the alert's 40 polls and demoted on attempt 1 alone (the
22-of-29 count in #8898).

Fix

  • babysit_postmerge.py: the new _lane_reruns() runs under --lane-merges-only after the merge
    loop, and also when no lane merge is judged. It lists workflow_dispatch full runs from the
    last LANE_RERUN_LOOKBACK (90 minutes), newest first. It marks Rerun(lane=True) for each run
    that meets all of these:
    • at attempt 1, outcome RERUN;
    • actor github-actions[bot];
    • lane_dispatched (has the pr-merge-dispatched-<id> record);
    • regressions(...) non-empty, which is the same baseline, affected-set and quarantine rule
      --judge-run applies.
  • The probe restores ctx.quarantines, so --remediate files no quarantine for these runs; the
    alert's --judge-run --file-quarantine already does that. A failed read becomes a
    lane-rerun-unreadable: warning, so the probe cannot make the merge gate's verdict unreadable.
  • The re-run happens only once per run, with no new state. The existing Re-run a red lane-dispatched full run step in pr-merge.yml re-runs only at run_attempt == 1 and records
    pr-merge-rerun-<id>-attempt-2. Once attempt 2 exists, the outcome is no longer RERUN.
  • The alert needs no change: it already waits up to red-main.confirm-wait-minutes for the bot's
    attempt 2, files nothing when that attempt passes, and judges attempt 2 when it fails.
  • Comments and docs that stated the old rule are updated: pr-merge.yml,
    post-merge-demotion-alert.yml, docs/conventions/pr-pipeline/README.md ("Red main") and
    scripts/post-merge-demotion-alert.test.sh. A changelog fragment is added for source-control
    and one for pr-pipeline.

Verification

  • Red first. The new LaneRerunOutsideAWindow tests in test_babysit_postmerge_quarantine.py
    failed 2 of 7 before the fix: the in-set red was not marked, and there was no warning on an
    unreadable record.
  • After the fix:
    • all 7 pass;
    • the babysit-prs Python suites pass (2495 passed), run with the pinned pytest 9.1.1;
    • scripts/post-merge-demotion-alert.test.sh passes (152 passed, 0 failed);
    • the pinned ruff wrapper reports check and format clean;
    • check-changelog-fragments.sh --check-required origin/main passes.
  • A mutant that dropped the quarantine restore failed the out-of-set test.
  • The two outcomes of the re-run, judged on the alert side:
    • re-run passes, nothing filed: scripts/post-merge-demotion-alert.test.sh case "a dispatched
      red per-merge run whose re-run passes files nothing";
    • re-run fails, record filed: case "a dispatched failure per-merge run files the record and a
      fix issue" (RERUN=failure).
  • On the selector side, the existing LaneRerun tests cover a bot attempt 2 that passes (a
    flake) and one that fails (red).

Related

🤖 Generated with Claude Code

kyle-sexton and others added 5 commits October 22, 2026 13:47
…re demotion

With --lane-merges-only, babysit_postmerge.check() now also marks a red
attempt 1 of a full run pr-merge dispatched for post-merge-dispatch's one
re-run when no judged lane merge covers it, if the run is under 90 minutes
old and a newly failing check demotes by the affected-set rule. The
existing step re-runs it only at attempt 1 and records it, so it never
repeats; post-merge-demotion-alert.yml demotes only if that re-run is red.

Closes #9126

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The lane re-run lookback was a static 90 minutes tied to
red-main.confirm-wait-minutes only by a comment. It is now that config
value, read at the branch tip through read_config_at (default 40, valid
0 to 45 as red-main.mjs resolves it), plus a 50-minute full-run
allowance, so the default stays 90 and raising confirm-wait widens it.

Drop the selector's own actor check, which lane_dispatched repeats, and
judge the lane record before the run's outcome so a run the lane did not
send reads nothing more. Add lookback boundary tests at 89 and 91
minutes, tests that the lookback follows a changed confirm-wait, and a
test that the repository's config gives 90 minutes.

Refs: #9126

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the artifact read

outcome() decides attempt-1 green runs from the run object, so checking it
before lane_dispatched() skips an artifact listing per green run and keeps a
failed artifact read on a green run from dropping the pass to a warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 22, 2026 19:02
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-22T19:02:33.372739Z 602ba1d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 602ba1d8a0a20eed7bb20493d3cc7ced932513cc: 0 finding(s), 0 as inline comments.

Security review: PR #9132 (head 602ba1d)

Result: no security findings. No inline comments posted.

The PR lets the pr-merge lane re-run a red full run once, even when no lane merge covers it. It adds a red-main.confirm-wait-minutes config read in babysit_merge_policy.py and a _lane_reruns probe in babysit_postmerge.py. The rest is comments, docs, changelog fragments and tests.

Checks

  • Config parsing: the value is read from the default-branch tip, not from PR-controlled content. The regex 0|[1-9][0-9]? is fully anchored and ASCII-only. The value is capped at 45, and anything invalid falls back to 40. The lookback therefore cannot exceed 95 minutes (45 + 50).
  • Re-run trigger scope:
    • A run is marked only when it is attempt 1.
    • It must be a workflow_dispatch run of pr-require-checks on the default branch.
    • ctx.lane_dispatched(run) must confirm it came from a pr-merge.yml push run in this repository, via the pr-merge-dispatched-<id> artifact. This check already existed and the PR reuses it.
    • ctx.regressions must report a newly failing check that demotes.
    • Attempt 2 is never re-marked.
    • An outside actor cannot make the lane re-run runs it did not dispatch. At most it spends one extra rerun-failed-jobs on a lane-dispatched red.
  • Failure handling: _lane_reruns catches read errors and returns a lane-rerun-unreadable warning. Its finally block restores ctx.quarantines, so the probe files no quarantine issues. The verdict stays readable. This is fail-open on the re-run only. The alert still judges attempt 1 as before, so it is not a bypass.
  • Workflows: the .yml changes are comment-only. No permissions:, triggers, run: expressions or action pins changed, so nothing falls in the zizmor-deferred categories.
  • Plugin manifests: no plugin.json or marketplace.json is touched, so there are no manifest <field> lines.
  • Instruction surfaces: the diff removes no standing instruction. The doc and comment edits only widen the description of the re-run window to match the code.
  • Instruction exception register: I did not consult it, because the diff deletes no rule. I reasoned by consequence instead.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 602ba1d8a0a20eed7bb20493d3cc7ced932513cc: 0 finding(s), 0 as inline comments.

No findings. I read the full diff, the PR context and the surrounding code in babysit_postmerge.py and pr-merge.yml. I did not run the test suites: the sandbox refused the pytest invocation, so the PR's test results are author-claimed and unverified by me.

What I checked

  • _lane_reruns and check().
    • It marks only a run that is at attempt 1, in the RERUN state, lane-dispatched, and has regressions, which is the same rule the merge loop uses.
    • It skips runs the merge loop already marked.
    • finally restores ctx.quarantines, so the probe adds no quarantine entries to the verdict.
    • Both read errors (PostMergeReadError and PolicyReadError) become a lane-rerun-unreadable: warning instead of an unreadable verdict.
    • Building _Context before the if not merges return changes nothing else in check().
  • Consumers.
    • verdict_exit ignores reruns, so a marked re-run cannot block a merge.
    • The pr-merge.yml post-merge-dispatch job runs on schedule and workflow_dispatch every 15 minutes. It reads .reruns[] | select(.laneDispatched) and re-runs only at run_attempt == 1, so the 90-minute lookback is reachable and the re-run happens once.
    • --remediate calls attribute() on the extra reruns the same way it did for judged ones, so there is no new failure mode.
  • Config. The CONFIRM_WAIT_MINUTES default (40) and cap (45) match red-main.mjs (red-main.mjs:12 and :20) and docs/conventions/pr-pipeline.yaml:581. The regex accepts 0 and rejects leading zeros, and 0 is not treated as absent.
  • Closing issue fix(pr-pipeline): re-run a dispatched in-set post-merge red once before demotion #9126.
    • Criterion 1 (a selector re-run for a dispatched in-set red) is met by _lane_reruns and the new LaneRerunOutsideAWindow tests.
    • Criterion 2 asks for a test of an in-set red that passes on re-run and one that fails again. The new selector tests cover only marking, no second re-run, the lookback and an unreadable record. The pass and fail outcomes sit in the existing alert-side shell cases and the existing LaneRerun selector tests. I confirmed the alert-side "re-run passes files nothing" case exists at scripts/post-merge-demotion-alert.test.sh:1155. That case sits on the alert side of the design, so I count criterion 2 as met and not as a gap.
  • Docs and changelog. The comments in pr-merge.yml and post-merge-demotion-alert.yml, the README "Red main" section and the changelog fragments agree with the code. Each fragment is bump: patch, which fits a fix. There is no plugin manifest change, so no manifest <field> lines apply.

Worth knowing, not a finding

  • The re-run starts at the next 15-minute schedule tick after the red run ends, then takes about 20 minutes to finish. That is tight against the alert's 40-minute confirm-wait-minutes. If it overruns, the alert judges attempt 1 alone, which is the behavior before this change. This is a judgment call on timing, and the PR text and code comments already say so.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 2b26c7e Oct 22, 2026
55 checks passed
@kyle-sexton
kyle-sexton deleted the feat/postmerge-red-one-rerun branch October 22, 2026 19:12
github-merge-queue Bot pushed a commit that referenced this pull request Oct 22, 2026
… its dispatch runs (#9167)

Refs: #9145

## Summary

During GitHub's degraded-API window on 2026-10-22 (about 14:18-17:41Z),
pr-merge's post-merge check read a dispatched-run listing that answered
HTTP 200 without the runs it holds. It took that as "no dispatch run by
the agent identity within 6 h" and filed demotion records #9081, #9088
and #9114, which set unattended merging to rung off. Both merges had
passing lane-dispatched full runs at their merge commits. A lagging
record listing also filed #9088 as a second record for #9081's failure.
Root cause and evidence:
#9145 (comment)

## Fix

All changes are in
`plugins/source-control/skills/babysit-prs/scripts/babysit_postmerge.py`:
- **Confirm the absence before failing.** Before the deadline failure,
`_judge` reads the branch's dispatch runs at the merge commit by
`head_sha`, with no `created` filter (`_Context.dispatch_runs_at`,
cached per commit). A run there that the listing lacked raises
`PostMergeReadError`, so the verdict is unreadable (pr-merge holds and
files nothing) instead of a failure. When the by-SHA read also shows
nothing, the failure stands.
- **A short listing raises.** In this module's `_paginated`, an object
listing whose `total_count` exceeds the items returned raises instead of
reading as complete. This covers `_runs`, the new by-SHA read and the
failed-jobs read. `babysit_gh.flatten_paginated_items` is unchanged for
its other callers. `_baseline` and `affected` read a capped
`per_page=20` page on purpose and are left out.
- **Re-read before filing.** When no existing record matches a failure,
the filer reads the record listing once more just before the POST, and
files only when that read also lacks the record (`_record_of`).

An empty artifact listing in `_lane_record` can still read as "not the
lane's run". Telling that apart from a run that really is not the lane's
needs a design choice, so it is left to a follow-up.

## Verification

- `uv run --with pytest python -m pytest
plugins/source-control/skills/babysit-prs/scripts/tests/ -q`: 2508
passed, 1952 subtests passed.
- 10 new tests. Each test of changed behavior failed before the fix:
  - a dropped dispatch run gives an unreadable verdict;
  - the same with `--remediate` makes no issue POST;
  - an empty by-SHA read keeps the deadline failure (stay-loud);
  - a short `total_count` raises;
- a record that appears on the second read is matched, not filed again.
- `scripts/run-ruff.sh check` on the scripts directory: clean.
`scripts/check-changelog-fragments.sh --check`: valid.
- Live read-only probes: the by-SHA read returns run 39696300084 for
861bf26, and healthy listings return as many runs as their
`total_count` (62 of 62 dispatch, 88 of 88 canary).

## Related

- #9081, #9088, #9114: the false records. Closing them is the owner's
re-arm.
- #9132: post-merge red re-run, same file, already merged into this
branch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

fix(pr-pipeline): re-run a dispatched in-set post-merge red once before demotion

1 participant