Skip to content

fix(oauth): surface registry connection failures - #4426

Open
wbxl2000 wants to merge 2 commits into
mainfrom
fix/registry-refresh-network-details
Open

wbxl2000 wants to merge 2 commits into
mainfrom
fix/registry-refresh-network-details

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — 来自已确认的 desktop 自定义 registry 诊断案例,无单独 issue。

Problem

自定义 registry 的 api.json 请求因网络或代理不可用时,刷新结果只保留笼统的 fetch failed,丢失底层 cause 和 registry 分组信息。客户端因此无法给出准确的网络排查建议,也无法区分同一次故障影响多个 provider 的情况。与此同时,非法 URL、userinfo、主动取消和 Fetch bad-port 限制不应被归类为传输网络错误。

What changed

  • 为自定义 registry 的传输错误保留完整 cause 与 AggregateError.errors[] 链,并对 registry URL 及原始/编码后的敏感组成部分脱敏;AbortError 原样保留,请求构造错误不标记为 network。
  • failed 新增可选 kind、registry_group、registry_url,同次响应内同组 provider 共享分组 ID,非网络失败保持原结构。
  • 同步 discovery、klient、kap-server REST/WS 和 node-sdk 镜像契约,避免字段在运行时投影中丢失。
  • 增加 OAuth、discovery、真实 HTTP 路由、memory klient、WS broadcaster 回归测试,并同步更新中英文 server-api.md。
registry fetch rejection
  ├─ AbortError                 → preserve original cancellation
  ├─ request construction error → sanitized reason, no network kind
  └─ transport failure          → cause chain + network kind + registry group

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior
Registry transport failure details Only the outer fetch failed message is retained Root causes and a sanitized registry URL are retained Desktop, web, CLI, and SDK consumers diagnosing registry connectivity
Registry failure grouping Each failure has only provider and reason Related failures share an opaque group id for that response Clients that aggregate provider-refresh failures
Request construction failures Failures are returned without network metadata Invalid URLs, userinfo, bad ports, and cancellations remain outside the network classification Users with malformed provider configuration or cancelled requests
Other provider failures Existing { provider, reason } shape Unchanged Existing API, WS, and SDK consumers

Validation

  • pnpm vitest run packages/oauth/test/custom-registry.test.ts packages/oauth/test/oauth.test.ts packages/agent-core-v2/test/app/kosongConfig/discovery.test.ts packages/kap-server/test/modelCatalog.test.ts packages/kap-server/test/sessionEventBroadcaster.test.ts packages/node-sdk/test/sdk-rpc-client-v2.test.ts
  • pnpm lint
  • pnpm sherif
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • pnpm -C docs run build
  • Full-suite note: 17,473 tests passed; 3 unrelated fake-timer tests timed out. The foreground-subagent timeout also occurs on an unmodified origin/main checkout, and the two compaction tests pass in isolation. These tests were not changed to manufacture a pass.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (N/A — confirmed diagnostic case; the problem and reproduction are described above).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f66e15

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 commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T11:35:22.214876Z 9f66e15 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

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

commit: 9f66e15

@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: 51f7330b19

ℹ️ 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".

Comment on lines +301 to +305
if (!(error instanceof TypeError) || error.cause === undefined || !URL.canParse(sourceUrl)) {
return false;
}
const url = new URL(sourceUrl);
return url.username === '' && url.password === '';

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 Reject unsupported schemes before labeling failures as network

When a configured registry uses a parseable but unsupported URL such as ftp://... or file://..., Node's fetch rejects with a TypeError whose cause is unknown scheme or not implemented, so this predicate classifies a request-construction/configuration error as kind: 'network'. That changes the existing base failure shape and can make desktop, web, or SDK clients present irrelevant connectivity diagnostics; restrict the classification to transport-capable protocols such as HTTP and HTTPS.

AGENTS.md reference: AGENTS.md:L111-L113

Useful? React with 👍 / 👎.

Comment on lines +252 to +258
const sensitiveValues = new Set([
url.username,
url.password,
...url.searchParams.values(),
...rawRegistryQueryValues(sourceUrl),
url.hash.slice(1),
]);

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 Redact empty-valued and short keyless query credentials

Registry URLs can carry an opaque credential as a key-only query, but ...?sensitive-token= is parsed as a key with an empty value and query keys are omitted from this sensitive-value set, while a short keyless value such as ...?123 is skipped by replaceStandaloneRegistryValue. If a proxy or custom fetch error echoes the query separately or uses a canonicalized URL that does not exactly match sourceUrl, the credential survives into reason and is then exposed through REST and WebSocket refresh results; explicitly treat raw keyless entries and empty-valued keys as sensitive query values.

Useful? React with 👍 / 👎.

Comment on lines +313 to +315
kind: failure.kind,
registry_group: failure.registryGroup,
registry_url: failure.registryUrl,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Publish failure-only catalog refresh events

When a scheduled or user-triggered refresh produces only registry failures (the normal result of a registry outage) and no provider changes, ProviderDiscoveryService.refreshProviderModels does not publish ModelCatalogChanged because publication is still gated on response.changed.length > 0. Consequently these newly mapped fields never reach WebSocket consumers in the primary failure scenario; they are emitted only when some unrelated provider also changes, so the publication condition must include failures.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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