Repository navigation
feat(guard): add process guard facade and unified sandbox configuration draft - #334
tardisblue9 wants to merge 4 commits into
Conversation
|
head_sha: 变更摘要本 PR 为 iCode 引入可选“文件访问沙箱”的接入层:新增门面模块 主要改动
|
|
head_sha: 代码审查审查结论
💬 仅评论 |
|
|
||
| # Also reaches the command behind a sandbox stub (a linked session). | ||
| if kill_process_group(pid): | ||
| return |
There was a problem hiding this comment.
head_sha: 27fe466850a6b9a9296489cd179eab82857f8ab5
🟡 Medium Priority
建议:不要用 kill_process_group 的结果短路掉 killpg:二者覆盖的集合不同(进程树 vs 进程组)。改成树杀之后仍然补一次 killpg(用 suppress 包住 ProcessLookupError/PermissionError/OSError),或仅在进程组确实不存在时跳过,保持原「整组必杀」的语义。
| return | |
| kill_process_group(pid) | |
| try: | |
| posix_os.killpg(pid, posix_signal.SIGKILL) | |
| except ProcessLookupError, PermissionError, OSError: |
There was a problem hiding this comment.
Thanks. No change here: kill_process_group(pid) already sends that same os.killpg(pid, SIGKILL) to the whole group (after also reaching the command behind a sandbox stub, when there is one), and returns True only when that killpg succeeded. When it returns False, the code continues with the original path unchanged: the same killpg, then the fallback to the leader. So the whole group is still always killed; nothing is skipped.
感谢。这里不改:kill_process_group(pid) 内部就会对整个进程组执行同一个 os.killpg(pid, SIGKILL)(有沙箱桩程序时还会先处理其背后的命令),只有这次 killpg 成功才返回 True。返回 False 时,代码照原来的路径继续:同样的 killpg,再回退到组长进程。所以整组仍然一定会被杀掉,没有跳过任何一步。
| doc = read_yaml_doc_readonly(Path(os.path.realpath(path)) if owned else path) or {} | ||
| settings_edit(doc) | ||
| except Exception: | ||
| return {} |
There was a problem hiding this comment.
head_sha: 27fe466850a6b9a9296489cd179eab82857f8ab5
🟡 Medium Priority
变更行:guard.py:286-293 的 settings_doc() 用 try: ... except Exception: return {} 包住了 import、read_yaml_doc_readonly、settings_edit 和整个 flatten 步骤,且不记录任何日志。
契约/影响:decide()(第 346-358 行)完全依赖这个 {} 来决定 sandbox.enabled、workdir.config_enabled 与 sandbox.on_unavailable;{} 意味着“用户没开沙箱、没设 on_unavailable”。
失效模式:用户在 settings.yaml 里写了 sandbox.enabled: true,但文件有一个 YAML 语法错误(或 settings_edit 在旧键名迁移上抛异常、或文档结构不是 dict 使 flatten 抛错),于是 doc == {},decision.enabled 保持默认 False、source == "default",install_at_startup 走 not decision.enabled 分支安装 _NoGuard()——iCode 在用户以为“沙箱已开”的情况下完全无沙箱启动,status_line() 也不打印任何东西(requested 为 False),既没有 WARNING 也没有退出。这正是本模块头部声称“It never runs a program outside a guard that is on”所禁止的 fail-open,且无日志无法事后发现。
建议:只吞掉“文件不存在/为空”的情况,对解析或旧键迁移失败向 stderr 输出一条明确警告(并把它计入 GuardStatus.reasons),避免坏掉的 settings.yaml 静默把沙箱关掉。
There was a problem hiding this comment.
Good catch, fixed. The user's own settings file is now read strictly: if it exists but can't be read or parsed, startup says which file and why (never its contents), and the reason is recorded in the sandbox status, instead of silently counting as "sandbox off". A missing or empty file is still no problem. A working directory's file is only ignored when broken: a repository must not be able to make iCode warn, just as it can't stop it from starting. Tests cover invalid YAML, a non-mapping document and non-UTF-8 bytes.
说得对,已修复。现在严格读取用户自己的设置文件:文件存在但读不出来或解析失败时,启动时会说明是哪个文件、为什么(不显示文件内容),并把原因记入沙箱状态,不再悄悄当作"沙箱关闭"。文件不存在或为空时照常处理。工作目录里的文件损坏时只忽略:仓库不能让 iCode 报警,就像它不能让 iCode 无法启动。测试覆盖了 YAML 语法错误、不是映射、不是 UTF-8 三种情况。
27fe466 to
9d226fd
Compare
|
head_sha: WarningThe PR label(s) can not be got! |
|
head_sha: WarningThe PR commit(s) can not be got! |
|
head_sha: WarningThe corresponding operation log is missing! please check it. |
3 similar comments
|
head_sha: WarningThe corresponding operation log is missing! please check it. |
|
head_sha: WarningThe corresponding operation log is missing! please check it. |
|
head_sha: WarningThe corresponding operation log is missing! please check it. |
9d226fd to
c14056b
Compare
|
在 PR #334 当前提交 c14056b 上确认了以下 8 个问题,建议合并前处理。
|
Preserve user startup policy across workdir settings, browser sessions and forked windows. Show unavailable status without the optional package, retain sandbox denial metadata, and retract abandoned approvals safely.
c14056b to
f32008e
Compare
|
@0x7c13 感谢详细审查。这 8 项问题已在新提交
验证情况:
PR 说明、相关用户文档和协议文档也已同步更新。请帮忙复核,感谢! |
|
Paired: GitHub #334 ↔ GitCode !232
Summary
This PR adds the optional process-guard facade and its core call sites, preserving the eight review fixes below. It also proposes a common configuration layer for the process guard and the jiuwenbox work in #223 / #341, with an executable, independently tested initial configuration and capability contract.
The design proposal describes the intended integration. The initial implementation and adapter example distinguish implemented behavior from later work.
The new common layer is not wired into production startup, Shell, guard, TUI or ACP. Its schema and Python interfaces are review-stage contracts, not supported application settings. Existing runtime behavior and the eight fixes are retained. There are no real backend adapters, legacy migration, settings-loader registration, public CLI/environment names or kernel-enforcement acceptance in this draft. The process implementation remains in PR2, which waits for PR1 to merge; this PR does not modify #341's branch.
Initial common layer
warn, and no backend/host fallback is performed.Relative to the previous PR head combined with current main, this milestone adds nine files (843 lines) and modifies none of the existing runtime, test, dependency or workflow files. The original proposal document is retained unchanged. The current head incorporates main
350290f3and the exact additions tested in the fork.Existing implementation and review fixes
When no sandbox is requested, core guard hooks remain inert. The existing facade resolves startup policy, loads the expected distribution's entry point and supplies approval, workspace, subprocess, lifetime, rollback and TUI integration points. Named workspaces resolve before confinement; grants retain their directory scope.
The eight findings on c14056b9 remain addressed:
serveto browser-session children, leaving the HTTP server unconfined.--sandbox-on-unavailable=refuse|warn.sandbox_deniedresult metadata through main-agent/sub-agent result and hook paths.active | degraded | inactive, withrequested: truefor an unavailable requested sandbox.User documentation, protocol documentation and Chinese translations accompany the existing facade. A working directory may request stricter protection but cannot weaken an enabled user request. Workdir-only requests may warn; explicit user requests refuse by default. These existing runtime rules remain separate from the new, unwired versioned-schema draft.
Validation
eba0192a8e43144f9ec2eea7b116a0b283f0556d. Main tested:350290f36a66c47f33cffa2fc45eb0274953b708. Initial contract commit:d9abbb7dabd2b01c9fd44676a00a314a293b296e.f012910e59c9d5dd3e7d4b0d5df8acbd053b93be.db18977179c6714813d5ad1a53ea40c7287321b2. This includes full Linux/macOS/Windows test shards, architecture, lint, build and installed-wheel gates. The trial differs from the formal head only by the fork-only workflow entry that calls the existing full CI; that entry is not included in this PR.bdc92fa1, hit a Windows TUI teardownPermissionErrorreadingsession.jsonintest_the_same_content_lets_a_running_side_question_check_finish. Its precise cause is not established and no root-cause fix is claimed. The new current-main combination passed that Windows shard on its first attempt (3,492 passed / 41 skipped) with the relevant runtime and test paths unchanged. Initial failure evidence is retained.Design review requested
For discussion with @0x7c13, @MichaelLing83 and @alanhungyl:
The initial module has no dependency on #341. PR2 and a jiuwenbox adapter would depend on an agreed common contract when runtime integration begins. The proposed division of work is a request for agreement, not an assignment or commitment by other contributors. Composition of both mechanisms remains outside the first milestone.
中文说明
本轮在既有 PR1 和八项修复之上,新增统一配置层的可执行初稿:版本化配置、来源权限、后端选项校验、分作用域能力和预检接口,并附测试与接入示例。相对原 PR 与当前 main 的组合仅新增 9 个文件;没有修改原有生产路径或测试。
初稿尚未接入应用运行时,示例不是当前可直接使用的用户配置。 真实后端适配、旧配置迁移、设置加载器及 CLI/env 公共名称仍待评审。不会因提交本初稿改变现有 guard 行为;PR2 继续等待 PR1 合入,不改动 #341 作者分支。
两轮完整 fork CI 均首轮 20/20 通过,其中一轮验证当前 main 的完整组合;本地契约、既有功能回归、架构、静态检查和安装包验收见上方。旧 SHA 的 Windows 关闭阶段失败已保留证据,不把一次通过称为根因修复;新 SHA 的官方检查另行跟进。
请优先反馈公共配置和能力边界,以及 PR2 / jiuwenbox 接入的接口、分工和依赖顺序。