fix: handle Ask GitHub rate limits - #1476
Open
brendan-kellam wants to merge 2 commits into
Open
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
WalkthroughAuthenticated GitHub repository lookups now classify rate-limit failures, return HTTP 429, propagate a dedicated web error code, and render a retryable busy state in the Ask GitHub page. ChangesGitHub rate-limit flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AskGithubPage
participant addGithubRepo
participant experimental_addGithubRepo
participant GitHub
AskGithubPage->>addGithubRepo: add repository
addGithubRepo->>experimental_addGithubRepo: repository lookup request
experimental_addGithubRepo->>GitHub: authenticated API request
GitHub-->>experimental_addGithubRepo: rate-limit failure
experimental_addGithubRepo-->>addGithubRepo: HTTP 429
addGithubRepo-->>AskGithubPage: GITHUB_RATE_LIMITED
AskGithubPage->>AskGithubPage: render busy state
AskGithubPage->>AskGithubPage: refresh on retry
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/backend/src/api.ts`:
- Around line 159-161: Protect the /api/experimental/add-github-repo endpoint
with mandatory authentication before constructing the Octokit client or
performing any GitHub lookup. Replace the optional-auth behavior with the
backend’s required-auth guard and reject unauthenticated requests; preserve the
existing authenticated repository persistence and indexing flow.
In `@packages/backend/src/errors.ts`:
- Around line 43-48: The rate-limit classifier must inspect wrapped errors
consistently with getStatus. Update the logic around the responseHeaders and
message extraction to read metadata from cause.response and the wrapped error
message as well as the top-level fields, preserving existing top-level handling;
add a regression test covering a wrapped GitHub 403 with rate-limit metadata and
verifying it is classified as HTTP 429.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5201e88a-275b-4c9e-9367-1697a360b466
📒 Files selected for processing (10)
CHANGELOG.mdpackages/backend/src/api.tspackages/backend/src/errors.test.tspackages/backend/src/errors.tspackages/web/src/app/(app)/askgh/[owner]/[repo]/components/githubRateLimitExceeded.test.tsxpackages/web/src/app/(app)/askgh/[owner]/[repo]/components/githubRateLimitExceeded.tsxpackages/web/src/app/(app)/askgh/[owner]/[repo]/page.tsxpackages/web/src/features/workerApi/actions.tspackages/web/src/lib/errorCodes.tspackages/web/src/lib/serviceError.ts
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.
Fixes SOU-1546
Fixes SOU-1547
Summary
Test plan
Note
Low Risk
Changes are scoped to Ask GitHub repo onboarding and error handling; token use is via an existing env var and rate-limit detection is covered by unit tests.
Overview
Ask GitHub now uses
EXPERIMENT_ASK_GH_GITHUB_TOKENfor experimental add-repo GitHub API calls instead of unauthenticated Octokit requests.When GitHub returns primary or secondary rate limits, the backend maps them via
isGitHubRateLimitError(429, or 403 with rate-limit headers/message) to HTTP 429 instead of a generic failure. The web layer surfacesGITHUB_RATE_LIMITEDand the Ask GitHub page shows a recoverable “GitHub is temporarily busy” state with Try again (router.refresh()).Reviewed by Cursor Bugbot for commit 6dd4ad0. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit