Skip to content

fix(agent-core-v2): preserve explicit loop profile binding semantics - #4840

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/loop-binding-adapter
Nov 11, 2026
Merged

sailist merged 2 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/loop-binding-adapter

Conversation

@pvzheroes125

@pvzheroes125 pvzheroes125 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Requirement or Bug

宿主需要读取 Agent 已绑定的工具名单和思考设置,以便用原值重新绑定。当前工具名单包含运行期临时激活的工具,思考设置可能经过模型能力修正。显式重绑后,旧的临时工具名单还可能继续覆盖新绑定。

Core 共用的子代理允许名单刷新也会把模型解析后的思考档位写回绑定快照。使用始终开启思考的模型时,刷新名单可以把原始 off 改写成模型默认档位。

Bug Reproduction Steps

  1. 在 Agent loop 上绑定 activeToolNames: ['Read'],调用 addActiveTool('InheritedTool') 模拟临时继承一个工具。
  2. 通过 loop.applyBindingSnapshot() 重新绑定,并将 activeToolNames 留空以恢复默认工具范围。
  3. 读取 loop.getActiveToolNames()。修复前返回 ['Read', 'InheritedTool'],预期返回 undefined,由现有工具策略决定可用工具。

名单刷新问题可在始终开启思考且默认档位为 high 的模型上复现。显式绑定 thinkingLevel: 'off' 后注册一个可加入的子代理 profile,修复前绑定快照中的 off 会变为 high。

Root Cause

已绑定的 profile 存在 loop 的内存状态中。data() 返回模型修正后的设置和包含临时增删的工具名单。loop.applyBindingSnapshot() 此前直接调用 setProfile(),保留临时增删。普通 profile 更新也使用 setProfile(),包括子代理允许名单刷新,因此显式重绑需要单独清理临时增删。

名单刷新此前以 data(current) 为基础创建新绑定。该方法会解析模型的实际思考档位,于是刷新名单时也持久化了这个解析值。

Code Changes

+ loop.bindingSnapshot() 返回只读的已绑定 profile
  loop.applyBindingSnapshot(snapshot)
+   提取已写入提示词的 AGENTS.md 路径,初始化对应的提醒状态
+   清除运行期临时工具名单
    setProfile(snapshot)
  刷新已绑定的子代理允许名单
-   从 data(current) 创建替换快照
+   复制当前绑定快照,仅替换 subagents

bindingSnapshot() 直接读取 loop 已持有的快照,保留绑定的思考级别和工具名单。applyBindingSnapshot() 与新 Agent 初始化复用已有的 AGENTS.md 路径提取和提醒初始化逻辑。

Behavior Changes and Affected Users

行为 修改前 修改后 受影响调用方 退路
读取已绑定的工具名单和思考级别 loop 的 data() 提供运行值 bindingSnapshot() 提供只读绑定值,data() 继续提供运行值 使用 Core loop 的宿主 需要运行值时继续使用 data()
显式绑定快照 保留临时工具增删 清除临时增删并使用本次绑定的名单 调用 loop.applyBindingSnapshot() 的宿主 需要保留临时增删时可继续使用 setProfile()
普通 setProfile() 更新 保留临时工具增删 仍保留临时工具增删 子代理允许名单刷新 不需要
名单刷新时持久化的思考设置 始终开启思考的模型可能将原始 off 写成实际档位 持久化原始 off,请求仍按模型能力解析实际档位 Core 共用的 profile catalog 刷新与恢复流程 不需要
从快照初始化 AGENTS.md 提醒 新 Agent 初始化在发出配置状态后初始化提醒,显式 loop 重绑不初始化提醒 两处均复用路径提取和提醒初始化,新 Agent 在发出配置状态前完成提醒初始化 继承 profile 的 fork 和显式重绑调用方 不需要

