Skip to content

perf(ci): read CI Status labels and comments from the GraphQL pool - #16644

Closed
kyle-sexton wants to merge 3 commits into
mainfrom
perf/15497-ci-reads-graphql
Closed

kyle-sexton wants to merge 3 commits into
mainfrom
perf/15497-ci-reads-graphql

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #15497

Summary

CI Status (pr-require-checks.yml, job ci-status) now reads the pull request's labels and issue comments from GitHub's GraphQL API. GitHub meters GraphQL for GITHUB_TOKEN in a separate pool from the per-repository core REST limit of 5,000 per hour. CI on every open pull request spends that core limit, so these reads no longer count against it.

Fix

  • gh-read.sh gains two helpers, pr_labels <n> and pr_comments <n>. Each sends one GraphQL query and prints the result in the REST shape the steps already parse:

    • a REST id is GraphQL's databaseId;
    • a bot login gets back the [bot] suffix that GraphQL drops;
    • user.type comes from __typename.
  • Three reads move to these helpers:

    • the human-gated step's labels read;
    • its hold-reason comments read;
    • the hold-lift step's comments read.
  • Fail-safe: anything short of a whole, well-formed answer reads REST through gh_read, every page, exactly as before. That covers:

    • a failed send;
    • an errors answer;
    • hasNextPage on the connection;
    • a comment author that REST would show differently (a deleted account, a type other than User or Bot);
    • any review-lane hold comment. A hold comment's updated_at feeds lane-binding.mjs wasEdited, and nothing shows that GraphQL's updatedAt moves only when REST's does. So holds keep the REST read, and only the common no-hold path reads GraphQL.

    A GraphQL failure costs one core read, never a red required check, including in merge_group runs. A spent GraphQL primary limit stops only the graphql pool in the rate guard, so the REST fallback still goes out (tested).

    Known residual: a RATE_LIMITED answer that still shows GraphQL points left is a secondary limit. The generated rate guard stops every pool for it, so the REST fallback is not sent and the step fails closed. A REST secondary limit does the same today; this is not a new kind of failure, and a test pins it.

  • The new calls go through the api-budget gh wrapper, so they are counted, as graphql=, in the job's api-calls notice line.

Reads that stay on REST, by parity check against the live schema:

Read Why it stays
PR files PullRequestChangedFile has path, changeType, additions, deletions and viewerViewedState, with no previous path. ci-status reads .previous_filename.
Issue events LabeledEvent has actor, createdAt, label and labelable, with no performed_via_github_app. The hold-lift step uses that field to refuse an App lifting a hold for a person.
Actions runs, jobs and artifacts GraphQL has no Actions API. These are the largest share of CI Status and of the other three target jobs.
The cost-hold step's and lanes-hold step's reads Left for a follow-up. The lanes-hold discussion rows feed merge-holds.mjs, which reads more REST fields.

Verification

GraphQL pool measurement (hub call logs gh-token-windows.jsonl and gh-job-calls.jsonl, github-token only):

Measure Value
Measured GraphQL limit (limit header) 5,000 points/hour
Peak window since 2026-11-14 868 points (17%)
Peak window all-time 1,138 points (23%), on 2026-11-08
Peak hourly volume of the four target job types since 2026-11-14 288 jobs
Worst case if all four moved +288 × 3 = +864 points
Projected peak window 2,002 points (40%), under the 60% stop line
This PR alone 2 one-point GraphQL sends per pull_request CI Status job (3 while held), at most 98 jobs/hour (under +300 points)

The GraphQL rate-limit docs state 1,000 points/hour for GITHUB_TOKEN. The measured header says 5,000. Against 1,000, today's peak is already 87%. The measured value governs here; if GitHub enforces the documented number, the REST fallback covers it.

Parity:

  • A REST and a GraphQL answer were recorded for the same pull request (feat(fleet): start a relay session on a Windows lane in the target's plugin profile #16631: 1 User and 4 Bot comments, 1 label) in scripts/fixtures/ci-gh-read-graphql/.
  • scripts/ci-gh-read-graphql.test.sh asserts the adapter's output equals the REST answer on every field the steps and filterLaneHolds read: id, node_id, body, created_at, updated_at, user.login, user.id and user.type. It asserts label names too.
  • The same suite covers:
    • pagination: a second GraphQL page reads all 101 comments over REST;
    • each fallback, the hold-comment one included;
    • a spent GraphQL limit and a secondary limit;
    • the api-calls count.
  • The parity pin was checked by breaking it on purpose: with the [bot] mapping removed, the parity and login cases go red.

Core calls per CI Status job:

Core calls per job
Before (1,351 jobs since 2026-11-15, measured) 5.7
After (estimate) about 4.6

The estimate removes the labels route (0.58 per job) and the hold-lift step's comments read on pull requests with no hold comment (up to 0.57 per job). At the 98-jobs/hour peak that is about 110 fewer core calls per hour.

Measure after merge: in gh-job-calls.jsonl, compare rows with source pr-require-checks.yml:CI Status done after the merge against those before:

  • calls / jobs should fall by about 1.1;
  • graphql / jobs should rise by about 1.1;
  • the routes field should show repos/{repo}/issues/{n}/labels near 0 per job.

Tests run (all green):

Suite Passed
scripts/ci-gh-read-graphql.test.sh (new) 19
ci-gh-read 65
ci-hold-human-gated 81
ci-hold-lifted-by (updated for the GraphQL send; adds a no-hold GraphQL case and a hold-reads-REST case) 83
ci-hold-cost-decision 194
ci-hold-merge-group 82
scripts/check-affected.sh --base origin/main --no-fetch 14 passed, 5 skipped

pr-require-checks.yml is on the trusted-path hold list, so this pull request holds for a person.

Related

  • ci: the lanes App installation token runs out under many concurrent PRs #15497: the core-limit ceiling (about 237 core calls per open pull request per hour, about 21 open pull requests).
  • Left for follow-up PRs, one per workflow:
    • pr-verify Check Intent: its heaviest routes are Actions artifacts and runs, which have no GraphQL. commits/{sha}/pulls (1.18 per job) can move to associatedPullRequests.
    • The review lanes' Review Subscription: pulls/{n} (1.27 per job) and comments (1.0 per job) can move. compare (2.0 per job) needs a parity check.
    • Wait For Refine: pulls/{n} (1.14 per job). Its runs and artifacts reads stay.

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits November 16, 2026 16:18
CI Status read the pull request's labels and its issue comments over
REST, spending the per-repository GITHUB_TOKEN core limit that every
open pull request's CI shares. Two new gh-read.sh helpers, pr_labels and
pr_comments, read them in one GraphQL send each, which GitHub meters in a
separate pool, and print the REST shape the steps already parse. Any
doubt (a failed send, an errors answer, another page, a comment author
REST would show differently) reads REST through gh_read as before, so a
GraphQL failure costs a core read and never a red required check.

PR files and issue events stay on REST: GraphQL has no previous path for
a renamed file and no performed_via_github_app on a label event.

Refs: #15497

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The full REST answer carried an organization node id that the typos
check reads as a misspelling; the parity case compares only the fields
the steps and filterLaneHolds read, so the fixture keeps just those.

Refs: #15497

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A hold comment's updated_at feeds lane-binding.mjs wasEdited, and
GraphQL's updatedAt is not shown to move only when REST's does: a
reaction or a minimize that moved one and not the other could drop a
real hold's footer and pass the check. pr_comments now reads REST
whenever any comment carries a review-lane hold marker, so only the
no-hold path, the common one, reads GraphQL.

Tests pin the hold fallback, the no-hold GraphQL path in the hold-lift
step, and a secondary-limit answer stopping every pool as on REST.

Refs: #15497

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

chatgpt-codex-connector Bot commented Nov 16, 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-16T21:38:44.881536Z 24a5f02 PR opened
ℹ️ 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.

@kyle-sexton

Copy link
Copy Markdown
Member Author

Closing on its own measurement, not on a defect. CI Status spends 5.7 core calls per job; this moves about 1.1 of them to GraphQL. At about 60-65 CI Status jobs an hour that saves about 70 core calls an hour, about 1.4% of the 5,000 limit, and it adds 323 lines of GraphQL-with-REST-fallback logic to a required check. The other jobs could move only about 2.3 (review lanes) and 1.2 (Check Intent) calls each, so the whole GraphQL route tops out around 6%, well below the 21-to-26-PR estimate in #15497. PR files, events and Actions runs have no GraphQL equivalent (introspection). The ceiling has to move through a design choice, not read shuffling. The branch stays, so this can be reopened if a later measurement changes the sums. Refs #15497

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