Skip to content

fix(oauth): ignore field order when detecting refreshed model changes - #4532

Merged
sailist merged 1 commit into
mainfrom
test/oauth-refresh-max-output-size
Oct 30, 2026
Merged

sailist merged 1 commit into
mainfrom
test/oauth-refresh-max-output-size

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Requirement or Bug

#3733 合入后,main 的 CI 在 refreshProviderModels.test.ts 的一个用例上稳定失败,所有 PR 的 test (2) 都被卡住。查下来不只是测试数据的问题:刷新判断"模型有没有变"时连字段顺序一起比较,导致部分自定义注册表用户每次刷新都被报告为"模型元数据已更新"。

Bug Reproduction Steps

  1. 配置一个自定义注册表(apiJson 来源)的 provider,注册表里的模型同时声明 limit.output 和 support_efforts(或 default_effort、upgrade)。
  2. 升级到包含 fix(oauth): record max_output_size from custom-registry model limits #3733 的版本后执行 /provider refresh:第一次报告元数据更新,补上 max_output_size,这是预期的。
  3. 再执行一次 /provider refresh:注册表没有任何变化,仍然显示 <provider>: model metadata updated.,之后每次都一样。

Root Cause

刷新前后,refreshProviderModels 把模型和 provider 配置 JSON.stringify 后比较字符串,所以字段顺序不同也算变化。而配置里的字段顺序和刷新构造的顺序本来就可能不一致:写回配置时,已有字段留在原位、新字段追加到末尾;刷新则按固定顺序构造别名。#3733 把 maxOutputSize 排在 displayName 之后、supportEfforts 之前,于是升级后追加到末尾的 max_output_size,和刷新结果的顺序永远对不上:

config.toml(升级后第一次刷新写回)   … display_name, support_efforts, max_output_size
刷新构造的别名                       … displayName, maxOutputSize, supportEfforts
比较结果                             内容相同、顺序不同 → 判定为有变化 → 写回(顺序不变)→ 下次仍然不同

CI 失败是同一个原因的另一面:那个用例预存的别名没有 maxOutputSize,而注册表返回了 limit.output,所以它本来就不满足"元数据没变"的前提。

这是根本修复:比较前先把字段排序,顺序不再影响判断。

Code Changes

 providerModelSnapshot(config, providerId, aliasKeys)
-  return JSON.stringify(snapshot)
+  return JSON.stringify(sortKeysDeep(snapshot))   // 递归按键名排序,数组保持原顺序

 providerConfigSnapshot(config, providerId)
-  return JSON.stringify(provider)
+  return JSON.stringify(sortKeysDeep(provider))
  • provider 配置的比较有同样的问题:只有顺序不同时虽然不会报告变化,但每次刷新都会静默重写一次 provider 配置。这里一起修掉。
  • 数组仍按原顺序比较:capabilities 原本就会先排序,其他数组(比如 supportEfforts)顺序变了依然算变化。
  • 测试:原用例预存的别名补上 maxOutputSize,让它重新符合"元数据没变"的前提;新增一个用例,把模型字段和 provider 字段的顺序都打乱,断言既不报告变化,也不重写配置。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
模型元数据只有字段顺序不同 判定为变化:/provider refresh 显示 model metadata updated,发布 ModelCatalogChanged,重写配置 判定为未变化 无,内容并没有变化 无
自定义注册表 provider 配置只有字段顺序不同 报告未变化,但每次刷新都重写 provider 配置 不再重写 无 无
字段值确实变化(包括新增 max_output_size、数组顺序变化) 判定为变化 不变 — —

受影响模块:packages/oauth 的刷新比较逻辑。模型比较被 Kimi 托管、Open Platform、Kimi Code API key 端点和自定义注册表四条刷新路径共用,provider 配置比较只在自定义注册表路径上;经模型发现服务影响 TUI、print、server 定时刷新和 desktop / web。对这四条路径来说,唯一的变化都是不再把顺序差异当成变化。

验证:

  • oauth 全部 380 个用例通过。去掉修复后,原用例和新用例都会失败;只去掉 provider 部分的排序,新用例会在"不重写配置"的断言上失败。
  • 下游的 agent-core-v2 discovery.test.ts,以及 kap-server modelCatalog、modelCatalogRefreshScheduler 测试通过;oauth typecheck 和 oxlint 通过。
  • 没有在真实 TUI 里手动复现。复现依据是配置读写代码(读取保持文件顺序,写回保留已有字段的位置)和单测模拟。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 14:59

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a8e0cb9

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 29, 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-29T15:01:18.323829Z a8e0cb9 PR opened
🔒 Security Review ✅ Completed 2026-10-29T15:02:24.962328Z a8e0cb9 PR opened
ℹ️ 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 29, 2026

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

commit: a8e0cb9

@sailist
sailist merged commit 7cd571a into main Oct 30, 2026
17 checks passed
@sailist
sailist deleted the test/oauth-refresh-max-output-size branch October 30, 2026 02:18
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
The behaviour of MoonshotAI#4421 has been in the requester since 94397aa, but its
suite still asserted only that the lowered system message lost its
`tools` field, which a message kept in place would also satisfy. Assert
instead that no system message survives and the history keeps its
length, and rename the case after what it protects.

Also settle ten ledger rows that were already implemented here: MoonshotAI#3733,
MoonshotAI#4413, MoonshotAI#4418, MoonshotAI#4421, MoonshotAI#4435, MoonshotAI#4460, MoonshotAI#4465, MoonshotAI#4516, MoonshotAI#4523, MoonshotAI#4532 and the
MoonshotAI#4558 test calibration, each with a probe over the suite that pins it.
Two rows carried a probe without a test-name selector (MoonshotAI#4557, MoonshotAI#4558),
which aborted `--verify` for every other row; MoonshotAI#4557 is a changelog sync
and now carries a manual probe.
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.

3 participants