Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(host-core): make the desktop tool dispatch budget actually nest
vastsaa8794133eaee
diff --git a/apps/desktop/test/plugin-timeout-budgets.test.mjs b/apps/desktop/test/plugin-timeout-budgets.test.mjsindex 4d869f97a..7a3ddf0ce 100644--- a/apps/desktop/test/plugin-timeout-budgets.test.mjs+++ b/apps/desktop/test/plugin-timeout-budgets.test.mjs@@ -22,6 +22,8 @@ const pluginMcp = source("apps/desktop/electron/main/plugin-mcp.ts");const sharedTimeouts = source("packages/shared/src/rpc-timeouts.ts");const hostTools = source("crates/host-core/src/tools/mod.rs");const hostPermissions = source("crates/host-core/src/permissions.rs");+const hostToolBudget = source("crates/host-core/src/tool_budget.rs");+const hostRpc = source("crates/host-core/src/rpc/mod.rs");test("plugin completion and MCP calls fit inside the plugin tool budget", () => {const tool = constMs(pluginRuntime, "PLUGIN_TOOL_TIMEOUT_MS");@@ -29,12 +31,39 @@ test("plugin completion and MCP calls fit inside the plugin tool budget", () =>assert.ok(constMs(pluginMcp, "MCP_CALL_TIMEOUT_MS") < tool);});-test("host-core dispatch outlasts the plugin tool budget and matches its TS mirror", () => {+test("host-core dispatch outlasts every Electron budget it wraps", () => {const hostDispatch = constMs(hostTools, "DESKTOP_TOOL_DISPATCH_TIMEOUT_MS");assert.ok(constMs(pluginRuntime, "PLUGIN_TOOL_TIMEOUT_MS") < hostDispatch);+ // An `mcp_` call has no plugin-tool budget around it: it runs in Electron+ // main, which pays the lazy handshake and the whole `tools/list` traversal+ // before the call itself, all inside the same dispatch.+ const mcpLeg =+ constMs(pluginMcp, "MCP_CONNECT_TIMEOUT_MS") ++ constMs(pluginMcp, "MCP_TOOL_DISCOVERY_TIMEOUT_MS") ++ constMs(pluginMcp, "MCP_CALL_TIMEOUT_MS");+ assert.ok(mcpLeg < hostDispatch, `MCP leg ${mcpLeg}ms >= dispatch ${hostDispatch}ms`);+});++test("host-core dispatches through the shared dispatch deadline", () => {+ // The constants can be right while the call site ignores them: this is where+ // a hard-coded 60s lived, and reverting that one line would leave every other+ // assertion in this file green.+ assert.match(+ hostRpc,+ /is_desktop_dispatched\(&p\.tool_name\)[\s\S]{0,400}?desktop_dispatch_timeout_ms\(p\.timeout_ms\)/,+ "tools.execute must dispatch desktop tools through desktop_dispatch_timeout_ms",+ );+});++test("host-core budgets match their TypeScript mirrors", () => {+ const hostDispatch = constMs(hostTools, "DESKTOP_TOOL_DISPATCH_TIMEOUT_MS");assert.equal(constMs(sharedTimeouts, "DESKTOP_TOOL_DISPATCH_TIMEOUT_MS"), hostDispatch);assert.equal(constMs(sharedTimeouts, "PERMISSION_TIMEOUT_MS"),constMs(hostPermissions, "PERMISSION_TIMEOUT_MS"),);+ assert.equal(+ constMs(sharedTimeouts, "TOOL_QUEUE_WAIT_MS"),+ constMs(hostToolBudget, "TOOL_QUEUE_WAIT_MS"),+ );});diff --git a/crates/host-core/src/tool_budget.rs b/crates/host-core/src/tool_budget.rsindex 244965d8c..3e224d2a9 100644--- a/crates/host-core/src/tool_budget.rs+++ b/crates/host-core/src/tool_budget.rs@@ -13,7 +13,12 @@ pub const MAX_IN_FLIGHT_MUTATIONS_PER_SESSION: usize = 1;pub const MAX_IN_FLIGHT_PLUGINS: usize = 4;pub const MAX_IN_FLIGHT_PER_SESSION: usize = 4;pub const MAX_QUEUED_TOOLS: usize = 64;-const QUEUE_WAIT: Duration = Duration::from_secs(30);+/// How long a call waits for its class permit before admission fails. A call+/// waits here after the permission gate and before it runs, so the transport+/// deadline has to carry it too. Mirrored by `TOOL_QUEUE_WAIT_MS` in+/// `packages/shared/src/rpc-timeouts.ts`.+pub const TOOL_QUEUE_WAIT_MS: u64 = 30_000;+const QUEUE_WAIT: Duration = Duration::from_millis(TOOL_QUEUE_WAIT_MS);#[derive(Debug, Clone, Copy, PartialEq, Eq)]enum ToolClass {diff --git a/crates/host-core/src/tools/mod.rs b/crates/host-core/src/tools/mod.rsindex 2c786d198..58211d47c 100644--- a/crates/host-core/src/tools/mod.rs+++ b/crates/host-core/src/tools/mod.rs@@ -964,13 +964,16 @@ pub fn is_desktop_dispatched(tool_name: &str) -> bool {}/// How long host-core waits for Electron main to answer an approved-/// desktop-dispatched tool. It must outlast Electron's own budgets (plugin-/// tool 110s, MCP call 100s, plugin `agent.complete` 90s) so the innermost-/// layer reports its own timeout instead of being cut off here-/// (`07-plugins/12-plugin-ipc-and-host-services.md`, ADR 0038). Mirrored by-/// `DESKTOP_TOOL_DISPATCH_TIMEOUT_MS` in `packages/shared/src/rpc-timeouts.ts`,-/// which sizes the transport deadline around it.-pub const DESKTOP_TOOL_DISPATCH_TIMEOUT_MS: u64 = 120_000;+/// desktop-dispatched tool. It must outlast every budget Electron enforces+/// inside it — the plugin tool budget (110s), and the widest MCP leg: a lazy+/// handshake (10s) plus the whole `tools/list` traversal (30s) plus the call+/// (100s) — so the innermost layer reports its own timeout instead of being cut+/// off here (`07-plugins/12-plugin-ipc-and-host-services.md`, ADR 0038).+/// Mirrored by `DESKTOP_TOOL_DISPATCH_TIMEOUT_MS` in+/// `packages/shared/src/rpc-timeouts.ts`, which sizes the transport deadline+/// around it. The admission queue wait happens before this budget starts, so+/// that transport deadline carries it instead of this constant.+pub const DESKTOP_TOOL_DISPATCH_TIMEOUT_MS: u64 = 150_000;/// Dispatch deadline for a desktop-dispatched tool. The sidecar sends no/// `timeoutMs` for these tools, so the default is what normally applies.@@ -2837,16 +2840,29 @@ mod tests {}#[test]- fn desktop_dispatch_outlasts_the_electron_plugin_tool_budget() {- // Electron main gives a plugin tool 110s (`PLUGIN_TOOL_TIMEOUT_MS`).- // host-core must not give up first, or a plugin that is still inside- // its own budget (e.g. an `agent.complete` call) gets TOOL_TIMEOUT.- const ELECTRON_PLUGIN_TOOL_TIMEOUT_MS: u64 = 110_000;+ fn desktop_dispatch_outlasts_every_electron_budget_it_wraps() {+ // Copies of the Electron budgets, bound to their sources by+ // `apps/desktop/test/plugin-timeout-budgets.test.mjs`, which reads both+ // sides: the plugin tool budget (`PLUGIN_TOOL_TIMEOUT_MS`, 110s) and the+ // widest MCP leg (`MCP_CONNECT_TIMEOUT_MS` + `MCP_TOOL_DISCOVERY_TIMEOUT_MS`+ // + `MCP_CALL_TIMEOUT_MS`). host-core must not give up first, or a tool+ // that is still inside its own budget (e.g. an `agent.complete` call, or+ // an MCP call that first pays a lazy handshake and a catalog traversal)+ // gets TOOL_TIMEOUT.+ const PLUGIN_TOOL_TIMEOUT_MS: u64 = 110_000;+ const MCP_CONNECT_TIMEOUT_MS: u64 = 10_000;+ const MCP_TOOL_DISCOVERY_TIMEOUT_MS: u64 = 30_000;+ const MCP_CALL_TIMEOUT_MS: u64 = 100_000;+assert_eq!(desktop_dispatch_timeout_ms(None),DESKTOP_TOOL_DISPATCH_TIMEOUT_MS);- assert!(desktop_dispatch_timeout_ms(None) > ELECTRON_PLUGIN_TOOL_TIMEOUT_MS);+ assert!(desktop_dispatch_timeout_ms(None) > PLUGIN_TOOL_TIMEOUT_MS);+ assert!(+ desktop_dispatch_timeout_ms(None)+ > MCP_CONNECT_TIMEOUT_MS + MCP_TOOL_DISCOVERY_TIMEOUT_MS + MCP_CALL_TIMEOUT_MS+ );assert_eq!(desktop_dispatch_timeout_ms(Some(5_000)), 5_000);}diff --git a/docs/adr/0038-plugin-mcp-bridge.md b/docs/adr/0038-plugin-mcp-bridge.mdindex ad9a11781..3b1ef370e 100644--- a/docs/adr/0038-plugin-mcp-bridge.md+++ b/docs/adr/0038-plugin-mcp-bridge.md@@ -37,7 +37,12 @@ differently.3. The client lives in `apps/desktop/electron/main/plugin-mcp.ts` and speaksprotocol `2025-06-18`: `initialize`, `tools/list`, `tools/call`. Framing isNDJSON over stdio pipes, or streamable HTTP with SSE responses. Budgets: 10s- to complete the handshake, 100s per call (under the 110s plugin tool budget,+ to complete the handshake, 100s per call, 4MB per stdio line, 8 servers per+ plugin. 2048 tools, 100 `tools/list` pages, 30s for the whole traversal, and+ a cursor that repeats or is malformed — a server that breaks any bound is+ refused instead of truncated. host-core's 150s dispatch deadline carries the+ whole leg — handshake, traversal, and call — so the client reports its own+ timeout first.itself under host-core's 120s), 4MB per stdio line, 8 servers per plugin.2048 tools, 100 `tools/list` pages, 30s for the whole traversal, and a cursorthat repeats or is malformed — a server that breaks any bound is refuseddiff --git a/docs/diagrams/plugin-architecture.html b/docs/diagrams/plugin-architecture.htmlindex 214626e66..d1afc7a78 100644--- a/docs/diagrams/plugin-architecture.html+++ b/docs/diagrams/plugin-architecture.html@@ -481,7 +481,7 @@<li><span class="step-n">1</span><span class="step-where" style="--tint:var(--agent)">Sidecar</span><span class="step-what">模型发起 tool_use,工具名形如 <code>plugin_demo_hello_echo</code></span></li><li><span class="step-n">2</span><span class="step-where" style="--tint:var(--rust)">host-core</span><span class="step-what"><code>plugin_</code> 前缀命中 → 不本地执行,改发 <code>plugins.execute</code> 通知(executionId + toolCallId)</span></li><li><span class="step-n">3</span><span class="step-where" style="--tint:var(--main)">Main</span><span class="step-what">按 fullName 在注册表找工具;找不到即 <code>TOOL_NOT_FOUND</code></span></li>- <li><span class="step-n">4</span><span class="step-where" style="--tint:var(--child)">Child</span><span class="step-what"><code>tool.execute</code> 帧下发,预算 <span class="gate">110s</span><em>(压在 host-core 120s 之下,好让插件侧错误先返回)</em></span></li>+ <li><span class="step-n">4</span><span class="step-where" style="--tint:var(--child)">Child</span><span class="step-what"><code>tool.execute</code> 帧下发,预算 <span class="gate">110s</span><em>(压在 host-core 150s 调度之下,好让插件侧错误先返回)</em></span></li><li><span class="step-n">5</span><span class="step-where" style="--tint:var(--child)">Child</span><span class="step-what">执行 <code>tool.execute(args, ctx)</code>,ctx 提供 sessionId/turnId/log;抛错归一化为 <code>TOOL_FAILED</code></span></li><li><span class="step-n">6</span><span class="step-where" style="--tint:var(--rust)">host-core</span><span class="step-what"><code>plugins.resolveExecution</code> 回填结果 → 进模型上下文;同时 <code>logger.app</code> 落审计、drainToasts 推 UI</span></li></ol>@@ -583,7 +583,7 @@<li><code>PLUGIN_LOAD_TIMEOUT_MS</code> — 15s(模块求值 + onLoad)</li><li><code>PLUGIN_HOOK_TIMEOUT_MS</code> — 5s(onUnload)</li><li><code>PLUGIN_COMMAND_TIMEOUT_MS</code> — 30s(面向用户,快速失败)</li>- <li><code>PLUGIN_TOOL_TIMEOUT_MS</code> — 110s(< host-core 的 120s)</li>+ <li><code>PLUGIN_TOOL_TIMEOUT_MS</code> — 110s(< host-core 的 150s)</li><li>watcher 去抖 300ms / 最多 16 个开发插件</li></ul></div>diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex bc02cdb00..4800eb9ed 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -7706,6 +7706,7 @@ identify the platform validation still needed.| Security (imported extension dependencies) | E2E-PLUGIN-import-extension-installs-dependencies, E2E-PLUGIN-import-extension-reports-missing-dependency || Quality (imported extension dependencies) | E2E-PLUGIN-import-extension-installs-dependencies, E2E-PLUGIN-import-extension-reports-missing-dependency || F / G / Security / Quality — Imported extension npm recovery | E2E-PLUGIN-import-extension-recovers-missing-npm |+| G — Plugins (desktop tool dispatch budget) | E2E-PLUGIN-slow-tool-is-not-cut-off-by-host-dispatch || C — Conversation & stream (Independent session communication) | E2E-SESSION-independent-top-level-communication || D — Plugin security (Independent session communication) | E2E-SESSION-independent-top-level-communication || G — Plugins (Independent session communication) | E2E-SESSION-independent-top-level-communication |@@ -7752,6 +7753,7 @@ identify the platform validation still needed.| Post-MVP remote control | E2E-221, E2E-222, E2E-223, E2E-224, E2E-225, E2E-226, E2E-227, E2E-228, E2E-229, E2E-230, E2E-231, E2E-232 || Trusted extensions (R7 v1) | E2E-241, E2E-242, E2E-TRUSTED-EXTENSION-custom-agent-stream-and-binding, E2E-243, E2E-244, E2E-245, E2E-PLUGIN-imported-pi-package-skills, E2E-PLUGIN-import-extension-installs-dependencies, E2E-PLUGIN-import-extension-reports-missing-dependency, E2E-PLUGIN-declared-provider-appears-in-the-native-provider-list || Trusted extensions (R7 v1 npm recovery) | E2E-PLUGIN-import-extension-recovers-missing-npm |+| Post-MVP regression coverage (plugin tool dispatch) | E2E-PLUGIN-slow-tool-is-not-cut-off-by-host-dispatch || M6+ (Project delete) | E2E-PROJECT-delete-removes-project-and-owned-sessions || M6+ (Two-click delete) | E2E-SESSION-two-click-delete-arms-first || C — Conversation & stream (model fallback) | E2E-SUBAGENT-ordered-model-fallback-preserves-work |@@ -13694,18 +13696,21 @@ the latest destination. These assertions measure work counts, not device FPS.the call to finish. Repeat with the permission card left open for a whilebefore approving.- **Expected:** The call returns the plugin's result. host-core does not answer- `TOOL_TIMEOUT` before Electron's plugin tool budget expires, and no transport- layer reports `host RPC timeout` or `sidecar RPC timeout` for the call. Budgets- nest from the inside out: plugin `agent.complete` 90s < MCP call 100s < plugin- tool 110s < host-core dispatch 120s, and the transport deadline covers the- permission wait plus that dispatch.+ `TOOL_TIMEOUT` before Electron's budget expires, and no transport layer reports+ `host RPC timeout`, `sidecar RPC timeout`, or `parent host proxy timeout` for+ the call. Budgets nest from the inside out: plugin `agent.complete` 90s < MCP+ call 100s < plugin tool 110s < host-core dispatch 150s, while the widest MCP leg+ (a lazy handshake, then a `tools/list` traversal, then the call) is 140s. The+ transport deadline covers the permission wait, the admission queue wait, and+ that dispatch, so a call that waited for a saturated plugin class before it was+ dispatched is still inside it.- **Specs:** `07-plugins/12-plugin-ipc-and-host-services.md` agent-tooldispatch; ADR 0038; ADR 0174.- **Acceptance:** G (plugin agent tool).- **Milestone:** Post-MVP regression coverage.- **Automation:** `apps/desktop/test/plugin-timeout-budgets.test.mjs` checks the- budget order across the TypeScript and Rust sources;- `packages/shared/src/protocol.test.ts` covers the transport deadline;- host-core `desktop_dispatch_outlasts_the_electron_plugin_tool_budget` covers- the dispatch default.+ budget order and the dispatch call site across the TypeScript and Rust sources;+ `packages/shared/src/protocol.test.ts` covers the transport deadline; host-core+ `desktop_dispatch_outlasts_every_electron_budget_it_wraps` covers the dispatch+ default.- **Status:** Contract-covered; no end-to-end driver waits out a real 70s call.diff --git a/docs/spec/07-plugins/12-plugin-ipc-and-host-services.md b/docs/spec/07-plugins/12-plugin-ipc-and-host-services.mdindex 4e88975ea..cc30776cb 100644--- a/docs/spec/07-plugins/12-plugin-ipc-and-host-services.md+++ b/docs/spec/07-plugins/12-plugin-ipc-and-host-services.md@@ -207,7 +207,7 @@ Panel bridge file channels are permission-gated as follows:**Implemented (2026-07-29, ADR 0008):** the broker lives in`electron/main/plugin-runtime.ts` and every plugin call is a request to theplugin's own `utilityProcess`. Budgets: load 15s, lifecycle hook 5s, command 30s,-tool 110s (under host-core's 120s tool budget). On process exit the broker+tool 110s (under host-core's 150s dispatch budget). On process exit the brokerrejects pending calls with `PLUGIN_CRASHED`, deregisters that plugin's commandsand tools, closes its panel, writes a `plugin.crash` audit entry, and emits atoast plus `pluginChanged` to the renderer.@@ -237,12 +237,14 @@ permission gate and result envelope stay in host-core:Electron main executing the registered plugin tool JS and answering via RPC`plugins.resolveExecution` `{ executionId, ok, content, errorCode? }`.4. host-core resolves the pending execution and returns a standard- `ToolsExecuteResult` to the sidecar. Dispatch waits up to 120s- (`DESKTOP_TOOL_DISPATCH_TIMEOUT_MS`, above the 110s plugin tool budget) and- then maps to `TOOL_TIMEOUT`; an unknown/unloaded tool maps to- `TOOL_NOT_FOUND`. The transport deadline for these calls covers the- permission wait plus that dispatch plus 10s of slack (`rpcTimeoutMs`), so no- outer layer gives up before host-core reports the outcome.+ `ToolsExecuteResult` to the sidecar. Dispatch waits up to 150s+ (`DESKTOP_TOOL_DISPATCH_TIMEOUT_MS`, above both the 110s plugin tool budget+ and the widest MCP leg — a 10s lazy handshake, a 30s `tools/list` traversal,+ then the 100s call) and then maps to `TOOL_TIMEOUT`; an unknown/unloaded tool+ maps to `TOOL_NOT_FOUND`. The transport deadline for these calls covers the+ 120s permission wait, the 30s admission queue wait, that dispatch, and 10s of+ slack (`rpcTimeoutMs`), so no outer layer gives up before host-core reports+ the outcome.The model-facing registry gains plugin tools per prompt: main passes registereddefs (`fullName`, description, JSON-schema parameters) to `agent.prompt`, anddiff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex 00ba4e453..bdf24dffa 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -5097,6 +5097,7 @@ IPC 请求无法关闭。| 安全性(导入扩展依赖) | E2E-PLUGIN-import-extension-installs-dependencies、E2E-PLUGIN-import-extension-reports-missing-dependency || 品质(导入扩展依赖) | E2E-PLUGIN-import-extension-installs-dependencies、E2E-PLUGIN-import-extension-reports-missing-dependency || F / G / 安全性 / 品质 — 导入扩展的 npm 恢复 | E2E-PLUGIN-import-extension-recovers-missing-npm |+| G — 插件(桌面工具调度预算) | E2E-PLUGIN-slow-tool-is-not-cut-off-by-host-dispatch || C — 对话与流式(独立会话通信) | E2E-SESSION-independent-top-level-communication || D — 插件安全(独立会话通信) | E2E-SESSION-independent-top-level-communication || G — 插件(独立会话通信) | E2E-SESSION-independent-top-level-communication |@@ -5137,6 +5138,7 @@ IPC 请求无法关闭。| MVP 后远程控制 | E2E-221、E2E-222、E2E-223、E2E-224、E2E-225、E2E-226、E2E-227、E2E-228、E2E-229、E2E-230、E2E-231、E2E-232 || 受信任扩展(R7 v1) | E2E-241、E2E-242、E2E-243、E2E-244、E2E-245、E2E-PLUGIN-imported-pi-package-skills、E2E-PLUGIN-import-extension-installs-dependencies、E2E-PLUGIN-import-extension-reports-missing-dependency、E2E-PLUGIN-declared-provider-appears-in-the-native-provider-list || 受信任扩展(R7 v1 npm 恢复) | E2E-PLUGIN-import-extension-recovers-missing-npm |+| Post-MVP 回归覆盖(插件工具调度) | E2E-PLUGIN-slow-tool-is-not-cut-off-by-host-dispatch || M6+(删除项目) | E2E-PROJECT-delete-removes-project-and-owned-sessions || M6+(两步删除) | E2E-SESSION-two-click-delete-arms-first || C — 对话和直播(模型回退) | E2E-SUBAGENT-ordered-model-fallback-preserves-work |@@ -8078,18 +8080,21 @@ the latest destination. These assertions measure work counts, not device FPS.the call to finish. Repeat with the permission card left open for a whilebefore approving.- **Expected:** The call returns the plugin's result. host-core does not answer- `TOOL_TIMEOUT` before Electron's plugin tool budget expires, and no transport- layer reports `host RPC timeout` or `sidecar RPC timeout` for the call. Budgets- nest from the inside out: plugin `agent.complete` 90s < MCP call 100s < plugin- tool 110s < host-core dispatch 120s, and the transport deadline covers the- permission wait plus that dispatch.+ `TOOL_TIMEOUT` before Electron's budget expires, and no transport layer reports+ `host RPC timeout`, `sidecar RPC timeout`, or `parent host proxy timeout` for+ the call. Budgets nest from the inside out: plugin `agent.complete` 90s < MCP+ call 100s < plugin tool 110s < host-core dispatch 150s, while the widest MCP leg+ (a lazy handshake, then a `tools/list` traversal, then the call) is 140s. The+ transport deadline covers the permission wait, the admission queue wait, and+ that dispatch, so a call that waited for a saturated plugin class before it was+ dispatched is still inside it.- **Specs:** `07-plugins/12-plugin-ipc-and-host-services.md` agent-tooldispatch; ADR 0038; ADR 0174.- **Acceptance:** G (plugin agent tool).- **Milestone:** Post-MVP regression coverage.- **Automation:** `apps/desktop/test/plugin-timeout-budgets.test.mjs` checks the- budget order across the TypeScript and Rust sources;- `packages/shared/src/protocol.test.ts` covers the transport deadline;- host-core `desktop_dispatch_outlasts_the_electron_plugin_tool_budget` covers- the dispatch default.+ budget order and the dispatch call site across the TypeScript and Rust sources;+ `packages/shared/src/protocol.test.ts` covers the transport deadline; host-core+ `desktop_dispatch_outlasts_every_electron_budget_it_wraps` covers the dispatch+ default.- **Status:** Contract-covered; no end-to-end driver waits out a real 70s call.diff --git a/docs/zh-CN/spec/07-plugins/12-plugin-ipc-and-host-services.md b/docs/zh-CN/spec/07-plugins/12-plugin-ipc-and-host-services.mdindex 9a5370aef..187123e23 100644--- a/docs/zh-CN/spec/07-plugins/12-plugin-ipc-and-host-services.md+++ b/docs/zh-CN/spec/07-plugins/12-plugin-ipc-and-host-services.md@@ -182,7 +182,7 @@ plugin runtime**实施(2026-07-29,ADR 0008):** 经纪人居住在`electron/main/plugin-runtime.ts` 和每个插件调用都是对插件自己的 `utilityProcess`。预算:加载 15 秒,生命周期挂钩 5 秒,命令 30 秒,-工具 110 秒(根据 host-core 的 120 秒工具预算)。进程退出经纪人+工具 110 秒(根据 host-core 的 150 秒调度预算)。进程退出经纪人使用 `PLUGIN_CRASHED` 拒绝挂起的调用,取消注册该插件的命令和工具,关闭其面板,写入 `plugin.crash` 审核条目,并发出toast 加上 `pluginChanged` 到渲染器。@@ -212,11 +212,12 @@ toast 加上 `pluginChanged` 到渲染器。Electron主要执行注册的插件工具JS并通过RPC应答`plugins.resolveExecution` `{ executionId, ok, content, errorCode? }`。4. host-core 解析待执行并返回一个标准- `ToolsExecuteResult` 到 sidecar。调度最多等待 120 秒- (`DESKTOP_TOOL_DISPATCH_TIMEOUT_MS`,高于 110 秒的插件工具预算),超时映射到- `TOOL_TIMEOUT`; unknown/unloaded 工具映射到 `TOOL_NOT_FOUND`。这类调用的传输- 截止时间覆盖权限等待、上述调度和 10 秒余量(`rpcTimeoutMs`),因此外层不会在- host-core 报告结果之前先放弃。+ `ToolsExecuteResult` 到 sidecar。调度最多等待 150 秒+ (`DESKTOP_TOOL_DISPATCH_TIMEOUT_MS`,高于 110 秒的插件工具预算,也高于最宽的+ MCP 支路:10 秒惰性握手 + 30 秒 `tools/list` 遍历 + 100 秒调用),超时映射到+ `TOOL_TIMEOUT`;unknown/unloaded 工具映射到 `TOOL_NOT_FOUND`。这类调用的传输截止+ 时间覆盖 120 秒权限等待、30 秒准入排队、上述调度和 10 秒余量(`rpcTimeoutMs`),+ 因此外层不会在 host-core 报告结果之前先放弃。面向模型的注册表根据提示获得插件工具:已注册主要通道defs(`fullName`、描述、JSON 架构参数)到 `agent.prompt`,以及diff --git a/packages/shared/src/protocol.test.ts b/packages/shared/src/protocol.test.tsindex a2c7bc149..a4b309c5b 100644--- a/packages/shared/src/protocol.test.ts+++ b/packages/shared/src/protocol.test.ts@@ -242,23 +242,25 @@ describe("Plan protocol contracts", () => {);});- it("covers the permission wait and host-core dispatch for plugin and MCP tools", () => {- // Permission (120s) + host-core dispatch (120s) + slack (10s). A flat 130s- // would cut off a prompted plugin tool that is still inside its budget.+ it("covers the permission wait, the admission queue, and host-core dispatch", () => {+ // Permission (120s) + admission queue (30s) + host-core dispatch (150s) ++ // slack (10s). A flat 130s would cut off a prompted plugin tool that is+ // still inside its budget, and dropping the queue wait would cut off a call+ // that had to wait for a saturated plugin class before it was dispatched.expect(rpcTimeoutMs("tools.execute", { toolName: "plugin_advisor_ask" })).toBe(- 250_000,+ 310_000,);expect(rpcTimeoutMs("tools.execute", { toolName: "mcp_github_search" })).toBe(- 250_000,+ 310_000,);expect(rpcTimeoutMs("tools.execute", {toolName: "plugin_advisor_ask",timeoutMs: 5_000,}),- ).toBe(135_000);+ ).toBe(165_000);expect(rpcTimeoutMs("tools.execute", { toolName: "plugin_advisor_ask", timeoutMs: 0 }),- ).toBe(250_000);+ ).toBe(310_000);});});diff --git a/packages/shared/src/rpc-timeouts.ts b/packages/shared/src/rpc-timeouts.tsindex 7e6baccdf..57a69f682 100644--- a/packages/shared/src/rpc-timeouts.ts+++ b/packages/shared/src/rpc-timeouts.ts@@ -4,14 +4,27 @@ export const DEFAULT_COMMAND_TIMEOUT_MS = 60_000;export const COMMAND_RPC_BUFFER_MS = 10_000;export const DEFAULT_BASH_RPC_TIMEOUT_MS =PERMISSION_TIMEOUT_MS + DEFAULT_COMMAND_TIMEOUT_MS + COMMAND_RPC_BUFFER_MS;+/**+ * host-core's admission queue wait: what a call costs when its tool class is+ * saturated. It is spent after the permission gate and before the tool runs, so+ * a transport deadline that omits it can still give up before host-core reports+ * an outcome. Mirrors `TOOL_QUEUE_WAIT_MS` in+ * `crates/host-core/src/tool_budget.rs`.+ */+export const TOOL_QUEUE_WAIT_MS = 30_000;/*** host-core's dispatch budget for `plugin_*` / `mcp_*` tools, which Electron- * main executes. It outlasts Electron's plugin tool budget (110s). Mirrors+ * main executes. It outlasts every budget Electron enforces inside it: the+ * plugin tool budget (110s) and the widest MCP leg, a lazy handshake plus the+ * whole `tools/list` traversal plus the call (10s + 30s + 100s). Mirrors* `DESKTOP_TOOL_DISPATCH_TIMEOUT_MS` in `crates/host-core/src/tools/mod.rs`.*/-export const DESKTOP_TOOL_DISPATCH_TIMEOUT_MS = 120_000;+export const DESKTOP_TOOL_DISPATCH_TIMEOUT_MS = 150_000;export const DEFAULT_DESKTOP_TOOL_RPC_TIMEOUT_MS =- PERMISSION_TIMEOUT_MS + DESKTOP_TOOL_DISPATCH_TIMEOUT_MS + COMMAND_RPC_BUFFER_MS;+ PERMISSION_TIMEOUT_MS ++ TOOL_QUEUE_WAIT_MS ++ DESKTOP_TOOL_DISPATCH_TIMEOUT_MS ++ COMMAND_RPC_BUFFER_MS;const MAX_TIMER_DELAY_MS = 2_147_483_647;function isRecord(value: unknown): value is Record<string, unknown> {@@ -27,10 +40,11 @@ function isDesktopDispatchedTool(toolName: unknown): boolean {/*** Return the transport deadline for an RPC call. Bash and desktop-dispatched- * (`plugin_*` / `mcp_*`) tools include the permission wait, the effective- * execution timeout, and transport slack, so the transport never gives up- * before host-core reports its own timeout. Every call has a finite deadline so- * a lost response cannot leave a pending promise forever.+ * (`plugin_*` / `mcp_*`) tools include the waits host-core can spend before it+ * reports an outcome — the permission gate, the admission queue, and the+ * effective execution timeout — plus transport slack, so the transport never+ * gives up before host-core reports its own timeout. Every call has a finite+ * deadline so a lost response cannot leave a pending promise forever.*/export function rpcTimeoutMs(method: string,@@ -40,15 +54,29 @@ export function rpcTimeoutMs(const input = isRecord(params) ? params : undefined;if (isDesktopDispatchedTool(input?.toolName)) {- return executionRpcTimeoutMs(input?.timeoutMs, DEFAULT_DESKTOP_TOOL_RPC_TIMEOUT_MS);+ return executionRpcTimeoutMs(+ input?.timeoutMs,+ DEFAULT_DESKTOP_TOOL_RPC_TIMEOUT_MS,+ TOOL_QUEUE_WAIT_MS,+ );}if (input?.toolName !== "Bash") return DEFAULT_RPC_TIMEOUT_MS;if (input?.timeoutMs === undefined) return DEFAULT_BASH_RPC_TIMEOUT_MS;+ // Bash keeps the arithmetic it shipped with (permission + command + slack):+ // the admission queue wait is deliberately not added to that path here, so+ // its existing deadline is unchanged by this change.return executionRpcTimeoutMs(input.timeoutMs, DEFAULT_BASH_RPC_TIMEOUT_MS);}-/** Permission wait + execution timeout + slack, or `fallbackMs` when absent or invalid. */-function executionRpcTimeoutMs(executionTimeoutMs: unknown, fallbackMs: number): number {+/**+ * Permission wait + optional admission queue wait + execution timeout + slack,+ * or `fallbackMs` when the caller sent no usable timeout.+ */+function executionRpcTimeoutMs(+ executionTimeoutMs: unknown,+ fallbackMs: number,+ queueWaitMs = 0,+): number {if (typeof executionTimeoutMs !== "number" ||!Number.isFinite(executionTimeoutMs) ||@@ -59,6 +87,9 @@ function executionRpcTimeoutMs(executionTimeoutMs: unknown, fallbackMs: number):return Math.min(MAX_TIMER_DELAY_MS,- PERMISSION_TIMEOUT_MS + Math.ceil(executionTimeoutMs) + COMMAND_RPC_BUFFER_MS,+ PERMISSION_TIMEOUT_MS ++ queueWaitMs ++ Math.ceil(executionTimeoutMs) ++ COMMAND_RPC_BUFFER_MS,);}