Fix: Don't tell clients to re-authorise when we failed to validate - #412
Merged
Conversation
`GetBearerInfo` collapsed every non-200 from `/launchpad/v1/userinfo.json` into `ErrBearerInfoUnauthorized`, so a 500 or 502 was indistinguishable from a rejected token. The middleware turned that into 401 plus `WWW-Authenticate`, which per RFC 9728 tells the client to discard its token — costing a full re-authorisation, and an MFA prompt where MFA is enabled, over what may have been a momentary upstream failure. Now split three ways: `ErrBearerInfoUnauthorized` (401/403 only, still challenges), `ErrBearerInfoUnavailable` (503, no challenge), `ErrBearerInfoCanceled` (our request context died because the client hung up — logged at debug, no response written). That last case accounts for the overwhelming majority of these errors in practice: clients closing their stream on `GET /`, previously reported as server errors of ours. `classifyAuthStatus` isolates the status decision; the sweep over 100-599 asserts nothing outside 401/403 can read as a rejection. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
hmarron
approved these changes
Jul 29, 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.
Description
GetBearerInfocollapsed every non-200 from/launchpad/v1/userinfo.jsonintoErrBearerInfoUnauthorized, so a 500 or 502 was indistinguishable from a rejected token. The middleware turned that into 401 plusWWW-Authenticate, which per RFC 9728 tells the client to discard its token — costing a full re-authorisation, and an MFA prompt where MFA is enabled, over what may have been a momentary upstream failure.Now split three ways:
ErrBearerInfoUnauthorized(401/403 only, still challenges),ErrBearerInfoUnavailable(503, no challenge),ErrBearerInfoCanceled(our request context died because the client hung up — logged at debug, no response written). That last case accounts for the overwhelming majority of these errors in practice: clients closing their stream onGET /, previously reported as server errors of ours.classifyAuthStatusisolates the status decision; the sweep over 100-599 asserts nothing outside 401/403 can read as a rejection.Type of Change
Testing
go test -v ./...)Checklist