Skip to content

fix(agent-core-v2): order dynamic tool replacement announcements - #5592

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/dynamic-tool-replacement-order-20261126
Nov 27, 2026
Merged

sailist merged 1 commit into
MoonshotAI:mainfrom
pvzheroes125:fix/dynamic-tool-replacement-order-20261126

Conversation

@pvzheroes125

Copy link
Copy Markdown
Contributor

Requirement or Bug

同名动态工具的定义更新会同时产生 removed 和 added。当前公告先说新增、再说移除,并要求不要选择被移除的名字;模型可能因此拒绝重新加载实际可用的新定义。本 PR 使公告与注册表的移除后新增语义一致,并在请求投影中修正已保存的同名替换公告。

Bug Reproduction Steps

  1. 在会话内用 select_tools 加载并调用某个动态 MCP 工具。
  2. 更新同名工具的 schema。
  3. 下一轮公告同时包含该名字的 added/removed,旧文案要求不要再选择它;即使注册表允许重新加载,模型也可能认定工具已移除。
  4. 恢复已保存该公告的会话,仍会把原矛盾文案发送给模型。

Root Cause

注册状态与公告折叠已经按 removed→added 处理同名替换,模型看到的文字顺序却相反。旧文案的禁止选择指令也没有说明后续新增可以恢复可加载状态。

Code Changes

  • 复用现有公告生成器,将顺序统一为 removed→added。
  • 将移除约束明确为“再次新增前不可加载”,并说明重新新增的名字应使用更新后的定义。
  • 仅对 lifecycle metadata 中存在同名交集的旧公告,在请求视图中复用该生成器;原消息和 wire 不改写。
  • 原 unload_tools 和重新 select_tools 加载 schema 的流程保留。
旧完整 schema → 移除旧定义、公告新定义 → unload 旧 schema → select_tools → 新完整 schema

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
同时 added/removed 的公告顺序 added→removed removed→added,与状态折叠一致 使用动态加载的 CLI、Desktop、VS Code、SDK 会话 无配置变更
“removed 不可加载”的提示 无条件要求不要选择 限定为再次新增前不可加载 收到动态工具目录公告的模型 真正移除仍不可加载
重新新增名字的提示 没有说明同名替换 明确可加载更新后的定义 同名工具更新及移除后重新加入的会话 无配置变更
已保存的同名替换公告 原矛盾文本直接进入模型请求 只在请求投影中生成一致文案 包含旧 lifecycle metadata 公告的恢复会话 原始记录保持原样
完整定义卸载、重新选择及普通移除 unload 后需重新 select,移除工具不可用 保持 动态工具 provider 和 SDK 调用方 不需要

必要回归验证公告顺序、原记录不变、无关内容保留、unload_tools 及新 schema 重新加载。真实模型已验证新会话同名更新、冷恢复,以及大更新前会话先加载旧定义、升级后更新和冷恢复调用。

**验证边界:**一个此前已积累错误拒绝回复的会话仍沿用旧结论,没有重新选择工具;修正后的公告已到达模型。因此本 PR 修正公告与投影,不承诺所有已有错误回复历史都会自动恢复,也不改写这些历史回复。

Validation
  • pnpm exec vitest run --reporter=agent packages/agent-core-v2/test/agent/toolSelect/dynamicTools.test.ts packages/agent-core-v2/test/agent/toolSelect/toolSelectService.test.ts
  • pnpm exec vitest run --reporter=agent packages/agent-core-v2/test/agent/toolSelect/toolSelect.e2e.test.ts:17 条引擎回归通过,前述单测 109 条通过。
  • pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit
  • pnpm lint
  • pnpm run check:duplication 46beafd3da53441749d6d0ceadebad7f75b320e8
  • 同主线基底的 CI 守卫脚本、注释检查脚本、选测脚本测试及 workspace 检查通过。
  • 本地 macOS / Node 24.15.0;未运行 Windows/Linux 安装包。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve). No linked issue; reproduction and scope are documented above.
  • 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. No configuration or usage changes.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0b07df4

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

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/agent-core-v2 Patch
@moonshot-ai/kimi-code Patch
kimi-code-app Patch
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 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T21:03:26.833317Z 0b07df4 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 Nov 26, 2026

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

