Repository navigation
Conversation
Refs loopx-project#8918. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent (self_reported, Gemini, Google)
动机 / Motivation
面向的问题对象与触发任务:需要自动清理已完成 Goal 工作树并审计执行结果的运维者与代理宿主。
改动前后场景对照:改动前:停止、注销或归档 Goal 时不触发任何外部清理命令,且配置中心不存在该项;改动后:仅直接调用 Python 函数 run_goal_closeout 可执行命令并记账,但 CLI 与 Dashboard 已可见 goal_closeout 命名空间,而 stop、retire 与 archive 仍完全不调用它。
当前可观测结果与非目标范围:目前仅单元测试直接调用 run_goal_closeout 可验证 payload、超时与失败返回;任意生产终态命令均无行为变化,且 machine-config 注册表与 HTTP 目录已发生变化。非目标边界:不包含内置 git worktree 清理逻辑(proposal 2)、worktree 状态发现命令(proposal 3)以及在本次提交内完成终态入口接线或 Dashboard 可视化编辑器。
放任现状不修会持续累积数十 GB 孤立工作树,但当前 PR 以正式非 Draft 状态提交了一个“配置已暴露、调用方为零、安全与静态检查均有缺失”的半成品,不仅无法交付终态自动清理,反而破坏既有机器配置目录契约。
改动思路 / Approach
该实现将尚未接线的执行器提前注册进公开 machine_configuration 目录,既破坏现有配置契约又通过未鉴权 HTTP 接口开放任意命令写入,且重复实现了 process_runtime.py 与 paths.py 的既有能力。
当前边界判断:必须先收回或隔离公开 HTTP 命令写入面、复用既有进程树与 goal_id 校验所有者并接通至少真实终态入口或退回 Draft,当前边界不具备合并条件。
按代码路径追踪,PR 在 loopx/capabilities/goal_closeout/machine_defaults.py 定义 goal_closeout 命名空间,通过 loopx/capabilities/machine_configuration/builtins.py 注册进全局配置注册表;执行层 loopx/capabilities/goal_closeout/hooks.py 通过 read_machine_configuration 读取配置,启动 subprocess.Popen(..., start_new_session=True) 传入 JSON stdin 并写 closeout-ledger.jsonl。与仓库既有方案相比,loopx/extensions/process_runtime.py 已经提供了带跨平台进程树清理和实时字节上限的 run_capped_process / terminate_process_tree,loopx/paths.py 也提供了防穿越的 validate_goal_id_path_segment,本 PR 均未复用;同时本 PR 直接将任意命令 command: list[str] 暴露到了无认证 loopback HTTP 的 machine_configuration 读写面,但未在 configuration_ui.py 注册对应界面字段,也未在 set_goal_activation_state、retire_global_registry_goals 或 archive_runtime_goal 中接入调用。
具体改动 / Changes
本次共涉及 5 个文件(+433 / -0):新增 loopx/capabilities/goal_closeout/__init__.py、machine_defaults.py、hooks.py 与 tests/capabilities/test_goal_closeout_hook.py,修改 loopx/capabilities/machine_configuration/builtins.py。
对照规格 Issue #8918(基准版本 issue-8918-opened-by-cuipengcx90-0-comments,proposal 1)的逐项验收如下:
| Criterion | 要求 | 当前 Head 状态 | 依据 / 缺口 |
|---|---|---|---|
C-1 |
配置声明 closeout 命令与超时 | not_met |
允许经无认证 loopback HTTP /apply 写入任意可执行命令并回显;未补齐 configuration_ui.py 与既有目录测试 |
C-2 |
stdin 传递有界 JSON 负载(loopx_goal_closeout_v1) |
implemented |
hooks.py::run_goal_closeout + 单元测试 |
C-3 |
有界超时且失败不阻塞主命令 | not_met |
未复用 process_runtime.py,Windows 无法清理后代进程,临时文件无运行期上限且 cwd=repo 锁死待删工作树 |
C-4 |
每次调用记入关闭账本 | not_met |
goal_id 未校验可路径穿越、FileNotFoundError 跳入 internal_error 漏记账、archive 后写盘会重建 goals/<id> 目录 |
C-5 |
stop / retire / archive 后自动触发 | not_met |
全仓搜索显示 0 处生产调用点 |
关键代码讲解
loopx/capabilities/goal_closeout/hooks.py#L95(run_goal_closeout):读取goal_closeout配置并以subprocess.Popen执行,捕获超时与异常后通过_write_ledger追加账本。问题在于将Path(repo).is_dir()与Popen放在同一外层try块中,缺失二进制触发FileNotFoundError时直接落入internal_error而不写入账本,且cwd=repo会在待删除 worktree 内持有目录句柄。loopx/capabilities/goal_closeout/hooks.py#L35(goal_closeout_ledger_path):直接返回runtime_root / "goals" / goal_id / "closeout-ledger.jsonl",既未调用validate_goal_id_path_segment防穿越,也会在archive_runtime_goal搬走goals/<id>后因mkdir(parents=True)重新造出空目录。loopx/capabilities/goal_closeout/hooks.py#L30(_Capture.text) &#L59(_terminate):前者因handle: Any导致mypy报no-any-return且不限制进程运行期写入临时文件的总大小;后者仅用os.killpg清理进程组,在 Windows 回退到单进程process.kill()。loopx/capabilities/goal_closeout/machine_defaults.py#L50(goal_closeout_machine_configuration_namespace):以project_public=dict、apply_public_update=dict注册了包含任意command: list[str]的命名空间,使得公开 HTTP API 既可写也可回显本机可执行路径与脚本参数。loopx/capabilities/machine_configuration/builtins.py#L82(build_builtin_machine_configuration_registry):延迟注册了goal_closeout,立即改变了默认可用命名空间集合与/api/chat/machine-configuration目录输出,破坏了 3 项既有测试。
对主干的风险 / Risks
- [P0] 暴露无生产调用方的配置面且破坏 3 项既有契约测试:在
builtins.py注册goal_closeout后,未配置状态下也会改变默认目录,实测导致test_builtin_catalog_lists_every_owner_in_namespace_order、test_inspection_lists_registered_namespaces_without_local_refs、test_machine_catalog_discovers_goal_features_without_granting_machine_writes全部FAIL(207 passed, 3 failed, 41 skipped)。同时操作者在配置后不会看到stop/retire/archive有任何效果,违反AGENTS.md关于不得只交付未接入真实触发点空壳的要求。最小修复:接通set_goal_activation_state、retire_global_registry_goals、archive_runtime_goal并更新契约测试,或在完成前退回 Draft 并移除builtins.py注册。 - [P0] 无认证 loopback HTTP 接口允许写入任意操作系统命令:
ChatRequestHandler._require_loopback_origin允许无Origin头的本地请求与同源浏览器请求调用POST /api/chat/machine-configuration/preview与/apply。反事实测试实测直接通过 HTTP 成功持久化了['/bin/sh', '-c', 'id > /tmp/pwned'](HTTP 201 -> 200applied),并在GET响应中回显。最小修复:禁止经由公开 HTTPapply_public_update写入任意command(或仅限受保护的本地 CLI /0600配置文件 / 显式扩展清单注册),并对project_public脱敏本机路径。 - [P1]
goal_id路径穿越与 archive 幽灵目录复活:反事实测试传入goal_id="../../evil",run_goal_closeout未拒绝而是返回ledger_recorded=True并写入越界路径;此外archive_runtime_goal移除runtime_root/goals/<id>后若写同位置账本会重建空目录,被loopx/history.py再次识别为运行时 Goal。最小修复:使用validate_goal_id_path_segment(goal_id),移除cwd=repo,并将账本改为不会在归档后复活goals/<id>的路径。 - [P1]
mypy失败、canary premerge失败及跨平台/漏记账缺陷:mypy对 5 个文件实测FAIL(hooks.py:32: error: Returning Any from function declared to return "str" [no-any-return]);loopx canary premerge --tier quick --from-git-diff --git-diff-base 5cfd6ae7d571f2f97da40982db23f76540723c89实测FAIL(git diff --check报hooks.py:218: new blank line at EOF.)。此外反事实测试确认不存在的二进制文件会落入internal_error且ledger_recorded=False。最小修复:修复类型注解与 EOF 空行,复用loopx/extensions/process_runtime.py并把启动失败记入账本。
我的整体评价 / Verdict
基于当前精确 head 7423d748adbfd7cee0c01ff03e314ed82bc5a8ee 的实测验证,本次评审结论为请求修改(REQUEST_CHANGES)。
- 长程与用户体验影响:
long_horizon与user_experience均判定为regression(visual_review为not_applicable:本 PR 未改动前端源码,仅核对了configuration_ui.py与 Settings 界面回退行为)。在未接线终态调用点且未收紧 HTTP 写入边界的情况下向builtins.py注册该命名空间,会同时造成配置假象与安全面扩大。 - 本地验证摘要:
pytest tests/capabilities/test_goal_closeout_hook.py:PASS(4 passed,仅测孤立函数)pytest(机器配置/API/分布/语义/边界/ratchet 合集):FAIL(207 passed, 3 failed, 41 skipped;核心分布安装态因未设LOOPX_CORE_TEST_PYTHON跳过)pytest tests/capabilities/test_capability_configuration_ui.py tests/test_configuration_backup.py:PASS(82 passed)ruff check与node --test personal-workspace-contract.test.mjs:PASSmypy(5 个改动文件):FAIL(hooks.py:32 no-any-return)loopx canary premerge --tier quick:FAIL(hooks.py:218: new blank line at EOF.;另control-plane-maintainability-ratchet-smoke.py有 2 条基线无关 advisory 告警)- 反事实验证(
../../evil穿越、缺失二进制漏记账、无认证 HTTP 写 shell 命令):FAIL(均已实测复现) - 远端 CI:
UNVERIFIED / not_applicable(遵循wait_for_ci=false策略,未查询或等待远端 CI)
- 语义词表结论:
semantic_alignment判定为not_applicable——PR 未改动loopx/semantics/vocabulary_v0.json中任何跨运行时词表,hooks.py新增的状态字符串为局部结果字段,且examples/semantic-vocabulary-drift-smoke.py(29/29 词表)PASS;不过hooks.py的trigger与terminal_reason建议后续收敛为显式Literal或StrEnum。 - 残留风险:Windows 进程树清理与
loopx-core独立 wheel 安装态尚未在本机验证。请作者修复上述 4 项阻塞缺陷(接入终态入口或撤回builtins.py暴露、收敛 HTTP 命令写入安全边界、校验goal_id并解决 archive 冲突、修复mypy/EOF 空行并复用process_runtime.py)后重新提交复审。
English verdict: REQUEST_CHANGES on 9065@7423d748adbfd7cee0c01ff03e314ed82bc5a8ee due to unwired terminal lifecycle callers exposing a dead config namespace (breaking 3 contract tests), unauthenticated loopback HTTP command registration in machine_configuration, unvalidated goal_id path traversal, missing ledger recording on spawn errors, mypy failure, and canary premerge diff check failure.
Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
Run the command from the lifecycle layer so control-plane keeps its import boundary, validate the Goal id before any write, reuse the capped process runtime for bounded output and process-tree cleanup, and record launch failures in the ledger. Keep the command local-private: the Dashboard sees configured/timeout only and cannot persist a command. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
|
已在
执行器从 验证:closeout/archive/registry/process-runtime 117 passed、1 skipped;goal activation 55 passed;架构套件在基线与本头均为 1798 passed,98 failed(94 项同为本机缺少 npm dev dependencies)。canary quick 的六项直接检查通过;semantic-vocabulary 与 quota-plan canary 在基线同样因本机 npm/TS 环境失败。 |
archive_runtime_goal held the runtime-artifact, source, maintenance and registry locks while the terminal hook ran, so a slow operator command blocked every other registry writer for up to the configured timeout. The archive transition now resolves the hook facts under the locked snapshot and invokes the hook once every lock is released. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent (self_reported, Gemini, Google)
动机 / Motivation
面向的问题对象与触发任务:需要自动回收已完成 Goal 工作树并保留执行审计记录的运维者与代理宿主。
改动前后场景对照:改动前:执行 goal-lifecycle stop、retire-global-goal 或 archive-runtime 仅更新注册表或移动目录,不触发任何本机清理命令,也不写关闭账本;改动后:若本机通过 CLI 配置了 goal_closeout.command,三条终态路径在事务提交且释放全部规范锁之后,自动以受限子进程执行该命令、通过 stdin 传入 loopx_goal_closeout_v1 JSON 负载并将结果追加到 closeout-ledger.jsonl。
当前可观测结果与非目标边界:当前可观测结果:配置 goal_closeout 后,stop(仅首次切换至 stopped,重复调用幂等不重触发)、retire 与 archive 均在提交并释放锁后触发命令并记账,超时/失败/缺失二进制绝不阻塞或改写主命令结果;未配置时三条终态命令保持零副作用且不生成账本;loopback HTTP 接口无法写入或读取本机 command。非目标边界:不包含内置 git worktree 自动删除逻辑(proposal 2)、worktree 状态发现命令(proposal 3)、经由无认证 HTTP 注册可执行命令,以及在 Dashboard 中新增本地命令路径编辑框。
对上一轮审查 #5968911212(head 7423d748ad)提出的 4 项阻塞缺陷,本轮精确头 f92547362cfd10dce59e8912dfe067776064b028 已逐项完成修复并闭环了 archive 锁边界问题,交付了一个完整、可逆且默认关闭的终态钩子切片。
改动思路 / Approach
架构边界与所有权拆分合理:配置契约留在 machine_configuration 注册表并隔离 command 为本机 CLI 私有,子进程执行下沉至 loopx/lifecycle/goal_closeout.py 并复用 process_runtime 进程树清理与 paths 路径段校验,终态调用方在提交并释放规范锁之后以尽力而为方式触发,既未引入跨层依赖也未创建重复控制面决策所有者。
当前 PR 边界为 Issue #8918 方案一的完整可逆交付:覆盖 machine_configuration 命名空间(CLI 写 command、Dashboard 仅调 timeout_seconds)、stop/retire/archive 终态后锁外调用、以及 closeout-ledger.jsonl 账本;不包含内置 git worktree 自动删除与 worktree 状态扫描命令。
关于 TypeScript-First 与模块落点:machine_configuration 注册表、三个终态入口(activation_service.py、global_registry.py、runtime.py)及受限子进程调度(process_runtime.py)均属 Python 运行时所有者,将 run_goal_closeout 置于 loopx/lifecycle/goal_closeout.py 使 loopx/control_plane 无需反向依赖 loopx.capabilities(test_control_plane_import_boundaries.py 全部通过)。
| 路径 / 阶段 | 7423d74(旧) | f925473(当前 Head) |
|---|---|---|
| 终态入口接线 | 0 处生产调用点 | stop / retire / archive 均在提交且释放全部规范锁后调用 |
| HTTP 安全边界 | 允许经 loopback HTTP 写入任意 command |
local_only_fields 拒绝 HTTP 写 command(400),公开投影脱敏为 configured |
| 路径与账本 | 未校验 goal_id、cwd=repo、归档重建 goals/<id> |
validate_goal_id_path_segment、cwd=None、归档写目标目录、retire 回退 closeout/<id> |
| 进程治理 | 自写 Popen/临时文件、mypy 与 EOF 失败 |
复用 run_capped_process 并暴露 stderr,启动失败记为 launch_error |
具体改动 / Changes
本次基于合并基线 9dbe0f2a56077ed133d5bb3796bc2fa6df7d75a2 至精确 head f92547362cfd10dce59e8912dfe067776064b028 共改动 16 个文件(+1213 / -3),其中生产代码 12 个文件(+535 / -1),测试 4 个文件(+678 / -2)。
对照规格 Issue #8918(基准版本 issue-8918-opened-by-cuipengcx90-0-comments,proposal 1)的逐项验收如下:
| Criterion | 要求 | 当前 Head 状态 | 依据 / 验证 |
|---|---|---|---|
C-1 |
配置声明 closeout 命令与超时且安全隔离 | implemented |
goal_closeout/machine_defaults.py + contract.py + configuration_ui.py;HTTP 写 command 实测返回 400 |
C-2 |
stdin 传递有界 JSON 负载(loopx_goal_closeout_v1) |
implemented |
loopx/lifecycle/goal_closeout.py::run_goal_closeout + 单元测试与 SQLite CLI 探针 |
C-3 |
有限超时、受限输出与失败不阻塞主命令 | implemented |
复用 process_runtime.py::run_capped_process(cwd=None);实测 exit 42、1s 超时与缺失二进制均不阻塞主命令 |
C-4 |
每次调用记入只追加账本且防越界/不复活目录 | implemented |
validate_goal_id_path_segment + exclusive_file_lock;archive 写目标目录、retire 回退 closeout/<id> |
C-5 |
stop / retire / archive 提交并释放锁后触发 |
implemented |
activation_service.py、global_registry.py、runtime.py;stop 幂等重跑不重触发,archive 锁探针 FREE/FREE |
关键代码讲解
loopx/capabilities/goal_closeout/machine_defaults.py(goal_closeout_machine_configuration_namespace):定义loopx_goal_closeout_configuration_v0,通过local_only_fields=frozenset({"command"})将command锁定为本机 CLI 专属字段;_public_goal_closeout_configuration仅向 Dashboard/API 暴露configured布尔值与timeout_seconds(1–600),_apply_goal_closeout_public_update允许在线调整超时并原样保留已配置的command。loopx/capabilities/machine_configuration/contract.py(merge_machine_configuration_namespace):新增allow_local_only: bool = False默认保护。MachineConfigurationRequestMixin(loopback HTTP)默认拒绝任何命中local_only_fields的键并落回 HTTP 400;machine_configuration/cli.py在preview/apply时显式传入allow_local_only=True。loopx/lifecycle/goal_closeout.py(run_goal_closeout):入口先调用validate_goal_id_path_segment防路径穿越,再按namespace_ids=("goal_closeout",)惰性读取配置;未配置时零盘写直接返回not_configured。启用时经run_capped_process(..., cwd=None)启动进程组并截断捕获 8 KiBstdout/stderr,所有启动、超时、超输出与写账本异常均转化为结构化状态并写回closeout-ledger.jsonl,绝不向上抛错。loopx/control_plane/goals/activation_service.py(set_goal_activation_state/_stop_closeout_payload):在project_registry_transaction锁块外、仅当execute and target_state is GoalActivationState.STOPPED and changed and payload.get("ok") and payload.get("written")时调用一次钩子;已处于STOPPED状态的幂等重试changed=False,不会重复触发。loopx/runtime.py(archive_runtime_goal) &loopx/global_registry.py(retire_global_registry_goals):retire_global_registry_goals在释放维护锁与全局注册表锁后遍历retired_goals,当goals/<id>不存在时改写runtime/closeout/<id>;archive_runtime_goal(a00dd3763a)在 4 重规范锁内完成移动与元数据快照,退出ExitStack释放全部锁后再执行run_goal_closeout(..., ledger_dir=destination),实测子进程检查运行期产物锁与注册表锁均为FREE。
对主干的风险 / Risks
未发现阻塞主干或破坏兼容性的 P0/P1 缺陷;与上一轮 #5968911212 相比,3 项破坏的契约测试已全部通过,HTTP 任意命令写入、goal_id 越界、cwd=repo 锁目录、缺失二进制漏记账、mypy 报错及 EOF 空行均已修复。
- 禁用态隔离与基线对等(
default_off_isolation):基于基线9dbe0f2a56与当前 headf92547362c的同构对照执行显示,未配置goal_closeout时stop/retire/archive均正常提交(ok=true),不产生进程或账本副作用,仅在配置目录新增goal_closeout条目与返回体附加status='not_configured'状态对象。 - 两项非阻塞
P3观察:loopx/runtime.py::archive_runtime_goal在加锁前从registry提取archive_goal元数据,而非从锁内locked_registry再次取值;虽有locked_source_registry_paths与_archive_source_goal_refs预检保护,后续可顺手改读locked_registry以保持单快照一致。apps/presentation/dashboard/src/features/personal-workspace/capability-localization.ts尚未补充goal_closeout的中文翻译键,界面目前安全回退展示后端英文标题与说明;此外 Dashboard 通用的移除按钮可删除整个goal_closeout命名空间,但不构成命令注入风险。
我的整体评价 / Verdict
基于对精确 head f92547362cfd10dce59e8912dfe067776064b028 的独立测试、基线对照与真实 SQLite/CLI/HTTP 端到端探针验证,当前评审结论为建议批准(APPROVE)。
- 长程与用户体验影响:
long_horizon与user_experience均判定为improved(visual_review为not_applicable:本 PR 未修改前端代码,已核对configuration_ui.py、machine-configuration-settings.tsx与capability-localization.ts的timeout_seconds表单消费及回退路径)。钩子严格在提交且释锁后执行,失败不阻塞终态,且通过本机 CLI 与 loopback HTTP 权限切分降低了配置风险与运维负担。 - 本地验证摘要(
wait_for_ci=false,未查询或等待远端 GitHub Actions CI):pytest(closeout / 终端钩子 / machine-config API & 契约 / UI 编辑器 / 备份 / goal activation / runtime archive / global registry / process_runtime 共 11 个测试集):PASS(305 passed, 1 skipped——Windows 专属用例在 macOS 跳过)pytest tests/test_runtime_archive_concurrency.py -q:PASS(9 passed)pytest tests/architecture/test_control_plane_import_boundaries.py tests/architecture/test_goal_id_path_segment_owner.py -q:PASS(47 passed)pytest tests/architecture -q(带完整node_modules):1894 passed, 2 failed——两项失败(test_retrodiction_holds_its_frozen_baseline在E07报11/15 < 12/15,以及test_direct_project_registry_loaders_have_source_session_denial报未改动文件loopx/presentation/goal_storage_api.py)已在不可变合并基线9dbe0f2a56上复现出完全一致的失败签名(pre_existing_unrelated)- 真实 SQLite/CLI/HTTP 端到端隔离探针:
PASS(覆盖 3 个 SQLite Goal:goal_closeout禁用态、启用态stop→幂等重复stop→retire→archive、缺失goals/<id>目录回退closeout/<id>、exit 42、1s 超时、缺失二进制launch_error、../escape拒绝以及真实ChatHTTPServer拦截command注入返回 400) - 静态与契约检查:
ruff check全通过;mypy --follow-imports=silent(12 个改动文件)0 报错;git diff --check 9dbe0f2a56..HEAD通过;Dashboardtsc --noEmit与node --test personal-workspace-contract.test.mjs(4/4)通过 loopx check --scan-path ...:PASS(16 个改动文件公开边界扫描 0 error / 0 warning)loopx canary premerge --tier quick --from-git-diff --git-diff-base 9dbe0f2a56077ed133d5bb3796bc2fa6df7d75a2:PASS(ok=true,merge_gate_passed=true;direct checks 4/4、semantic-vocabulary-drift-smoke.py、quota-plan-smoke.py均通过;control-plane-maintainability-ratchet-smoke.py仅有 1 条基线已存在的interaction_contract.py::_admitted_interaction_next_cli_actionsadvisory 告警)
- 语义词表 conclusions /
semantic_alignment:判定为not_applicable——PR 未修改loopx/semantics/vocabulary_v0.json中任何跨运行时词表,新增字段均为goal_closeout模块局部值且semantic-vocabulary-drift-smoke.py通过。 - 残留风险:Windows 平台进程树终止(
CREATE_NEW_PROCESS_GROUP+taskkill)与独立安装态loopx-corewheel 尚未在当前 macOS 宿主验证;远端 CI 按wait_for_ci=false策略未查询。批准本评审本身不构成合并授权,是否合并及基线同步由维护者依据仓库策略决定。
English verdict: APPROVE on 9065@f92547362cfd10dce59e8912dfe067776064b028 — all prior blockers from review 5968911212 and the archive lock-release boundary are resolved and verified via 305 focused tests, static/canary checks, and isolated SQLite CLI/HTTP probes.
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI (runtime_reported, max)
Reviewed head f92547362cfd10dce59e8912dfe067776064b028
-
[P2] 保留已经提交并确认的停止结果。两份注册表都确认停止后,钩子的参数准备仍会重新读取来源。读失败时 CLI 退出 1 并返回
written=false。建议利用已确认的快照准备参数,并把准备失败纳入钩子诊断。停止后的注册表读取 -
[P2] 用注册表解析后的绝对路径填充钩子载荷。使用已有的相对
state_file注册时,停止、退役和归档的外部状态文件分支都把相对值传给子进程。请复用现有路径解析,归档后按文件实际位置生成路径。停止 · 退役 · 归档
动机 / Motivation
用独立 Git worktree 执行 Goal 的操作者,在停止、退役或归档之后需要知道何时可以开始整理工作目录。
过去归档只移动 LoopX 运行目录,操作者还要逐个对照 Goal 和工作目录,或为每种宿主维护一套清理入口。这个 PR 允许操作者设置一次本机命令,让三种操作在提交后把 Goal 和路径交给同一个程序,并留下一条调用记录。
用真实 CLI 验证了三条成功路径。现有注册的相对状态路径会让消费方拿不到所需的绝对路径,停止后读取注册表的异常还会掩盖已经提交的结果。
范围限于提供终态通知和调用记录。目录清理规则和通用扩展触发器属于 Issue 中的其他提案。
改动思路 / Approach
三个生命周期入口各自保留已有的权限检查、锁和提交顺序。已提交的终态才产生可选通知。执行器从本机配置读命令,使用已有进程约束处理退出、超时与输出,并把此次执行追加到本机记录。 终态钩子实现 · 通用进程执行器
把机器配置当作一次注册,将命令放在终态确认之后,复用通用进程边界。提交后的通知仍要隔离路径解析和读取异常。 本 PR 可在既有状态路径解析和终态写回的边界内补齐,不需要新增运行时或扩展调度。 项目注册的状态路径已有明确规则,退役资格检查也已解析相对值。这两处规则能直接支撑载荷中的路径语义。 项目注册路径 · 全局路径解析
具体改动 / Changes
本次改动涉及 16 个文件,+1213 / −3。主要新增集中在机器配置、三个提交后的调用点、钩子执行和验证。验收依据为 Issue #8918 的 Proposal 1,读到的正文版本为 sha256:aa2fd7a4818b17cf5627f14fd7b557706548e16eb1297c3b90b3308e70e6ba3d。 Issue #8918
terminal-triggers。停止、退役和运行目录归档成功提交后触发一次。 已验证。set_goal_activation_state、retire_global_registry_goals、archive_runtime_goal三条真实 CLI 执行及无写入预览对照。stdin-payload。向标准输入提供loopx_goal_closeout_v1及 Goal、绝对 worktree 和状态路径、终态原因和 runtime root。 未满足。相对state_file从三个入口原样进入载荷。 通过各入口现有注册表路径所有者生成绝对路径。timeout。执行有有限超时。 已验证。run_goal_closeout与run_capped_process本地 1 秒超时、普通命令退出及启动失败用例。best-effort。钩子失败时触发命令仍报告实际完成的终态。 未满足。停止后准备参数的注册表读取失败会覆盖已写入结果。 将准备异常与执行异常放在同一 best-effort 边界,保留原有终态回执。ledger。记录已执行的调用。 已验证。_write_ledger三个 CLI 的合成 ledger 行及归档后位置读回。
关键代码讲解
-
merge_machine_configuration_namespace通过已有机器配置事务写入。CLI 可设置命令,Dashboard 表单可设置超时;配置投影只返回是否已有命令及超时值。 命名空间更新 · 编辑器描述 -
set_goal_activation_state先完成注册表写回和验证,再根据本次是否确实进入停止状态调用钩子。相同状态的重复停止不产生第二条调用记录。 停止触发门 -
retire_global_registry_goals从实际移除的记录取信息,保留原有备份与资格检查,释放维护锁后逐项通知。 退役后通知 -
archive_runtime_goal在原锁内移动运行目录,释放锁后执行。随目录移动的状态文件与留在项目中的状态文件需要各自准确定位。 归档与位置选择 -
run_goal_closeout复用进程执行器处理退出、超时和诊断输出,给尝试过的调用追加 ledger。未设置命令时没有子进程或账本记录。 执行与记录 · 执行器用例
对主干的风险 / Risks
用同一合成状态分别运行基线 9dbe0f2a56077ed133d5bb3796bc2fa6df7d75a2 和当前 head,检查进程退出、终态读回和账本结果。
| 验证条件 | 实际结果 |
|---|---|
| 缺省配置,正常执行三种操作 | 基线与 head 都完成相同终态,预览无调用;head 增加可选的钩子结果字段。 |
| 成功读回后注入来源注册表读取错误 | 基线退出 0。head 退出 1,报告 written=false,持久化状态已经停止。 |
| 在项目之外调用,用相对路径登记状态 | 三条命令完成终态,接收方因路径不符合契约退出,账本各留一条失败。绝对路径对照组各留一条成功。 |
两个失败都可以在一次小修后重跑。停止保留原回执并单独记录钩子准备错误,路径修复复用注册表解析。建议回归用例从另一个目录走真实 CLI,并同时检查返回值、注册表和账本。
本地定向测试 223 项通过,1 项 Windows 用例跳过。标准 premerge 通过,有一条与本 diff 无关的既有可维护性 advisory。已观察到目标分支存在测试文件冲突,合并前需更新分支并验证新 head。
语义与 CI 对齐
终态成功的判定仍由写入和读回构成。可选钩子仅消费该结果;当前 head 的准备异常改变了可观察行为。新版本化载荷与账本记录作为生命周期接口扩展,解决路径和返回值契约后,用同一文件系统 fixture 重跑三条命令。GitHub CI 未纳入本次验证。
我的整体评价 / Verdict
REQUEST_CHANGES。长期运行中,停止已提交却显示失败会引发多余的重试。用户操作方面,设置页的超时预览和应用已在实际 Chat HTTP 后端读回,过期预览被拒绝,重新加载并应用后保留了本机命令。三个终态入口仍需把报告的结果与持久状态、路径对齐。
在同一源码构建的能力中心,超时输入和变更按钮集中在一个卡片。桌面默认视图显示配置来源,是否有命令要展开原始 JSON 才看得到。窄屏保留了可读的超时值,展开后能读到配置状态。 浏览器覆盖本地构建和合成机器配置。正式打包安装、Lark 界面及更长的真实目录数据保留为未验证。
范围和共用进程执行器都适合这项需求。当前最有价值的收敛是共用已有路径规则,并保持通知失败的诊断留在钩子结果里。修复后请用相同 fixture 验证缺省关闭、相对路径、提交后读失败和正常重试。
English verdict: REQUEST_CHANGES. At f92547362cfd10dce59e8912dfe067776064b028, the stop hook can mask a committed stop after a registry read error, and supported relative registrations reach the hook without the required absolute state path. Local CLI, browser settings, and focused tests were run.
| from ...lifecycle.goal_closeout import run_goal_closeout | ||
|
|
||
| closeout_runtime_root = resolve_runtime_root( | ||
| load_registry(source_registry), |
There was a problem hiding this comment.
[P2] 保留已提交的停止回执
这个 load_registry 发生在两份注册表都读回 stopped 之后。用相同 fixture 只让这次读失败,基线退出 0,当前 head 退出 1 并报告 written=false,但写入已经完成。空配置也会进入这里。请从已验证的快照取所需参数,并把剩余准备异常记入钩子诊断。回归用例应在真实 goal-lifecycle --operation stop --execute 上同时断言退出码、written 和两份持久状态。
| runtime_root=closeout_runtime_root, | ||
| goal_id=goal_id, | ||
| repo=str(closeout_goal.get("repo")) if closeout_goal.get("repo") else None, | ||
| state_file=str(state_file), |
There was a problem hiding this comment.
[P2] 使用注册表解析后的绝对状态路径
相对 state_file 是已有的合法注册值。从独立目录执行真实 CLI 时,接收器收到原始相对路径,因不符合 Issue #8918 的载荷约定而失败。停止、退役和归档外部状态文件的分支都复现了。请复用已有注册路径规则,并在归档后按文件是否移动生成目标路径。用等义的相对/绝对注册各跑三条公开入口,核对接收路径和 ledger。
Closes #8918.
Goal And Delivered Outcome
goal-lifecycle stop,retire-global-goalandarchive-runtimeinvoke the configuredgoal_closeoutcommand after the terminal transition commits. The command receives one bounded JSON payload on stdin, runs with a finite timeout under the shared capped-process runtime (process-tree cleanup, bounded stdout/stderr), and the attempt is appended to a closeout ledger. A command failure, timeout or launch error never changes the triggering command's result.main.Review follow-up (
3d784d44a)commandcommandis a local-only field: the namespace merge used by/previewand/applyrejects it,project_publicreturns onlyconfiguredandtimeout_seconds, and the localmachine-configCLI keeps write access. A real HTTP request now returns 400 and writes no file.goal_idpath traversalvalidate_goal_id_path_segmentbefore reading the configuration or writing a ledger; an invalid id returnsinvalid_goal_idwith no disk change.cwd=repoheld a handle inside a worktree being archivedcwd=None.internal_errorwithledger_recorded=falselaunch_errorin the ledger and returned without raising.run_capped_process/terminate_process_tree;CappedProcessResultnow also exposes the boundedstderr.no-any-returnin the capture helpergit diff --checkblank line at EOFgoals/<id>runtime/closeout/<id>; the archive test asserts the source directory stays gone.timeout_seconds; the command stays CLI-only and the field copy says so.The executor moved from
loopx/capabilities/goal_closeout/hooks.pytoloopx/lifecycle/goal_closeout.pysoloopx/control_planedoes not depend onloopx.capabilitiesand the stop function stays under the decision-size ratchet.Review follow-up (
a00dd3763)archive_runtime_goalnow resolves the hook facts inside the locked snapshot and invokesrun_goal_closeoutonly after theExitStackreleases all canonical locks. The stop and retire paths already ran the hook outside their locks.test_archive_runs_closeout_after_canonical_locks_are_releasedconfigures a real probe command that tries to acquire the runtime-artifact and registry locks with a zero deadline from a child process, and asserts both are free when the hook runs. The test fails against the previous head and passes witha00dd3763.Author Declaration
Implemented against
loopx/capabilities/goal_closeout/machine_defaults.pyloopx/capabilities/machine_configuration/contract.py,loopx/capabilities/goal_closeout/machine_defaults.pyloopx/lifecycle/goal_closeout.pyloopx/lifecycle/goal_closeout.pyloopx/lifecycle/goal_closeout.pyloopx/control_plane/goals/activation_service.pyloopx/global_registry.pyloopx/runtime.pyScope And Continuation
goal-lifecycle stop,retire-global-goalandarchive-runtime; each path has an entry-point test.Validation
a00dd3763unitpassedpython3 -m pytest tests/control_plane/test_goal_activation.py tests/capabilities/test_goal_closeout_hook.py tests/capabilities/test_goal_closeout_terminal_hooks.py tests/test_runtime_archive.py tests/test_global_registry_write_serialization.py tests/extensions/test_process_runtime.py tests/extensions/test_process_runtime_startup.py -q— 173 passed, 1 skipped.real_entrypointpassedtests/capabilities/test_goal_closeout_terminal_hooks.py.real_entrypointpassedpython3 -m pytest tests/test_chat_machine_configuration_api.py tests/capabilities/test_machine_configuration_contract.py -q— 50 passed, including the real loopback HTTP command rejection.real_entrypointpassedpython3 -m pytest tests/control_plane/test_goal_activation.py -q— 55 passed; the archive lock probe intest_archive_runs_closeout_after_canonical_locks_are_releasedasserts the child process can take the runtime-artifact and registry locks while the hook runs.staticpassedpython3 -m mypy loopx/lifecycle loopx/capabilities/goal_closeout loopx/capabilities/machine_configuration/contract.py loopx/runtime.py;git diff --check;loopx canary premerge --tier quick --from-git-diffdirect checks pass (diff hygiene, compile, module ceiling).regression_paritypassedpython3 -m pytest tests/architecture -q— 1798 passed, 98 failed on both this head and the base commit; 94 failures share the missing local npm dev dependencies.staticnot_runFrontend / Visual Evidence
timeout_secondseditor field only).Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
Boundary Checklist
none.Signed-off-bytrailer.