Repository navigation
fix(agent-core-v2): pin the initial tool baseline after startup MCP discovery - #5217
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 444c5a1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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: |
sailist
force-pushed
the
bug-414-11-22-mcp-startup-tools
branch
2 times, most recently
from
November 22, 2026 06:04
6effc90 to
cd0a629
Compare
5 of 6 tasks
sailist
force-pushed
the
bug-414-11-22-mcp-startup-tools
branch
from
November 22, 2026 08:54
cd0a629 to
444c5a1
Compare
6 tasks done
sailist
added a commit
that referenced
this pull request
Nov 23, 2026
7Sageer
pushed a commit
that referenced
this pull request
Nov 23, 2026
sailist
added a commit
that referenced
this pull request
Nov 23, 2026
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
Resolve #4904。
2.6.0 引入的回归:会话在初始 MCP 发现完成前就固定了工具基线,启动较慢的 MCP 服务器发现的工具对整个会话不可见——
tool_select.initialized包含全部工具,但llm.tools_snapshot缺失这些工具,后续 turn 也不会恢复。本 PR 之后,启动期发现的 MCP 工具从首个请求起就在请求工具列表里。Bug Reproduction Steps
See linked issue(慢速 stdio MCP 服务器 + 新会话立即提交 prompt,观察首个请求的
llm.tools_snapshot)。Root Cause
根本修复,非绕过。
agent 的请求工具列表来自 loop 启动时钉死的基线(
profile.tools),而不是 toolSelect 的工具目录。initializeLoop()捕获基线时不等待 MCP 就绪,钉入的是启动瞬间的注册表快照;之后没有任何路径重建基线。启动期稍晚发现的 MCP 工具只进入 toolSelect 目录和公告,永远到不了请求——这就是 issue 里"目录有、请求没有"的分层错位。修复把"等待 MCP 首轮发现 settle"放到钉基线之前:等待之后注册表必然完整(connected 事件同步注册工具,且先于连接尝试 resolve),此刻钉入的基线天然包含启动期发现的全部 MCP 工具。
Code Changes
核心思路:把 MCP 就绪等待收敛到 loop 启动这唯一一处,钉基线发生在等待之后;会话过程中不再有任何对 MCP 连接的 await,工具增删改全部走既有的事件驱动 reconcile。
关键决策:
initializeLoop钉基线前prepareInitialTools钩子(issue 评论区的方案)packages/core,不新增钩子机制,改动面最小unprovideUnit('reminder')会级联 disposeAgentLoopService),留作后续项阅读指南:先看
packages/agent-core-v2/src/agent/loop/loopService.ts的initializeLoop(全部修复就这一处等待),再看mcpService.ts与toolSelectService.ts的删除(纯收敛),测试看toolSelect.e2e.test.ts的启动发现三例与forkParity.test.ts的基线一致两例。可略读:changeset 与测试桩清理。Behavior Changes and Affected Users
POST /sessions、ACPsession/new、desktop 打开会话startupTimeoutMs;不配置 MCP 无影响turn.endedcancelled)受影响模块与测试覆盖:
loopService.initializeLoop(等待 + 钉基线):toolSelect.e2e.test.ts启动发现公告用例、disclosure 形态矩阵(inline/deferred × 开关)、"启动等待期间按 id 取消排队 prompt"用例;forkParity.test.tsstartup/runtime 两用例断言 fork 基线与父 loop 基线完全一致。mcpService钩子删除:mcp.test.ts+ 上述 e2e(原 "holds the LLM step" 用例随钩子删除,契约由 e2e 在真实入口覆盖)。reconcileForRequest等待删除:toolSelectService.test.ts+ e2e。forkParity.test.ts新增 2 用例。验证记录
tsc -p packages/agent-core-v2/tsconfig.json --noEmit通过。check-comments.mjs与check:duplication在 jj-only 工作区因 git 根解析上溯无法整体运行(预存在的工具问题),已改为对全部改动文件显式验证无注释。testkitAgentFixtures+model.script,fork 子代理走subagentlane);toolSelect.e2e 的 legacymockNextResponse计数 44 → 42(净减少,基线已随 PR 下调),forkParity 保持 14 零新增。forkParity 新用例将 btw fork 安排在父代理任何 turn 之前:harness 的PersistenceAppendLogStore.read不按 scope 过滤,父代理已有 turn 时子代理 restore 会 replay 到父记录、触发initializeHistory的 BugIndicatingError(基线同样复现的 harness 限制),父历史为空时 fork 不调用 initializeHistory,语义不变。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.