Skip to content

fix(core): refresh tool catalog within the current turn - #4526

Merged
7Sageer merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/same-turn-tool-catalog
Oct 29, 2026
Merged

7Sageer merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/same-turn-tool-catalog

Conversation

@pvzheroes125

Copy link
Copy Markdown
Contributor

Requirement or Bug

MCP 授权成功后,同一轮的模型仍看不到新工具目录,无法可靠地选择并继续调用真实工具。

Bug Reproduction Steps

  1. 使用启用动态工具选择的模型,将需要授权的 HTTP MCP server 配置为 deferred。
  2. 在一条用户消息中要求完成授权并使用该服务,先通过 select_tools 加载 authenticate。
  3. 授权完成后,服务重连并用真实工具替换 authenticate。
  4. 检查同一轮的下一次模型请求:真实工具已注册,但上下文仍只有旧目录;新目录要等下一轮才出现。

Root Cause

目录提醒虽然在每个步骤准备时运行,但 provider 在非新轮次直接返回,遗漏了轮内发生的 MCP 工具变化。本修复调整通知时机,复用已有目录差异计算、权限过滤和去重。

Code Changes

 before model step
-  skip unless this is a new turn
+  skip only when dynamic tool selection is disabled
   wait for initial MCP discovery on a new turn
   announce added/removed tools using the existing catalog diff

新增同轮 HTTP MCP 授权回归,并更新目录通知测试;附带 CLI patch changeset。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
轮内工具新增、移除或权限变化后的目录通知 等下一轮才更新 下一次模型请求前发送增量 启用动态工具选择的 TUI、print、desktop/web、VS Code、ACP 和 SDK 会话 不新增选项;沿用现有动态工具选择开关
首次 MCP discovery 新轮开始等待 discovery 新轮仍等待;后续步骤只计算当前目录差异 MCP 初始连接尚未结束的上述会话 不变
无目录变化或工具不可用 使用已有去重、profile 与权限过滤 继续沿用,目录不变时不重复通知 工具白名单、权限限制及长会话用户 不变
inline 工具 / 关闭动态工具选择 inline 直接暴露工具,关闭时不发目录 同样保持;不会因本修复强制转为 deferred 使用 inline 或关闭动态工具选择的会话 不变

受影响模块为 agent-core-v2 的工具目录提醒,不修改 schema 加载方式、历史工具 schema 保留规则、公开 API 或持久化格式。

验证:

  • 工具选择相关 3 个测试文件共 117 项通过。
  • 本地 HTTP MCP + TestAgent 内核覆盖单条 prompt 内授权、重连、目录新增/移除、select_tools 加载 schema、调用真实 MCP 工具;同时验证 inline 路径。
  • 实际模型请求快照断言授权后的准确工具名与 schema;模型响应和 OAuth 完成回调使用可控测试输入,不依赖外部服务。
  • 修复前 deferred 回归失败:授权后的模型请求缺少新增工具;修复后通过。
  • agent-core-v2 类型检查通过,修改文件 lint 零错误,comment check 和 diff-check 通过。

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.

未关联 issue。本修复不改变用户配置或操作方式,无需新增用户文档;发布说明已包含在 changeset 中。

@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a11ce9

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-29T12:31:27.064806Z 4a11ce9 Manual request
ℹ️ 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@4a11ce9
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4a11ce9

commit: 4a11ce9

@pvzheroes125

Copy link
Copy Markdown
Contributor Author

@codex review

@7Sageer
7Sageer merged commit 8a5a430 into MoonshotAI:main Oct 29, 2026
28 of 29 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 4a11ce9030

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

7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…pe gap

MoonshotAI#4526 is already in the tree: the loadable-tools announcement refreshes
on every turn and only awaits the MCP initial load when the turn is new.

MoonshotAI#4600 does not port as written. This fork binds a session to
`{ workspaceId, runtimeId }` rather than upstream's
`{ environmentId, cwd }`, and `IEnvironmentService` is not exported from
the agent-core-v2 root, so the legacy `acp:<id>` rebind needs a field
mapping plus a public export. Recorded rather than forced, so the next
attempt starts from the shape difference instead of rediscovering it.

Ledger: closed 34 -> 35, remaining 64.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…probe

MoonshotAI#4554 lands in 8caec0b with a probe over the new message case.

MoonshotAI#4526's probe carried unescaped parentheses, so `rg` read them as groups
and the pattern could never match; it now escapes them. The full
`--verify` run is green again (33 probes).

Ledger: closed 39 -> 40, remaining 59.
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.

2 participants