Repository navigation
fix: repair CLI and host contracts, harden runtime cleanup, and prune dead code - #8985
Conversation
Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>
Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>
Signed-off-by: aihop <4408344+hhyykk@users.noreply.github.com>
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. |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google (self_reported)
已针对 PR #8985 exact head c4c30344e3e4d78019e5e51d72d6886f225487d7 完成全量代码审查(按 PR 实际 merge-base 3c03e91e6736f129d78e7c895b9d4a871f132a7f 核查全部 144 个变更文件 +1350 / -1117;注:远端 baseRefOid 已推进至 0d4233f723,使用三点 diff ...HEAD 对应精确分支改动)、跨仓引用检索与本地实测验证(审查结论:APPROVE,无 P0/P1 阻断问题,附 1 项非阻断 P2 关注与主干既往 CI lint 说明)。
动机 / Motivation
受影响调用方与运维者:运行 loopx postgres、loopx explore、loopx opencode2-goal-worker、loopx content-ops、loopx preset 的 CLI 运维者,使用 OpenCode / OpenCode2 / Pi / Claude Code / Antigravity Goal 桥接与个人工作区代理(/api/goals)的 Host 运行时调用方,构建 loopx-core 独立分发包的维护者,以及阅读公开文档、Skill 链接与维护 loopx/control_plane/、loopx/status.py、loopx/quota.py 死代码边界的开发者。
修改前(3c03e91e6736f129d78e7c895b9d4a871f132a7f):审计发现多处可复现缺口,包括 loopx/cli.py 在 build_parser() 漏注册 register_postgres_commands 且 _main() 保留已由 dispatch_common_command 处理的 6 组不可达冗余分派块;opencode2_goal_worker.py 将子进程诊断打到 stdout 破坏 --format json 且掩盖 ok=False;effect_runtime.py 在 Linux 容器场景遇到孤儿僵尸进程组(leader Z 而工作线程未退出)与 explore_research_terminal.ts / shadow_drain_files.ts 子进程关闭路径缺少 rl.close() / SIGKILL 升级保护;remote_authority_policy.ts 未先校验 digest 长度即调用 timingSafeEqual;opencode_goal_mode / opencode2_goal_mode 锁文件接受 pid <= 0 且 waitPlan 未适配 cold_path_detail.local_scheduler 与 unchanged_poll.limits;claude_goal_mode 在空 file_path 时未 fail-closed 且未基于 cwd 解析相对路径;packages/loopx-core 漏打包 *.toml 清单文件;以及 status.py / quota.py / control_plane/ 遗留 17 处无消费者 re-export、已退场导出与指向旧仓库路径的文档链接。修改后(c4c30344e3e4d78019e5e51d72d6886f225487d7):系统性修复上述 CLI、Host 桥接、进程/锁清理、输入校验与打包缺口,同步将公开仓库引用对齐至 loopx-project/loopx 并清理确认无调用方的死代码路径。
可观测结果:在 c4c30344e3e4d78019e5e51d72d6886f225487d7 上实测:变更 Python 文件 ruff check 0 错误;全仓 mypy(17 个配置源码文件)0 错误;npm run typecheck:control-plane 通过;scripts/check_rfc_bilingual.py --base 3c03e91e6736f129d78e7c895b9d4a871f132a7f --head HEAD 通过;scripts/generate_turn_contract.py --check 显示 Turn contract bindings: up to date;node --test tests/opencode2_goal_worker.test.mjs tests/opencode_goal_bridge_runtime.test.mjs 通过(67 passed, 0 failed),6 组 tests/control_plane_ts/*.test.ts(含 delivery_response、effect_runtime_handler_loading、effect_runtime_handlers、usage_statistics_environment、zcode_app_server:62 passed, 2 skipped;remote_authority:16 passed)全部通过;两组 Python pytest 覆盖新增审计回归、status/quota 词表、Lark、Claude hook、Content-Ops、Core 打包与 Effect Runtime 集成共 309 passed, 42 skipped(164 passed, 42 skipped + 145 passed);examples/release-artifacts-smoke.py 与 examples/dev-book-publication-smoke.py 通过;loopx canary premerge --tier quick --from-git-diff --git-diff-base 3c03e91e6736f129d78e7c895b9d4a871f132a7f(ok=true, failures=0)与 loopx check --scan-path(143 个未删除文件,errors=0)均干净通过。
非目标边界:本 PR 不改动已合入 main(0d4233f723)的 codex_adapter / chat_runtime 上下文策略,不修改 PostgreSQL 运行时策略、桌面端回滚保留或更大范围跨模块重构,亦不替主干修复 tests/test_chat_manager_model_adoption.py:416 既往 lint 错误。
改动思路 / Approach
架构与放置判断:按各缺陷既有所有权边界就地修补——CLI 解析与帮助/手册更新留在 loopx/cli.py、help_surface.py、man/loopx.1;Host 运行时与锁/进程回收留在各自 agy_goal_mode / claude_goal_mode / opencode* / pi_goal_mode / effect_runtime.py;类型与输入边界收紧留在对应 TS/Python 模块;打包后缀修正留在 packages/loopx-core;未引入任何新抽象层或并行控制器。针对本 PR 删除的 29 个 Python 定义、7 个 TS 导出、17 个 status.py/quota.py re-export 与 shadow_drain_fault_process.ts,已同时在当前头与最新 origin/main 全仓检索确认无任何剩余调用方。
当前 PR 边界:包含 CLI/Host/打包修复(93493f5563)、控制面进程清理与死代码裁剪(7bea701365)及仓库 URL/CI/lint 对齐(c4c30344e3)共 3 个提交(144 文件,相对 merge-base 3c03e91e6736f129d78e7c895b9d4a871f132a7f);.github/workflows/full-public-smokes.yml 仅在 smoke-fleet-health 增加 github.repository == 'loopx-project/loopx' 条件以防止 fork 误跑,未触及主干权限与合并门禁逻辑。
| 域 / 改动类 | 关键修复与裁剪内容 | 验证证据 |
|---|---|---|
| CLI / 帮助 / 打包 | cli.py 注册 register_postgres_commands 并移除 6 组已被 dispatch_common_command 覆盖的不可达分派;opencode2_goal_worker.py 诊断转 stderr 并透传 ok=False;packages/loopx-core 纳入 *.toml |
test_audit_cli_and_runtime_fixes.py + test_core_distribution.py |
| Host 与进程/锁清理 | effect_runtime.py 检查 Linux /proc/<pid>/task/*/stat 确认全线程退为 Z;explore_research_terminal.ts / shadow_drain_files.ts 释放 readline 并升级 SIGTERM→SIGKILL;goal-bridge-runtime.mjs 使用 "wx" 排他锁 + token 校验释放且更新 waitPlan |
opencode2_goal_worker.test.mjs + opencode_goal_bridge_runtime.test.mjs + test_effect_runtime_integration.py |
| 输入安全与死代码清理 | remote_authority_policy.ts 长度预检后再 timingSafeEqual;goal_policy.py 空路径 fail-closed 并解析相对 cwd;runtime_workspace.py unquote 路径;清理 17 项无调用 re-export 与 36 处死函数/导出 |
全仓调用方检索 0 残留 + remote_authority.test.ts + test_status_facade_vocabulary_owners.py |
| 文档链接与仓库卫生 | 公开文档与配置从 huangruiteng/loopx 对齐为 loopx-project/loopx;.github/CODEOWNERS 与 .gitignore 移除已退场 deprecate/ / apps/dashboard/ 规则;vite.config.ts 代理 /api/goals |
dev-book-publication-smoke.py + canary premerge --tier quick + loopx check |
具体改动 / Changes
本次有效 diff(3c03e91e6736f129d78e7c895b9d4a871f132a7f..c4c30344e3e4d78019e5e51d72d6886f225487d7)共触及 144 个文件(+1350 / -1117,无 RFC 文件变更):
- CLI 与扩展合约(
loopx/cli.py、loopx/help_surface.py、man/loopx.1、loopx/cli_commands/explore.py、loopx/cli_commands/opencode2_goal_worker.py、loopx/presets.py、loopx/chat_attachments.py、loopx/capabilities/content_ops/*、loopx/capabilities/change_quality/cli.py、loopx/capabilities/explore/router_state.py):补齐postgres解析注册并移除重复分派、修正explore空goal_id默认注册表回退、隔离opencode2stderr、加固content-ops重复stdin ('-')检测与 Markdown 渲染、presets.py对cli_bin做 shell 引用并容忍空列表、chat_attachments严格校验type(declared_size) is int、router_state要求计数双非空后再转换。 - Host 适配器与运行时清理(
loopx/agy_goal_mode/host_runtime.py、loopx/capabilities/native_chat/antigravity_adapter.py、loopx/claude_goal_mode/*、loopx/opencode2_goal_mode/opencode2-goal-worker.mjs、loopx/opencode_goal_mode/goal-bridge-runtime.mjs、loopx/pi_goal_mode/loopx-goal.ts、scripts/loopx、scripts/loopx.ps1):支持ANTIGRAVITY_LS_URL与--antigravity_app/--cli-bin,校验轨迹响应字典形状;Claude hook 空写入路径 fail-closed 且goalmode_cmd检查退出码;OpenCode 锁文件拒收pid <= 0、使用"wx"原子创建与 token 校验释放、waitPlan对齐真实cold_path_detail/limits;Pi 适配器解析非零退出码下的有效 JSON 决策。 - 控制面安全、清理与死代码裁剪(
loopx/control_plane/effect_runtime.py、explore_research_terminal.ts、shadow_drain_files.ts、remote_authority_policy.ts、checkpoint_commit.ts、effect_runtime_handlers.ts、删除shadow_drain_fault_process.ts及 20+ 控制面模块无消费者导出、loopx/status.py、loopx/quota.py、loopx/extensions/lark/*、loopx/presentation/*):安全关闭子进程与 readline、Linux 全线程僵尸态校验、timingSafeEqual长度前置校验、explore_results_api.py跳过重复校验并按original_goal_id匹配且对SourceScopeError返回 404、runtime_workspace.py对静态路径先unquote。 - 打包、CI、测试与仓库引用对齐(
packages/loopx-core/*、packages/loopx-codex-provider-routing/__init__.py、apps/presentation/dashboard/vite.config.ts、.github/CODEOWNERS、.github/workflows/full-public-smokes.yml、.gitignore、CONTRIBUTING.md、sonar-project.properties、docs/*、examples/*、skills/loopx-self-repair/*、新增tests/test_audit_cli_and_runtime_fixes.py等):修正loopx-core包含*.toml、对齐loopx-codex-provider-routing__version__(0.15.8)与pyproject.toml、为 Vite 开发代理补全/api/goals、对齐仓库 URL 至loopx-project/loopx。
关键代码讲解
_linux_thread_group_is_zombie与_stop_effect_runtime(loopx/control_plane/effect_runtime.py:640-660, 958-964):_reap_exited_runtime_child仅在waitpid确认ECHILD(非本进程直接子进程)时返回True,随后在 Linux 检查/proc/<pid>/task/*/stat所有线程均为Z且无新增线程,才允许判定孤儿进程组已终止,防止主线程先退出而工作线程仍写盘时误判停止。createFileLockStore与waitPlan(loopx/opencode_goal_mode/goal-bridge-runtime.mjs:179-265, 326-360):以fs.open(lockPath, "wx", 0o600)取代覆盖式rename竞态,并在释放锁时校验current.token === token防止误删后续持有者锁文件;waitPlan兼容cold_path_detail.local_scheduler与unchanged_poll.limits。remoteAuthorityPolicyAdmission(loopx/control_plane/coordination/remote_authority_policy.ts:96-103):先比较candidate.length === digest.length再调用timingSafeEqual,消除非法或截断 hex 凭据哈希触发RangeError的边界异常。
对主干的风险 / Risks
- 无 P0/P1 阻断性问题:已核对与
origin/main(0d4233f723/a79e781340)重合区,所有被本 PR 删除的函数、导出与重导出在origin/main均无新增调用方;唯一须注意合入前需要按 GitHub 正常合并/变基处理main在3c03e91e6736f129d78e7c895b9d4a871f132a7f之后推进的提交(067ad42cc4等)。 - 远端 CI 与非阻断关注:远端 CI
kernel-static-checks失败于主干既有tests/test_chat_manager_model_adoption.py:416(F811),致使下游checks/pytest/stage2c/merge-gate失败或跳过;局部非阻断 P2 关注:loopx/presets.py:336通过common_setup[0].rsplit(" ", 1)[0]反推cli_prefix对直接传入非标准common_setup的调用方略脆弱(build_beginner_preset_packet默认生成"{_shell(cli_bin)} doctor"不受影响)。
我的整体评价 / Verdict
PR #8985 系统修复了 CLI 注册与流分离、Host 锁/孤儿进程回收、输入校验与 loopx-core 打包等多项审计缺陷,按既有所属边界裁剪 50 余项无调用死代码/重导出并同步将公开引用迁至 loopx-project/loopx;经本地 Ruff、17 文件 Mypy、控制面 TS 类型检查、67 项 Node MJS + 78 项 TS(2 skipped)+ 309 项 Python(42 skipped)测试与 quick premerge / 边界扫描独立验证,未见对主干行为或 origin/main 新增路径的回归风险。visual_review:not_applicable(原因:仅修改 apps/presentation/dashboard/vite.config.ts 本地开发 /api/goals 代理与后端/CLI/文档文件,未改动任何前端 UI 组件、样式或渲染视图;未验证范围:none)。审查结论为 APPROVE(合入前需待主干 lint 恢复及维护者合入授权)。
English verdict: APPROVE exact head c4c3034; across 144 files relative to merge-base 3c03e91, PR #8985 repairs CLI parser/stream handling (postgres, explore, opencode2-goal-worker, presets, content-ops), hardens runtime/lock cleanup (effect_runtime.py, explore_research_terminal.ts, shadow_drain_files.ts, goal-bridge-runtime.mjs), fixes input bounds (remote_authority_policy.ts, goal_policy.py, runtime_workspace.py), packages *.toml in loopx-core, prunes verified dead exports/re-exports (0 callers on both HEAD and origin/main), and aligns loopx-project/loopx links; verified locally via ruff, 17-file mypy, typecheck:control-plane, 67 Node MJS + 78 TS (2 skipped) + 309 Python (42 skipped) tests passing, canary premerge --tier quick (failures=0), and loopx check (errors=0); remote kernel-static-checks failure (tests/test_chat_manager_model_adoption.py:416 F811) is pre-existing on main.
Main deleted the unused readGoalHeartbeatReceipts helper (loopx-project#8985). The branch's receipt reader had grown around that helper, so the merge keeps main's removal and carries only the scoped receipt view, the committed-successor admission and the committed-row marker. scheduler_hint.py, quota.py, status.py and the settlement readback test merged without overlap; the receipt reader was the only textual conflict. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
Goal And Delivered Outcome
Repair reproducible gaps found in a repository audit. Base:
mainat3c03e91e6.Author Declaration
Scope And Continuation
Existing follow-ups cover release recovery, stale canary configuration, and adjacent control-plane refactors. Publication policy, desktop rollback retention, and broader dead-code candidates require separate review. See #8703, #8737, #8890, #8898, #8908, #8936, #8965, #8972, and #8973.
Validation
c4c30344e3e4d78019e5e51d72d6886f225487d7. Earlier broad checks are marked separately.examples/install-local-smoke.py. The same smoke passed on its own with a higher limit. The other nine catalog cases, all eight risk-profile cases, direct checks, and the changed-path scan passed.v2.3.0entry. The full-tree command also includes local registry health diagnostics.Frontend / Visual Evidence
Type of Change
Boundary Checklist