Repository navigation
fix(client): harden HTTP retry and add 401-triggered token refresh - #151
Merged
Merged
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>
Member
Author
|
Status check (2026-05-28): still relevant. Current
PR #157 (default retry transport + structured errors, merged 2026-05-26) introduced the default transport plumbing but did not touch these behaviors — orthogonal. Recommend rebase + un-draft. |
staticcheck SA1012: do not pass a nil Context. The TTL-expiry test calls `tr.getToken(...)` and discards the context internally (the refresh path doesn't need it), but passing nil trips the lint check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tim-thacker-nullify
marked this pull request as ready for review
May 29, 2026 13:43
scrut-nick
pushed a commit
to scrut-nick/nullify-cli
that referenced
this pull request
Aug 28, 2026
Our transport had no 401 handling at all. It refreshed on a five-minute TTL and, when the provider failed, fell back to the stale cached token - so against a credential revoked mid-life every single request failed, forever, with no attempt to fetch a replacement. That is the shape of the outage we just spent a week diagnosing. This ports the behaviour of upstream Nullify-Platform#165 onto our simpler transport rather than adopting the file wholesale, because this fork branched at Nullify-Platform#138 and the upstream version depends on Nullify-Platform#151/Nullify-Platform#158 that we do not carry. - refreshProvider is a second, distinct provider used only after a 401. tokenProvider returns the stored token untouched while it still looks valid, so reusing it for the retry would replay the rejected string - the exact bug Nullify-Platform#165 was written to fix. - auth.ForceRefreshToken refreshes regardless of the recorded expiry, and reports ErrNotRefreshable when the credentials carry no refresh token. - lib.RefreshNullifyToken reports client.ErrTokenNotRefreshable for sources that yield a fixed string (--nullify-token, NULLIFY_TOKEN), so the transport surfaces the 401 instead of retrying something that cannot change. - Separate backoff clocks for the TTL and 401 paths: one provider failing says nothing about the other, and without them a rejected credential puts a blocking refresh in front of every request. - A refresh that returns nothing, or returns the token just rejected, leaves the cache alone rather than overwriting a working value with junk. - Request bodies are buffered so a retried POST carries its payload. Tested: retry-and-succeed, fixed-source surfaces the 401, same-token and empty returns do not loop or clobber the cache, body replay, backoff suppression, concurrent rotation, non-401 passthrough, and provider-failure backoff. Upstream's own note on Nullify-Platform#165 was that this code went broken from February to August precisely because it had no tests. CLAUDE.md records what remains unported, including Nullify-Platform#159 - the GitHub PAT is still sent in a URL query string. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mcq6LfAVPzKZL5rpvww13R
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