Skip to content

fix(agent-core-v2): inline deferred tools without dynamic loading - #4971

Merged
sailist merged 1 commit into
release/2026-11-16from
bug-378-11-16-deferred-tool-fallback
Nov 16, 2026
Merged

sailist merged 1 commit into
release/2026-11-16from
bug-378-11-16-deferred-tool-fallback

Conversation

@sailist

@sailist sailist commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

在模型不支持 dynamically_loaded_tools 的会话中,initial baseline 里的 deferred 工具会被从请求中删除;全新会话没有历史加载记录,因此这些工具永远无法调用,Desktop 内置浏览器就是一个受影响场景。

本 PR 将这些工具恢复为普通 inline 默认工具,使用户在不支持动态加载的模型上也能直接调用它们,不依赖 select_tools。

Bug Reproduction Steps

  1. 创建一个 initial baseline 包含 deferred 工具的全新会话,使用不支持 dynamically_loaded_tools 的模型。
  2. 确保 History 中没有该工具的 dynamic_tool_schema,然后经过 dynamic=true 的 turn resolver 发起首次请求。
  3. 修复前,该 deferred 工具不会出现在请求 tools 中;修复后,它会作为普通 inline 工具出现,且 deferred 标记已清除。

Root Cause

requestTools() 在 dynamic=true && disclosure=false 时直接过滤 baseline 中所有 deferred === true 的条目,随后只补回 History 中曾经通过 select_tools 加载的 schema。全新会话没有这类 History,因此 initial deferred 工具被永久删除。

这是降级语义实现错误的根本修复,而不是绕过:baseline 只过滤 select_tools 自身,其余 deferred 条目统一映射为 deferred: undefined,History 中已加载的 schema 仍按原规则去重补回。

Code Changes

 requestTools(baseline, disclosure=false, dynamic=true)
-  删除 baseline 中所有 deferred 工具
+  仅删除 select_tools 自身
+  将 baseline 中的 deferred 工具转为普通 inline 工具
   按 History 去重补回已加载 schema

dynamic=true / disclosure=true 和 dynamic=false 两条路径保持不变,baseline + History 的配置来源和实时 registry 的职责均未改变。

测试同步修正原先“deferred 应被排除”的错误预期,覆盖 baseline 中从未加载过的 MCP_BETA 也保留且清除 deferred 标记,同时继续断言 select_tools 被移除、History 中已加载的 MCP_ALPHA 不重复出现。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
dynamic=true、disclosure=false,baseline 含 initial deferred 未加载过的 deferred 工具从请求中消失 保留为普通 inline 工具;select_tools 仍移除 使用不支持动态加载模型的 Desktop / CLI / SDK 会话,尤其是依赖内置 deferred 工具的全新会话 无需退路;这是恢复既有降级契约。支持动态加载及非 dynamic 请求路径不变
History 中已通过 select_tools 加载的 schema 去重补回 保持原行为 同上会话在模型切换后的请求 不变

受影响模块与验证:

  • packages/agent-core-v2/src/agent/toolSelect/toolSelectService.ts:requestTools() 的静态降级映射。
  • packages/agent-core-v2/test/agent/toolSelect/toolSelectService.test.ts:目标回归先在旧实现上失败(缺少 MCP_BETA),修复后通过;测试声明总数未增加。
  • dynamicTools、toolSelect.e2e、coreLoopService、forkParity:相关回归通过,未发现其他分支行为变化。
验证记录
  • 本地:toolSelectService.test.ts 96/96 通过。
  • m0-dev:toolSelectService、dynamicTools、toolSelect.e2e、coreLoopService、forkParity 共 159/159 通过。
  • m0-dev:@moonshot-ai/agent-core-v2 typecheck 通过。
  • 独立只读复审:未发现 P0 / P1 / P2 语义问题或公开信息问题。
  • 未在本地运行全仓完整测试;CI 作为完整验证门禁。

Checklist

  • I have read the CONTRIBUTING document.
  • I have included the reproduction steps and root cause directly in this PR.
  • 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.

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f49f5e

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 16, 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-16T12:19:13.714436Z 9f49f5e 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 16, 2026 •

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

