Skip to content

perf(github): read action metadata through batched GraphQL queries - #639

Closed
Exypte wants to merge 3 commits into
mainfrom
feature/637-github-graphql-analyze
Closed

Exypte wants to merge 3 commits into
mainfrom
feature/637-github-graphql-analyze

Conversation

@Exypte

@Exypte Exypte commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

perf

What this PR does / why we need it:

Step 1 of #637. Action enrichment sent several REST requests per action reference, so the cost of an analyze grew with every uses: line. On github.com these reads (repository info, releases and the immutable flag, tag and branch lookups, commit checks, advisories, tag listings) now go through aliased GraphQL queries, ten repositories per query. The results fill the caches Resolve already reads, so findings and degraded messages don't change.

Measured on the 11 repositories of the #619 corpus, against a build of #619:

#619 this PR
Requests 2458 939
Rate-limit quota used 2092 573
REST core requests 2072 487 (−77%)
GraphQL queries (points) 86 (86)
Total time 1100 s 367 s

Findings, score and exit code are the same on all 11. The JSON reports match apart from one warning on vercel/next.js, where the cause text for vercel/gh-sts-action is worded differently.

Which issue(s) this PR is related to:

Refs #637 (steps 2 and 3 follow in their own PRs)

This branch builds on #619 and contains a local merge of it. It stays a draft until #619 is merged, then gets rebased on main.

Special notes for your reviewer:

  • Errors per alias: a null or failed alias means the repository is missing or unreadable, as a 404 did before. A query that fails as a whole marks every repository in it as could-not-verify. A 5xx or a timeout splits the chunk in half and retries, down to one repository; the first corpus run hit a 502 on an 11 s query with bigger chunks.
  • The tag listing is loaded only for repositories that have a SHA pin and advisories. The latest release's commit comes from its tag in a second batched load.
  • GHES keeps advisories and the immutable flag on REST. The anonymous fallback for tag listings is removed.
  • Definition reads (action.yml) still go to raw.githubusercontent.com first. The contents-API fallback isn't batched: it sent 6 requests across the whole corpus.
  • New code is in github/metadata_graphql.go (queries) and github/metadata_facts.go (prefetch and the cached facts the checks read).

Does this PR introduce a user-facing change?

Analyzing a GitHub repository sends far fewer REST requests: action metadata is read through batched GraphQL queries. The --debug report has a new "GraphQL queries" section with the cost of each query. Findings and scores are unchanged.

How was this tested?

  • Unit tests: github/metadata_graphql_test.go and github/metadata_facts_test.go (query shape, values sent as variables, decoding, missing and failed aliases, chunk splitting, release paging, GHES path, tag paging, cost recording, prefetch grouping), the REST-based tests ported in github/, and the new GraphQL section in internal/httpcount.
  • make build, make test, and golangci-lint on ./github/... and ./internal/httpcount/... pass. The full make lint reports 7 govet findings in configuration/schema.go and control/catalog.go and a deadcode finding (ConfigSchemas) that are already on main.
  • plumber analyze --debug on the 11 corpus repositories with this branch and with feat(github): send fewer GitHub requests per analyze #619, comparing the JSON reports, exit codes and request reports (table above).

AI usage disclosure:

YES. Claude Code wrote the code and tests under my direction, ran the corpus comparison and drafted this description. I reviewed the changes.

🤖 Generated with Claude Code

Exypte and others added 3 commits November 24, 2026 14:39
An analyze of a large GitHub repository can hit the rate limit (#618).

Count every request and write a --debug report. internal/httpcount counts
each request per host and per rate-limit quota. `analyze --debug[=file]`
(env PLUMBER_ANALYZE_DEBUG) writes a markdown report of every request and
of the rate limit before and after the run. Query strings outside the
GitHub API are redacted, so a signed job-log URL never reaches the report.

Answer repeated GETs from memory (httpcount.MemoTransport). Only 2xx and
404 answers are kept, keyed on the URL and every header. Identical
concurrent requests are sent once. Bodies are capped at 1 MB each and
32 MB in total. Only the GitHub API and raw-content clients use it. The
OIDC token, --score-push, the update check, the job logs and the GraphQL
client stay on the counting-only DefaultTransport, so a minted token, a
signed URL or a GraphQL existence answer is never replayed.

Trust a raw 404 only when it was sent with a token, at a commit SHA, in a
repository where the contents API already accepted that token. SAML SSO
or an IP allow list can refuse a valid token for one organization: the
raw host answers 404, the API 403, and the read stays could-not-verify.
On a branch or a tag, the raw CDN keeps a 404 for about a minute, so
those reads always ask the API.

Ask GitHub once which entrypoint guesses exist. One GraphQL query per 25
actions checks action.js, index.js, dist/index.js and src/index.js, and
a null answer is read as missing without a request. With no token, or
offline, no query is sent.

Drop a branch that GitHub redirects to another name before reading its
protection, which could only 404.

Against v0.7.23 with GH_TOKEN exported, on 11 public repositories pinned
to a tag, the JSON reports, exit codes and scores are identical.

Refs #618

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uests' into feature/637-github-graphql-analyze
Action enrichment used to send several REST requests per action
reference: repository info, releases, tag and branch lookups, commit
checks, the immutable release flag, advisories and the tag listing.
On github.com these reads now go out as aliased GraphQL queries, ten
repositories per query, and fill the caches that Resolve already reads,
so findings and degraded messages stay the same.

A null or failed alias means the repository is missing or unreadable,
as a 404 did before. A query that fails as a whole marks every
repository in it as could-not-verify. A 5xx or a timeout splits the
chunk in half and retries, down to one repository. The tag listing is
loaded only for repositories with a SHA pin and known advisories.

GHES keeps advisories and the immutable flag on REST. The anonymous
fallback for tag listings is gone. The --debug report gains a GraphQL
section with the cost of each query.

Refs #637

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.

GitHub: analyze through the GraphQL API to cut requests and run time

1 participant