Skip to content

perf(pr-pipeline): drop ci-status reads the run already has - #11851

Merged
kyle-sexton merged 3 commits into
mainfrom
perf/ci-status-read-cuts
Nov 1, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
perf/ci-status-read-cuts

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: GITHUB_TOKEN counter-A cut assigned by GitHub Support

Summary

ci-status in pr-require-checks.yml makes REST reads whose answers the run already has or never uses. This PR removes them, so counter A (pulls, issues, commits, repo, git refs, compare), the one that trips the hourly breaker, takes fewer calls per run. Every hold decision stays the same.

Fix

  1. Merge queue, pull requests not opened by the lanes App. A new step, queued_author ("Read whether the queued pull request is the lanes App's"), reads the queued pull request through pr_read, using the same args the pr-unblock and lanes-hold steps already use. Those two later reads now come from the cache, so the job makes no extra REST call. verdict_reads_restore and verdict_reads_carry now skip whenever that step proves the author is not the lanes App. The test is the lanes-hold step's own: .user.id == LANES_APP_ID and .user.type == "Bot". Their only consumer is the lanes-hold step, which exits at that same author check for every other author. If the author cannot be read, lanes stays unset and both steps run as before. The new step has continue-on-error and has its opt-out in scripts/lane-coverage-step-opt-outs.txt.
  2. pull_request, pull requests not opened by the lanes App. The lanes-hold step now tests the author from the payload first (github.event.pull_request.user.id / .type), and exits before reading the pull when it is well formed and not the lanes App. A pull request's author never changes, so the payload is as good as a live read here. A malformed or missing payload author falls through to the live read and its existing fail-closed test. The merge queue path is unchanged, since a merge group names no author.
  3. Lanes App pull requests, changed files. On pull_request, the lanes-hold step builds files.jsonl from the broker step's pr-files.json. That file holds every page of the same pulls/<n>/files endpoint, read live earlier in the same job. The review-lane step already reuses it. The fields (filename, previous_filename, status) are the same, and merge-holds.mjs parses each line with JSON.parse. The pages are used only while the live pull's head still equals the event's head (PR_HEAD_SHA), so a push between the two steps cannot pair an old file list with a new head. The changed_files completeness check still runs. A missing or unparsable file, a moved head, or a merge_group event takes the live read.

Not changed: the issue-comments read in the lanes-hold step. The job's documented rule (the pr_read comment) says comments are read live so that a member's veto is never missed. The hold-lift step's earlier read has the same fields and pagination, but reusing it would let a veto posted between the two steps go unseen, and a comment does not re-run ci-status. Also unchanged: the three contents reads at the base commit, draft handling, the api-calls emit position, and ci-workflows.

Verification

Per-run REST delta, by event class:

Event class Counter A Counter B Notes
pull_request, not the lanes App -1 0 for every non-exempt author. 0 for exempt authors (Dependabot, plugin release, standards sync): on a non-draft run the review-lanes step's pr_read of the pull now misses and reads it
pull_request, lanes App -1 0 files read (cut 3); the comments reuse was dropped (see Fix)
merge_group, not the lanes App about -3.6 about -2.8 git/ref x2 + compare (A); workflow runs + artifacts (B); plus 1-2 uncounted gh run download calls. These per-run figures come from the cut's assignment, not from a measurement in this change
merge_group, lanes App 0 0 the pull read moves earlier with the same cache key

Expected hourly effect at the 2026-11-01 01:58-03:58Z rates. Run counts come from the token-spend report's runs.json:

  • pull_request: 48.5 runs/h, split by branch prefix into lanes App (work-resolve-issue/) 10, plugin release 2.5, other 36.
  • merge_group: 12 runs/h. The 24 queued pull requests were matched to their squash commits on main: 4 by the lanes App, 20 by others, so 10 non-App runs/h.

Per class:

  • non-App pull request: 36 A/h
  • App pull request: 10 A/h
  • non-App merge group: 36 A/h and 28 B/h

That totals about -82 A/h and -28 B/h. The earlier estimate was -96 A/h. It assumed -2 A per lanes App pull request and the full -1 A for exempt authors; the dropped comments reuse and the exempt-author case take that out.