commit: 0b07df4

@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: 0b07df447d

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

const removed = lifecycle.removed.filter((name) => declaredDynamicTools.delete(name));
if (removed.length === lifecycle.removed.length) {
const text = lifecycle.added.some((name) => lifecycle.removed.includes(name))
? wrapSystemReminder(renderLoadableToolsAnnouncement(lifecycle.added, lifecycle.removed))

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 Update the request-shaping contract for projected reminders

This branch replaces part.text when projecting persisted same-name replacement announcements, but the LLM design contract at packages/agent-core-v2/docs/en/llm.md:67 still says that shapeActiveHistory narrows lifecycle metadata without rewriting the reminder text. Update that contract to distinguish the projected normalization from the unchanged persisted history; otherwise it documents an invariant that this fix intentionally breaks.

AGENTS.md reference: AGENTS.md:L10-L10

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 10cbda8 into MoonshotAI:main Nov 27, 2026
22 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Dec 2, 2026
`bun scripts/upstream-ledger.mjs --refresh` at upstream/main 4eb2919
added 126 rows, so every open upstream commit and every PR it references
now has a ledger row: 0/596, down from 125 at 8bf8ba3 and 126 at the
fetched tip. The refresh only reads `upstream/main ^ main`, so the three
release-2.6.2 commits named by the mission (MoonshotAI#4875/MoonshotAI#4905/MoonshotAI#4922) gained
rows with the refresh's row shape.

Settled with live probes in this tree:

- ported: MoonshotAI#5533 (docs 2.8.1 changelog), MoonshotAI#4875 (registry search_url and
  feedback_url plus the feedback service), MoonshotAI#4905 (Kimi upload status
  validation in packages/core), MoonshotAI#4922 (swarm task events in
  sessionTaskFeed), MoonshotAI#5438 (unload only declared dynamic tools), MoonshotAI#5592
  (dynamic tool replacement order), MoonshotAI#5595 (append-log known length),
  MoonshotAI#5573 (skill roots for every work dir), MoonshotAI#5576 (date reminder cwd
  comparison), MoonshotAI#5618 (session titles for skill openers), MoonshotAI#5638 (frozen
  loop tool baseline), MoonshotAI#5626 (legacy turn-input origins)
- partial: MoonshotAI#5505 (processLiveness source and consumers present; the
  upstream unit test file was never carried), MoonshotAI#5571 (program-resume and
  OSC 7577 present; the upstream test helper was never carried), MoonshotAI#5532
  (gitService half present; fsService still leaks the environment lease
  at fsService.ts:1133 and :1267), MoonshotAI#5557 (app-client icon registry kept;
  the move to app-ui was never carried)
- not-applicable: MoonshotAI#4655 (upstream reverted auto review in MoonshotAI#5649), MoonshotAI#5333
  (PLAYBOOK:111 deliberate flat experimental flags)

M39's "likely present" list was checked, not trusted: MoonshotAI#5438 is present
(upstream test passes), MoonshotAI#5487 is not (nativeStartSettleMs/leg.nativeSettled
absent), MoonshotAI#5635 is not (ToolsSettled absent), MoonshotAI#5429 needs a visual probe.
The remaining 194 pending rows stay open with their reasons; no feature
was ported and no upstream-drift allowlist entry was added.

Verification: verify -> 332 closed rows, 332 carry every file of their
PR; 317 probes pass, 2 foreign-runner skips, 0 fail; a second verify is
byte-identical (ledger sha256 cbf53638...). Probe tests 29 pass; bun run
lint and node scripts/checks/ratchet.mjs green.
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