fix(scan github): surface GitHub rate limits instead of silent success#1426
Open
John-David Dalton (jdalton) wants to merge 1 commit into
Open
Conversation
`socket scan github` read every GitHub API response body and JSON-parsed it without checking the HTTP status. A rate-limited PAT (403 with x-ratelimit-remaining: 0, 429, or a secondary-limit body) was misread as "no default branch / no manifests", the per-repo error was swallowed by the scan loop, and the run exited 0 reporting "N repos / 0 manifests" — so users and CI believed the scan succeeded when nothing had been uploaded. - New utils/github-errors.mts: classify rate-limit / auth / abuse responses, plus a bounded-retry request wrapper that respects Retry-After / x-ratelimit-reset for short windows and retries 5xx / network with capped backoff. - Route the repo-details / tree / commit / contents calls through it. - Manifest download responses run through the same classifier so a token-wide block during download is surfaced instead of swallowed. - Scan loop stops on a blocking error and returns ok:false (non-zero exit); a run where every repo failed is no longer reported as success. Genuine empty repos still succeed. Refs ASK-167.
John-David Dalton (jdalton)
force-pushed
the
jdalton/ask-167-improve-cli-to-handle-github-api-rate-limiting-issues
branch
from
July 24, 2026 21:50
ba7c23e to
349fa46
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
socket scan github(the GitHub-API scanning path) read every GitHub REST response body and JSON-parsed it without ever checking the HTTP status. When the user's PAT is rate-limited, GitHub returns one of:403withx-ratelimit-remaining: 0(primary limit),429, or403with asecondary rate limitbody.The old code misread these as "repo has no default branch / no manifests", the per-repo error was swallowed by the scan loop, and the run exited 0 printing:
So users and CI believed the scan succeeded when nothing had been uploaded.
Fix
New
utils/github-errors.mts:classifyGitHubResponse— detects rate-limit / abuse-detection / auth responses and returns a clear, actionableCResulterror.githubApiRequest— bounded-retry wrapper aroundapiFetch: waits once on shortRetry-After/x-ratelimit-resetwindows (≤ 30s), surfaces long/hourly resets immediately, retries 5xx / network with capped exponential backoff, never retries auth.Wired in:
githubApiRequest; the raw manifest-download host is checked too.runGithubScanLoopstops on a blocking error (rate limit / auth / abuse) and returnsok:false→ non-zero exit, printing which condition hit and, when known, when it resets. A run where every repo failed is no longer reported as success. Genuine empty repos still succeed.Before / after
GitHub rate limit exceeded …Tests
src/utils/github-errors.test.mts+src/commands/scan/create-scan-from-github.test.mts— 25 tests, no network and no module mocks (injected fakefetch/scanRepoFn). Cover 403+remaining:0/ 429 / secondary-limit / 401 detection,Retry-After& reset parsing, cheap-retry-then-succeed, 5xx backoff, loop stop-on-blocking + non-zero exit, and empty repo still succeeds.tsgo,eslint, andbiomeare clean on the changed files.Note
mainalready carries an equivalent (Octokit-based) fix, so no companion PR is needed there. This ports the same behavior to the shippingv1.xline, adapted to its raw-apiFetcharchitecture.Refs ASK-167.
Note
Medium Risk
Changes CLI exit semantics and GitHub request handling for a CI-facing scan path; behavior is well covered by 25 unit tests with injected fakes.
Overview
Fixes ASK-167:
socket scan githubno longer exits successfully when GitHub rate limits, auth failures, or abuse detection block the run.Adds
utils/github-errors.mtswithclassifyGitHubResponse(rate limit / auth / abuse),githubApiRequest(bounded retries for short reset windows, 5xx, and network errors), and canonical blocking error messages. Repo details, tree, commit, and contents calls usegithubApiRequest; manifest download responses also run throughclassifyGitHubResponse.Extracts
runGithubScanLoopso multi-repo scans stop early on blocking GitHub errors, returnok: false(non-zero exit), and fail when every repo errors for non-blocking reasons instead of reporting "N repos / 0 manifests" as success. Empty repos and partial success behavior are unchanged.Reviewed by Cursor Bugbot for commit 30806f1. Configure here.