Re-measure: use the same method as the 01:58Z report (fetch.py + analyze.py over pr-require-checks/ci-status), over 2 h starting at merge + 30 min. Compare A calls/h for ci-status (385 A/h in the after-window) with the counter-A window peaks.

Tests:

  • scripts/ci-lanes-pr-hold.test.sh: PASS=291 FAIL=0. On origin/main's workflow, 19 of the new and updated cases fail. They cover:
    • a non-App payload author reading no pull
    • the author step's lanes output (true, false, and unset on an unreadable author, ref or id)
    • the lanes-hold step answering from the author step's cache in the queue
    • both carry steps gated on lanes != 'false'
    • the broker pages used with no files read, including the completeness check
    • fallback to the live read on unparsable pages and in the merge queue
    • fallback to the live read when the live head differs from the payload head (these pass on origin/main too, which always reads live)
  • scripts/ci-hold-pr-unblock-status.test.sh 32/0, scripts/ci-broker-pin.test.sh 25/0, scripts/ci-hold-lifted-by.test.sh 64/0, scripts/ci-hold-cost-decision.test.sh 172/0.
  • scripts/check-lane-coverage.sh --check: all 79 gate steps fed, 5 opted out.
  • node --test over reconcile.test.mjs, resolve-pr.test.mjs and merge-job.test.mjs: 366/0.
  • actionlint on the workflow: clean. shellcheck on the test: clean.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits November 1, 2026 00:48
Cut GITHUB_TOKEN REST reads in ci-status with identical decisions:

- merge_group: a new queued_author step reads the queued pull request
  through pr_read with the args the pr-unblock and lanes-hold steps use,
  so their reads become cache hits. The two carry steps (pr-merge's
  carried verdict reads and the run cache) now skip a pull request the
  step proves is not the lanes App's; an unread author keeps them.
- pull_request: the lanes-hold step tests the payload author first and
  exits before reading the pull for a well-formed non-App author; any
  other payload falls through to the live read and its test.
- lanes App pull requests: the lanes-hold step takes the changed files
  from the broker step's saved pages on a pull_request event, falling
  back to the live read when they are missing or do not parse; the
  changed_files count check still applies.

The issue-comments read stays live: the job's rule is that comments are
read live so a veto is never missed, and reusing the hold-lift step's
earlier read would widen that window.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The lanes-hold step now takes the broker step's file pages only while
the live pull's head equals the event's head, so a push between the two
steps cannot pair an old file list with a new head; otherwise it reads
the files live as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 1, 2026 05:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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-11-01T05:58:10.426171Z 01e41cc 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 1, 2026

Copy link
Copy Markdown
Contributor

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

Security review: no findings

critical-findings: 0

I read all three changed files in full: .github/workflows/pr-require-checks.yml, scripts/ci-lanes-pr-hold.test.sh and scripts/lane-coverage-step-opt-outs.txt. The workflow matches a trusted path. Its changed steps are the ci-status lanes-hold step, which is a merge hold. I judged each change from the code and checked whether it lets through anything the base blocked. None does.

1. Payload author short-circuit in the lanes-hold step (L6256-L6263)

  • On a pull_request event, the step now exits early when the payload author is well formed and not the lanes App. The base already exited for those authors, just after a live read (L6269-L6272), so the hold covers the same pull requests as before.
  • github.event.pull_request.user.id and .type come from GitHub, not from the pull request author.
  • The test is the same as before: the id equals LANES_APP_ID and the type is Bot.
  • A missing or malformed payload author falls through to the live read and its fail-closed check.
  • A spoofed payload cannot skip the holds on a lanes App pull request, because the payload is not under an attacker's control. The test at L181 also covers this.

2. Reusing the broker step's file pages (L6327-L6337)

  • The pages are only used if they were written earlier in this job.
    • The broker step writes pr-files.json from a full gh_read --paginate (L4807-L4815).
    • If every attempt fails, that step exits before writing the file.
  • ci-status only checks out the default branch and the base config (L4914-L4916, L4999-L5001). No pull request code runs in the job that could plant that file in RUNNER_TEMP.
  • jq -c '.[] | [...]' gives the same lines as --jq '... | @json', and multi-page output parses the same way.
  • The pages are only used while the pull's head still equals the event's head. Parse errors and merge_group events take the live read.
  • The changed_files completeness check still runs.
  • One race remains: the pull may come from the pr_read cache and be older than the file list. The base had the same race, since it compared a cached pull against a live file list, so this is not new. The merge queue still reads the files live.

3. Merge-queue queued_author step (L5937-L5966) and the carry gates (L5988, L5999)

  • The step only gates the two carry steps that warm a cache. The workflow says a warm reader never turns a FAIL away or allows a pass, and a cold reader holds when the token has no headroom.
  • lanes=false is set only when the lanes-hold step's own author test fails. An unread author leaves the output unset, and the carry steps run as before.
  • Skipping the carry steps for a pull request not opened by the lanes App leaves no hold weaker: the lanes-hold step returns early for those authors anyway.
  • The step adds a pr_read with the same arguments the existing steps use. That moves the cached pull snapshot a few steps earlier and opens no new path.
  • The new entry in lane-coverage-step-opt-outs.txt matches this fall-through behaviour.

Other checks

  • Trust controls: no change to who is trusted, to token scope, to the kill switch, or to what untrusted text reaches a lane. The kill-switch check at L6273-L6295 still runs for every lanes App pull request.
  • Throughput-phase holds: the change removes none of the owner's named friction holds.
  • PR context: no embedded instructions aimed at the review.
  • Spend: none. The change only reduces GITHUB_TOKEN REST calls and adds no billed resource.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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

Code review: perf(pr-pipeline): drop ci-status reads the run already has

Result: no findings. I read every hunk in all 3 changed files: .github/workflows/pr-require-checks.yml, scripts/ci-lanes-pr-hold.test.sh and scripts/lane-coverage-step-opt-outs.txt. I also read the surrounding workflow code each change depends on: gh_read/pr_read, the broker step that writes pr-files.json, the cost-hold step's pr_read_put, the pr-unblock step and the lanes-hold step.

What I checked:

  • Merge-queue author step (queued_author). It builds the cache key from the same pr_read args (repos/$GITHUB_REPOSITORY/pulls/$pr) as the pr-unblock step's READER=pr_read read3 call and the lanes-hold step's READER=pr_read read_api call. Both of those pass "${@:2}", so the key is identical and their reads come from the cache. The author test matches the lanes-hold step's own test (.user.id == $id and .user.type == "Bot"). An unparsable ref, an invalid LANES_APP_ID, a failed read or a malformed author all leave lanes unset. Both carry steps are gated on != 'false', so in each of those cases they run as before. The step has continue-on-error, and its opt-out is in scripts/lane-coverage-step-opt-outs.txt.
  • Payload author shortcut (pull_request). The early exit runs after the LANES_APP_ID / merge.agent-identity consistency check, so that check still runs on every pull request. Only a numeric id with a non-empty type skips the read. Every other payload falls through to the existing live read, which fails closed.
  • Reusing the broker step's file pages. The broker step saves the raw output of gh api --paginate, which is one JSON array per page written back to back. jq -c '.[] | [.filename, .previous_filename, .status]' turns that into the same per-line JSON as the live read's --jq '... | @json'. On the pull_request path, the earliest read of the pull that the head check can see is in the cost-hold step, which runs after the broker step. So when the pull still has PR_HEAD_SHA, the pages were read at that head; the only exception would be a force-push back to the same head. The changed_files completeness check still applies to the reused list. If jq fails partway, the live read overwrites files.jsonl.
  • Tests. The new cases cover a non-App payload author (no read), a malformed or missing payload author (falls through), the author step's three lanes outcomes, the cache reuse in the queue, both carry gates, reused pages (a rename across pages, a short list, a clean list), unparsable pages, a different head, and the merge-queue fallback. The author's pass counts (PASS=291 and the others) are their own claim; I did not run the tests.

Other checks

  • Closing issue: none. The PR says it has no related issue, so there are no acceptance criteria to check.
  • Path-scoped rules: no .claude/rules/ glob matches a changed file.
  • Plugin manifests: none changed.
  • Paved paths: not evaluated.
  • Security: left to the dedicated security lane.
  • Embedded instructions: none found in the PR context.
  • Spend: nothing new. The change cuts GITHUB_TOKEN REST reads per ci-status run, which is free and spends no credits or minutes.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 73cddb4 Nov 1, 2026
80 checks passed
@kyle-sexton
kyle-sexton deleted the perf/ci-status-read-cuts branch November 1, 2026 06:26
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