Repository navigation
CLI: classify OAuth and fetch-guard failures instead of exiting 1 (#2842) - #2940
Merged
Merged
Conversation
OAuth protocol errors (a declined consent redirect, the SDK's token-endpoint OAuthError) now exit 3 with code oauth_error and the server's error / error_description as oauthError / oauthErrorDescription envelope fields. The OAuth callback timeout exits 3 as oauth_timeout. A declined step-up and insufficient scope after re-auth exit 3 as step_up_declined / insufficient_scope. A destination-guard refusal (FetchTargetError, including undici's fetch failed wrapping one) exits with the new code 12 as fetch_refused. mcpdo relays the new OAuth fields across the daemon socket. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
2 tasks done
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the OAuth and destination-guard error-handling changes.
No open issues 🎉
What changed in this PR
Addresses #2842 by giving the shared CLI error handler distinct outcomes for OAuth failures and destination-guard refusals, so scripts can distinguish them from usage errors.
Changes:
- Classifies OAuth failures as exit
3with specific envelope codes, and fetch-guard refusals as exit12. - Preserves structured OAuth error fields through mcpdo’s daemon relay, with sanitization and URL redaction.
- Adds classification and relay tests, and updates CLI documentation.
| File | Description |
|---|---|
skills/mcpdo/SKILL.md |
Documents exit-3 authentication recovery outcomes. |
docs/cli-smoke-testing.md |
Updates the exit-code reference. |
core/cli/exit-codes.ts |
Defines exit 12 and OAuth envelope fields. |
core/cli/error-handler.ts |
Classifies new failures and redacts OAuth fields. |
core/cli/cliOAuth.ts |
Assigns explicit step-up failure codes. |
core/auth/node/runner-interactive-oauth.ts |
Introduces typed callback and timeout errors. |
core/auth/node/index.ts |
Exports the new OAuth error classes. |
clients/web/src/test/core/auth/runner-interactive-oauth.test.ts |
Tests typed interactive OAuth failures. |
clients/mcpdo/src/daemon/server.ts |
Relays structured OAuth error fields. |
clients/mcpdo/src/daemon/protocol.ts |
Extends the daemon error contract. |
clients/mcpdo/src/daemon/client.ts |
Rebuilds and sanitizes relayed OAuth fields. |
clients/mcpdo/__tests__/oauth-error-envelope.test.ts |
Tests daemon relay and client sanitization. |
clients/cli/README.md |
Documents new outcomes and an OAuth envelope example. |
clients/cli/__tests__/error-handler.test.ts |
Covers classification, field omission, redaction, and relay handling. |
clients/cli/__tests__/cliOAuth.test.ts |
Tests declined step-up and insufficient-scope classifications. |
Review effort: Balanced
Member
Author
|
Copilot review loop closed: round 1 was clean (no inline comments, no suppressed findings, 'no open issues'). Stopping per pr-flow 7c on the first clean round. |
This was referenced Nov 11, 2026
Merged
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 #2842
What changed
classifyError(core/cli/error-handler.ts) sent every OAuth failure and every destination-guard refusal to its catch-all, which exits1, the codeEXIT_CODESreserves for usage errors, with envelope code"error". A script could not tell "the authorization server said no" from "the command line is wrong". This PR adds typed errors where the failures start and classifies them:code?error=(e.g.access_deniedfrom a declined consent), or the token exchange after the callback fails (SDKOAuthError, e.g.invalid_grant)oauth_error, withoauthError/oauthErrorDescription3oauth_timeout3[y/N]answered N (cliOAuth.ts)step_up_declined3cliOAuth.ts)insufficient_scope3FetchTargetError, either thrown directly or wrapped by undici asfetch failed)fetch_refused12(new)error1(unchanged)core/auth/node/runner-interactive-oauth.tsaddsOAuthCallbackErrorandOAuthCallbackTimeoutError. They replace the plainErrors the flow threw before, and their messages are unchanged, so the TUI renders exactly what it did.core/cli/cliOAuth.ts: the two plain-Errorsites (declined step-up and insufficient scope) now throwCliExitCodeError(AUTH_REQUIRED, …). Their messages are also unchanged.oauthError/oauthErrorDescriptionacross the socket the same way it relays the CLI and mcpdo JSON error envelopes drop the structured Retry-After data from a 429 #2772 rate-limit fields. The client sanitizes both fields because they are server text. mcpdo's front-end OAuth already goes throughhandleError, so it gets the new codes directly.oauth_errorenvelope example, thedocs/cli-smoke-testing.mdtable is updated, andskills/mcpdo/SKILL.mdnow names the new exit-3 codes.Why these exit codes
3for the OAuth failures. Authorization is what failed, and running it again is what can fix it, which is what3already means. The more specificcodetells a script which auth failure happened without making it readmessage. For example, an explicit N (step_up_declined) is now distinct from a prompt that timed out (auth_required).12(FETCH_REFUSED) for the guard. It is not1, because the command line is fine. It is not4(UNREACHABLE) either, even though undici-wrapped refusals used to land there. Exit4tells a caller the network failed and a retry or a proxy may help. A refusal is a deterministic policy decision, so every retry gets the same answer. It gets its own code for the same reason11(RATE_LIMITED) has one: the right response is different from every neighbouring code's.error/error_descriptionas separate envelope fields. They are separate fields here, namedoauthError/oauthErrorDescription. The envelope already sits under anerrorkey and uses camelCase (retryAfterMs), so a literalerrorfield would read.error.error.Tests
clients/cli/__tests__/error-handler.test.ts: each new classification, field omission when the server sent nothing, redaction, and relayed fields on a pre-classified error.clients/cli/__tests__/cliOAuth.test.ts:step_up_declinedandinsufficient_scoperound-trip throughclassifyError.clients/mcpdo/__tests__/oauth-error-envelope.test.ts: the daemon relays the fields and the client rebuilds them.clients/web/src/test/core/auth/runner-interactive-oauth.test.ts: the flow rejects with the typed errors.npm run local:gatepasses.🤖 Generated with Claude Code