Skip to content

perf(check-key-credit): read the credit stop from one artifact marker - #973

Merged
kyle-sexton merged 2 commits into
mainfrom
perf/key-credit-stop-marker
Nov 3, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
perf/key-credit-stop-marker

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: hub volume cut #2. The key-credit gate read run history on every run: 2-4 GITHUB_TOKEN calls (1 runs list + up to 3 job lists), ~152 calls/h across the claude-code-plugins review lanes. The API-key leg actually ran on only a few of those runs.

Summary

The gate now reads the credit stop from one exact-name artifact marker: GET /repos/{repo}/actions/artifacts?name=<marker>&per_page=100. That is 1 call on every path. A credit-stopped key leg uploads the marker; the gate skips the key while the newest unexpired marker is inside the window.

Fix

  • .github/actions/check-key-credit/gate.cjs:
    • markerName(workflow, keyJob) builds key-credit-stop-<caller-workflow-file>-<key-job>, so each caller is judged only on its own stops, as before.
    • judgeMarkers takes the newest created_at with expired == false inside the window. It does not rely on response order, since the docs state none. A skip cites workflow_run.id, and every read failure runs the key, as before.
    • The run/job scan (RECORD_PATTERN, MODEL_STEP, MAX_JOB_READS, judgeRun) is removed, along with the starved-scan case (newest runs that carry no record).
  • action.yml: new marker output.
  • .github/workflows/pr-review-cli.yml:
    • The gate job drops its carry step and exposes marker.
    • The key job, after lane-class == 'credit-stop', writes a one-line file, scans it with scan-upload, and uploads it with retention-days: 1 (all continue-on-error).
    • The subscription and fallback legs' record steps, which no gate read, are deleted.
    • All three legs' timeouts rise by 2 min, because the existing ceiling test was at its limit and the parity tests require one shared limit.
  • README entry updated.

name filter, from List artifacts for a repository: "When specified, only artifacts with this name will be returned." Anyone with read access may call it, so actions: read is enough. No new permission, token, secret or cache use.

