Repository navigation
Conversation
🦋 Changeset detectedLatest commit: c9a9dc5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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: |
Open
5 of 6 tasks
Collaborator
Author
|
Closing this release/2026-11-26 PR: the release window has passed and the same MCP timeout fix already landed on main via #5433. Branch is retained. |
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
本 PR 将 #5433(提交
2222fd5d)移植到release/2026-11-26,随 11-26 发版带出。会话创建与恢复会在
initializeLoop中等待 MCP 首轮工具发现全部 settle,单个挂起或启动缓慢的 MCP server 会把会话可用时间拖长到startupTimeoutMs(默认 30 秒)。如果简单把startupTimeoutMs默认值改成 2 秒,stdio server 每次重试都会重新spawn子进程并在 2 秒时被杀,导致冷启动稳定超过 2 秒的 stdio server 永远连不上。本 PR 将「会话启动时等待 MCP 的时长上限」与「MCP server 连接/进程启动的存活超时」解耦:默认将所有 MCP 工具按 deferred 披露,首轮最多等待 2 秒即带着已就绪工具开始对话,未就绪的 server 保持pending在后台继续按 30 秒超时连接;同时 stdio 首次启动失败不再进入无限后台重试。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
移植方式:以
release/2026-11-26tip(46d9085f)为基线移植 #5433 的单笔提交2222fd5d。业务代码、测试断言与文档语义与 #5433 完全一致,仅按 release 分支现状做以下 4 处最小适配:McpTunables.startupWaitMs类型字段与toMcpTunables透传落在 release 现有的packages/agent-core-v2/src/workspace/workspaceMcpConfig/(release 尚未合入主线的workspace/→project/重命名)。packages/agent-core-v2/test/agent/loop/loop.test.ts:feat(agent-core-v2): defer MCP tools by default and cap startup wait at 2s #5433 仅为主线 fix(loop): cancel prompts while their turn is starting #5394 新增的「取消启动中 prompt」用例补await agent.restorePersisted();release 无该用例,保持原样。packages/agent-core-v2/docs/en/llm.md:保留 release 原文(不引入主线bug-466的shapeActiveHistory说明),仅合入「Loop 基线请求平铺迟到 MCP 工具」与「Runtime inline additions」两处描述更新。scripts/checks/baselines/fixed-waits.json:release 尚无fixed-waits棘轮检查,不带入该文件。核心思路与 #5433 相同:把「等待上限」从
startupTimeoutMs中拆出来,并让迟到连上的 MCP 工具通过既有 deferred 目录与公告机制(或非动态模型的基线外平铺)在后续步骤对模型可见:mcpCore/connection-manager.ts):resolveDeferred内置兜底改为true,普通 MCP 工具与 OAuth 授权工具统一生效;server 级mcp.jsondeferred与[mcp] default_deferred = false保留为逃生口。app/mcpConfig/configSection.ts、workspace/workspaceMcpConfig/*、agent/loop/loopService.ts):新增[mcp] startup_wait_ms/KIMI_MCP_STARTUP_WAIT_MS(0–2147483647,默认2000,0表示不等;空白环境变量忽略)。限时等待ISessionMcpHandle.ready,超时只停止等待,不关闭任何 client,也不改变ready表示「首轮全部 settle」的语义;same-profile fork/btw 显式传入initialTools,继续绕过等待。connection-manager.ts):failureTarget对transport === 'stdio'且failureStreak === 0直接返回'failed',避免「每次新起子进程、到点强杀、再重起」的死循环;HTTP/SSE 启动失败及已建立连接后的掉线仍按既有指数退避自动重连。agent/toolSelect/toolSelectService.ts):当请求携带 Loop 自身冻结基线(与baselineTools()同名同序)时,将当前已连接的基线外source === 'mcp'工具(不区分 deferred/inline)去除deferred标记后平铺进请求tools;显式旁路工具覆盖列表、既有工具 schema 钉住以及 Tower 等内置 deferred 工具的行为均保持不变。docs/config-manifest.toml,以及agent-core-v2、@moonshot-ai/kimi-code-sdk、CLI/Desktop/VS Code 三份 patch changeset。Behavior Changes and Affected Users
deferred时 MCP 工具的披露方式tools<tools_added>+select_tools按需加载tools中直接可见的客户端/工作流(TUI、print、Desktop/Web、VS Code、ACP、SDK)deferred: false,或全局设[mcp] default_deferred = falsestartupTimeoutMs(默认 30s)startup_wait_ms(默认 2s),未就绪 server 保持pending在后台继续按 30s 超时连接[mcp] startup_wait_ms/KIMI_MCP_STARTUP_WAIT_MS;0表示完全不等待<tools_added>可见,非动态模型下一步直接平铺进toolsnpx/uvx冷缓存、Python 重依赖、浏览器自动化等慢启动 stdio server 的用户deferred: false且要求首个请求必须包含该工具,可调大startup_wait_msdynamically_loaded_tools的模型遇到运行期新增 MCP 工具(含deferred: false慢启动 server)tools中无对应 schematools(无deferred标记);旁路显式工具列表与内置 deferred 工具行为不变dynamically_loaded_tools能力的第三方模型且 MCP server 迟到连上或中途切换模型的用户EAGAIN、进程提前退出)reconnectRetryEnabled时进入无限指数退避后台重试failed,不自动后台重试;手动reconnect重试一次/mcp/ SDK 中手动reconnectping5s受影响模块与测试覆盖:
mcpCore/connection-manager.ts:test/mcpCore/connection-manager.test.ts覆盖内置默认 deferred 与逃生口、三传输默认 30s 透传、2s 时仍pending不关闭连接并在 30s 超时、stdio 首次启动失败/超时不重试且手动reconnect可恢复、远程启动失败仍退避重试、已连接 stdio 掉线后仍自动重连。agent/loop/loopService.ts与agent/toolSelect/toolSelectService.ts:test/agent/toolSelect/toolSelect.e2e.test.ts覆盖默认 2s 放行不取消后台连接、迟到 deferred 工具经<tools_added>+select_tools调用、非动态模型下一请求平铺 schema、KIMI_MCP_STARTUP_WAIT_MS=0立即放行、中途切换非动态模型平铺;toolSelectService.test.ts覆盖显式工具覆盖列表不被突破;towerDeferredTools.e2e.test.ts覆盖内置 deferred 工具不变;forkParity.test.ts覆盖父 agent 与 btw 子代理基线与请求工具列表一致。test/app/config/config.test.ts、test/workspace/workspaceMcpConfig覆盖startup_wait_ms解析、边界与环境变量优先级。验证结论:
tsc -p packages/agent-core-v2/tsconfig.json --noEmit0 错误;上述定向套件共 19 个测试文件 510/510 通过。46d9085f):完整pnpm lint(0 警告 0 错误,含全部守卫与棘轮检查)与check:duplication(无新增重复)通过。custom-e2e/mcp-startup-lifecycle/:4/4 通过(2s 放行不杀 stdio 子进程、dynamic/static 迟到工具可用、stdio 首败不后台重启、startup_wait_ms=0立即放行)。custom-e2e/mcp-tool-list-refresh/(需构建 CLI 产物,本次未复跑,其底层toolSelect与forkParity已由单测覆盖)。验证命令
corepack pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmitcorepack pnpm exec vitest run --reporter=agent packages/agent-core-v2/test/mcpCore/connection-manager.test.ts packages/agent-core-v2/test/agent/toolSelect packages/agent-core-v2/test/agent/loop packages/agent-core-v2/test/features/tower/towerDeferredTools.e2e.test.ts packages/agent-core-v2/test/workspace/workspaceMcpConfig packages/agent-core-v2/test/app/config/config.test.ts packages/agent-core-v2/test/session/subagent/forkParity.test.tspnpm lint与pnpm run check:duplication 46d9085f37c1b145ccfc82a24387e26aa940e94fKIMI_E2E_REPO=$PWD TSX_TSCONFIG_PATH=$PWD/tsconfig.json node --import tsx --import ./build/register-raw-text-loader.mjs ../../custom-e2e/mcp-startup-lifecycle/run.mtsChecklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.