Skip to content

perf(pr-review-cli): read PR files and pulls.get once per review run - #869

Merged
kyle-sexton merged 1 commit into
mainfrom
perf/pr-review-cli-read-once
Oct 23, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
perf/pr-review-cli-read-once

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: the org's GITHUB_TOKEN bucket for pull_request jobs ran dry three times on 2026-10-23, and a security-review publish failed on it (claude-code-plugins run 39931559612, PATCH .../issues/comments/... - 403, "API rate limit exceeded for installation"). This cuts the requests each review-lane run spends.

Summary

Each pr-review-cli.yml run read the pull request's file list three times (scope, publish, hold) and pulls.get three times. It also spent three REST calls fetching the publish gate and a second compare for the merge base. Now the file list is read once and pulls.get twice. A whole review with an inline comment drops from 15 job-token requests to 8.

Fix

  • Scope passes the file list on. The scope step writes a pr-files output: each name, its rename's old name, the patch's hunk ranges, and the PR's changed_files. It writes it only when the live head is the run's head and the JSON fits 100,000 bytes, the same cap as the review output and one environment string's limit. Both model jobs expose it, so the jobs' steps and outputs stay identical. The status job reads it from review-key, as it already does for every other scope output.
  • Publish builds its anchor lines from those hunk ranges (hunkLines, which a test holds equal to commentableLines on fixtures). It keeps one pulls.get to catch a head that moved during the review. It lists review comments only when it has an inline comment to post: the rerun de-duplication stays, and a run with no inline comment skips a read whose result nothing uses.
  • The hold matches hold-paths against the scope list and checks truncation against its changed_files. Without a usable list (absent, malformed, too large, another head, scope failed) it does its own listFiles and pulls.get as before, so a missing list can never drop a trust-gate hold. A test pins that.
  • The full diff uses the merge base the scope step read, which the marker already records. Without it (incremental-review off, or scope failed) it runs the old compare.
  • The publish gate comes through an anonymous --filter=blob:none --no-checkout clone of claude-code-plugins plus git show <tip>:lib/publish-gate.mjs. That is the route the plugin staging step already takes, and it spends no REST request. The import check and the tip log are unchanged.
  • Trust. pr-files is a step output of the scope step, which runs before any model step. The runner gives each step its own outputs file, so the later model step, which has no shell or write tool, cannot rewrite it. The status job already trusts the same step's outputs for its skip decisions. The SECURITY MODEL header and publish-review/action.yml now describe this.
  • Unchanged: check names, the marker text, the claude-lane-review-complete notice and the lane records.

Verification

.github/scripts/pr-review-cli-api-calls.test.cjs runs the shipped scope, full-diff and gate steps, then publish and the hold. The env comes from the workflow's own expressions, and one counting fake stands in for the API. The same harness, copied into a git archive of v0.64.1 (9aca743), measured the before column.

run shape v0.64.1 this PR
whole review, one inline comment 15 8
whole review, no inline comment 14 6
incremental review, one inline comment 17 10
no-change skip after a base-branch merge 13 8
whole review that holds on a hold-paths file 17 11

The counts assume one page per list. Per run, pulls.listFiles goes from 3 to 1 and pulls.get from 3 to 2 (1 on a skip). The gate goes from 3 calls to 0, and the full-diff compare from 1 to 0. Checkout and the PR-context GraphQL query are the same before and after, so neither column counts them.

At about 22 reviewing runs an hour per lane, that saves about 7 requests per reviewing run, roughly 150 an hour per lane and 300 an hour for both lanes.

