Usage endpoint should trigger auth banner when Claude OAuth token is expired#455
Merged
Merged
Conversation
…th token When getClaudeUsage() receives a 401 or 403 from Anthropic's usage API, it now records an auth event and publishes an auth:failed WebSocket event so the UI shows the re-auth banner immediately — without waiting for the next 5-minute /api/auth/status poll or a task launch failure. Closes #454 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
jplorier
pushed a commit
to jplorier/optio
that referenced
this pull request
May 5, 2026
…th token (jonwiggins#455) When getClaudeUsage() receives a 401 or 403 from Anthropic's usage API, it now records an auth event and publishes an auth:failed WebSocket event so the UI shows the re-auth banner immediately — without waiting for the next 5-minute /api/auth/status poll or a task launch failure. Closes jonwiggins#454 Co-authored-by: Optio Agent <optio-agent@noreply.github.com> Co-authored-by: Claude Opus 4.6 (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.
Closes #454
What changed
When
getClaudeUsage()inauth-service.tsreceives a 401 or 403 from Anthropic's usage API (https://api.anthropic.com/api/oauth/usage), it now:recordAuthEvent('claude', ..., 'usage-endpoint')so the failure is visible togetRecentAuthFailures()and surfaces in/api/auth/usage'sauthFailures.claudeflag.auth:failedevent so connected clients trigger theGlobalAuthBannerimmediately — without waiting for the next 5-minute/api/auth/statuspoll or a task launch failure.This brings the usage endpoint path in line with the agent-output path (
task-worker.ts) and the proactive-probe path (token-validation-worker.ts), both of which already publishauth:failedevents.Both
recordAuthEventandpublishEventare wrapped in try/catch so failures in these side-effects don't break the usage response itself.How to test
CLAUDE_CODE_OAUTH_TOKENin secrets/api/auth/usage(e.g., the dashboard)npx vitest run apps/api/src/services/auth-service.test.ts— all 6 tests pass, covering:recordAuthEvent+publishEventrecordAuthEvent+publishEventrecordAuthEventorpublishEventdon't break the response