Skip to content

修复:隔离私有 Git Bash 执行器,恢复 route B 的 bash 工具注册 - #20

Merged
KannaKuron merged 2 commits into
KannaKuron:mainfrom
KouzakiUmi:fix/private-gitbash-executor-isolation
Oct 13, 2026
Merged

KannaKuron merged 2 commits into
KannaKuron:mainfrom
KouzakiUmi:fix/private-gitbash-executor-isolation

Conversation

@KouzakiUmi

@KouzakiUmi KouzakiUmi commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

摘要

修复 v0.39.0 route B 中私有 Git Bash 执行器与官方 PowerShell shell 服务冲突,导致 bash 工具无法注册的问题。

Closes #19

关联问题:v0.39.0 route B 回归:私有执行器未隔离 shell 服务,导致 bash 工具消失

根因

createScope(ctx) 创建的是 Cordis 子插件 fiber,并不建立服务隔离命名空间。GitBashSandboxExecutor 的父类链最终通过 ShellExecutor 调用 super(ctx, 'shell'),依然注册 shell 服务。route B 保留了官方 SandboxPwshExecutor,两者使用同一个 isolation key,因此构造阶段立即报:

service "shell" has been registered at <SandboxPwshExecutor>
own bash tool activation failed for this agent

Git Bash 路径已解析成功时也会发生。错误发生在工具注册之前,不属于 progressive tool discovery 的展示问题。

具体修复

  • 提取 mountPrivateExecutor(),在 ctx.isolate('shell') 派生上下文中创建自有执行器 scope。
  • 仅隔离 shell:宿主的 subprocess、sandbox、sandboxPolicy 等依赖继续继承。
  • 仍通过 plugin(GitBashSandboxExecutor) 挂载真实类,保留 Config/volatile/static inject 与 Cordis 生命周期语义。
  • 空 scope 用 get('shell') 读取活跃执行器,用 get('tools') 检查工具就绪;不依赖未声明的属性访问注入。
  • 构造/挂载失败时释放 scope;成功/失败均清理 deadline timer。
  • 修正文档中「普通私有 scope 不会注册服务」的错误表述:父类确实注册 shell,但现在注册于隔离服务槽,不触碰根 shell。

没有修改 bundle patch、官方 PowerShell 执行器、shell 执行/沙箱/后台协议、工具参数/输出、preset 组合或版本下限;没有版本号变更或发布工作流变更。

回归测试与 CI

新增 5 项使用真实 Cordis Context/Service 的生命周期回归,覆盖:

  1. 普通子 fiber 重现服务冲突。
  2. 独立 shell 命名空间保留宿主依赖、真实 Config/inject 和原 PowerShell;卸载时清理私有 provider。
  3. 构造失败释放部分注册,之后可以重新挂载。
  4. 缺失必需服务时失败关闭并释放 pending scope。
  5. 挂载未完成时触发 deadline 并清理 scope。

同时修正两处既有测试结构问题,保持原断言:

  • minimal PTY 的非 Windows 分支现在显式模拟 Linux,而不是在恢复真实 Windows 平台后误断言 /bin/bash。
  • 两项 error-content 测试恢复为独立顶层测试;首轮 CI 发现原结构在 Node 22 下会因未等待的嵌套测试而取消。没有通过跳过测试或移除 Node 22 矩阵来规避。

新增只读权限的非发布 ci 工作流,覆盖 Windows/Linux × Node 22/24;每项运行锁定依赖安装、完整测试和包文件 dry-run。对修复分支 push 和 PR 触发,不使用 pull_request_target。

验证结果

  • npm test:127/127 通过。
  • npm pack --dry-run --ignore-scripts、JavaScript 语法、workflow YAML 和 git diff --check:通过。
  • 远端四组合 CI:最终提交 095940f 的 CI:四个组合全部成功。
  • 隔离已安装宿主 runtime preview:通过。
    • Windows,Core 0.2.1-alpha.2,Cordis 4.0.5-alpha.1,Node 24.13.0。
    • 使用真实 SandboxPwshExecutor、ToolRuntime、SystemPrompt、shell-env 和 subprocess runtime;旧路径重现相同重复服务错误。
    • 固定后 bash 出现在实际 per-agent schema,不污染全局工具面;执行 command -v bash、uname -s 和 sentinel,退出码 0。
    • pwsh 显示时,原官方执行器能执行 Get-Process;默认隐藏时,bash 仍可调用。
    • 卸载 patch 后 bash 移除、pwsh 恢复,原 shell provider 保持不变。

preview 使用真实宿主服务和真实 Windows 进程,policy/session/working-directory 接线为夹具;覆盖 danger-full-access。它是无头运行时验证,完整 GUI、预设选择器、PTY、后台任务和受限模式不在本次测试覆盖范围内。复验入口及范围见 tests/README.md。

检查清单

  • 真实运行时重现根因,而非仅静态推断
  • 保留 route B 的官方 PowerShell 执行器
  • 默认 pwsh 隐藏和显式显示两态通过
  • 生命周期、失败清理、卸载恢复测试通过
  • 全量测试与打包预检通过
  • 已安装宿主 runtime preview 通过
  • 远端 Windows/Linux × Node 22/24 CI 通过
  • 已更新 CHANGELOG 与验证文档

2026-10-13 后续全面审查与修复

原服务隔离问题已由 PR #20 合并解决,并随 v0.39.1 发布;本记录保持已完成状态。 新一轮确认的功能/逻辑回归由独立的 后续 PR #22 承载,不属于原 PR 的已合并内容。

后续提交:6b26ded,基于当前上游 521be01,完整保留 v0.39.1 的私有服务隔离与 #21 glob real-array 修复,不更改已发布版本号。

确认并修复 16 项既有问题:

  • 三个 Windows 全工具 Git Bash 变体实际走根 PowerShell,现接同一私有 bash 补位通道;minimal persistent 不改。
  • 存活 agent 的 pwsh 动态工具面、异步导入/挂载跨卸载的失效工具残留、jobs 卸载后前台 bash 不恢复。
  • 两个受控模块解析降级分支:plain definition 的嵌套 required schema 非法;审批 helper 缺失导致会话 standing policy 丢失。未声称生产正在发生导入失败。
  • preset register/unregister 的卸载竞态,以及动态关闭变体后部署默认悬空;只迁移部署默认,不迁移钉住会话。
  • better-sidebar 动态恢复与手选保护;run_code 关键字后正则的误翻译,保守整份 no-op。
  • FastCtx execution 方言门控、spawn error Promise、MCP isError 失败面,以及并发发现/懒连接丢失所有权。
  • 设置卡 Hook 数变化、工具链进度轮询单次暂态错误后永久停止。

保留根官方 PowerShell、route B 纯新增 patch、成功 FastCtx 全文回显、Windows 明示 unconfined 取舍,以及 autoTerminalShell OFF 只停止未来写入的独立语义。无新增依赖、功能、兼容下限调整、发布或安装动作。

本次实际验证

  • 完整测试:156/156,0 fail / 0 cancelled / 0 skipped。
  • 实际 Core 无头 preview:14/14,0 fail / 0 cancelled / 0 skipped。
  • 语法、diff 和打包 dry-run:通过。
  • 本提交 CI 38356641905:Windows/Linux × Node 22/24 四组合全部成功,不是引用原提交的旧 CI。
  • 目标实际宿主为 Core 0.2.1-alpha.2、Cordis 4.0.5-alpha.1;普通可移植测试使用锁定 Cordis 4.0.4。Grok 修复后只读反证未发现确定遗漏。

真实 Windows 进程验证 Git Bash uname/sentinel 与原官方 PowerShell,新增真实 Core API 回归同时含内存 subprocess、延迟注册和受控 MCP 传输。UI/并发连接使用确定性夹具;不等同于完整 Electron GUI、生产 PresetTree、真 MCP exe 并发或受限模式端到端验收。详细触发链、修复与分层覆盖见 PR #22。

Use a shell-only Cordis isolation namespace, explicit get() service reads, and scoped failure cleanup. Add real Cordis lifecycle regressions, an installed-host Windows runtime preview, and Windows/Linux Node 22/24 CI without changing the official PowerShell executor or bundle patch.
Move the parent test's closing assertion before the two independent dialect cases. Preserve every assertion and all four CI matrix entries; record the initial Node 22 cancellation failure in the changelog.
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.

v0.39.0 route B 回归:私有执行器未隔离 shell 服务,导致 bash 工具消失

2 participants