Skip to content

fix(source-control): stop counting rate-limited merge-queue removals - #15546

Merged
melodic-automation-lanes[bot] merged 6 commits into
mainfrom
fix/queue-ejected-skip-rate-limit
Nov 12, 2026
Merged

melodic-automation-lanes[bot] merged 6 commits into
mainfrom
fix/queue-ejected-skip-rate-limit

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: merge-queue removals caused by GITHUB_TOKEN exhaustion strand lane PRs (hub finding L570, 2026-11-12)

Summary

When the repository's GITHUB_TOKEN pool is exhausted, the merge-group CI Status job fails on
the rate limit, the merge queue removes the pull request, and pr-merge's queue-ejected cap
counts that removal like a real failed check. Example: run
43155083740
(merge group for #15535) failed with could not record ci-lanes ... rate limited past rate-limit-wait-seconds, and the enable-auto-merge sweep in run
43151505468
left #15486 on queue-ejected:2. Lanes App PRs then stay stranded until someone pushes.

Fix

At the cap only (raw count >= merge.max-queue-ejections), queue_ejection_hold checks each
failed-check removal at the current head. It stops reading as soon as limit removals have
counted. A removal is not counted only when all of these hold:

  • the removal time (createdAt, now read in the existing timeline query at no extra call)
    falls within 2 minutes of the end of exactly one merge-group entry's failed run (perf(pr-merge): end an uncovered wake on one read #15535's
    removal and its run both ended at 04:40:05Z);
  • every failed run of that entry has failed only CI Status and its ci-status alias
    (merge_policy.GATE_CHECK / GATE_ALIAS), so a failed lane or another workflow counts;
  • every failure annotation on CI Status is either a rate-limit line the gate's guards write
    or a generic line (Process completed with exit code N., ...; re-run this run.), and at
    least one is a rate-limit line. The patterns come from the pinned ci-workflows composites
    (aggregate-results/run.sh:266, check-contract/run.sh:221 at ac4d878),
    .github/actions/log-api-budget/api-budget.bash, and ci-status's gh_read;
  • the limit the annotations name has reset (or one hour after the removal when they name no
    reset time). Before the reset a re-enqueue would only fail on the same exhausted pool, so
    the removal still counts and the refusal and comment behave as before.

Anything unreadable counts the removal as before: a failed listing, jobs or annotations read,
a removal with no time, no matching entry or two of them, a full jobs or annotations page.
Below the cap nothing is read. Both consumers get the change: the unattended enqueue and
evidence --lane-queue (enable-auto-merge).

Why not make the merge-group CI Status wait for the reset instead: the status write lives in
the pinned ci-workflows composite, outside this repository, and run 43155083740 shows the
exhausted pool failing at least four separate steps of the job (the status write, several
gh_read holds, the runner-tail read, the run-cache carry). Waiting would mean changes in
each of those steps and in another repository, and would hold the serial merge queue for up
to an hour.

Cost per sweep: 0 extra calls for heads under the cap. For a head at the cap: the
failed-merge-group listing, which the refusal comment already reads at the cap and which is
now shared through the run cache across the sweep's PRs. Then per checked removal, one
attempt-jobs read per failed run of the matched entry (usually one) plus one annotations read
for CI Status. That is about 2 calls per removal, stopping once limit removals count: about
4 per refused head per sweep at the default limit of 2. Per-run answers are cached for the
rest of the run. They are not carried across runs (carry-run-cache.mjs keeps only its
carried-* sections).

