feat: ship Slice K2 — chat-lane fail-fast on Claude Code auth errors#89
Merged
Conversation
When the OAuth refresh token is revoked or rejected, the chat lane now
fails fast within the first SDK roundtrip with an actionable re-auth
reply instead of stalling for ~5 minutes.
- packages/core/src/auth/refresher.ts: AUTH_REQUIRED_ERROR_CTORS const
+ isAuthRequiredError(err) helper as single source of truth for
"user must re-authenticate" classification.
- packages/core/src/agent/sdk-source.ts: broadens rethrow-don't-retry
to also catch RefreshTokenRevokedError (HTTP 400 invalid_grant). Was
previously masked by the transient-retry branch.
- packages/core/src/agent/types.ts: failed.subtype is now narrowly
typed as AgentFailureSubtype — typo at any callsite is a compile
error, not a silent fallthrough.
- packages/core/src/agent/runner.ts: tags failed events with
subtype 'auth_required' when isAuthRequiredError(err) matches.
- packages/core/src/messaging/chat-bridge.ts: routes auth_required
failures to CHAT_AUTH_REQUIRED_REPLY ("run claude login then mc auth
bootstrap") via a private ChatAuthRequiredError carrier class.
- packages/core/src/orchestrator/orchestrator.ts: prefixes failureMsg
with auth_revoked: so dashboards can render an actionable error.
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
When the OAuth refresh token is revoked (HTTP 400
invalid_grant) or rejected (HTTP 401), the chat lane now fails fast within the first SDK roundtrip with an actionable re-auth reply instead of stalling ~5 minutes. K1 fixed the refresher's classification of these errors; K2 wires the structured failure all the way through to a user-visible Discord reply.What changed
@mc/core/auth—isAuthRequiredError(err)helper + exportedAUTH_REQUIRED_ERROR_CTORSconst as the single source of truth for "user must re-authenticate" classification. Used by both sdk-source's rethrow branch and runner's failed-event tagging.@mc/core/agent/sdk-source— broadens the rethrow-don't-retry clause to includeRefreshTokenRevokedError. Previously a 400/invalid_grantslipped through to the transient-retry branch and looped until the access token expired.@mc/core/agent/types—AgentEvent.failed.subtypeis nowAgentFailureSubtype(string union) instead ofstring. A typo at any callsite is a compile error.@mc/core/agent/runner— catch block tagsfailedevents withsubtype: 'auth_required'when the thrown error is an auth-required class.@mc/core/messaging/chat-bridge— exportsCHAT_AUTH_REQUIRED_REPLY(Claude Code authentication expired. Run \claude login`, then `mc auth bootstrap` to restore access.); a privateChatAuthRequiredErrorcarries theauth_required` discriminator from the inner switch arm to the outer catch's reply branch.@mc/core/orchestrator— prefixesfailureMsgwithauth_revoked:when the agent failure isauth_required. Dashboards / CLIs can match the prefix to render an actionable error.Test plan
pnpm typecheckcleanpnpm buildclean (all 7 workspaces)biome check .clean (388 files)pnpm test1463/1463 passingsubtypeto typed union (kills 4 stringly-typed sites), sharedAUTH_REQUIRED_ERROR_CTORSconst between refresher andrunner.test.ts, exportedCHAT_AUTH_REQUIRED_REPLYfrom messaging barrelsdk-source-401.test.ts, 3 parametrized subtype-tagging tests + 1 negative case inrunner.test.ts, 1 friendly-reply test inchat-bridge.test.ts, 1 task-lane prefix test inorchestrator.test.ts~/.mc/credentials.json, send a Discord chat message → reply within ~30s saying re-auth needed (not the generic 5-min stall)Deferred
errorKindfield on TaskPatch (would require a schema migration; one writer, zero readers today).refresher.invalidate()wiring so re-auth recovery doesn't need a daemon respawn.