Skip to content

GitHub: cut the number of API requests per analyze (rate limit hit too often) #618

Description

@Exypte

Is your feature request related to a problem? Please describe.

One plumber analyze on a GitHub repository sends a lot of REST requests, and we hit the rate limit too often. Every request goes out one at a time through go-gh api.RESTClient. There is no GraphQL, no response cache, no conditional request (ETag), and nothing reads x-ratelimit-remaining or retry-after. On top of that, several resources are fetched more than once in the same run.

Most of the cost scales with the number of distinct action references (owner/repo@ref, direct and nested). Each one costs about 4–6 REST calls.

Every GitHub request in one analyze

Variables: R = distinct action repos, A = distinct owner/repo@ref refs (direct and nested), K = distinct action containers (owner/repo/subpath@ref), T = third-party containers, C = steps with a # vX.Y.Z comment, W = workflow files.

Action metadata (enrichActions, github/github_workflows.go:299). This runs unless all 10 consumer controls are benched in code. Disabling them in .plumber.yaml does not skip it.

# Request Where Used for How often
M1 GET repos/{o}/{r} github_metadata.go:901 archived, stars, full name (ISSUE-702, 713) per repo, cached
M2 GET repos/{o}/{r}/releases?per_page=50 (1–3 pages) github_metadata.go:944 latest semver release (ISSUE-709) per repo, cached
M3 GET repos/{o}/{r}/git/ref/tags/{latest} (+ git/tags/{sha} if annotated) github_metadata.go:317 SHA of the latest release per ref, resolveTag has no cache
M4 GET advisories?ecosystem=actions&affects={o}/{r} github_metadata.go:545 advisories (ISSUE-703) per repo, cached
M5 GET repos/{o}/{r}/tags?per_page=100 (up to 20 pages, retried anonymously on 403) github_metadata.go:776 SHA → version for advisory ranges per SHA-pinned repo with advisories
M6 GET repos/{o}/{r}/git/ref/tags/{ref} (+ git/tags/{sha}) github_metadata.go:328 is the ref a tag (ISSUE-701, 402, 401) per ref
M7 GET repos/{o}/{r}/branches/{ref} github_metadata.go:1152 is the ref a branch, ambiguity (ISSUE-402) per ref
M8 GET repos/{o}/{r}/releases/tags/{ref} github_metadata.go:1198 immutable release (ISSUE-701) per tag ref
M9 GET repos/{o}/{r}/commits/{ref} github_metadata.go:1168 commit exists (ISSUE-707) per SHA pin
M10 GET repos/{o}/{r}/git/tags/{sha} (up to 4) + M9 github_metadata.go:1099, 1123 SHA pin that names a tag object (ISSUE-401) only when M9 answers 404/422
M11 GET repos/{o}/{r}/git/ref/tags/{commentVersion} (+ git/tags) github_workflows.go:360 pin comment matches SHA per step occurrence, no cache

When ref equals the latest release tag, M3 and M6 fetch the same URL twice in a row.

Action and workflow definitions (resolveNestedActions, github/nested_actions.go:993). These always run.

# Request Where How often
D1 raw action.yml, then action.yaml nested_actions.go:268 per container K
D2 raw reusable workflow file from another repo nested_workflows.go:88 per distinct workflow
— GET repos/{o}/{r}/contents/{path}?ref= fallback nested_actions.go:207 (readWith) after every raw miss, including a plain 404

ISSUE-714 mutable remote exec (github/action_source.go:1046), when the control is enabled. For each third-party container it reads the main entrypoint, then every candidate (action.js, index.js, dist/index.js, src/index.js) without stopping at the first hit (action_source.go:976). Each missing candidate costs one raw 404 and one Contents API 404. A typical dist/index.js action costs 3 raw + 3 REST 404s.

Scanned repo (once per analyze, control/task_github.go:508, :664)

# Request Where Note
R1 GET repos/{o}/{r} github_branch_protection.go:380 default branch
R2 GET repos/{o}/{r} github_branch_protection.go:411 visibility, full name: same call as R1
R3 GET repos/{o}/{r} github_branch_protection.go:443 third copy, when zero branches come back
R4 GET repos/{o}/{r}/environments?per_page=30 (paged) github_environments.go:77 per_page could be 100
R5 GET repos/{o}/{r}/actions/workflows?per_page=100 (paged) github_workflow_states.go:57
R6–R9 actions/runs, runs/{id}/jobs (×3), jobs/{id}/logs, releases?per_page=20 github_token_default.go:307-492 default GITHUB_TOKEN permissions
B1 GET repos/{o}/{r}/branches/{name} github_branch_protection.go:263 default config: main, master, production, dev and the default branch
B2 GET repos/{o}/{r}/branches/{name}/protection github_branch_protection.go:548 per protected branch
B3 GET repos/{o}/{r}/rules/branches/{name} (paged) github_branch_protection.go:468 per protected branch
B4 GET repos/{o}/{r}/branches?per_page=100 (paged) github_branch_protection.go:529 when a pattern is a glob (release/* by default)

Every lane function builds a new REST client (newGitHubRESTClient, github_workflows_remote.go:165).

Remote mode only (--project): one Contents listing of .github/workflows, one Contents call per workflow file (W), and Contents calls for local ./ composites. A 404 on the listing adds another GET repos/{o}/{r} and commits/{ref}.

Rough total for a SHA-pinned repo with no advisories: about 3R + 4–5A + C REST calls for metadata, plus about 10 for the scanned repo and branch protection, plus one REST call for every raw miss. ISSUE-714 adds about 3–4T REST calls.

Describe the solution you'd like

Get the same information with fewer requests, in line with GitHub's REST best practices:

  1. Fetch the scanned repo once. R1, R2 and R3 (and W2 in remote mode) should share one GET repos/{o}/{r}, and one REST client per run.
  2. Cache resolveTag per owner/repo@tag. That removes the per-ref M3, the M3/M6 double fetch, and the per-occurrence M11.
  3. Batch the per-ref probes in GraphQL. M1, M2/M3 and M6–M10 are single-object lookups (repo fields, tag ref, branch ref, commit by SHA, release by tag). One GraphQL query with aliases can answer them for many refs at once (repository { isArchived stargazerCount nameWithOwner }, ref(qualifiedName: "refs/tags/…"), ref(qualifiedName: "refs/heads/…"), object(oid: …), release(tagName: …)). GraphQL also has its own budget, separate from REST. We need to check field by field that GraphQL exposes what each control needs (for example the immutable-release flag); anything it doesn't expose stays on REST.
  4. Stop the Contents API fallback after a definitive raw 404. Today every raw miss costs one more REST call. For ISSUE-714, stop at the first entrypoint candidate found, or list the action directory once instead of probing each candidate.
  5. Use conditional requests (best practice). A 304 doesn't count against the primary rate limit. go-gh can cache responses (EnableCache/CacheTTL in api.ClientOptions), and we never turn it on. Tag refs, releases and action files at a SHA rarely change between runs.
  6. Handle rate limits (best practice): honor retry-after and x-ratelimit-reset, stop sending requests when the limit is reached, and report the checks we skipped as degraded instead of failing silently. Log the remaining quota at the end of a run (debug) so we can measure the gain.
  7. Small ones: per_page=100 for environments (R4).

Implementation Hints

  • Metadata client and per-ref probes: github/github_metadata.go (resolveUncached, resolveTag, branchExists, commitResolves, releaseIsImmutable).
  • Comment tags: github/github_workflows.go:356-362.
  • Raw/Contents fallback: github/nested_actions.go (readWith), github/action_source.go (resolveMutableExec).
  • Scanned repo lanes: github/github_branch_protection.go, github/github_workflows_remote.go (newGitHubRESTClient).

Why It's Valuable

Analyzes that hit the rate limit lose controls, or fail, on repositories with many actions. Fewer requests per analyze also leave room for users who run Plumber in several workflows with the same token.

Activity

  1. added theissue type on Nov 17, 2026
  2. self-assigned this
    on Nov 18, 2026
  3. Exypte commented on Nov 18, 2026

    @Exypte
    ContributorAuthor

    I'm working on this one, a PR is on the way.

  4. Totara-thib commented on Nov 19, 2026

    @Totara-thib
    Contributor

    One case that #619 does not change: when the repository's token quota is already spent by other runs, the first API call fails with HTTP 403: API rate limit exceeded and the action ends red with exit 2 ("usage, configuration, or runtime error"), with no finding produced. The attestation check in the install step spends the same quota. Could an exhausted quota end neutral instead (a warning annotation and a skipped score push), keeping exit 2 for real configuration errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions