Skip to content

fix(source-control): stop pr-merge demoting on a listing that dropped its dispatch runs - #9167

Merged
kyle-sexton merged 7 commits into
mainfrom
fix/9145-postmerge-false-demotion
Oct 22, 2026
Merged

kyle-sexton merged 7 commits into
mainfrom
fix/9145-postmerge-false-demotion

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

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

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits October 22, 2026 15:11
… its dispatch runs

Before a missing dispatch run becomes a deadline failure, read the
branch's dispatch runs at the merge commit by head SHA; a run there the
listing lacked makes the verdict unreadable. Object listings read through
_paginated raise when total_count exceeds the items returned. The
demotion filer re-reads the record listing before filing a new record.

Refs: #9145

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

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 ✅ Completed 2026-10-22T19:26:21.471614Z ad421bb 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

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

No security issues found in the incremental change (3f7a062..3824978). It touches only plugins/source-control/skills/babysit-prs/scripts/babysit_postmerge.py, where the _paginated cap condition (total > len(items) and len(items) >= RUN_SEARCH_CAP and capped is not None) is reformatted from three lines to one. The logic is identical, so no control, trust boundary or input handling changes. No plugin manifest changed, so there are no manifest <field> lines. No standing instruction was deleted or softened. I did not read the instruction exception register, since nothing in the diff removes an instruction.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 38249786d5f8e68f3798b32c33baa900194864ed: 0 finding(s), 0 as inline comments.

Incremental review of 3824978 against 3f7a062, which changes only plugins/source-control/skills/babysit-prs/scripts/babysit_postmerge.py.

The one change collapses the multi-line if total > len(items) and len(items) >= RUN_SEARCH_CAP and capped is not None: condition in _paginated onto a single line. The three conditions, their order and the and operators are the same, and the elif/raise branches are untouched, so behavior does not change.

I did not run the tests or the formatter. The earlier test and ruff results are the PR author's claims, which I have not verified.

No findings. Files unchanged since 3f7a062 were reviewed then.

…mits and drop the same-pass record re-read

The by-SHA confirmation now reads the merge commit and every descendant
on the branch committed by the deadline (from compare to the branch tip,
which raises when it lists fewer commits than total_commits), and counts
only a missing run by the lane or the identity created in time. Run rows
of another event or head repository are dropped. A listing past the
1,000-result search cap reads with a listing-capped warning instead of
raising. The same-pass record re-read is removed: it cannot catch a
lagging index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The compare from the merge commit to the branch tip lists at most 250
commits, so a merge judged after 250 later commits would hold on every
sweep. The candidates now come from the branch's commits between the
merge and the deadline, kept when they descend from the merge commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kyle-sexton and others added 2 commits October 22, 2026 15:54
…he cap

A degraded answer can carry a total_count past the search cap with few
items; only a listing that returned at least RUN_SEARCH_CAP items is short
by design. Document that the window commit listing has no total, so a
silent drop falls back to the read at the merge commit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 0174bdf Oct 22, 2026
27 checks passed
@kyle-sexton
kyle-sexton deleted the fix/9145-postmerge-false-demotion branch October 22, 2026 20:08
github-merge-queue Bot pushed a commit that referenced this pull request Oct 22, 2026
…9186)

Closes #9168

## Summary

When GitHub answers the `pr-merge-dispatched-<id>` artifact listing with
HTTP 200 and no artifacts, pr-merge's post-merge check read a run the
lane did dispatch as not the lane's. Past the 6 h deadline that became a
dispatch failure, which files a demotion record. This implements the
owner's option (a)
([decision](#9168 (comment))):
read the listing once more, and when it is still empty, hold with an
unreadable verdict instead of failing.

## Fix

All code changes are in
`plugins/source-control/skills/babysit-prs/scripts/babysit_postmerge.py`:

- `_Context._lane_record` reads the dispatch record's listing a second
time when the first read names no artifact. A second empty read is noted
in `_Context.lane_empty`, and the record still reads absent, so an empty
listing never makes a run count as the lane's.
- In `_judge`'s deadline block, beside the existing by-SHA hold, a
github-actions[bot] dispatch run at or after the merge commit, created
by the deadline, whose record listing read empty twice raises
`PostMergeReadError`. The verdict is unreadable (exit 3), so pr-merge
files nothing and starts no run. The next sweep builds a fresh
`_Context`, reads the listing again, and clears once it reads the
record.
- The raise sits at the deadline, not in `_lane_record`, so nothing
changes before the deadline: an unrecorded bot run still reads as
pending and `needsDispatch`, and the lane dispatches a recorded run.
- A listing that names a sender other than the lane's pr-merge.yml run
is not empty. It reads as not the lane's run and still fails at the
deadline. The re-run record (`pr-merge-rerun-<id>-attempt-2`) is still
read once.

## Verification

- `uv run --with pytest python -m pytest
plugins/source-control/skills/babysit-prs/scripts/tests/ -q`: 2523
passed, 1954 subtests passed.
- 4 new tests in `EmptyLaneRecordListing`. The first two failed before
the fix:
- both reads empty, past the deadline: verdict unreadable, no failure, 2
listing reads;
- the second read returns the record: the run counts as the lane's and
the merge verifies;
  - stay-loud: a dispatch by another actor still fails at the deadline;
- stay-loud: a record uploaded by another workflow (a non-empty listing)
still fails at the deadline, with one listing read.
- `scripts/run-ruff.sh check` and `format` on the scripts directory:
clean. `scripts/check-changelog-fragments.sh --check`: valid.
- Left out: no live probe against a degraded artifacts API, which cannot
be reproduced on demand.

## Related

- #9167: the by-SHA dispatch hold this follows.
- #9145: the degraded-API incident.


🤖 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.

1 participant