commit: 9f49f5e

@sailist
sailist force-pushed the bug-378-11-16-deferred-tool-fallback branch from 717ddc7 to 9f49f5e Compare November 16, 2026 12:17
@sailist
sailist changed the base branch from release/2026-11-13-2 to release/2026-11-16 November 16, 2026 12:17
@sailist
sailist merged commit a29c2d0 into release/2026-11-16 Nov 16, 2026
15 checks passed
@sailist
sailist deleted the bug-378-11-16-deferred-tool-fallback branch November 16, 2026 12:55
@github-actions github-actions Bot mentioned this pull request Nov 16, 2026
wbxl2000 pushed a commit that referenced this pull request Nov 17, 2026
* fix: resume sessions with removed default models (#4982)

* fix(node-sdk): resume sessions with missing default model

* fix(cli): check auth for the resumed session model

* chore: add changeset for unavailable model recovery

* fix(agent-core-v2): stop rebuilding mismatched session indexes (#4980)

* fix(agent-core-v2): reject repeated model responses (#4977)

* fix(agent-core-v2): reject repeated model responses

* chore: add changeset for repeated model responses

---------

Co-authored-by: 7Sageer <[email protected]>

* fix(agent-core-v2): inline deferred tools without dynamic loading (#4971)

* fix(agent-core-v2): record restored task notifications without model requests (#4949) (#4989)

* fix(agent-core-v2): record restored task notifications without model requests

- queue restored task notifications as prompt-only turns after loop initialization
- preserve interrupted and queued turns during resume and fork
- complete reconciliation before initialization and reset return to keep Wire reads ordered
- run loop and container cleanup when reconciliation fails
- surface restored notification persistence failures

* chore: add changeset for restored task notifications

* fix(agent-core-v2): restore overflow recovery after LLM retries (#4950) (#4990)

* fix(agent-core-v2): restore step state after LLM retries

* test(agent-core-v2): scope retry event to overflow regression

* fix(config): allow sessions with invalid user config (#4951) (#4991)

* fix(agent-core-v2): tolerate config read failures for permission rules

* chore: add changeset for permission config recovery

* docs: document permission config recovery

* docs: qualify permission config recovery scope

* fix(config): surface read error diagnostics

* fix(config): allow sessions with invalid user config

* fix(config): preserve valid values and replay diagnostics

* fix(config): remove startup diagnostic replay

* fix(agent-core-v2): ignore non-user prompts during Tower wake (#4952) (#4992)

* fix(agent-core-v2): ignore non-user prompts during Tower wake

* chore: add Tower notification fix changeset

* fix(agent-core-v2): preserve slash prompts during Tower wake

* fix(agent-core-v2): route foreground shell events by origin (#4954) (#4994)

* fix(agent-core-v2): route foreground shell events by origin

* test(agent-core-v2): expect tool event origins in snapshots

* fix(klient): accept tool events from pre-origin hosts

* fix(agent-core-v2): run external Stop hooks after turn completion (#4956) (#4995)

* fix(agent-core-v2): run external Stop hooks after turn completion

* chore: add changeset for external Stop hooks

* docs: clarify post-turn Stop hook timing

* fix(agent-core-v2): wait for subagent quiescence (#4953) (#4993)

* fix(agent-core-v2): reject incomplete model streams (#5006)

* fix(agent-core-v2): preserve choice-level OpenAI token usage (#5017)

* fix(capability): confirm stopping WebBridge before Windows updates (#4999)

* fix(capability): confirm stopping WebBridge before Windows updates

* fix(capability): harden WebBridge update recovery

* fix(capability): restore WebBridge after startup failure

* fix(capability): wait for WebBridge process exit

* fix(capability): handle WebBridge confirmation edge cases

---------

Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>

* chore: sync release 2.6.3 back to main

* chore: finish release 2.6.3 backsync

* chore: sync node-sdk lockfile importer

* fix(sdk): preserve main core type dependencies

* fix: complete release 2.6.3 backsync

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
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