Skip to content

feat(pr-merge): read the merge sweep through the lanes App token - #17306

Closed
kyle-sexton wants to merge 2 commits into
mainfrom
feat/pr-merge-app-token-reads
Closed

kyle-sexton wants to merge 2 commits into
mainfrom
feat/pr-merge-app-token-reads

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

No related issue: owner decision D398 (2026-11-18, hub session): the scheduled merge sweeps read through the lanes App's allowance instead of the shared GITHUB_TOKEN pool. Scope: pr-merge's reads only, no new App.

Summary

The shared GITHUB_TOKEN pool (5,000 an hour) ran out 14 times on 2026-11-18, and every time it did, every lane paused. pr-merge's Merge job spent about 320 GITHUB_TOKEN calls an hour in the six hours to 22:16Z. Over the same period the lanes App's own pool never fell below 4,100 remaining in an hour.

This PR moves the Merge job's reads onto the lane token the job already mints. Each read now has one designated token. No read switches to the other token when its own pool runs low.

D398 replaces the 2026-10-23 decision that kept these reads on GITHUB_TOKEN because of GitHub's Terms of Service ("You may not share API tokens to exceed GitHub's rate limitations"), and the revert in #9438 that followed it. The October record compared three options: (a) designed routing, (b) fallback when exhausted, and (c) no App reads. It judged (b) the shape closest to the ban. This PR builds (a). The owner should confirm that D398 knowingly supersedes the Terms-of-Service rationale before this merges.

Fix

  • lane-rules.json: the pr-merge row grants merge-pr actions: read again. The broker already accepts that grant for pr-merge.yml's merge-pr activity and refuses it to every other activity (azure-iac src/lanes-token-broker/src/authorize.mjs, the check from azure-iac#83). No broker change is needed.
  • pr-merge.yml, Merge job: these steps now read with the lane token and name it lanes-app to the rate guard:
    • the candidate listing (GraphQL);
    • the rotation, head-ref map, verdict-read carry and lane-records reads;
    • the post-merge check;
    • the skip filter;
    • the gate (BABYSIT_VERIFY_GH_TOKEN is now the lane token);
    • the sweep-count read.
  • babysit_gh.py job_token_env: a REST GET of a commit's statuses goes under BABYSIT_JOB_GH_TOKEN (the job's GITHUB_TOKEN) when it is set, because the lane grant has no Commit statuses permission. Check runs, check suites and annotations stay on the lane token. The gate already read those with it before this change: run 44399528272 made 5 check-suite reads under lanes-app, and its log has no check suites unreadable refusal. _budget_token_name now names a call whose GH_TOKEN override equals the process token API_BUDGET_TOKEN, so a verdict reader set to the lane token budgets against lanes-app.
  • babysit_whole_review.py: the job-bucket and running-job reads prefer BABYSIT_JOB_GH_TOKEN, so the whole-review guard still watches GITHUB_TOKEN.
  • Comments, docs/conventions/pr-pipeline/README.md and the changelog fragments describe the new routing.

What stays on GITHUB_TOKEN, and why:

Call Reason
who and superseded They decide whether to mint the lane token, so they run before it exists.
Commit-status reads The lane grant holds no Commit statuses permission.
Re-fire and escalation-clear steps One JS client serves both their run reads and their check and status reads.
Dispatch Post Merge Runs, Report Gate Checks, Report Unarmed Status, Dispatch Full Run, Wake Eval Released These jobs mint no lane token. Most of them write with permissions the App lacks (dispatch, statuses, check runs).
Enable Auto Merge The broker refuses actions to the enable-auto-merge activity (authorize.mjs line 420). Moving its Actions reads needs a broker change first.

Two stops still act on GITHUB_TOKEN alone, and this PR leaves both unchanged:

  • the Merge job's "Stop on dispatch-post-merge-runs's rate limit" step;
  • the pacer (pace.mjs), which skips the Merge job when GITHUB_TOKEN burns fast.

The hub brake also reads only the GITHUB_TOKEN pool when it sets CLAUDE_LANES_REPO_DISABLED. That kill switch still stops this job whichever pool its reads use.

Behaviour change: the post-merge check and the gate's lane-run annotation reads now use the lane token. If one is refused, _failed_gates returns None and excuses nothing, which is the safe direction.

Verification

  • node --test over .github/scripts/pr-merge/*.test.mjs, .github/scripts/pr-verify/workflow.test.mjs, and .github/actions/resolve-config/{live-config,callers}.test.mjs: 1,436 pass, 0 fail.
  • python3 -m unittest discover in babysit-prs/scripts/tests: all pass (19 skipped).
  • New tests:
    • commit-status reads go under the job token, and every other read and every write does not;
    • a call that carries the process token reads into lanes-app;
    • whole-review's job bucket uses BABYSIT_JOB_GH_TOKEN;
    • the Merge job's steps carry the lane token and token names;
    • the live config gives actions to merge-pr alone.
  • actionlint .github/workflows/pr-merge.yml: clean.
  • scripts/check-affected.sh --uncommitted: 17 passed, 5 skipped (those 5 run the checked tree's own code and run in CI).
  • Expected saving (estimate): about 280 to 300 GITHUB_TOKEN calls an hour. Merge averaged 320 an hour over six hours. In the two sampled runs (44399528272 and 44378219249, per their api-routes annotations), every GITHUB_TOKEN route except statuses (1 call) and the collaborator read (2 calls) belongs to a step that now uses the lane token. The re-fire and escalation-clear steps' share is not split out, which is why this is a range. The lanes App pool takes on the same load, with at least 4,100 of its 5,250 an hour remaining since 19:00Z.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 18, 2026 17:49
Owner decision D398 (2026-11-18): the scheduled merge sweep reads
through the lanes App's own installation allowance instead of the
repository's shared GITHUB_TOKEN pool.

- lane-rules.json gives the merge-pr grant actions read, which the
  token broker already allows to that activity alone.
- The merge job's candidate listing, carried artifact reads, post-merge
  check, skip filter, gate verdict and review-evidence reads and
  sweep-count read use the lane token, named lanes-app to the rate
  guard.
- babysit_gh sends check-run, check-suite, annotation and commit-status
  reads under BABYSIT_JOB_GH_TOKEN (the job's GITHUB_TOKEN) when set,
  since the lane grant holds neither permission, and names a call whose
  GH_TOKEN equals the process's own as API_BUDGET_TOKEN.
- Whole-review reads its job bucket with BABYSIT_JOB_GH_TOKEN when set.

Enable Auto Merge stays on GITHUB_TOKEN: the broker refuses actions to
the enable-auto-merge activity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gate already read check suites, check runs and annotations with the
lane token on this public repository (run 44399528272: 5 check-suite
reads under lanes-app, no unreadable refusal). Routing those reads to
GITHUB_TOKEN moved calls back onto the pool this change drains, so
BABYSIT_JOB_GH_TOKEN now carries commit-status reads only, which need
the Commit statuses permission the lane grant lacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyle-sexton

Copy link
Copy Markdown
Member Author

Closed by owner decision (2026-11-18): the 2026-10-23 decision stands that no pr-merge read moves to the lanes App token to gain quota, because GitHub's Terms of Service section H says 'You may not share API tokens to exceed GitHub's rate limitations' (decision record: #9297 (comment)). Quota relief comes from cutting calls.

@github-actions
github-actions Bot deleted the feat/pr-merge-app-token-reads branch November 19, 2026 13:22
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