Skip to content

fix(oauth): include the transport root cause in connection error messages#1808

Open
wbxl2000 wants to merge 2 commits into
mainfrom
qer/oauth-error-cause
Open

fix(oauth): include the transport root cause in connection error messages#1808
wbxl2000 wants to merge 2 commits into
mainfrom
qer/oauth-error-cause

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

No issue — the problem is explained in the next section.

Problem

When the OAuth device flow hits a transport-level failure, users only see:

OAuth request to https://auth.kimi.com/api/oauth/device_authorization failed: fetch failed

fetch failed is the generic undici TypeError — the real reason (DNS failure, connection refused, TLS interception, timeout) lives in the nested error.cause chain, which the previous code discarded. This makes reports like "cannot log in with OAuth" undiagnosable without reproducing locally: nobody can tell whether the user's network needs a proxy, the OAuth host is blocked, or certificates are being intercepted. This was reported in the wild by a VS Code extension user.

What changed

  • OAuthError / OAuthConnectionError now accept standard ErrorOptions, and postForm (src/oauth.ts) throws the connection error with { cause: error } attached, so log stacks show the full Caused by: chain.
  • The surfaced message now walks the cause chain (describeFetchFailure) and includes the root reason, e.g.:
    OAuth request to ... failed: fetch failed: connect ECONNREFUSED 127.0.0.1:1 — deduplicated, non-Error throwables fall back to String(error).
  • Behavior for callers is unchanged: same error class, so retry/refresh logic that branches on OAuthConnectionError/status codes is unaffected.
  • Added a test asserting the root cause appears in the message and that .cause preserves the original rejection.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset. (Changeset included: @moonshot-ai/kimi-code patch — the change enters the CLI bundle and improves kimi login error messages; the oauth workspace itself is private/unpublished.)
  • Ran gen-docs skill, or this PR needs no doc update. (Error-message wording only, no documented behavior change.)

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 37082db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37082dbdc8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

let current: Error | undefined = error;
while (current !== undefined) {
messages.add(current.message);
current = current.cause instanceof Error ? current.cause : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Traverse AggregateError entries when describing fetch failures

When connection attempts cover multiple resolved addresses, Node 24.15 can reject fetch with a TypeError whose cause is an AggregateError; the individual ECONNREFUSED details are in AggregateError.errors, while its own message is empty and it has no cause. This loop therefore produces fetch failed: and still hides the transport reasons this change is meant to expose. Flatten AggregateError.errors as well as the linear cause chain.

Useful? React with 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@37082db
npx https://pkg.pr.new/@moonshot-ai/kimi-code@37082db

commit: 37082db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant