[CXP-204] improve rate limit and temporary error handling#121
Open
johnallers wants to merge 1 commit intomainfrom
Open
[CXP-204] improve rate limit and temporary error handling#121johnallers wants to merge 1 commit intomainfrom
johnallers wants to merge 1 commit intomainfrom
Conversation
WalkthroughAdds rate-limit detection and wrapping utilities to connector helpers: functions to derive rate-limit details from GitHub errors and Retry-After, expanded wrapGitHubError to attach RateLimitDescription to gRPC errors, and a helper to classify temporary service-unavailable responses (502/503/504). Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Connector
participant GitHubAPI
participant gRPCStatus
Client->>Connector: API request
Connector->>GitHubAPI: Call GitHub
alt RateLimitError
GitHubAPI-->>Connector: RateLimitError (with Rate)
Connector->>Connector: rateLimitDescriptionFromRate()
Connector->>gRPCStatus: attach RateLimitDescription
gRPCStatus-->>Connector: gRPC error with details
Connector-->>Client: gRPC rate-limited error
else AbuseRateLimitError
GitHubAPI-->>Connector: AbuseRateLimitError (with Retry-After)
Connector->>Connector: rateLimitDescriptionFromRetryAfter()
Connector->>gRPCStatus: attach RateLimitDescription
gRPCStatus-->>Connector: gRPC error with details
Connector-->>Client: gRPC rate-limited error
else TemporaryServerError (502/503/504)
GitHubAPI-->>Connector: 502/503/504
Connector->>Connector: isTemporarilyUnavailable()
Connector-->>Client: treated as unavailable error
else OtherError
GitHubAPI-->>Connector: Other error
Connector->>Connector: existing auth/permission checks
Connector-->>Client: wrapped error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
When go-github blocks requests client-side due to rate limits, it returns a RateLimitError with a synthetic 403 response that has empty headers. The existing isRatelimited() check failed because it expects the X-Ratelimit-Remaining header to equal "0", but the synthetic response has no headers at all. This caused rate limit errors to be misclassified as PermissionDenied, which is not retried by the SDK. Changes: - Check for *github.RateLimitError and *github.AbuseRateLimitError types using errors.As() before checking HTTP status codes - Extract rate limit data (reset time, limit, remaining) from the error and attach it to the gRPC status details for proper backoff - Add isTemporarilyUnavailable() to handle 503, 502, and 504 errors - Return codes.Unavailable for all these cases, enabling SDK retry logic Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
7896b65 to
1498c3e
Compare
luisina-santos
approved these changes
Feb 4, 2026
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.
Summary
PermissionDeniedinstead ofUnavailable, causing syncs to fail instead of retry*github.RateLimitErrorand*github.AbuseRateLimitErrorerror types usingerrors.As()Unavailable(retryable)Problem
When go-github blocks requests client-side due to rate limits, it returns a
RateLimitErrorwith a synthetic 403 response that has empty headers. The existingisRatelimited()check failed because it expectsX-Ratelimit-Remainingheader to equal"0", but the synthetic response has no headers. This caused rate limit errors to be misclassified asPermissionDenied, which is not retried by the SDK.Solution
Check for go-github error types before checking HTTP status codes:
*github.RateLimitError→ extractRate.Reset,Rate.Limit,Rate.Remaining→codes.Unavailablewith rate limit details*github.AbuseRateLimitError→ useRetryAfterduration →codes.Unavailablewith rate limit detailscodes.Unavailable(retryable)The SDK's retry logic now receives proper rate limit data to calculate appropriate backoff times.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit