Skip to content

perf(ci): cut CI Status REST reads on merge_group runs - #17299

Merged
kyle-sexton merged 2 commits into
mainfrom
perf/ci-status-merge-group-reads
Nov 19, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
perf/ci-status-merge-group-reads

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: the repository's 5,000-call hourly GITHUB_TOKEN pool runs out almost every hour, and CI Status on merge_group spends about 4x what a pull_request run does.

Summary

Measured over 15:55Z-21:58Z on 2026-11-18 from the job-call records: 99 merge_group CI Status runs spent 1,579 calls, minus GraphQL about 16 per run. A pull_request run spends about 4. Each merge group holds one queued pull request (pr-N in the ref), so nothing reads "every PR in the group". The extra cost is the merge-queue verdict reader, its carried-cache read and the runner-tail step, which run only in the queue:

route (merge_group) per run runs hitting it
actions/artifacts (named PASS/FAIL lookups) 3.52 83
actions/runs/{n}/artifacts 2.58 97
compare/{x} (run heads against main) 2.45 97
graphql (separate pool) 2.42 99
actions/runs/{n} 1.33 79
actions/artifacts/{n}/zip 1.21 79
actions/workflows/{x}/runs 1.17 98
pulls/{n} 1.13 97
actions/runs/{n}/attempts/{n}/jobs (runner tail) 1.08 99
git/ref/heads/main 0.84 83
pulls/{n}/commits 0.66 65
pulls/{n}/reviews 0.54 53
contents/ 4 segments (trusted-actor list, admission rules at main's tip) 0.53 38
contents/ 3 segments (pipeline config) 0.48 24
issues/{n}/timeline 0.45 45
issues/{n}/comments, pulls/{n}/comments, issues/{n}/labels 0.63 30 / 27 / 6

Fix

  • The verdict reader (babysit_verify_evidence.py) read the trusted-actor list, admission rules and pipeline config at main's tip through the contents API, although the job's .base checkout already sits at that tip. BABYSIT_CONFIG_CHECKOUT now takes several checkouts separated by os.pathsep (base-config and .base), the .base sparse list carries those three files, and _raw_file and _text_file take a file from a checkout only when its HEAD is the commit asked (merge_policy.checkout_file_at). The tip itself is still read live, so if main moved after the checkout the read goes to the API as before. The file is read from git objects (ls-tree, cat-file), never the work tree, and .base is main's own code, which this job already runs.
  • Record each job's runner tail enforces nothing and now runs on one merge-group run in ten (endsWith(github.run_id, '0')), which still shows the trend.

Reads kept, and why:

  • Named PASS/FAIL artifact lookups, run reads, verdict downloads and the run-head compares: they catch a FAIL uploaded after arming and require a pass at the head (owner decisions 2026-11-04 "Hold on FAIL only" and "FAIL holds, cap not", and verdictHold, quoted in the lanes-hold step's comment).
  • The carried-cache and head-ref-map reads (about 3 per run): they replace about 860 cold reads.
  • pulls/{n}, reviews, comments, timeline and commits: a veto, approval or push after queueing changes the verdict, and the step reads them live by design.
  • git/ref/heads/main: the reader resolves the live tip so a since-removed trusted actor or policy change is never read from a stale commit (carry_base_tip takes a passed tip only where an older one can only refuse more).
  • Hold labels and the kill switch: a label added after queueing must still stop the merge. The labels route costs 0.06 per run, and the kill switch costs nothing because it comes from the vars context with no API read.

Calls saved per hour, against the 6 h data (calls minus GraphQL): the runner tail drops about 96 of 107 reads (16/h). The contents reads drop up to 100 (up to 17/h): fewer if main moves between the checkout and the read, or if some 3-segment reads are docs/upstream page pins, which this change does not cover. Total 16-33 calls per hour, out of about 257/h.

Follow-ups not taken here: _contains (2.45/run) has no local-history path the way _GreenMain.ahead does. Adding one needs a history fetch in ci-status, and a stale local "no" must fall back to the API, so it is a separate change.

Hold paths touched (pr-require-checks.yml, babysit_verify_evidence.py and the other babysit scripts), so this needs a trusted approval.

Verification

  • ConfigFromTheBaseCheckout (merge policy) gains two tests: the listed checkout whose HEAD is the commit answers, and a checkout file reads only at its HEAD. FilesAtTheTipFromTheCheckout (verify evidence) shows the trusted list and pipeline config come from the checkout with no API read, and that another commit reads the contents API.
  • scripts/ci-lanes-pr-hold.test.sh pins the new BABYSIT_CONFIG_CHECKOUT value and the three files in .base's sparse list.
  • scripts/check-affected.sh: 19 passed, 0 skipped. scripts/run-ruff.sh check is clean on the changed Python.

Related

  • #12400 added the runner-tail step.

🤖 Generated with Claude Code

In the merge queue, the verdict reader read the trusted-actor list,
admission rules and pipeline config at main's tip through the contents
API on every run, although the job's .base checkout already sits at
that tip. BABYSIT_CONFIG_CHECKOUT now lists both checkouts
(base-config and .base), the .base sparse list carries those three
files, and the reader takes a file from a checkout only when its HEAD
is the commit asked. The tip itself is still read live, so a main that
moved since reads the API as before.

The runner-tail step enforces nothing; it now samples one merge-group
run in ten instead of reading the attempt's jobs on every run.

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

chatgpt-codex-connector Bot commented Nov 18, 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-18T22:51:24.376347Z 8195176 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 18, 2026 •

Copy link
Copy Markdown
Contributor

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

Security review (incremental, blocking only): no findings

This review covers only what changed since 8195176. That is one file, plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_verify_evidence.py, and I read its whole change.

The change is in a test module. When the module is imported, it removes git variables it may have inherited (GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR, GIT_PREFIX, GIT_OBJECT_DIRECTORY, GIT_CONFIG) from os.environ. This keeps the suite's git calls inside the test's own temporary repositories. A parent process's repository, such as a hook running under git commit, can no longer leak in. The change does not touch the verdict reader (babysit_verify_evidence.py), any merge hold, the trusted-trigger check, any token request or the kill switch. It only narrows what the tests inherit, so it adds no attack surface.

This head already has a review, so this one reports blocking findings only. The earlier review's conclusions for the other 6 files still stand, since none of them changed. The change spends nothing new.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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

Code review (incremental, blocking only): perf(ci): cut CI Status REST reads on merge_group runs

This round looks only at the push since 8195176a. It changes one file, tests/test_babysit_verify_evidence.py. Because this lane already reviewed an earlier head, the review was blocking only.

New change. When the module loads, it now removes GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR, GIT_PREFIX, GIT_OBJECT_DIRECTORY and GIT_CONFIG from os.environ. That stops a git environment inherited from the caller (for example a git hook) from pointing the suite's temporary checkouts at the outer repository. os is already imported (line 32), and the loop variable is deleted afterwards. Changing the environment at import time affects the whole test process, but that matches what the commit says it does. It is test-only and relaxes no expected value. I found no blocking problem.

Earlier finding restated. The earlier review raised this as a summary comment with no line anchor, so it is restated each round. The code it points to is unchanged at this head:

  • babysit_merge_policy.py#L6404-L6432: _config_checkout returns the first listed checkout whose HEAD is sha. If _git_file_at fails there, checkout_file_at returns None and never tries the next checkout.
  • On merge_group, base-config (listed first in BABYSIT_CONFIG_CHECKOUT) usually sits at the same commit as .base. Its sparse list leaves out the admission-rules file, so that read still goes to the contents API.
  • As a result, part of the contents-read savings the PR description claims does not happen in the common case.
  • Fix: try each checkout whose HEAD matches until one returns the file, rather than stopping at the first.
  • Already posted: perf(ci): cut CI Status REST reads on merge_group runs #17299 (comment)

PR context: the PR closes no issue, so there are no acceptance criteria to check. The PR text contains no embedded instructions to the lane.

Spend (not a finding): this push adds no paid usage.

Loosened-check verdict: fail. That is the default, because the prompt had no loosened_check_verdict: or loosened_check_patterns: line; patterns: 0. No decision-record line was supplied, so the citation requirement was not checked. No loosening was found in the changed test lines.

I ran no tests. The author's verification is author-claimed and unverified.

Verifier dropped 0 of 0 candidates.

…suite

The new checkout fixture builds a git repository, so the suite must
clear GIT_DIR, GIT_WORK_TREE and GIT_CONFIG before any test spawns git
(scripts/check-fixture-git-isolation.sh), as the merge-policy suite does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 253fe6b Nov 19, 2026
65 checks passed
@kyle-sexton
kyle-sexton deleted the perf/ci-status-merge-group-reads branch November 19, 2026 01:33
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant