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): isolate Windows Bash runner jobs
vastsad8790fdfafef
diff --git a/crates/host-core/src/tools/mod.rs b/crates/host-core/src/tools/mod.rsindex 7f39a4fde..4503165d2 100644--- a/crates/host-core/src/tools/mod.rs+++ b/crates/host-core/src/tools/mod.rs@@ -40,6 +40,20 @@ pub const MIN_BASH_TIMEOUT_MS: u64 = 1_000;pub const MAX_BASH_TIMEOUT_MS: u64 = 21_600_000;pub const DEFAULT_BASH_TIMEOUT_MS: u64 = 60_000;pub const INTERNAL_TOOL_RUNNER_FLAG: &str = "--internal-tool-runner";+// Windows inherits the parent process' Job Object unless the child is created+// with CREATE_BREAKAWAY_FROM_JOB. The hidden runner is immediately assigned to+// its own kill-on-close job, so it must first leave any outer launcher job;+// otherwise terminating the runner job can terminate the whole Desktop tree.+#[cfg(any(windows, test))]+const WINDOWS_CREATE_NO_WINDOW: u32 = 0x0800_0000;+#[cfg(any(windows, test))]+const WINDOWS_CREATE_BREAKAWAY_FROM_JOB: u32 = 0x0100_0000;++#[cfg(any(windows, test))]+const fn windows_tool_runner_creation_flags() -> u32 {+ WINDOWS_CREATE_NO_WINDOW | WINDOWS_CREATE_BREAKAWAY_FROM_JOB+}+const PIPE_DRAIN_TIMEOUT: Duration = Duration::from_millis(750);const PROCESS_TERMINATION_TIMEOUT: Duration = Duration::from_millis(2_000);const OUTPUT_CHANNEL_CAPACITY: usize = 64;@@ -2609,7 +2623,7 @@ async fn spawn_tool_runner(#[cfg(unix)]command.process_group(0);#[cfg(windows)]- command.creation_flags(0x0800_0000);+ command.creation_flags(windows_tool_runner_creation_flags());let mut child = spawn_with_retries(&mut command).await?;let pid = child.id().unwrap_or_default();@@ -3283,6 +3297,19 @@ mod tests {assert!(encode_runner_config(&nul_config).is_err());}+ #[test]+ fn windows_tool_runner_leaves_outer_job_before_owning_the_process_tree() {+ assert_eq!(windows_tool_runner_creation_flags(), 0x0900_0000);+ assert_ne!(+ windows_tool_runner_creation_flags() & WINDOWS_CREATE_BREAKAWAY_FROM_JOB,+ 0,+ );+ assert_ne!(+ windows_tool_runner_creation_flags() & WINDOWS_CREATE_NO_WINDOW,+ 0,+ );+ }+#[tokio::test]async fn bash_large_output_does_not_deadlock() {// >64KB (OS pipe buffer) must not deadlock the child; reader tasksdiff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.mdindex e0ed51224..d415ec53e 100644--- a/docs/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/spec/03-runtime/03-tools-and-permissions.md@@ -440,7 +440,7 @@ or executable path hash is accepted as shell identity.2. Unix: well-known locations (`/bin/bash`, `/usr/bin/bash`, `/usr/local/bin/bash`, Homebrew), then PATH3. Windows: `bash.exe` from Git for Windows — derived from the `git` on PATH, then standard install dirs, then PATH excluding the WSL launcher in `System32`-- Unix invokes `bash -lc` (login shell keeps profile PATH for Finder/Dock launches); Windows invokes `bash -c` with `CREATE_NO_WINDOW`+- Unix invokes `bash -lc` (login shell keeps profile PATH for Finder/Dock launches); Windows invokes `bash -c` with `CREATE_NO_WINDOW`. The hidden host-core runner that owns the command tree is created with both `CREATE_NO_WINDOW` and `CREATE_BREAKAWAY_FROM_JOB`, then assigned to its own kill-on-close Job Object. This keeps a launcher or policy Job around the Desktop process from becoming the runner's termination scope. If Windows refuses the breakaway, runner creation fails closed; the shell itself stays inside the host-owned job so timeout and abort still terminate the complete command tree.- On Unix, the Bash tool additionally probes the user's login shell for itsPATH — `$SHELL` (fallback `/bin/zsh` → `/bin/bash` → `/bin/sh`) with`-lic 'printf %s "$PATH"'`, 5s-bounded, cached per process — and injects itdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex cd4ca9e3a..8f29a9c3b 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -7767,7 +7767,10 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.descendants, output events, audit, and turn state after the shutdown grace.- **Expected**: The process group/job tree is terminated, no descendant remains,no later output arrives, the turn returns `TURN_ABORTED`, and the workspace is- not rolled back automatically.+ not rolled back automatically. On Windows, the hidden runner first breaks+ away from any parent Job Object before entering its own kill-on-close job; a+ denied breakaway fails the tool closed instead of allowing the Desktop tree+ to become the termination scope.- **Specs linked**: `03-runtime/03-tools-and-permissions.md`,`03-runtime/07-process-model.md`, `03-runtime/08-error-codes.md`,`03-runtime/16-tool-result-limits.md`, `05-security/01-security.md`, ADR 0054diff --git a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.mdindex 063922f8a..72b617c07 100644--- a/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md+++ b/docs/zh-CN/spec/03-runtime/03-tools-and-permissions.md@@ -365,7 +365,7 @@ tool/protocol 名称,请求中单独携带固定的 shell ID。2. Unix:众所周知的位置(`/bin/bash`、`/usr/bin/bash`、`/usr/local/bin/bash`、Homebrew),然后是 PATH3. Windows:来自 Git 的 Windows 的 `bash.exe` — 派生自 PATH 上的 `git`,然后是标准安装目录,然后是排除 `System32` 中的 WSL 启动器的 PATH-- Unix 调用 `bash -lc`(登录 shell 为 Finder/Dock 启动保留配置文件路径); Windows 使用 `CREATE_NO_WINDOW` 调用 `bash -c`+- Unix 调用 `bash -lc`(登录 shell 为 Finder/Dock 启动保留配置文件路径);Windows 使用 `CREATE_NO_WINDOW` 调用 `bash -c`。负责拥有命令树的隐藏 host-core runner 还会使用 `CREATE_BREAKAWAY_FROM_JOB` 创建,然后被分配到自己的 kill-on-close Job Object 中。这样,启动器或策略 Job 不会成为 Desktop 进程的终止范围。如果 Windows 拒绝 breakaway,runner 会安全失败而不启动命令;shell 本身仍留在 host 拥有的 job 中,因此超时和中止仍会终止完整的命令树。- 在 Unix 上,Bash 工具另外探测用户的登录 shell 以获取其信息路径 — `$SHELL`(回退 `/bin/zsh` → `/bin/bash` → `/bin/sh`)`-lic 'printf %s "$PATH"'`,5 秒范围内,每个进程缓存 — 并注入它diff --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 049b14a37..247104dd8 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@@ -4517,7 +4517,9 @@ eleven-tool-round desktop paths are verified by后代、输出事件、审核以及关闭宽限后的状态。- **预期**:进程 group/job 树终止,没有后代保留,没有后续输出到达,本轮返回 `TURN_ABORTED`,工作空间为- 不会自动回滚。+ 不会自动回滚。在 Windows 上,隐藏 runner 会先脱离任何父 Job Object,+ 再进入自己的 kill-on-close job;如果系统拒绝 breakaway,工具会安全失败,+ 不会让 Desktop 进程树成为终止范围。- **链接规格**:`03-runtime/03-tools-and-permissions.md`,`03-runtime/07-process-model.md`、`03-runtime/08-error-codes.md`、`03-runtime/16-tool-result-limits.md`、`05-security/01-security.md`、ADR 0054