fix(client): harden HTTP retry and add 401-triggered token refresh#151
Draft
tim-thacker-nullify wants to merge 1 commit into
Draft
fix(client): harden HTTP retry and add 401-triggered token refresh#151tim-thacker-nullify wants to merge 1 commit into
tim-thacker-nullify wants to merge 1 commit into
Conversation
The HTTP plumbing the CLI (and long-running MCP server) depends on had two reliability gaps and no test coverage. retry.go: - Make retries method-aware. 5xx is now retried only for idempotent methods (GET/HEAD/PUT/DELETE/OPTIONS/TRACE); a POST/PATCH that may have committed server-side before erroring is no longer blindly replayed (was a duplicate-scan / duplicate-autofix hazard). 429 is still retried for any method since the server rejected it without processing. - Honor the server's Retry-After header (seconds or HTTP-date), capped at maxDelay, instead of only client-side exponential backoff. - Drain the response body before retrying so the connection can be reused. - Switch to math/rand/v2. refreshing_transport.go: - React to 401. The cached token can become invalid before its 5-minute TTL (revocation, server session kill, clock skew); previously every request kept sending the dead token for up to 5 minutes. Now a 401 forces a token refresh and retries the request once. The forced refresh is storm-safe: concurrent 401s collapse to a single refresh, and the request body is buffered so it replays correctly. Adds the first tests for internal/client: retry status/method gating, Retry-After parsing + cap, body replay, context cancellation, and the 401 refresh-and-retry / storm-safety / TTL paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Why
The HTTP plumbing the CLI and the long-running MCP server depend on had reliability gaps and zero test coverage.
What
retry.goPOST/PATCHthat may have committed server-side before erroring is no longer blindly replayed — previously a duplicate-scan / duplicate-autofix hazard.429is still retried for any method (the server rejected it without processing).Retry-After(seconds or HTTP-date), capped atmaxDelay, instead of only client-side exponential backoff.math/rand/v2.refreshing_transport.goTests — first coverage for
internal/client: retry status/method gating,Retry-Afterparsing + cap, body replay, context cancellation, and the 401 refresh-and-retry / storm-safety / TTL paths.Test plan
go build ./...✅,go vet ./...✅,go test ./...✅ (13 new tests ininternal/client).🤖 Generated with Claude Code