Verification

  • python3 tests/test_babysit_merge_async.py: 102 tests OK. New
    RateLimitedQueueRemovalsAreNotCounted, using run 43155083740's real CI Status
    annotations, covers these cases:

    • a rate-limited removal is not counted while a lane failure beside it is;
    • a failed lane counts;
    • a gate hold beside the limit counts;
    • no rate-limit line counts;
    • a removal before the reset counts;
    • unreadable evidence (listing, jobs, annotations, no or two matching entries, no time)
      counts;
    • nothing is read under the cap;
    • a certain refusal stops reading.

    Also new: failedRemovals read-back. Mutation checks showed the tests catch the failure:
    disabling the discount, and separately dropping the hit GitHub's ... API rate limit
    pattern, each failed a test.

  • test_babysit_merge_unattended.py (314 OK) and test_babysit_lane_reviews.py (39 OK) each
    gain a wiring test showing the refusal lifts only when a removal is discounted.

  • Also green: test_babysit_merge.py (157), test_babysit_verify_evidence.py (441),
    test_babysit_merge_policy.py (580), test_babysit_merge_rate_limit_rerun.py (39),
    test_babysit_merge_report_only_state.py. ruff check is clean on the changed files.

  • scripts/check-changelog-fragments.sh --check-required origin/main passes (source-control
    and pr-pipeline fragments).

Related

session: GitHub Support

🤖 Generated with Claude Code

https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7

kyle-sexton and others added 5 commits November 11, 2026 23:56
When the GITHUB_TOKEN pool is exhausted, the merge-group CI Status job
fails on the rate limit, the merge queue removes the pull request, and
pr-merge's queue-ejected cap counts that removal like a real failed
check, stranding lane PRs until a push.

At the cap, queue_ejection_hold now charges each failed-check removal
at the head to the one merge-group entry whose failed run ended within
two minutes of it. The removal is not counted only when that entry's
only failed jobs are CI Status and its ci-status alias, every CI Status
failure annotation is a rate-limit line the gate's guards write or a
generic one, and the limit it names has reset. Anything else, an
unreadable read included, counts as before. Below the cap nothing is
read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7
Add the changelog fragment and the pr-pipeline convention sentence, and
refuse to judge a full annotations page, which may hide a failure line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7
Keep eight fields per listed merge_group run in the run cache instead of
the whole run object, cover the jobs read's "hit GitHub's ... rate
limit" line in the positive fixture, and state the exception in
safety.md beside the cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7
…flows SHA

check-contract is pinned at 2476d5d, where the line is run.sh:184;
aggregate-results stays at ac4d878 run.sh:266.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 12, 2026 05:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T05:19:48.168663Z 30e9555 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 Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed b0858a9c3cb6a785439297e9ab709b4a4c46403a: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15546 (head b0858a9)

I found no security issues. This review was blocking only: this lane already reviewed head 30e9555, so it reports CRITICAL and IMPORTANT findings only.

critical-findings: 0

What I read. I read every hunk of all 9 changed files. Two are trusted paths and merge-hold modules: babysit_merge.py and babysit_verify_evidence.py. I read their whole change against the merge-hold rule.

Merge hold checked: the merge.max-queue-ejections cap.

  • What changes: at the cap, queue_ejection_hold now subtracts a removal when GitHub's rate limit caused it (babysit_merge.py#L4590-L4591). A removal qualifies only when all of these hold:
    • it matches exactly one merge-group entry, within 2 minutes;
    • every failed job in that entry's failed runs is CI Status or its ci-status alias;
    • every failure annotation is a rate-limit line or a generic line, and at least one is a rate-limit line;
    • the limit has since reset.
  • Is it a named friction hold? No. It is not a path, trust-path, person-approval, bot-author or pin hold, and it is not a provenance hold. I judged it as an ordinary merge hold.
  • Who reaches it, and what they get: someone could fake rate-limit annotations in a pull request's own merge-group CI Status job. The most that gets them is a head put back in the queue. The merge queue still runs every required check on the merge-group commit before anything lands. So this path gives no leak, no compromise and no charge; it only adds queue runs.
  • Fails closed: any read that goes wrong still counts the removal:
    • if the run listing raises or returns None or an empty list, rate_limited_removals returns 0;
    • an exception while checking one removal counts that removal;
    • an incomplete jobs list (total_count differs from the listed count) gives None;
    • a full annotations page gives None;
    • a removal with no time does not parse, so it counts;
    • lane_queue passes removals on only when the timeline read had no error (babysit_verify_evidence.py#L4375).
  • API paths and tokens: the request paths are built from run and job id values that come from GitHub's own API responses. All reads still go through _verdict_read_env(). No token, permission or scope changes.
  • Run cache: the shared failed-run listing is filtered to each pull request's gh-readonly-queue/<branch>/pr-<n>- prefix after it comes out of the cache. Per-run answers are keyed by repo, run id and attempt, and stored only for completed attempts. One pull request cannot poison another's answer.

Trust controls: the trusted-trigger check, lane token scope, kill switch and token broker are untouched. Nothing widens who or what is trusted.

Instruction surface: the doc edits (docs/conventions/pr-pipeline/README.md, reference/safety.md) and the changelog fragments only describe the new behavior. They remove or soften no standing instruction.

Plugin manifests: none changed.

Embedded text: nothing in the PR context tries to direct this review.

Spend (not a finding): a head at the cap now costs about 2 extra GitHub API reads per removal checked, about 4 per refused head per sweep at the default limit, using the verdict reader's token. Heads under the cap cost nothing extra.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed b0858a9c3cb6a785439297e9ab709b4a4c46403a: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no blocking findings

This review was blocking only: this lane already reviewed an earlier head (30e95552) and found nothing. The new head b0858a9c is a merge of main into the branch. I read every hunk of all 9 changed files again. babysit_merge.py and babysit_verify_evidence.py are on the trusted-path list, so for those I also read the unchanged code they call: babysit_run_cache.get / put / MAX_AGE, plus the imports, _now and parse_github_timestamp in babysit_merge.py.

What I checked

  • The count is unchanged. _failed_removals walks the timeline exactly as the old counter did. It returns at the newest head change, and gives None on a malformed item or a full window. So _failed_ejections == len(_failed_removals) for both consumers.

  • The discount is fail-closed. rate_limited_removals / _rate_limited_removal / _run_rate_limit_reset leave a removal counted on any of these:

    • a failed listing, jobs read or annotations read;
    • a short jobs page or a full annotations page;
    • a removal with no time, or one that parses to nothing;
    • zero matching queue entries, or more than one;
    • any failed job other than CI Status / ci-status;
    • any failure line that is neither a rate-limit line nor a generic one;
    • a reset time that has not passed yet.

    Nothing is read below the cap.

  • The run cache is used safely.

    • The listing is cached under MAX_AGE, keyed by repository and filtered per pull request after the read.
    • A per-attempt answer is cached only once the attempt's status == "completed".
    • The reset comparison against _now() is recomputed on every call.
    • A stale cached listing can only miss a run, and a missed run leaves its removal counted.
  • Both consumers are wired. unattended_enqueue and lane_queue pass failedRemovals. lane_queue passes None when the read errored or the value is not a list.

Closing issue: none. The PR closes no issue (it cites hub finding L570), so there are no acceptance criteria to check.

Spend (not a finding): a head at the cap costs about 2 extra GitHub API reads per checked removal, roughly 4 per refused head per sweep at the default limit. That draws on the token pool only, not a billed resource.

I didn't run the PR's test results (102 / 314 / 39 OK, plus the mutation checks); they are the author's claims, since this lane has no shell.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

The unattended merge path enqueued this pull request at head b0858a9c3cb6a785439297e9ab709b4a4c46403a.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Verification evidence for b0858a9

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15546-b0858a9c3cb6a785439297e9ab709b4a4c46403a, expires on 2026-12-12.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit a7024af Nov 12, 2026
52 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the fix/queue-ejected-skip-rate-limit branch November 12, 2026 09:35
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

The post-merge check verified merge commit a7024afbe65c2f146cea02020dd86e1be456a6fb; later checks count it verified from this comment.

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