Propagate auth errors through stale cache fallback#4981
Merged
Conversation
refreshCache() was returning stale cached data for any API error, including auth failures (401/403 from registry and OAuth flow timeouts). Users saw previously-cached registry content with no error after their credentials expired or the OAuth browser flow timed out. Fix in two parts: - auth.Transport.RoundTrip now wraps all Token() errors with ErrRegistryAuthRequired, classifying token-acquisition failures as auth errors regardless of the underlying cause. - refreshCache() checks for ErrRegistryAuthRequired/ErrRegistryUnauthorized before the stale-cache fallback; transient errors (network, 5xx) still degrade gracefully. Fixes #4950 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
blkt
approved these changes
Apr 21, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4981 +/- ##
==========================================
+ Coverage 69.43% 69.62% +0.18%
==========================================
Files 539 552 +13
Lines 55760 55951 +191
==========================================
+ Hits 38716 38954 +238
+ Misses 14069 13996 -73
- Partials 2975 3001 +26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
CachedAPIRegistryProvider.refreshCache()treated every API error as a signal to fall back to stale cached data — including auth failures. Users saw previously-cached registry contents with no error after their token was revoked (401/403) or after the OAuth browser flow timed out, masking the actual failure entirely (thv registry list serves stale cache when OAuth flow fails, masking auth failure #4950).auth.Transport.RoundTripnow wraps allToken()failures withErrRegistryAuthRequired, classifying any token-acquisition failure as an auth error before it can be flattened into anUnavailableError.refreshCache()checks forErrRegistryAuthRequired/ErrRegistryUnauthorizedbefore the stale-cache branch; transient errors (network blip, 5xx) still degrade gracefully.provider_cached_authbug_test.gowith two tests (taken from draft PR Reproduce registry auth stale-cache bug #4951) that reproduce the two distinct error paths and now pass with the fix applied.Fixes #4950
Type of change
Test plan
task test)task lint-fix)Changes
pkg/registry/auth/transport.goToken()errors withErrRegistryAuthRequiredsentinelpkg/registry/provider_cached.gopkg/registry/provider_cached_authbug_test.goDoes this introduce a user-facing change?
Yes.
thv registry listnow returns an auth error (and exits non-zero) when the registry rejects credentials or the OAuth browser flow fails, instead of silently printing stale cached registry content.Special notes for reviewers
refreshCache()with a sentinel check would catch server-side 401/403 (Path 1) but miss OAuth browser-flow timeouts (Path 2), because that error chain carries no sentinel before the transport fix. The transport fix is the correct classification point — any failure to obtain a token is an auth error.TestTransport_RoundTrip/source_returns_error_propagates_errortest still passes because it usesErrorContains(t, err, "failed to get auth token")and the new message still contains that substring.CachedAPIRegistryProvideris used bypkg/api/v1/registry*.goandpkg/mcp/server/search_registry.gotoo, so this fix benefits headless contexts beyond the CLI.Generated with Claude Code