Skip to content

fix(agent-core-v2): refresh tools without dynamic loading - #4720

Merged
7Sageer merged 2 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/current-tools-without-dynamic-loading
Nov 5, 2026
Merged

7Sageer merged 2 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/current-tools-without-dynamic-loading

Conversation

@pvzheroes125

@pvzheroes125 pvzheroes125 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Requirement or Bug

修复 #4719 的 P2 评论 指出的遗漏:不支持动态工具加载的模型分支仍读取初始旧定义。

模型不支持动态工具加载时,工具的同名更新仍会使用初始快照中的旧参数。运行中更新工具或恢复已有会话后,模型可能继续按旧定义调用工具。本 PR 让这类请求也使用当前有效的同名定义。

Bug Reproduction Steps

  1. 注册一个初始工具并保存会话状态,其参数尚不要求 payload。
  2. 用同名工具替换它,新参数要求提供 payload;另外注册一个新的 runtime 工具。
  3. 通过 tool_use=true、dynamically_loaded_tools=false 的请求解析工具列表。
  4. 修复前,初始工具仍返回旧参数。修复后,同名工具返回新参数,新增 runtime 工具仍不进入该请求。

回归同时覆盖当前状态和序列化后恢复的旧状态,不需要模型网络请求。

Root Cause

defaultToolsForDisclosure(false) 直接读取 initialTools(),绕过了 #4719 已添加的同名定义更新逻辑,因此不支持动态加载的请求仍停留在旧快照。

Code Changes

复用现有的有效工具解析:初始名称优先采用 current 的同名定义,缺少当前定义时继续保留原初始定义。给该解析方法增加一个布尔参数,在不披露动态工具的请求中排除真正新增的 runtime 工具。

 defaultToolsForDisclosure(disclosure)
- disclosure=true 时解析当前同名定义,false 时直接使用原初始快照
+ 两个分支都解析当前同名定义
+ 仅 disclosure=true 时包含新增 runtime 工具

生产修改只有三个行级变化;权限过滤、select_tools 关闭和动态历史剥离继续沿用已有路径。
历史工具变更提醒同步改为以本次请求提供的工具定义为准;继续禁止 select_tools,保留运行时新增不可加载及已移除工具可能不可用的提醒。

Behavior Changes and Affected Users

行为 修改前 修改后 受影响用户 退路
未披露动态工具时的同名更新 请求继续使用初始旧参数 请求使用当前定义,含恢复的已有会话 使用不支持动态工具加载的模型,或本次请求未开启动态工具披露的 CLI、SDK、desktop/web、ACP 用户 无新增开关;修复旧参数问题
新增 runtime 工具 不自动进入该请求 保持不自动进入 同上 行为保留
权限、select_tools 与历史 过滤禁用工具,不公开 select_tools,剥离请求中的动态声明 继续走相同过滤路径,原始状态和历史不改写 同上,含旧版本保存的会话 不需要迁移或重建会话
工具提示缓存 同名更新后可能继续复用旧顶层内容 同名定义变化会更新顶层内容,可能使对应提示缓存失效 对这类请求使用工具提示缓存的用户 未变化工具和排序保留
历史工具变更提醒 提示初始快照仍可见,替换过的定义可能不可用或调用失败 指引使用本次请求提供的定义;继续禁止 select_tools,并保留新增、移除工具的限制 切换到不支持动态加载模型,或恢复包含旧工具公告的会话的用户 不承诺所有替换工具都可调用;实际工具列表和权限仍为准

已有测试文件增加当前状态、恢复状态两种回归,检查新参数、新增 runtime 排除、权限过滤、select_tools 不公开,以及持久化状态和历史保持不变。108 项聚焦测试、Core 类型检查和注释检查全部通过;局部类型感知 lint 为 0 错误,6 条警告均来自未修改的现有语句。

验证边界:没有请求线上模型,也没有复测真实用户原会话。
后续提醒文案更新复用了现有测试,dynamicTools.test.ts 12 项通过;没有重复运行无关测试。

验证
  • 两条新增回归在修复前均因返回旧参数失败。
  • pnpm -C packages/agent-core-v2 exec vitest run test/agent/toolSelect/toolSelectService.test.ts test/agent/toolSelect/dynamicTools.test.ts --config vitest.config.ts
  • pnpm -C packages/agent-core-v2 exec tsc --noEmit -p tsconfig.json
  • 对修改的 Core 源码和现有测试运行 oxlint --type-aware
  • node scripts/check-no-comments.mjs
  • git 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.

这是已合入 #4719 的后续修复,目前未关联已获维护者 /approve 的 issue。没有新增命令、配置或需要同步的公开文档。

@changeset-bot

changeset-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dd3e588

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 Nov 5, 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-11-05T15:19:51.593593Z dd3e588 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 Nov 5, 2026 •

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

commit: dd3e588

7Sageer
7Sageer previously approved these changes Nov 5, 2026
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