feat: typed rate-limit errors carrying the server's Retry-After hint - #118
Open
vegardx wants to merge 1 commit into
Open
feat: typed rate-limit errors carrying the server's Retry-After hint#118vegardx wants to merge 1 commit into
vegardx wants to merge 1 commit into
Conversation
vegardx
force-pushed
the
feat/rate-limit-error
branch
from
July 21, 2026 10:00
d7ea105 to
ed6baa8
Compare
Rate-limited responses previously surfaced as unwrapped generic errors, so callers could not distinguish rate limiting from other failures without string-matching status text. Wrap them like the other status sentinels: errors.Is(err, RateLimitedError) matches the condition, and errors.As against *RateLimitError reads the server's requested delay. Classification covers how GitHub actually signals rate limiting: 429 always; 403 when it carries Retry-After (secondary limits) or X-RateLimit-Remaining: 0 (a spent primary limit), with unrelated 403s untouched. The delay hint prefers Retry-After (delay-seconds or HTTP-date per RFC 9110, with overflow and negative guards) and falls back to X-RateLimit-Reset when the primary limit is spent. The retryable client's default error handler discards the final response once retries are exhausted, which made status classification unreachable on exactly the rate-limited path (429 is retried internally). The client now installs PassthroughErrorHandler centrally in newRetryableHTTPClient, replacing the single hand-rolled copy in getActionsServiceAdminConnectionRequest, so the last response flows into the normal status-code error path.
vegardx
force-pushed
the
feat/rate-limit-error
branch
from
July 22, 2026 18:22
ed6baa8 to
c67c39d
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.
What
Rate-limited responses currently surface as unwrapped generic errors, so callers cannot distinguish rate limiting from other failures without string-matching status text — and the server's requested delay is lost entirely (the
Retry-Afterheader is not part of the error message). This wraps them like the existing status sentinels (BadRequestError,UnauthorizedError,NotFoundError,ConflictError):Callers building autoscalers or control planes on this SDK need this signal to back off adaptively, emit throttling metrics, and honor the delay GitHub's API guidelines ask integrators to respect. It follows the sentinel pattern the client already uses for 400/401/404/409 — one more case in the existing switch, plus the delay hint.
Classification
Covers how GitHub actually signals rate limiting:
429— always.403withRetry-After(secondary rate limits) or withX-RateLimit-Remaining: 0(a spent primary limit). Unrelated 403s are untouched.The delay hint prefers
Retry-After(both RFC 9110 forms — delay-seconds and HTTP-date — with overflow and negative guards) and falls back toX-RateLimit-Resetwhen the primary limit is spent.Bug fix this depends on
go-retryablehttpretries 429s internally, and its defaultErrorHandlerdiscards the final response once retries are exhausted — so the status classification innewRequestResponseErrorwas unreachable on exactly the rate-limited path (the caller got a baregiving up after N attempt(s)error with no response attached). This PR installsretryablehttp.PassthroughErrorHandlercentrally innewRetryableHTTPClient(only when no custom handler is set), replacing the single hand-rolled copy ingetActionsServiceAdminConnectionRequest. After exhausted retries the final response now flows through the normal status-code error path, so these errors also gain the request/activity-ID context that path adds.Testing
retryAfterHinttests against a fixed clock: both RFC 9110 forms, theX-RateLimit-Resetfallback, precedence, past dates, negative/invalid/overflowing values.We carry this in our fork, where the consumer uses it to distinguish rate-limit push-back from ordinary failures in an adaptive mint-concurrency limiter.
Note on the base
This branch is stacked on #116 (
fix/testdata-cert-expiry) so its test suite runs green —maincurrently failsTestServerWithSelfSignedCertificateson the expired committed testdata certificates that #116 replaces with runtime-generated ones. The rate-limit change itself is the single top commit; the diff collapses to it once #116 merges.