Local: node --test --test-concurrency=1 .github/scripts/*.test.cjs gave 644 pass, 0 fail. actionlint and zizmor --offline on the changed workflow and actions were clean, and biome ci --error-on-warnings .github/scripts .github/actions was clean.

Related

  • Not changed here: the review-subscription job still repeats the whole scope step after a handoff, about 5 to 8 requests more on those runs. Handoffs are rare: 0 of 13 sampled runs between 14:26Z and 14:58Z, 1 at 09:24Z today.
  • Kept on purpose: the hold's issue-comment read before it posts its marker. A "re-run failed jobs" reuses the key job's outputs, so a snapshot taken in scope would miss attempt 1's marker and post a second one.
  • claude-code-plugins pins this workflow at v0.64.1 in pr-review-hosted.yml and pr-review-security-hosted.yml; a follow-up PR repins both.

🤖 Generated with Claude Code

The scope step now passes the pull request's file list (names, old names
and hunk ranges) to the status job as a job output, so publish and the
hold no longer list the files again; the hold reuses scope's changed-file
count instead of its own pulls.get. Publish keeps one pulls.get to catch a
head that moved during the review. The full diff reuses scope's merge base
instead of a second compare, the publish gate comes through an anonymous
git clone instead of three REST calls, and publish lists review comments
only when it has an inline comment to post. Every reuse falls back to the
old live read when scope's list is absent, malformed, too large or for
another head.

A whole review with an inline comment drops from 15 job-token requests to
8; a test pins the count for five run shapes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-10-23T15:18:19.793326Z bf413a5 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.

@claude

claude Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 4m 7s —— View job


Security review complete

  • Gather context (PR body, diff, changed files)
  • Review .github/actions/apply-review-hold/hold.cjs
  • Review .github/actions/publish-review/action.yml and publish.cjs
  • Review .github/workflows/pr-review-cli.yml
  • Review new test file for coverage gaps relevant to security
  • Check instruction-surface / trust-gate / manifest implications
  • Adversarial validation of candidate findings (none surfaced, so none to verify)
  • Post findings / summary

No security issues found in this diff.

What I focused on, since this PR restructures the trust boundary the hold/publish steps rely on:

  • pr-files provenance. writePrFiles runs in the scope step, before the job's model step, and is only written when a fresh pulls.get shows the live head still matches the run's head. scopedFiles re-validates head, the changed count, and every file entry's shape before anything downstream trusts the payload, and the model step has no shell/write tool and gets its own $GITHUB_OUTPUT file, so it cannot rewrite the scope step's output. The fallback-to-fresh-read path (absent/malformed/oversized/stale-head list) is exercised by pr-review-cli-api-calls.test.cjs (e.g. "publish and the hold read the file list themselves without a usable scope list", "without the scope list a hold-paths file still holds").
  • Hold-paths trust-gate. pathHold still falls back to its own listFiles/pulls.get whenever the scoped list isn't usable, so a missing/invalid list can't silently drop the trust-gate check — confirmed by the "a scope list shorter than the pull request's changed files holds" test.
  • Inline-comment anchors. scopedLines/hunkLines reproduce commentableLines's per-file diff-line sets from the hunk headers captured at scope time; a malformed hunk makes the whole scoped list null and publish falls back to a fresh diffLines read rather than widening what's commentable. The test "the scope step's hunk ranges give the lines commentableLines reads from the patch" pins the two extraction paths as equivalent.
  • Publish-gate fetch. Switching from repos.getContent to an anonymous git clone --filter=blob:none --no-checkout + git show <tip>:lib/publish-gate.mjs doesn't change the trust model: it's still read-only against melodic-software/claude-code-plugins's default-branch tip over TLS, the import check (node: builtins only) is unchanged, and no code from the clone is executed — only its text is parsed and, after the import check, loaded the same way loadGate already did.
  • All attacker-controlled strings that flow through the new path (filenames, patch text) end up either regex-extracted to digits (hunkLines) or JSON-stringified via core.setOutput (which is injection-safe), never interpolated into a shell command or RegExp source.

No GitHub Actions hardening findings to add beyond zizmor's lane (no trigger, permissions, or pin changes here), and no .claude-plugin manifest changes in this diff.

critical-findings: 0

claude-lane-summary: lane=claude-security-review sha=bf413a54191df72cbbcc4bb6e707c64134c4d354 run=39976842362
· Branch: perf/pr-review-cli-read-once

@claude

claude Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 6m 24s —— View job


Code review

  • Gather context (diff, CLAUDE.md, REVIEW.md, rules)
  • Review scope step / pr-files output changes
  • Review publish.cjs changes
  • Review hold.cjs changes
  • Review workflow yml changes
  • Review test coverage
  • Check closing issue / PR body contract
  • Post findings

Scope note: this repository runs a dedicated security lane (pr-review-security*.yml), so per REVIEW.md security findings are that lane's alone and are not reported here.

PR body contract: compliant — opens with No related issue: <reason> and includes ## Summary, ## Fix, ## Verification, ## Related.

Closing issue: none declared (No related issue: ...), so no acceptance criteria to check.

Paved paths / manifests: no paved-path row in docs/standards/README.md and no plugin manifest touched — nothing to apply.

What I checked

I traced through the core correctness claims by hand rather than just reading the summary:

  • hunkLines() in publish.cjs turns each hunk's "<old> <new>" header into line-number ranges without looking at +/-/context markers. I verified by hand (and against the new test) that this is mathematically equivalent to commentableLines() walking the actual patch body, since within one hunk the old-side line numbers are always exactly start..start+oldCount-1 and the new-side numbers start..start+newCount-1 — so the shortcut is sound, including the 0,0 (new/deleted file) and no-count (@@ -10 +11 @@) edge cases.
  • scopedFiles()/scopedLines() validate PR_FILES against HEAD_SHA and reject anything malformed/stale/oversized, falling back to a live listFiles/pulls.get read in publish.cjs and hold.cjs — confirmed this fallback path is exercised for every "unusable list" case the new test enumerates, and that a model step genuinely cannot have influenced pr-files since it's a scope-step output written before the model step runs, and GitHub Actions gives each step its own outputs file.
  • The reused merge-base for the full-diff compare (pr-review-cli.yml) is computed moments earlier in the same job run as before it's consumed, which is a tighter race window than the previous independent BASE_SHA...HEAD_SHA compare call issued fresh at that later step — not a regression.
  • status job wiring: PR_FILES is sourced from needs.review-key.outputs.pr-files in both the publish and hold steps, which is consistent with how marker-id/merge-base/last-summary are already leg-agnostic in this workflow (the review-subscription job also exposes pr-files for parity, per the "both model jobs... stay identical" note in the PR body, even though it's one of the known, disclosed, not-yet-fixed redundant-scope-step costs called out under "Related").

I was not able to execute node --test in this environment (sandboxed, no approval for node), so the "644 pass, 0 fail" and request-count table in the PR description are author-claimed and unverified by me — my analysis above is independent, from reading the code and the new test file's assertions, not a re-statement of the author's numbers.

No correctness, design, or maintainability issues met the bar for a finding.

claude-lane-summary: lane=claude-review sha=bf413a54191df72cbbcc4bb6e707c64134c4d354 run=39976842362

@github-actions

Copy link
Copy Markdown

claude-security-review has reviewed this pull request through bf413a5; a later push is reviewed from there.

@github-actions

Copy link
Copy Markdown

claude-review has reviewed this pull request through bf413a5; a later push is reviewed from there.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 6d6cb79 Oct 23, 2026
30 checks passed
@kyle-sexton
kyle-sexton deleted the perf/pr-review-cli-read-once branch October 23, 2026 15:26
kyle-sexton added a commit to melodic-software/standards that referenced this pull request Oct 23, 2026
…contract (#853)

No related issue: registers the pr-review-cli contract at ci-workflows
v0.64.2 so claude-code-plugins' review callers can repin to it.

## Summary

Registers `pr-review-cli.yml@6d6cb798e7cb7560a0f9327d8a22398961c23b31`
(ci-workflows
[v0.64.2](https://github.com/melodic-software/ci-workflows/releases/tag/v0.64.2)).

## Fix

v0.64.2 changes only how pr-review-cli's steps read the GitHub API
([ci-workflows#869](melodic-software/ci-workflows#869)):
the PR file list is read once instead of three times, and pulls.get
twice instead of three times. Inputs, secrets and routing are unchanged,
so the contract copies the v0.64.1 entry forward verbatim.

## Verification

- `node --test runner-policy.test.mjs` in `components/runner-policy`:
340 pass, including the new copy-forward test.

## Related

- Same shape as
[#851](#851)
(v0.64.1).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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