refactor(proxy): return remaining header from rateLimitSignal to eliminate duplicate read#9053
Merged
Merged
Conversation
4 tasks
…oxy handler Update rateLimitSignal to return remaining as a third return value, and update injectRetryAfterIfRateLimited to use it directly instead of re-reading the header. Update all callers and tests accordingly.
Copilot
AI
changed the title
[WIP] Fix duplicate reading of X-Ratelimit-Remaining header in proxy handler
refactor(proxy): return remaining header from rateLimitSignal to eliminate duplicate read
Jul 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the proxy rate-limit detection path to avoid reading X-Ratelimit-Remaining twice by returning the parsed “remaining” value from rateLimitSignal and reusing it in injectRetryAfterIfRateLimited. This reduces duplication and keeps the rate-limit header handling consistent within the call chain.
Changes:
- Extended
rateLimitSignalto return(isRateLimited, resetHeader, remaining)and updated call sites accordingly. - Removed redundant
resp.Header.Get("X-Ratelimit-Remaining")ininjectRetryAfterIfRateLimitedand reused the returnedremaining. - Updated unit tests to assert the new
remainingreturn value across allTestRateLimitSignalsubtests.
Show a summary per file
| File | Description |
|---|---|
| internal/proxy/handler.go | Updates rateLimitSignal signature and eliminates the duplicate header read in injectRetryAfterIfRateLimited; updates tracing call site to ignore the new return value. |
| internal/proxy/rate_limit_test.go | Updates tests to capture and assert the new remaining return value from rateLimitSignal. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Low
6 tasks
This was referenced Jul 10, 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.
X-Ratelimit-Remainingwas read twice in the same call chain: once insiderateLimitSignaland again in its callerinjectRetryAfterIfRateLimited. This creates a latent inconsistency risk if the header name is ever changed in one place but not the other.Changes
rateLimitSignal: Extended return signature from(bool, string)to(bool, string, string)— now returns(isRateLimited, resetHeader, remaining)injectRetryAfterIfRateLimited: Removed redundantresp.Header.Get("X-Ratelimit-Remaining")call; usesremainingfromrateLimitSignaldirectly_remainingreturn value in all threeTestRateLimitSignalsubtests