回归测试覆盖绑定名单与临时增删、普通更新、显式恢复默认工具范围,以及 AGENTS.md 路径提取和提醒初始化。名单刷新回归验证子代理成功加入,原始档位保持 off,有效档位仍为 high。Kimi Code 的 fork 继续走现有的 Agent 初始化入口。此次验证使用本地测试,模型使用测试配置。

首轮 GitHub 检查中 15 项通过,Windows 作业按现有配置跳过。测试分片 2 的 SDK 用例在 source.undoHistory(1) 报 records.write_failed,运行到该行时尚未创建 fork。在同一环境对主线基线 aa839f05f 重复运行该用例 6 次,其中 2 次复现同一错误。当前账号缺少 GitHub Actions 重跑权限。首轮失败的测试分片

修复提交 a254fe05c 的 GitHub 检查中 15 项通过,Windows 作业按配置跳过。首轮失败的 SDK 用例本轮通过。分片 2 有一项失败,taskManager.test.ts 的零超时等待用例收到 completed,预期为 running。在本地用修复提交和主线 aa839f05f 分别跑该文件,均为 53 项通过。本轮失败的测试分片

本地验证
  • Agent Core 与依赖构建通过,Agent Core 类型检查通过。
  • binding.test.ts、profileOps.test.ts、toolSelectService.test.ts 和 loop hooks.test.ts 共 209 项通过。
  • agentLifecycle.test.ts 和 agentsMdReminder.test.ts 共 133 项通过。
  • 全仓 pnpm run lint 通过,0 个错误。
  • 名单刷新修复前,扩展用例在刷新后读到 high,预期为 off。修复后 binding.test.ts 与 thinking.test.ts 共 87 项通过,Core 类型检查和改动文件 lint 通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue.(问题和复现步骤已写在本 PR。)
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete.
  • Ran gen-changesets skill. 名单刷新修复持久化的原始档位,CLI 的思考设置入口与模型档位解析规则保持原样。
  • This PR needs no user documentation update.

@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a254fe0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T12:44:21.933449Z a254fe0 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 Nov 11, 2026 •

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

commit: a254fe0

@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: d11885c56c

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

}

bindingSnapshot(): ProfileBindingSnapshot {
return this.profileAdapter.snapshot();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve raw thinking through allowlist refreshes

When a main agent explicitly binds thinkingLevel: 'off' to an alwaysThinking model and a catalog change alters its derived subagent allowlist, AgentProfileService.refreshBoundSubagentAllowlist() builds the replacement from data(current) (profileService.ts:283), which converts off to the model's effective/default effort, and profileAdapter.ts:223 then stores that converted value. This new accessor therefore returns (for example) high instead of the explicit off, so a host's later snapshot rebind still cannot preserve the setting this API is intended to expose; construct the allowlist-only replacement from the raw current snapshot instead.

AGENTS.md reference: AGENTS.md:L130-L132

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowlist refresh now copies the current binding snapshot and replaces only subagents. The existing catalog refresh test now verifies that a newly discovered subagent is added, the stored effort stays off, and the effective effort stays high for an always-thinking model.

The new assertion reproduced the rewrite before the fix. Both targeted test files pass after the fix (87 tests).

@pvzheroes125

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: a254fe05cf

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

@sailist
sailist merged commit d64909f into MoonshotAI:main Nov 11, 2026
29 of 30 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 15, 2026
Port MoonshotAI#4901, MoonshotAI#4909 and MoonshotAI#4911: complete the task before asserting a
zero-timeout wait sees the completed snapshot, restore the instructions
reload spy after the failure assertion, poll the search index until it is
ready before asserting the page, and run remote-session git probes
through a host process that refuses gh.

Record MoonshotAI#4840 as equivalent (the refresh path already rebuilds from the
effective binding here) and pin it with a regression case, record MoonshotAI#4883
as ported with the compaction profile already present, and record MoonshotAI#4830
as blocked on the absent loop requester/request-attribution layering.
Clear the generated-bundle, release-sync and working-notes rows with
their applicable verdicts.
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