Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 41cc602 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed43f5c2b2
ℹ️ 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".
| if (!inlineNames.has(tool.name) && isFirstDeclaration) { | ||
| if (kept !== undefined) kept.push(tool); | ||
| continue; |
There was a problem hiding this comment.
Avoid advertising replacement tools with their original schema
When a same-name replacement changes its parameters, these lines retain the first definition even though the registry and executor now contain the replacement and the persistent history makes it count as loaded. In the added test, the model is therefore shown the original permissive schema and can call the tool with {}, while toolArgsError validates that call against the replacement schema requiring payload and rejects it. Project a schema compatible with the active implementation, or mark the replacement unavailable until a new session instead of leaving it callable with a stale contract.
Useful? React with 👍 / 👎.
| toolSelectSchemaSignature(firstDeclaration.tool) !== toolSelectSchemaSignature(tool) | ||
| ) { | ||
| schemaUpdates.push(tool.name); |
There was a problem hiding this comment.
Only announce schema updates that are still pending
When a tool changes schema and is subsequently removed or reverts to its original schema, this comparison still treats the intermediate historical declaration as a pending update because every duplicate is compared only with the first declaration. Every later request then tells the model to start a new session for an update that is either unavailable or already matches the retained schema, potentially producing unnecessary restart guidance. Determine the reminder from the effective latest declaration and current availability rather than from every historical difference.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41cc6022dc
ℹ️ 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".
| if (validating !== undefined && 'args' in validating) { | ||
| const rewritten = await prepare(tool); | ||
| if (rewritten !== undefined) return control.returned(rewritten); | ||
| } |
There was a problem hiding this comment.
Skip duplicate preparation after validation rewrites
When a validating hook returns { args: ... }, this branch calls prepare(tool) and then falls through to the unconditional prepare(tool) on line 144. Any non-synthetic tool is therefore prepared twice, discarding the first prepared value and potentially repeating side effects in prepare/legacy resolveExecution; reuse the first result or skip the second preparation after a rewrite.
Useful? React with 👍 / 👎.
| if ( | ||
| toolSelectSchemaSignature(latestTool) === toolSelectSchemaSignature(currentSchema) && | ||
| toolSelectSchemaSignature(firstTool) !== toolSelectSchemaSignature(currentSchema) |
There was a problem hiding this comment.
Keep blocking after another live schema update
When a loaded tool has historical schemas A→B and the live registry advances again to C before another declaration is appended, latestTool no longer equals currentSchema, so this predicate stops treating the tool as pending. The request still retains only schema A, while isLoadedToolActive can regard the pinned B declaration as loaded and the executor invokes implementation C, allowing a call under a contract the model never saw. Fresh evidence beyond the prior stale-schema thread is this third-schema transition, which bypasses the newly added rejection guard; keep the tool pending whenever the live schema differs from the retained first schema, except when it is absent or has reverted to that first schema.
Useful? React with 👍 / 👎.
Requirement or Bug
启用动态工具加载的 TUI、desktop/web、ACP 与 SDK 会话在同一个工具被移除并重新加载后,可能在多条历史 system message 中携带同名工具定义,导致 Kimi 协议请求被
duplicate tool name ... between message tools拒绝,后续 turn 也无法继续。本 PR 在 tool-select resolver 的历史投影阶段去除重复定义,使每次请求只保留第一次消息级声明;完全相同的后续重复定义会被过滤,schema 不同的后新增 message 会转换为提醒,说明当前会话暂不支持更新并指引新会话。没有单独关联 issue,问题、复现和回归验证均记录在本 PR 中。
Bug Reproduction Steps
select_tools加载一个 deferred MCP 工具,使历史写入一条content: []、tools: [schema]的 system message。duplicate tool name ... between message tools拒绝。回归测试使用中性构造工具和真实 resolver 调用复现该请求结构,不依赖线上模型或真实用户会话。
Root Cause
AgentToolSelectService.shapeActiveHistory()只根据顶层 inline 工具名过滤历史 schema,没有处理不同 system message 之间的同名定义。每次select_tools加载都会追加一条 schema message,因此重载后旧、新定义会一起进入出站请求。这是 resolver 请求投影层的修复,而不是在 serializer 中掩盖问题或改写持久化历史。为避免改变已有消息前缀并维护缓存,投影保留第一次出现的旧定义;完全相同的后续重复定义直接过滤,schema 不同的后新增 message 转换为更新提醒,明确当前会话暂不支持应用新 schema 并指引新会话。提醒只针对最新仍有效的 schema 更新,A→B→A 或工具移除后不提示重启。既有顶层 inline 优先规则保持不变。
Code Changes
带正文的重复消息只移除后出现的重复 tool,正文继续保留;不同 schema 的后新增 message 转换为更新提醒,说明当前会话不支持更新并指引新会话。原始 context history、registry、wire/state 契约和 Kimi serializer 均未修改。
主要阅读位置:
packages/agent-core-v2/src/agent/toolSelect/toolSelectService.ts;回归位于现有toolSelectService.test.ts同名移除/替换用例,测试声明总数净零。Behavior Changes and Affected Users
受影响模块仅为
agent-core-v2的 tool-select resolver 及其既有测试。回归覆盖首次定义和首条消息对象保留、相同 schema 的空重复消息删除、不同 schema 转更新提醒、正文保留、原始历史不变,以及既有 inline 去重行为;还覆盖 pending 调用预检拦截、A→B→A 后提醒消失与调用恢复。未请求真实线上 provider,也未运行全仓测试;已执行本地修改测试、m0-dev 聚焦 tool-select 测试(含 E2E)、Core typecheck 和局部 type-aware lint。
验证命令与结果
corepack pnpm -C packages/agent-core-v2 exec vitest run test/agent/toolSelect/toolSelectService.test.ts --config vitest.config.ts,96/96 通过。test/agent/toolSelect三个文件,121/121 通过,包含 E2E。corepack pnpm -C packages/agent-core-v2 typecheck,通过。oxlint:0 errors;7 条 warnings 均位于未修改代码行。Checklist
/approve).(无单独 issue,问题、复现与验证见上文。)gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.(无配置、公开接口或用户文档变化。)