Verification

  • check-key-credit.test.cjs:
    • a marker inside the window skips with exactly 1 call and no /runs or /jobs URL;
    • one 6.02 h old runs the key (a topped-up key comes back within one window), and one at the edge still skips;
    • no marker runs the key;
    • the newest marker by created_at wins in any order, and expired, misnamed or malformed markers are ignored;
    • every read failure fails open;
    • the decision reads no run history.
  • pr-review-cli.test.cjs: only the key job uploads, only after a credit stop, never with an empty name, scanned first, with 1-day retention; the gate job has no carry step.
  • node --test .github/scripts/*.test.cjs: 881 pass. npx @biomejs/biome@2.5.11 ci --error-on-warnings on .github/scripts and .github/actions/check-key-credit: clean.

Related

  • Expected: ~152/h → ~59/h on the claude-code-plugins review lanes (2 calls each measured in runs 41599490946 and 41599490925).
  • A follow-up in claude-code-plugins after this merges: repin pr-verify.yml and pr-review-main.yml, replace their record steps with the marker upload and delete their carry steps. Then gate check-intent-credit and review-handoffs-credit after their no-op exits, which this change makes safe (~100-155/h more).
  • Accepted exposure, unchanged in kind: any workflow in a caller repository can plant a marker, which means subscription reviews for one window (gate header).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcupojVgxFqBnrah9DwFLE

No related issue: hub volume cut #2; the gate read run history on every run (2-4 calls, ~152/h on the review lanes)

The gate listed the caller workflow's completed runs, then read up to three
of their job lists to find a record step, so every run paid 2-4 calls and a
run that carried no record (a no-op) could push the stop out of the scan.

Now the key job uploads an artifact named for the caller workflow and key
job (gate.cjs markerName) after the launcher's credit-stop, after a
credential scan like every other upload, kept one day. The gate makes one
call, the repository's artifacts of that exact name, and skips the key while
the newest unexpired marker is inside the window, citing the run that
uploaded it. The window counts from that upload, so a topped-up key is tried
on the first run after it. Any failure runs the key, as before.

- gate.cjs: one artifacts?name= read replaces the run and job scan; outputs
  the marker name.
- pr-review-cli.yml: the gate job drops its carry step and hands the marker
  name on; the key job writes, scans and uploads the marker; the
  subscription and fallback jobs' record steps, which no gate read, go. The
  three legs' job limits rise by 2 minutes for the two added steps.
- Tests: a marker in the window skips with one call and no run or job read;
  an older one runs the key (the topped-up case); no, expired, misnamed or
  malformed markers run the key; runs without a record cannot starve the
  decision; every read failure fails open; the key job alone uploads the
  marker, only after a credit stop, kept one day.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VcupojVgxFqBnrah9DwFLE
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 3, 2026 09:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-03T09:09:35.217288Z a9c489c 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 3, 2026 •

Copy link
Copy Markdown

claude-review reviewed 9d976615f62349f04c957ac78396cbad4fe6f943: 0 finding(s), 0 as inline comments.

Incremental review of 9d97661 (since a9c489c): no findings.

The change makes judgeMarkers count an artifact only when workflow_run.repository_id and workflow_run.head_repository_id are both safe integers and equal. A fork's pull_request run can upload an artifact of any name, so this stops a fork from forging a credit-stop marker.

  • Gate logic (gate.cjs): the new condition guards the artifact.workflow_run.head_repository_id access, because a safe-integer repo already implies workflow_run exists. A missing, null or string id is ignored, so the gate fails open to running the key, as the earlier read failures do. The "newest marker" selection runs only after the filter, so a newer fork marker cannot hide an older same-repository one.
  • Tests (check-key-credit.test.cjs): the marker() helper now carries matching ids, so the existing cases still describe same-repository markers. The new test covers a fork head, a same-repository head, missing or malformed ids, and a fork marker newer than a genuine one. The main test adds a fork-only listing that must run the key with one call. I read the assertions but did not run the tests: the sandbox denied node --test.
  • Workflow comment (pr-review-cli.yml): the header comment now says the gate counts only a marker from a run headed in this repository. That matches the code.

The PR names no closing issue; its body says "No related issue", so there are no acceptance criteria to check. The README's entry on the marker (around line 782) is outside this increment.

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

claude-security-review reviewed 9d976615f62349f04c957ac78396cbad4fe6f943: 0 finding(s), 0 as inline comments.

Incremental security review of 9d97661 against a9c489c (gate.cjs, check-key-credit.test.cjs, pr-review-cli.yml comment). I found no security issues.

What changed: judgeMarkers in .github/actions/check-key-credit/gate.cjs now counts a credit-stop marker only when workflow_run.repository_id is a safe integer and equals workflow_run.head_repository_id.

Trust-control check: This narrows the gate, so it widens nothing. Before this change, a fork's pull_request run could upload an artifact named like the marker and push reviews onto the subscription for the window. After it, a fork-headed marker is ignored. Both ids are set by GitHub, not by the artifact's author. A missing, null or string id fails closed to "run the key", as the new tests cover. A same-repository run can still forge a marker, but that needs repository write access, and the code comment says so. The worst outcome there is reviews moving to the subscription, which is not a leak, a compromise or a charge.

Other files: The test changes only exercise the new check. The pr-review-cli.yml change is a comment.

manifest fields: not touched.
critical-findings: 0

@kyle-sexton
kyle-sexton enabled auto-merge November 3, 2026 09:09
A fork's pull_request run holds no secret, but it can upload an artifact of
any name from a modified caller workflow; the head-repository guard covers
only the reusable workflow's own jobs. A marker named
key-credit-stop-<caller>-<key-job> from such a run made every later run skip
the key leg for the window and spend subscription quota. The run-history
read excluded pull request runs; the marker read now does the same by
origin.

judgeMarkers counts a marker only when its workflow_run carries integer
repository_id and head_repository_id and they are equal, so only a run whose
head is this repository can start the window. The gate's and the workflow's
security comments now say so; the old comment claimed every forger already
held the secrets, which is false for a fork.

Tests: a fork marker inside the window is ignored and the key runs (in
judgeMarkers and in main); a same-repository marker still skips; a marker
missing either id, or with null or string ids, is ignored; a newer fork
marker does not hide an older same-repository one. Against the previous
gate.cjs the two new assertions fail.

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