Skip to content

feat(goal-closeout): invoke terminal hook on stop, retire and archive - #9065

Open
gcl-coder wants to merge 10 commits into
loopx-project:mainfrom
gcl-coder:codex/goal-closeout-hook
Open

gcl-coder wants to merge 10 commits into
loopx-project:mainfrom
gcl-coder:codex/goal-closeout-hook

Conversation

@gcl-coder

@gcl-coder gcl-coder commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Review follow-up (ea8fc1ebc)

Finding Fix
[P2] A raising projection writer bypasses the closeout hook and loses the committed stop receipt The post-commit boundary now reports faults instead of letting them escape. _project_committed_transition turns a raising sync_project_registry_to_global into a global_sync_failed receipt, and _readback_committed_transition turns a raising readback into readback_failed. Both run after the source commit, so written=true, partial_write=true, the failure reason, and the single hook dispatch all survive; the retry reconciles the projection without a second hook call.

Verification on ea8fc1ebc (rebased onto b97818e51): 135 tests across test_goal_closeout_terminal_hooks.py, test_goal_closeout_hook.py, test_goal_activation.py, test_runtime_archive.py, test_global_registry_write_serialization.py and test_chat_machine_configuration_api.py; ruff check clean; scoped mypy clean. New regressions test_stop_runs_closeout_when_shared_registry_writer_raises_eio and test_stop_runs_closeout_when_readback_raises fail on 58b164601 (OSError: [Errno 5] escaping) and pass here. I also replayed the reviewer's path through the real CLI handler with a temporary File registry, a real subprocess hook, and one injected EIO: first stop exits 1 with written=true, partial_write=true, global_sync.error_kind=global_sync_failed, closeout.status=success, one hook payload; the retry exits 0 with projection_reconciled=true, no closeout key, still one hook payload.

Review follow-up (58b164601)

Finding Fix
[P2] A committed stop followed by a transient projection sync failure never dispatches the configured closeout, and retries never back-fill The stop hook is now gated on the committed source transition (changed and written) instead of the combined readback. The source registry owns the transition, the shared projection is a separately reported, fixable fault, and a retry cannot re-enter the branch because the source is already stopped, so the hook runs exactly once for the committed stop. A preview or a repeated stop still runs nothing.

Verification on 58b164601 (rebased onto 871cc3634): 133 tests across test_goal_closeout_terminal_hooks.py, test_goal_closeout_hook.py, test_goal_activation.py (55), test_runtime_archive.py, test_global_registry_write_serialization.py and test_chat_machine_configuration_api.py; ruff check clean; scoped mypy clean. The new regression test_stop_runs_closeout_for_committed_transition_when_projection_fails fails on a16896db8 (KeyError: 'closeout', empty ledger) and passes here, including the retry that reconciles the projection with no second hook call.

Review follow-up (a16896db8)

Finding Fix
[P1] Committed retirement reported as wrote=false when hook preparation fails Each retired record is prepared inside _retire_closeout_payload after the removal commits; it never raises past the receipt, resolves nothing when no command is configured, and reports a per-record preparation_error while retirement keeps ok/wrote.
Preflight rejected an unexpandable state_file alias _global_goal_path treats a value that cannot be expanded as a missing path, so an old alias no longer blocks the retirement before it commits.

Verification on a16896db8: 132 tests across closeout hook, terminal hooks, goal activation, runtime archive, global-registry serialization and machine-configuration API; Ruff clean; scoped mypy clean. Both new retire regressions fail on c9d3b3184.

Closes #8918.

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Feature request: a terminal-state (closeout) hook so finished goal worktrees can be reclaimed #8918, proposal 1 — a terminal-state command declared in machine configuration.
  • Goal/source and gap: LoopX can stop, retire or archive a Goal, but it had no LoopX-owned seam for running a closeout step at that moment. Operators had to hook each host separately, and LoopX never recorded whether cleanup ran.
  • Observable before → after: Before this change, a configured closeout command was never invoked. After this change, goal-lifecycle stop, retire-global-goal and archive-runtime invoke the configured goal_closeout command 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.
  • Issue/task and intended base: Closes Feature request: a terminal-state (closeout) hook so finished goal worktrees can be reclaimed #8918. Intended base: main.

Review follow-up (3d784d44a)

Finding Fix
[P0] Three directory/contract tests still expect the old namespace list Updated the pinned lists and the machine-only capability set; real loopback HTTP tests pass.
[P0] Unauthenticated loopback HTTP can persist an arbitrary command command is a local-only field: the namespace merge used by /preview and /apply rejects it, project_public returns only configured and timeout_seconds, and the local machine-config CLI keeps write access. A real HTTP request now returns 400 and writes no file.
[P1] goal_id path traversal Validated with validate_goal_id_path_segment before reading the configuration or writing a ledger; an invalid id returns invalid_goal_id with no disk change.
[P1] cwd=repo held a handle inside a worktree being archived The command runs with cwd=None.
[P1] Missing executable fell into internal_error with ledger_recorded=false Launch errors are recorded as launch_error in the ledger and returned without raising.
[P1] Hand-rolled process handling Reuses run_capped_process / terminate_process_tree; CappedProcessResult now also exposes the bounded stderr.
[P1] mypy no-any-return in the capture helper The helper is gone; mypy is clean on the changed modules.
[P1] git diff --check blank line at EOF Removed; committed diff check passes.
[P1] Archive ledger recreated goals/<id> Archive writes into the archive destination, retire falls back to runtime/closeout/<id>; the archive test asserts the source directory stays gone.
Dashboard namespace had no editor Added a machine editor with timeout_seconds; the command stays CLI-only and the field copy says so.

The executor moved from loopx/capabilities/goal_closeout/hooks.py to loopx/lifecycle/goal_closeout.py so loopx/control_plane does not depend on loopx.capabilities and the stop function stays under the decision-size ratchet.

Review follow-up (c9d3b3184)

Finding Fix
[P1] mypy arg-type: Mapping snapshot passed to resolve_runtime_root _stop_closeout_payload keeps the transaction snapshot's concrete dict[str, Any] type for both the registry and the Goal record; scoped mypy --follow-imports=silent goes from 1 error to clean.
[P2] Global-registry archive and orphaned global stop deliver an unreadable state_file New goal_state_file_from_record in loopx/paths.py is the single hook-payload resolver: absolute wins; project registries keep resolving from their project root; a global registry resolves from the Goal repo, then its own directory. Both routes call it; regressions assert the payload is the project file and reads back.
[P2] Disabled hook can mask a committed archive The archive lock block copies confirmed facts and releases; all fallible preparation moved into the post-lock _archive_closeout_payload, which never raises and touches no declared path when no command is configured. Regression: stale home alias, no hook → exit 0, archive present, not_configured, no ledger.

Verification on c9d3b3184: 130 tests across closeout hook, terminal hooks, goal activation, runtime archive, global-registry serialization and machine-configuration API; Ruff clean; scoped mypy clean. The two global-path regressions and the stale-alias regression fail on 260babb49.

Review follow-up (a00dd3763)

Finding Fix
The archive transition ran the terminal command while it still held the runtime-artifact, source, maintenance and registry locks, so one slow hook could block every registry writer for up to the configured timeout archive_runtime_goal now resolves the hook facts inside the locked snapshot and invokes run_goal_closeout only after the ExitStack releases all canonical locks. The stop and retire paths already ran the hook outside their locks.
Regression coverage for the lock boundary New test_archive_runs_closeout_after_canonical_locks_are_released configures 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 with a00dd3763.

Author Declaration

  • Written by: model_agent, reviewed and submitted by the human operator.

Implemented against

Criterion (spec clause) Disposition Symbol / path Test or command
Terminal-state command declared in machine configuration implemented loopx/capabilities/goal_closeout/machine_defaults.py configuration plus executor unit tests
Command stays local-private; Dashboard read-only implemented loopx/capabilities/machine_configuration/contract.py, loopx/capabilities/goal_closeout/machine_defaults.py projection/update tests and real HTTP rejection test
Bounded JSON payload on stdin implemented loopx/lifecycle/goal_closeout.py payload and ledger unit test
Finite timeout; bounded output; failure never blocks the triggering command implemented loopx/lifecycle/goal_closeout.py timeout, launch-error and command-failure unit tests
Invocation recorded in an append-only ledger implemented loopx/lifecycle/goal_closeout.py ledger unit tests
Invoked after stop implemented loopx/control_plane/goals/activation_service.py stop entry-point test
Invoked after retire implemented loopx/global_registry.py retire entry-point test
Invoked after archive implemented loopx/runtime.py archive entry-point test
  • Self-check before submission: Reproduced each review finding on the prior head, then re-ran the focused suites on the new head on local macOS, including a real loopback HTTP request, an invalid Goal id, a missing executable and the archived-directory ledger path.

Scope And Continuation

  • Completed scope and remaining work: Complete within this scope. The executor is invoked from goal-lifecycle stop, retire-global-goal and archive-runtime; each path has an entry-point test.
  • Slice boundary / successor: Complete within this scope; no successor needed.

Validation

  • Tested revision: a00dd3763
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
unit passed python3 -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_entrypoint passed stop, retire and archive entry-point tests in tests/capabilities/test_goal_closeout_terminal_hooks.py.
real_entrypoint passed python3 -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_entrypoint passed python3 -m pytest tests/control_plane/test_goal_activation.py -q — 55 passed; the archive lock probe in test_archive_runs_closeout_after_canonical_locks_are_released asserts the child process can take the runtime-artifact and registry locks while the hook runs.
static passed python3 -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-diff direct checks pass (diff hygiene, compile, module ceiling).
regression_parity passed python3 -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.
static not_run The maintainability, semantic-vocabulary and quota-plan canaries are blocked by the same missing npm/TS local setup at both base and head; the maintainability result for this diff is advisory and inherited.
  • Coverage and gaps: Configuration, projection, HTTP rejection, invalid Goal id, missing executable, timeout, command failure and ledger paths are covered by focused tests; stop, retire and archive each have an entry-point test. Windows process handling and an installed-wheel invocation remain untested.

Frontend / Visual Evidence

  • UI impact: none (the Dashboard receives the existing capability catalog entry with a timeout_seconds editor field only).

Type of Change

  • New feature

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

Technical Direction

  • Direction / acceptance reference, when applicable: N/A — issue-scoped feature.

Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A
  • Semantic dimensions changed, or reviewed no-impact rationale: N/A
  • Provider conformance arms run: N/A
  • Read-only legacy/file/PostgreSQL three-arm rehearsal: N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths.
  • I did not duplicate maintainer-owned benchmark work.
  • I kept the change scoped to the linked issue/task.
  • No paired RFC changed; the bilingual RFC check is not applicable.
  • UI impact is marked none.
  • Every commit includes a DCO Signed-off-by trailer.

Latest revision (10df7a231)

Rebased onto a05425b57. Both findings from review 5979637102 are fixed:

  • Committed stop keeps its receipt. _stop_closeout_payload now uses the registry snapshot confirmed inside the committing transaction instead of re-reading the source registry. A read that would fail after the commit can no longer turn a persisted stop into written=false. Any preparation failure is reported as closeout.status = "preparation_error" while the stop keeps ok and written.
  • Relative state_file is resolved before the hook. Stop, retire and archive resolve a registered relative state_file against the registry project root; archive still points the payload at the archived copy after the move.

Verification: 126 tests pass across test_goal_closeout_terminal_hooks.py (14), test_goal_closeout_hook.py, test_goal_activation.py (55), test_runtime_archive.py, test_global_registry_write_serialization.py and test_chat_machine_configuration_api.py (21). ruff check is clean on the changed files. New regressions cover a relative stop/retire registration and a registry read that only fails once the stop is committed.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 处生产调用点

关键代码讲解

  1. 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 内持有目录句柄。
  2. 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) 重新造出空目录。
  3. loopx/capabilities/goal_closeout/hooks.py#L30 (_Capture.text) & #L59 (_terminate):前者因 handle: Any 导致 mypy 报 no-any-return 且不限制进程运行期写入临时文件的总大小;后者仅用 os.killpg 清理进程组,在 Windows 回退到单进程 process.kill()。
  4. 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 既可写也可回显本机可执行路径与脚本参数。
  5. loopx/capabilities/machine_configuration/builtins.py#L82 (build_builtin_machine_configuration_registry):延迟注册了 goal_closeout,立即改变了默认可用命名空间集合与 /api/chat/machine-configuration 目录输出,破坏了 3 项既有测试。

对主干的风险 / Risks

  1. [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 注册。
  2. [P0] 无认证 loopback HTTP 接口允许写入任意操作系统命令:ChatRequestHandler._require_loopback_origin 允许无 Origin 头的本地请求与同源浏览器请求调用 POST /api/chat/machine-configuration/preview 与 /apply。反事实测试实测直接通过 HTTP 成功持久化了 ['/bin/sh', '-c', 'id > /tmp/pwned'](HTTP 201 -> 200 applied),并在 GET 响应中回显。最小修复:禁止经由公开 HTTP apply_public_update 写入任意 command(或仅限受保护的本地 CLI / 0600 配置文件 / 显式扩展清单注册),并对 project_public 脱敏本机路径。
  3. [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> 的路径。
  4. [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:PASS
    • mypy(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.

@gcl-coder gcl-coder changed the title feat(goal-closeout): add bounded terminal-state hook executor feat(goal-closeout): invoke terminal hook on stop, retire and archive Nov 19, 2026
@gcl-coder

Copy link
Copy Markdown
Contributor Author

已在 3d784d44a 处理上一轮评审的全部阻塞项,PR 正文的 “Review follow-up” 表逐项对应。

  • [P0] 目录契约测试:更新了三处命名空间/能力清单,补齐 goal_closeout 的模板断言和 machine-only 集合。tests/test_chat_machine_configuration_api.py 与 tests/capabilities/test_machine_configuration_contract.py 共 50 项通过。
  • [P0] 匿名 loopback HTTP 写 command:command 现在是 local-only 字段。/preview 和 /apply 走的 namespace merge 会拒绝它,project_public 只返回 configured 与 timeout_seconds,本机 machine-config CLI 仍可写。真实 HTTP 测试断言 400、错误文案与 machine/configuration.json 不存在;Dashboard 编辑器只保留 timeout,并注明 command 仅限本机 CLI。
  • [P1] Goal ID 路径穿越:在任何读取配置或写账本之前调用 validate_goal_id_path_segment;非法 ID 返回 invalid_goal_id,不落盘、不执行。
  • [P1] cwd=repo:改为 cwd=None,归档时不再持有待删 worktree 内的目录句柄。
  • [P1] 缺失可执行文件:启动失败记为 launch_error 并写入账本,ledger_recorded=true,不再落进 internal_error。
  • [P1] 进程治理:复用 run_capped_process(超时终止进程组、stdout/stderr 有界);CappedProcessResult 增加 stderr 字段。mypy 与 git diff --check 均通过。
  • [P1] 归档账本重建 goals/<id>:归档写回 archive 目标目录,retire 在源目录不存在时写 runtime/closeout/<id>;归档测试断言源目录保持消失。
  • Dashboard 无编辑器:补了 goal_closeout 的 timeout_seconds 机器编辑器。

执行器从 loopx/capabilities/goal_closeout/hooks.py 移到 loopx/lifecycle/goal_closeout.py:loopx/control_plane 不再依赖 loopx.capabilities,set_goal_activation_state 也回到决策规模上限内(maintainability 棘轮只剩基线上已存在的两项,且本 diff 为 advisory inherited)。

验证: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 环境失败。

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

关键代码讲解

  1. 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。
  2. 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。
  3. 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 KiB stdout/stderr,所有启动、超时、超输出与写账本异常均转化为结构化状态并写回 closeout-ledger.jsonl,绝不向上抛错。
  4. 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,不会重复触发。
  5. 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 与当前 head f92547362c 的同构对照执行显示,未配置 goal_closeout 时 stop / retire / archive 均正常提交(ok=true),不产生进程或账本副作用,仅在配置目录新增 goal_closeout 条目与返回体附加 status='not_configured' 状态对象。
  • 两项非阻塞 P3 观察:
    1. loopx/runtime.py::archive_runtime_goal 在加锁前从 registry 提取 archive_goal 元数据,而非从锁内 locked_registry 再次取值;虽有 locked_source_registry_paths 与 _archive_source_goal_refs 预检保护,后续可顺手改读 locked_registry 以保持单快照一致。
    2. 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 通过;Dashboard tsc --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_actions advisory 告警)
  • 语义词表 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-core wheel 尚未在当前 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.

@mergify

mergify Bot commented Nov 19, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @gcl-coder.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

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 HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 19, 2026

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 使用注册表解析后的绝对状态路径

相对 state_file 是已有的合法注册值。从独立目录执行真实 CLI 时,接收器收到原始相对路径,因不符合 Issue #8918 的载荷约定而失败。停止、退役和归档外部状态文件的分支都复现了。请复用已有注册路径规则,并在归档后按文件是否移动生成目标路径。用等义的相对/绝对注册各跑三条公开入口,核对接收路径和 ledger。

@gcl-coder
gcl-coder force-pushed the codex/goal-closeout-hook branch from f925473 to 10df7a2 Compare November 20, 2026 06:33
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 20, 2026
@gcl-coder

Copy link
Copy Markdown
Contributor Author

Replying to review 5979637102. Both P2 findings are fixed at 10df7a231 (rebased onto a05425b57).

  1. Committed stop masked by registry read. _stop_closeout_payload now receives the registry snapshot confirmed inside the committing transaction (registry_snapshot=source_payload) and no longer re-reads the source registry. Any remaining preparation failure is converted to status: "preparation_error" / ledger_recorded: false while the stop keeps ok and written. The new regression makes load_registry fail only once a Goal is stopped: the stop still reports closeout.status == "success", which proves the post-commit re-read is gone, and the ledger is written.

  2. Relative state_file reached the hook raw. Stop resolves it against registry_project_root(source_registry); retire reuses _global_goal_path (repo-relative, like the other global fields); archive resolves against registry_project_root(registry_path) and the archived copy still wins after the move. Regressions assert absolute payload paths for a relative stop and retire registration; the archive test already asserted the archived copy.

Verification: 126 tests pass — test_goal_closeout_terminal_hooks.py (14), test_goal_closeout_hook.py, test_goal_activation.py (55), test_runtime_archive.py, test_global_registry_write_serialization.py and test_chat_machine_configuration_api.py (21). ruff check is clean on the changed files. The rebase conflict in test_chat_machine_configuration_api.py was resolved as the union of main's steward_memory and this PR's goal_closeout in the machine-only set.

@gcl-coder

Copy link
Copy Markdown
Contributor Author

CI note on 10df7a231 (not a review request). 31 checks pass, including checks, dashboard-acceptance and typescript-coverage. The six failures are in paths this PR does not touch:

  • prepare: stops at the existing runtime-default contract qualification (Runtime default contract is unqualified for public adoption).
  • windows-powershell: fails in test_sqlite_authority_cli.py quota writeback with refresh_task_lease_unavailable.
  • stage2c / stage2c-correctness-e2e: reports mutation locator drift in the stage2c oracle.
  • build x2: downstream of the above.

The same three PR-only jobs (windows-powershell, stage2c, stage2c-correctness-e2e) also fail on #9080, which only changes public-safe text and presentation, so they are shared baseline failures rather than regressions from either change. No local action remains on this PR; it is waiting for re-review.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google DeepMind · self_reported

基于当前精确 head 10df7a231c079576a034c5dd8f594b0e8255bb57 的静态检查、定向测试集与隔离 CLI/SQLite/File 反事实探针,本次复审结论为请求修改(REQUEST_CHANGES)。作者已修复上一轮(review 5979637102)中 stop 提交后重读注册表覆盖已写入回执的问题,并修复了项目注册表路由下的相对 state_file 解析;但本次新提交在 activation_service.py 引入了 mypy 类型回归,且在全局注册表路由的 archive-runtime(标准 bootstrap 目录布局)与孤立全局注册表 stop 回退路径下,相对 state_file 仍被解析到运行根或家目录而非项目目录。

动机 / Motivation

需要在 Goal 结束时自动回收独立 Git worktree 并审计清理执行的运维者与代理宿主,在执行 goal-lifecycle --operation stop、retire-global-goal 或 archive-runtime 时会遇到该问题。

改动前:上述三条终态命令仅更新注册表或迁移运行目录,不会调用任何由 LoopX 统一管理的外部清理钩子,也不会记录清理尝试是否成功,运维者只能在各宿主分别挂接脚本且无法在 LoopX 侧审计,导致大量历史工作目录持续占用磁盘。改动后:当本机配置了 goal_closeout 命令时,三条终态入口在事务提交并释放规范锁之后,通过有限超时子进程执行命令、向 stdin 传入状态载荷并把结果追加到账本,且钩子失败、超时或启动错误不会改写或阻塞主命令的终态结果。

本次 PR 的边界限于 Issue #8918 方案一:本机 CLI 配置 goal_closeout 命名空间、三条终态入口的锁外触发以及 closeout-ledger.jsonl 调用账本;不包含内置 git worktree 自动删除、worktree 状态发现命令,也不允许经由无认证 loopback HTTP 接口读取或写入可执行命令。已验证可运行路径在局部有效,但当前精确 head 仍存在一处新增 mypy 类型错误及全局注册表路由下 state_file 路径解析缺口,需修复后再合入。

改动思路 / Approach

整体将配置契约留在 machine_configuration 注册表、将子进程执行与账本落盘下沉至 loopx/lifecycle/goal_closeout.py 并复用 process_runtime 与 paths 校验,使控制面无需反向依赖能力包且不引入新的常驻决策者,权限与故障边界清晰。当前 PR 边界覆盖 goal_closeout 机器配置(CLI 读写命令、Dashboard 仅读写超时)、stop/retire/archive 终态提交并释锁后调用以及账本记录;未包含内置 worktree 删除或扫描命令。

flowchart LR
    T["stop / retire / archive 事务提交并释放全部锁 (10df7a231c)"] --> G{"goal_closeout.command 已配置?"}
    G -->|否| N["返回 not_configured · 零子进程/零账本"]
    G -->|是| P["构造 loopx_goal_closeout_v1 JSON 载荷"]
    P --> R["run_capped_process(cwd=None, 8KiB 上限, 超时杀进程组)"]
    R --> L["追加 closeout-ledger.jsonl · 主命令保持已提交结果"]
Loading

(说明:以上为基于精确 head 源码路径 set_goal_activation_state、retire_global_registry_goals、archive_runtime_goal 与 run_goal_closeout 的控制流示意,非运行时自动生成截图,其中相对 state_file 在全局归档路径中的分支存在下述实测偏差。)

在状态与所有权设计上:goal_closeout.command 属于本机管理员显式配置的不可推导意图,通过 MachineConfigurationNamespace.local_only_fields 隔离在本地 machine-config CLI 写通道,loopback HTTP /preview 与 /apply 默认以 allow_local_only=False 拒绝写入并通过 project_public 脱敏为 configured 布尔值;生命周期层严格在事务提交且全部规范锁释放后调用执行器,确保钩子异常与准备异常只落在 closeout 字段或 closeout-ledger.jsonl 中,不会掩盖已提交的终态结果。

具体改动 / Changes

本 PR 基于 a05425b576dafca2ba16105f796672ec89c07bfb 至 10df7a231c079576a034c5dd8f594b0e8255bb57 共修改 16 个文件(+1408 / -3),其中生产代码 12 个文件(+576 / -1)、测试代码 4 个文件(+832 / -2)。对照规格 Issue #8918(修订 issue-8918-proposal-1)各项要求验收如下:

Criterion 要求 当前 Head 状态 依据 / 缺口
C-1 配置声明 closeout 命令与超时且安全隔离 implemented loopx/capabilities/goal_closeout/machine_defaults.py、loopx/capabilities/machine_configuration/contract.py;test_goal_closeout_real_http_rejects_a_command_update 与单元测试通过
C-2 stdin 传递 loopx_goal_closeout_v1 有界载荷及绝对路径 not_met archive_runtime_goal 走 registry.global.json 且运行目录无 ACTIVE_GOAL_STATE.md 时,以及 ORPHANED_GLOBAL_STOP_FALLBACK 路径下,相对 state_file 解析到运行根或家目录而非 repo / source_registry 项目根
C-3 有限超时、受限输出且失败不阻塞主命令 implemented loopx/lifecycle/goal_closeout.py::run_goal_closeout 复用 run_capped_process;CLI 实测 exit 42、1 秒超时、缺失二进制均返回主命令 ok=true
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(注:activation_service.py 存在 1 处 mypy 静态类型回归)

关键代码讲解

  1. loopx/control_plane/goals/activation_service.py#L568 (_stop_closeout_payload):接收事务内确认的 registry_snapshot 和 closeout_goal,在外层 try/except 内计算 runtime_root 与绝对 state_file 并调用 run_goal_closeout,使提交后准备错误只返回 status="preparation_error" 而不覆盖已提交回执(修复了 review 5979637102 的第一项 P2)。但新增参数注解为 Mapping[str, Any] 后直接传给要求 dict[str, object] 的 resolve_runtime_root 导致 mypy 报错,且在 ORPHANED_GLOBAL_STOP_FALLBACK 分支下 source_registry 为全局注册表时仍错用 registry_project_root(source_registry)。
  2. loopx/runtime.py#L251 (archive_runtime_goal):在四重规范锁内移动 runtime_root/goals/<id> 并组装 closeout_request,退出 ExitStack 释锁后执行钩子并将账本写入归档目标目录。问题在于当 archived_state_file 不存在于归档目录时(标准 bootstrap 项目将其保存在 <project>/.loopx/goals/<id>/ACTIVE_GOAL_STATE.md),代码对 declared_state_file 直接使用 registry_project_root(registry_path),当 --registry 为全局注册表时解析结果落入运行根或家目录。
  3. loopx/global_registry.py#L662 (retire_global_registry_goals):释放维护锁与全局注册表锁后遍历 receipt["retired_goals"],复用 _global_goal_path 将相对 state_file 解析至 retired_goal["repo"],并在源运行目录不存在时将账本写入 runtime_root/closeout/<id>。
  4. loopx/lifecycle/goal_closeout.py#L74 (run_goal_closeout):先执行 validate_goal_id_path_segment,按作用域读取 goal_closeout 配置;未配置或命令为空时零磁盘写入直接返回 not_configured,启用时调用 run_capped_process(..., cwd=None) 捕获 8 KiB stdout/stderr 并加锁追加 closeout-ledger.jsonl。
  5. loopx/capabilities/machine_configuration/contract.py#L199 (merge_machine_configuration_namespace) & loopx/capabilities/goal_closeout/machine_defaults.py#L100:新增 local_only_fields 与 allow_local_only: bool = False 边界,阻断 HTTP /preview 与 /apply 写入 command,Dashboard 仅可通过 _apply_goal_closeout_public_update 调整 timeout_seconds 并完整保留本机已配置的 command。

对主干的风险 / Risks

Blocking Findings

  1. [P1] mypy 在 activation_service.py:588 静态检查失败(本轮新提交引入的回归)

    • 触发条件与路径:_stop_closeout_payload 将 registry_snapshot 声明为 Mapping[str, Any](loopx/control_plane/goals/activation_service.py#L571),并在第 588 行直接传入 resolve_runtime_root(registry_snapshot, ...)(loopx/paths.py#L335 要求 dict[str, object])。
    • 实测证据:在精确 head 10df7a231c 对 12 个修改的 Python 文件运行 uv run --extra test mypy --follow-imports=silent 报错:loopx/control_plane/goals/activation_service.py:588: error: Argument 1 to "resolve_runtime_root" has incompatible type "Mapping[str, Any]"; expected "dict[str, object]" [arg-type];而在当前 main 上执行同一检查返回 0 错误。
    • 最小修复与重跑命令:将参数类型改为 dict[str, Any](与 source_payload 及 _goal 一致)或传入 dict(registry_snapshot),随后对全部 12 个生产 Python 文件重新运行 mypy --follow-imports=silent。
  2. [P2] 全局注册表路由下 archive_runtime_goal 与孤立全局 stop 回退路径仍错误解析相对 state_file(上一轮 P2 未闭环)

    • 触发条件与路径:
      • 路径一(loopx/runtime.py#L260-L265):loopx bootstrap 默认写入相对 "state_file": ".loopx/goals/<id>/ACTIVE_GOAL_STATE.md",且将该值原样同步到 registry.global.json,同时运行目录 runtime_root/goals/<id>/ 仅存放租约或运行产物而无 ACTIVE_GOAL_STATE.md。当运维者使用全局注册表执行 loopx --registry <runtime_root>/registry.global.json archive-runtime --goal-id <id> --allow-registered --execute 时,archived_state_file.exists() 为假,回退分支调用 registry_project_root(registry_path) / declared_state_file。对于形如 .loopx/registry.global.json 的默认路径,因父目录名为 .loopx,registry_project_root 还会回退到其上一级目录(即用户家目录),最终算出运行根或家目录下的不存在路径而非项目 repo / source_registry 下的状态文件。
      • 路径二(loopx/control_plane/goals/activation_service.py#L600-L604):当 source_registry 缺失进入 ORPHANED_GLOBAL_STOP_FALLBACK 时,source_registry 即全局注册表本身,_stop_closeout_payload 同样错误调用 registry_project_root(source_registry)。
    • 实测证据:针对 10df7a231c 运行隔离 CLI 反事实探针,使用 .loopx/registry.global.json 归档标准布局 Goal 时,钩子实际收到运行根目录下的 ACTIVE_GOAL_STATE.md 路径而非项目目录路径;对缺失 source_registry 的全局注册表记录执行 goal-lifecycle --operation stop --execute 时,钩子同样收到运行根下的错误路径。
    • 最小修复与回归验证:在两处共用路径解析逻辑:当注册表为项目注册表时使用 registry_project_root;当其为全局注册表或 ORPHANED_GLOBAL_STOP_FALLBACK 时,优先依据 goal["source_registry"] 的项目根或 goal["repo"] 解析相对 state_file(同时将 archive_goal 改从锁内 locked_registry 读取,并在三处统一解析相对 repo)。补充基于 registry.global.json + 项目内相对 state_file 的 archive-runtime 与孤立 stop 回归用例。

默认关闭隔离、权限语义与非阻塞观察

  • 默认关闭隔离(default_off_isolation):隔离 CLI 探针实测在未配置 goal_closeout 时,goal-lifecycle stop、retire-global-goal 与 archive-runtime(含 SQLite 与 File Goal)均正常完成原终态提交并返回 status="not_configured"、ledger_recorded=false,不启动子进程也不生成 closeout-ledger.jsonl 或 closeout/ 目录;带 --dry-run(未传 --execute)的预览即使已配置命令也保持零触发。
  • 权限语义与范围契合(authority_semantics / scope_fit):loopx_goal_closeout_v1、loopx_goal_closeout_invocation_v0 与 loopx_goal_closeout_configuration_v0 均明确限定为本机管理员钩子执行与只追加审计记录,未声明跨节点或额外宿主权限;三个生产终态调用方与本机 CLI 配置入口均已接入。
  • 非阻塞 P3 观察:archive_runtime_goal 在加锁前从 registry 提取 archive_goal 元数据而非锁内 locked_registry;三处终态入口对相对 repo(如 ".")直接透传未解析为绝对路径;前端 capability-localization.ts 尚未补充 goal_closeout 中文译文键(当前安全回退后端英文描述)。

我的整体评价 / Verdict

基于精确 head 10df7a231c079576a034c5dd8f594b0e8255bb57 的独立验证与反事实探针,本次复审结论为请求修改(REQUEST_CHANGES)。

  • 长程与用户体验影响(outcome_impact):long_horizon 判定为 improved——钩子严格在提交并释放规范锁后以尽力而为方式执行,且 _stop_closeout_payload 现已保留已提交的 stop 回执,不阻塞后续重试或状态继续推进;user_experience 判定为 regression——核心问题集中在全局注册表路径下 archive-runtime 与孤立全局 stop 对相对 state_file 的解析仍指向运行根/家目录,导致真实消费者脚本拿到错误状态路径。visual_review 判定为 not_applicable——本 PR 未修改任何前端渲染源码,仅在 loopx/capabilities/configuration_ui.py 新增 goal_closeout.timeout_seconds 机器表单字段,已核对 machine-configuration-settings.tsx、capability-localization.ts 与 personal-workspace-contract.test.mjs 的消费与英文回退路径;unverified_scope 为正式打包桌面/Web 界面交互及 Lark 入口,当前均未受渲染改动影响。
  • 兼容性、代码量与简化评估:observable_semantics 判定为 unintended_drift——尽管默认关闭与项目注册表路径等价,全局注册表 archive-runtime 与孤立 stop 的相对 state_file 违背 loopx_goal_closeout_v1 绝对项目状态路径契约,且 activation_service.py 存在 mypy 类型漂移;code_volume 判定为 necessary,compatibility_assessment 判定为 retain(goal_closeout 为新增向后兼容的可选命名空间与 closeout/closeouts 字段);change_proportionality 判定为 proportionate,architecture_assessment 保持 retain(本 PR 边界为 Issue #8918 方案一的本机命令配置、三处终态锁外触发与账本记录,与既有 machine_configuration 及 process_runtime 所有者匹配)。
  • 语义词表对齐(semantic_alignment):判定为 not_applicable——PR 未改动 loopx/semantics/vocabulary_v0.json 中的跨运行时状态词表,Python 改动文件经检查无未分类直写项目注册表点位;goal_closeout 局部状态字符串可后续保持局部封装。
  • 本地验证摘要(遵循 wait_for_ci=false,未查询或等待远端 CI):
    • 定向 pytest(14 个测试文件,含 closeout、终端钩子、machine_configuration 契约与 HTTP API、goal activation、archive 与并发锁、global registry、process_runtime、导入边界与 goal_id 校验):PASS(366 passed, 1 Windows 用例 skipped)。
    • TS 控制面与工作台契约测试(cli_source_activation.test.ts、collaboration_goal_instance_lifecycle.test.ts、new_goal_initialization.test.ts、personal-workspace-contract.test.mjs):PASS(50 passed + 4 passed)。
    • ruff check(16 个改动文件)与 git diff --check:PASS。
    • loopx check --scan-path(16 个改动文件公开边界扫描):PASS(0 errors / 0 warnings)。
    • mypy --follow-imports=silent(12 个改动生产 Python 文件):FAIL(loopx/control_plane/goals/activation_service.py:588 报 1 处 arg-type 回归;main 基线为 0 错误)。
    • loopx canary premerge --tier quick --from-git-diff:direct_checks(4/4,含 check_rfc_bilingual.py)、py_compile、control-plane-maintainability-ratchet-smoke.py、quota-plan-smoke.py 均 PASS;semantic-vocabulary-drift-smoke.py 因独立 worktree 未安装 node_modules(NPM_DEV_DEPENDENCIES_MISSING)而失败;针对改动 Python 文件的独立语义扫描确认无新增未分类项目注册表 I/O。
    • 隔离 CLI / SQLite / File 反事实探针:默认关闭隔离、dry-run 零触发、exit 42 / 1s 超时 / 缺失二进制容错及 SQLite 正常 stop 均 PASS;但全局注册表 archive-runtime 与孤立全局 stop 相对 state_file 探针 FAIL(复现上述 P2 路径偏差)。
  • 残留风险:Windows 进程树清理(CREATE_NEW_PROCESS_GROUP + taskkill)、独立 loopx-core wheel 安装态、完整 TS 类型检查及 semantic-vocabulary-drift-smoke.py 的 TS AST 扫描(受限于隔离 worktree 无 node_modules)以及远端 GitHub Actions CI 状态在本轮均未验证。请修复 activation_service.py:588 的 mypy 错误并补全全局注册表归档及孤立全局停止的相对 state_file 解析(连同回归测试)后重新提交复审。

English verdict: REQUEST_CHANGES on 9065@10df7a231c079576a034c5dd8f594b0e8255bb57 due to a new mypy arg-type regression in loopx/control_plane/goals/activation_service.py:588 and incomplete relative state_file resolution when archive-runtime or orphaned goal-lifecycle stop runs against registry.global.json.

@gcl-coder
gcl-coder force-pushed the codex/goal-closeout-hook branch from 10df7a2 to 7d56c61 Compare November 21, 2026 00:35
@gcl-coder
gcl-coder force-pushed the codex/goal-closeout-hook branch from 7d56c61 to 260babb Compare November 21, 2026 04:59
@gcl-coder

Copy link
Copy Markdown
Contributor Author

Rebased onto 2b6dfe0a7. Head is now 260babb49, mergeable; the closeout review fixes are unchanged by the rebase. Verification: 127 tests across closeout hook, terminal hooks, goal activation, runtime archive, global registry serialization and machine-configuration API.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent; gpt-6.2-sol; OpenAI; runtime_reported; reasoning_effort=xhigh

动机 / Motivation

需要归档或停用 Goal 并回收工作区的本机运维者,希望清理脚本在终态提交后拿到可读取的项目状态,并留下调用记录。过去每个宿主都要单独接脚本;本提案用一处本机配置,把停止、退役和归档的终态接到账本。配置后的三个入口都能调用脚本,但全局注册表两条路径仍交付错误地址,且归档在未配置钩子时也可能移动成功却返回失败。范围是配置、调用与记录,内置 worktree 删除和发现命令属于议题的独立备选方案。

依据为 Issue #8918 的方案一,评审对照 issue-8918-proposal-1。沿用现有终态入口可省去逐宿主编排,现有工作区清理助手只解决其自己创建的候选目录。先保留本提案的可选本机命令,修复状态地址及失败隔离即可交付这一增量。

改动思路 / Approach

本机 machine-config 的 preview/apply 提交命令配置。通用 namespace contract 守住 local-only 字段,Settings 可发现该能力并设置超时,实际命令保留在本机。生命周期事务继续拥有停止、退役与归档。事务释放锁后,run_goal_closeout 使用现有受限进程执行器和独立账本写锁,将钩子结果与主操作结果一起返回。归档调用把钩子的输入准备也纳入主操作锁块,且放在不可逆的目录移动之后,当前失败隔离没有覆盖这一段。

可复用 _global_goal_path 的 repo 相对路径规则,同时保留正常 project registry 路由及已归档的真实状态文件优先级。把归档钩子的可失败准备移到成功提交之后的尽力而为边界,使用锁内已确认的数据。这样可以保留三个调用点和通用执行器,无需增设清理队列或宿主进程。

具体改动 / Changes

完整比较 2b6dfe0a70892289f42fc260616545cf7ad0b1db..260babb49963110bcc998596e8fcd027b74b05e4,16 个文件,+1408/-3。其中生产代码 12 个文件、+578/-1,测试 4 个文件、+830/-2。旧头 10df7a231c079576a034c5dd8f594b0e8255bb57 的五个提案提交在 range-diff 中逐一等价。新版基线含其他变更,本次重新执行验证;旧头的类型与全局路径发现 均在当前头独立复现。

规格 当前提交的结果
CLOSEOUT-CONFIG machine_defaults.py、内置 namespace 注册与配置 CLI 支持空命令默认、受限超时和本机命令写入。Settings 的 configuration_ui.py 只声明超时字段,当前头 HTTP 回归测试覆盖命令字段拒绝。
CLOSEOUT-PAYLOAD _stop_closeout_payload 和 archive_runtime_goal 在全局注册表路径下可把相对项目状态解析到机器运行根,见 P2。
CLOSEOUT-FAILURE run_goal_closeout 复用有界进程,CappedProcessResult 增加 stderr。归档的钩子参数准备仍可在目录移动后抛出并掩盖成功,见 P2。
CLOSEOUT-LEDGER 配置后五个 CLI 案例各有一条账本,archive 写入归档目录,两个 stop 重试不新增账本。退役的原登记已按预期移除。
CLOSEOUT-TERMINAL stop、retire、archive 均有生产调用。预览不调用,测试覆盖 archive 释锁后运行与 stop 已提交回执的保留。

_stop_closeout_payload 用提交事务读到的快照,项目路由和停止后回执回退仍通过定向测试。新增 merge_machine_configuration_namespace 的本机与公开更新分支保留同一配置所有者。retire_global_registry_goals 使用退役记录解析 payload,archive_runtime_goal 用目标目录保存账本。run_goal_closeout 负责超时、受限输出和账本错误,调用者继续负责终态和输入来源。

对主干的风险 / Risks

  • [P1] 新头仍有 mypy 类型错误。 activation_service.py:588 把 Mapping[str, Any] 直接传给要求 dict[str, object] 的 resolve_runtime_root。同一 mypy 1.20.2 四文件检查,实际基线零错误,当前头一个 arg-type。12 个生产文件的定向检查也仅此一错。请沿用已知具体快照类型,或在边界显式转换,再重跑检查。
  • [P2] 两个全局注册表入口交付的状态路径无法读取。 在项目存有相对登记的 ACTIVE_GOAL_STATE.md,运行目录只有产物的情况下,用全局注册表归档,或停止源注册表已缺失的 Goal。实测两个命令都退出 0 且钩子写入一条成功账本,但 stdin 的 state_file 指向运行目录下不存在的文件。同样的项目注册表对照可打开文件。请从项目来源或 repo 解析相对路径并覆盖这两条入口,确认钩子能读到内容。
  • [P2] 未配置钩子时,归档也可能在移动后返回失败。 在旧登记的 state_file 中使用一个已不存在的用户主目录别名,干净环境无 closeout 配置。相同 CLI 输入,基线退出 0,新头在 runtime.py:261 展开该路径失败并退出 1。两边都已移走原目录且归档物仍可读,新头重试只报源目录不存在,操作者失去这次归档的成功回执。请从锁内确认的记录取输入,将全部可失败准备放进锁外的尽力而为路径,无配置时不解析钩子专属参数。回归应同时断言主命令成功、归档物存在以及无钩子和零账本。

PASS:66 项定向 Python,Ruff,实际基线的 quick premerge 四项直接检查、编译及三个 canary。第一次 premerge 因隔离工作区缺 TypeScript 开发依赖失败,安装锁定依赖后完整重跑通过。五组普通的 feature-off CLI 配对均保留原结果和终态,零钩子、零账本。返回结构增加 closeout 字段,Settings 目录多一个可发现的配置项。FAIL:上面的类型错误、两条 hook 路径及 feature-off 归档回执回归。独立公共差异扫描覆盖 16 个文件且无发现;隔离扫描环境缺运行注册表的提示另计。按本次评审配置未查询 CI。

我的整体评价 / Verdict

REQUEST_CHANGES,绑定 260babb49963110bcc998596e8fcd027b74b05e4。共享执行器和本机配置边界值得保留。须先恢复归档提交后的可信回执,再补齐两个项目路径和类型检查。前一版本的演示与本次 API 通过记录可说明字段和权限;当前 Settings 整页的桌面与窄屏渲染、正式安装包和 Windows 进程树仍待验证。

English verdict: REQUEST_CHANGES at 260babb. A disabled hook can mask a committed archive, two global-registry routes pass an unreadable state path, and mypy reports a new argument type error. Targeted tests, Ruff, and quick premerge passed after restoring the test dependencies.


try:
closeout_runtime_root = resolve_runtime_root(
registry_snapshot,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 当前提交在此把 Mapping 传给要求 dict 的 resolve_runtime_root。同一 mypy 1.20.2 四文件检查,目标基线零错误,这个 head 报一项 arg-type。请保留事务快照的具体类型,或在调用边界显式转换。

Comment thread loopx/runtime.py Outdated
declared_state_file = Path(str(raw_declared_state_file)).expanduser()
if not declared_state_file.is_absolute():
declared_state_file = (
registry_project_root(registry_path) / declared_state_file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 全局 registry 所在目录不是项目根。隔离 CLI 归档成功且 callback 有账本,但收到的相对 state_file 指向运行目录下不存在的文件。孤立全局 stop 也复现。请使用锁内确认的项目来源或 repo 对相对路径求值。

Comment thread loopx/runtime.py Outdated
archive_goal.get("state_file") if archive_goal else None
)
if raw_declared_state_file:
declared_state_file = Path(str(raw_declared_state_file)).expanduser()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 这里在目录已经移动后展开可失败的可选路径。未配置钩子且旧 state_file 的用户主目录别名已失效时,基线退出 0,当前头退出 1,两边的归档内容均写成。请把输入准备纳入锁外的尽力而为边界,未配置时跳过准备,让原归档返回已提交的成功回执。

@gcl-coder
gcl-coder force-pushed the codex/goal-closeout-hook branch from 260babb to c9d3b31 Compare November 21, 2026 10:10
@gcl-coder

Copy link
Copy Markdown
Contributor Author

Replied to review 6003181028. All three findings are fixed at c9d3b3184 (rebased onto 00ef1c79a).

  1. [P1] mypy arg-type (activation_service.py:588). _stop_closeout_payload now keeps the transaction snapshot's concrete type (dict[str, Any] from payload_copy()) for both registry_snapshot and closeout_goal, so resolve_runtime_root receives a dict[str, object] without a cast. mypy --no-incremental --follow-imports=silent on the four changed modules: baseline 1 error, this head Success: no issues found.

  2. [P2] unreadable state_file on both global-registry routes. New goal_state_file_from_record in loopx/paths.py is the single resolver for hook payloads: absolute wins; a project registry (.loopx/registry.json) still resolves from its project root exactly as before; a global registry resolves from the Goal's repo, then the registry directory — the rule _global_goal_path already uses for retire. archive_runtime_goal and the ORPHANED_GLOBAL_STOP_FALLBACK stop both call it, so the two routes that used registry_project_root(registry.global.json) (i.e. the runtime root) no longer hand the hook a path that does not exist. Regressions run the real entry points with the project owning ACTIVE_GOAL_STATE.md and the runtime holding only artifacts: the payload is the project path and the file reads back. On 260babb49 both regressions fail with a runtime-relative path.

  3. [P2] disabled hook masking a committed archive. The lock block now copies the already-confirmed record and the destination, then releases; all fallible preparation moved into _archive_closeout_payload, which runs after every canonical lock is free and never raises. When no command is configured it returns not_configured without touching the record's state_file at all. Regression uses a state_file whose home alias does not exist, with no closeout configured: the archive exits 0, the archived contents are present, status is not_configured, and no ledger file is written. On 260babb49 the same input raises RuntimeError after the move.

Verification on c9d3b3184: pytest over closeout hook, terminal hooks, goal activation, runtime archive, global-registry serialization and machine-configuration API — 130 passed; ruff clean; the scoped mypy run above is clean. Feature-off pairs for stop/retire/archive still return the original results. Not run here: Windows file system, installed wheel, and hosted CI.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

在本机停止、退役或归档后接续工作树整理的操作者。 原终态入口提交各自状态,操作者自行协调额外整理命令。 在未配置 hook 的隔离退役操作中,只让提交后的钩子路径准备报错。实际 registry 已移除 Goal。基线退出 0 并回报 wrote=true,当前头退出 1 并回报 wrote=false。 让本机显式配置的一条终态命令在三种转换提交后运行并留下账本。 本次只涉及议题方案一,不新增内置工作树删除或发现能力,也不改变回环 API 的命令权限。

改动思路 / Approach

生命周期事务继续拥有终态写入,锁外入口复用一个本机受限进程执行器及账本。 保留三种终态调用方,在提交后把钩子的配置读取、参数准备、执行与诊断都放入尽力而为边界。 前轮同类停止和归档回执已经修复。退役应复用锁内确认的事实,也要让单个钩子准备失败时其他已退役项仍可读回。

具体改动 / Changes

逐项检查当前头 c9d3b31 和 merge base 23dacd5,17 个文件,+1626/-3。当前目标 main 指针是 23dacd5,提案实际 merge base 为 00ef1c7。按议题核对本机配置、终态钩子、调用账本、失败隔离。通用机器配置隔离 command 字段,设置编辑器保留超时。终态读取已确认 registry 记录,执行复用既有进程树超时并在事务锁外写独立账本。 评审依据为 Issue #8918 方案一。 目标规范

关键代码讲解

  • goal_closeout_machine_configuration_namespace 分别规定本机 CLI 配置与公共超时投影,command 保留在本机。 配置
  • _stop_closeout_payload、_archive_closeout_payload 通过已提交事实准备参数,保留主操作回执。归档的 feature-off 控制会先确认未配置。 停止 归档
  • retire_global_registry_goals 在写入完成后重新解析 state_file,而 run_goal_closeout 的错误转诊断边界在后面。 退役 执行与账本

对主干的风险 / Risks

[P1] 退役已提交但钩子准备失败会改写为未写入。 在未配置 hook 的隔离退役操作中,只让提交后的钩子路径准备报错。实际 registry 已移除 Goal。基线退出 0 并回报 wrote=true,当前头退出 1 并回报 wrote=false。 退役沿用已确认的路径或在公共 helper 内保护所有钩子准备步骤,保留原退出码与退役回执。仅把错误记为钩子诊断,并为配置关闭和多项退役分别回归。 此反事实只在独立 registry 提交后注入钩子准备异常,不执行真实清理。有无故障两组均无钩子调用或 ledger。若用户按错误回执重试,原 Goal 已经从 registry 消失。

重跑 closeout、终态入口、Goal activation、归档、全局 registry、机器配置、真实回环 HTTP 和进程适配测试,231 项通过、1 项跳过。四个改动模块的 scoped mypy 通过。 Quick premerge 6 项直接检查通过,3 项选定检查中 2 过 1 败。唯一失败是未修改的 Goal frontier 规模棘轮,同一命令在实际 merge base 重现相同诊断。 本轮验证源码、受限夹具命令与本机回环传输。Windows、已安装正式版本和远端 CI 未验证。

我的整体评价 / Verdict

请求修改。生命周期事务继续拥有终态写入,锁外入口复用一个本机受限进程执行器及账本。 保留三种终态调用方,在提交后把钩子的配置读取、参数准备、执行与诊断都放入尽力而为边界。 当前头仍违反议题的失败不掩盖原终态结果要求,属于既有退役使用者的回归。 应用了原生入口优先的复审建议,用实际提交后的读回判断结果。修复退役回执边界后再复审。

English verdict: REQUEST_CHANGES at c9d3b31. A closeout-only preparation error turns a committed retirement into a failed, wrote=false CLI response even with no hook configured. The exact merge-base comparison preserves success.

Comment thread loopx/global_registry.py Outdated
continue
# Reuse the registry path rule so a relative ``state_file`` reaches
# the hook as the absolute path its consumer contract requires.
state_file = _global_goal_path(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 退役已提交但钩子准备失败会改写为未写入。在未配置 hook 的隔离退役操作中,只让提交后的钩子路径准备报错。实际 registry 已移除 Goal。基线退出 0 并回报 wrote=true,当前头退出 1 并回报 wrote=false。 退役沿用已确认的路径或在公共 helper 内保护所有钩子准备步骤,保留原退出码与退役回执。仅把错误记为钩子诊断,并为配置关闭和多项退役分别回归。

@gcl-coder

Copy link
Copy Markdown
Contributor Author

Replied to review 6004643522. Fixed at a16896db8.

[P1] a committed retirement rewritten as wrote=false. The retire loop now prepares each record through _retire_closeout_payload, which runs entirely after the registry removal and never raises past the receipt. It reads the confirmed retired_goals entries, returns not_configured without touching state_file when no command is set, and turns any preparation failure into a per-record preparation_error while the retirement keeps ok=true / wrote=true and the other records still report.

Regressions (both fail on c9d3b3184):

  • two-record global retirement with goal_closeout_configuration raising after the commit: wrote=true, registry emptied, closeouts = two preparation_error rows, no ledger;
  • two-record global retirement with a state_file whose home alias no longer expands and no hook configured: wrote=true, registry emptied, two not_configured rows, no ledger.

Making the alias case reachable also required _global_goal_path to treat an unexpandable value as a missing path instead of raising during the preflight inspection: that inspection runs before the commit, so an old alias would otherwise still have blocked the retirement itself. A path that cannot be expanded is not a live source or state file, so the record stays eligible and keeps its raw value.

Verification on a16896db8: 132 tests across closeout hook, terminal hooks, goal activation, runtime archive, global-registry serialization and machine-configuration API; Ruff clean; scoped mypy clean on the five changed modules.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

要在 Goal 终态后自动整理本机资源的操作者,需要收到可核验的调用结果,尤其是在修复投影写入并重试之后。 原 stop、retire 和 archive 分别提交生命周期状态,配置清理需要在 LoopX 外安排。 仅让已提交源 registry 的首次 stop 遇到一次全局投影同步失败。CLI 读回源已 stopped、全局仍 active,返回 partial_write=true。撤掉故障并执行同一 stop,CLI 返回成功、projection_reconciled=true,两个 registry 都已 stopped,配置的 hook 始终未启动,账本仍为零。再次重试也没有补交。 本次对三种终态提供机器配置控制的 hook 和独立调用账本。 范围限于议题方案一。未增加内置工作树删除、发现或远端清理。

改动思路 / Approach

源 registry 拥有生命周期转换,共享 registry 是可修复投影。closeout 复用有界进程执行器、独立结果及账本。 使用显式本机配置,终态权威和 hook 结果保持各自的回执。恢复应以具体转换为单位。 前一轮退役阻塞已回归。独立对照正常 stop、一次同步过渡失败和关闭配置,再读双 registry、真实 provider 调用及账本。

具体改动 / Changes

逐项检查当前头 a16896d 和 merge base 00ef1c7,17 个文件,+1779/-5。当前 PR 目标指针 23dacd5,实际 merge base 00ef1c7。CLOSEOUT-CONFIG、CLOSEOUT-RETIRE 和 CLOSEOUT-ARCHIVE 的独立编排已验证。CLOSEOUT-STOP 的恢复路径缺失。 评审依据为 Issue #8918 方案一 2026-11-21 读回。 目标规范

关键代码讲解

  • 源提交与同步 分别推进权威记录与共享投影。 stop hook 条件 需要同一次操作同时有变更与成功读回。
  • 退役 逐记录捕获准备错误,避免改变已提交退役回执。 归档 在锁外准备并送往归档账本。
  • 执行器 负责有界输入、输出、超时和账本。 配置编辑器 只暴露超时字段。

对主干的风险 / Risks

[P2] 停止重试修复投影后仍漏掉已配置的 closeout。 仅让已提交源 registry 的首次 stop 遇到一次全局投影同步失败。CLI 读回源已 stopped、全局仍 active,返回 partial_write=true。撤掉故障并执行同一 stop,CLI 返回成功、projection_reconciled=true,两个 registry 都已 stopped,配置的 hook 始终未启动,账本仍为零。再次重试也没有补交。 把待执行记录绑定到已提交的具体 stop 转换,恢复投影时让同一转换补交一次并读回账本。若设计允许在源提交后立即调用,则应以已提交转换作为门槛,独立报告投影失败。保留重复 stop、旧 stopped 状态和恢复并发时的去重。 终态已经对操作者可见,原有重试入口成功,钩子没有调用记录,也没有待处理回执。

正常 stop 仅调用一次,预览和重复 stop 无额外调用。退役保留 ok=true/wrote=true 的旧问题在新头通过。归档后 hook 在锁外运行,账本留在归档目录。 170 项生命周期、closeout、归档、registry 和机器配置 API 测试通过,四文件 mypy 通过。quick premerge 的六项直接检查通过,目录棘轮项仍报 goal_frontier 的同一函数超限,实际 merge base 已有相同失败。 临时 File registry 实际写入和命令实际运行。只对同步返回注入一次失败,未在运行中的 Goal、已安装 Dashboard 或远程 CI 做验证。

我的整体评价 / Verdict

请求修改。源 registry 拥有生命周期转换,共享 registry 是可修复投影。closeout 复用有界进程执行器、独立结果及账本。 使用显式本机配置,终态权威和 hook 结果保持各自的回执。恢复应以具体转换为单位。 已经完成的终态转换在可恢复故障下可能永久遗漏其 hook。 请按 stop 的真实重试旅程覆盖调用和回执读回。退役回执修复有效。 本次新增 Dashboard 机器配置超时字段。已核对声明和回环 HTTP 边界,页面实际渲染仍待核验。 未核验 Dashboard 桌面和窄屏布局,亦未执行已安装版本的页面验收。

English verdict: REQUEST_CHANGES at a16896d. A committed stop followed by a transient projection sync failure never dispatches configured closeout, even after a successful retry reconciles both registries. The prior retirement receipt issue is fixed on this head.

execute
and target_state is GoalActivationState.STOPPED
and changed
and payload.get("ok")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 停止重试修复投影后仍漏掉已配置的 closeout。仅让已提交源 registry 的首次 stop 遇到一次全局投影同步失败。CLI 读回源已 stopped、全局仍 active,返回 partial_write=true。撤掉故障并执行同一 stop,CLI 返回成功、projection_reconciled=true,两个 registry 都已 stopped,配置的 hook 始终未启动,账本仍为零。再次重试也没有补交。 把待执行记录绑定到已提交的具体 stop 转换,恢复投影时让同一转换补交一次并读回账本。若设计允许在源提交后立即调用,则应以已提交转换作为门槛,独立报告投影失败。保留重复 stop、旧 stopped 状态和恢复并发时的去重。

@gcl-coder
gcl-coder force-pushed the codex/goal-closeout-hook branch from a16896d to 58b1646 Compare November 21, 2026 12:57
@gcl-coder

Copy link
Copy Markdown
Contributor Author

Replied to review 6005239468. Fixed at 58b164601 (rebased onto 871cc3634).

[P2] A committed stop after a transient projection failure never ran the hook. The stop hook is no longer gated on the combined readback. It now requires execute, target_state == stopped, changed and written — that is, the source transition that the registry actually committed — and reports the projection fault through the existing ok=false / partial_write=true fields, with the hook result alongside it. Because the source is already stopped on retry, the branch cannot be re-entered, so the hook runs exactly once for that transition and a repeated stop or a preview still runs nothing. The reviewer's alternative (back-fill on retry) is not needed for this path, and the committed transition is the gate.

The new regression test_stop_runs_closeout_for_committed_transition_when_projection_fails makes the shared sync fail once, asserts the first call returns ok=false, partial_write=true, written=true with closeout.status == "success" and one ledger row, then asserts the retry returns ok=true, projection_reconciled=true, no closeout key, and still one ledger row and one payload line. It fails on a16896db8 with KeyError: 'closeout' and an empty ledger.

Verification on 58b164601: 133 tests across test_goal_closeout_terminal_hooks.py, test_goal_closeout_hook.py, test_goal_activation.py (55), test_runtime_archive.py, test_global_registry_write_serialization.py and test_chat_machine_configuration_api.py; ruff check clean; scoped mypy --no-incremental --follow-imports=silent clean on the four changed modules. The PR body now carries the follow-up table for this head.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

Issue #8918 方案一要求操作者为 Goal 的 stop、retire 和 archive 配置一个有时限的本机回调,并能读回执行结果。使用者需要在可恢复的投影故障后确认终态是否已提交、回调是否已运行。 目标规范

向共享 registry 写入器注入一次 EIO。首次 CLI 退出 1,源端已 stopped 而全局仍 active,响应却报 written=false,未返回 partial_write 或 closeout。恢复后同一 stop 退出 0、projection_reconciled=true,账本和子进程调用次数仍为零。 范围限于可配置回调,内置工作树清理和远端清理仍在范围外。

改动思路 / Approach

源 registry 拥有终态,共享 registry 可按源记录修复。回调复用机器配置和有界进程执行器,并写独立账本。当前提交把回调门槛改绑源提交,已经修复同步正常返回故障回执时的漏调。共享写入器抛出异常时,执行到不了这个门槛。

具体改动 / Changes

评审提交 58b1646,实际 merge base 871cc36,全提案 17 个文件(+1864/-5)。CLOSEOUT-CONFIG 的命令只由本机 CLI 写入,Dashboard 投影超时与配置状态。CLOSEOUT-RETIRE 按记录报告失败并保留退役回执。CLOSEOUT-ARCHIVE 释放锁后运行,账本留在归档位置。CLOSEOUT-STOP 的异常退出仍缺处理。

  • 停止流程先提交源端状态,再写共享投影。新增回调条件检查 changed 和 written。 停止路径
  • 回调复用有界子进程并记录超时、启动失败和输出。归档与退役使用各自已提交的终态记录。 回调执行器 退役 归档

对主干的风险 / Risks

[P2] 投影写入抛出 I/O 异常时漏掉已提交 stop 的回调。 同一测试中,EACCES 会转换成失败回执,回调执行恰一次。在 activation owner 内保留源提交回执,将投影写入异常转换为独立故障。在释放锁后,对已提交的 stop 派发一次现有 hook。补测 EIO 首次失败与恢复重试,保留未提交及无配置对照。

同步返回失败及写入器 EACCES 均在首次部分提交时调用一次,重试不重复。提交前拒绝、预览和关闭配置均没有新增进程和账本。退役和归档的独立入口控制通过。 本地定向测试 234 过、1 跳,Ruff 与四个源码模块 mypy 通过。当前实际 merge base 的 quick premerge 六项直接检查和三项所选检查均通过。

我的整体评价 / Verdict

请求修改。上轮由同步失败回执引起的漏调已修。请在现有 activation owner 补齐投影抛异常的路径,让操作者仍能读到已提交状态和回调结果。采用临时 File registry、正式 CLI 入口和真实子进程,故障只注入共享 registry 写入器。Dashboard 布局、已安装版、其它平台与远程 CI 未验证。 已核验 Dashboard 超时字段的声明和回环 HTTP 边界。 实际页面布局和已安装版尚待验证。

English verdict: REQUEST_CHANGES at 58b1646. A transient exception from the projection writer still bypasses the closeout hook and loses the committed stop receipt. Retry reconciles the registries but records zero hook attempts.

or f"rerun loopx sync-global --goal-id {normalized_goal_id} after repairing the shared registry route"
)
# The stop itself is committed in the source registry, which owns the
# transition. A failed shared projection is a separately reported, fixable

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 投影写入抛出 I/O 异常时漏掉已提交 stop 的回调

向共享 registry 写入器注入一次 EIO。首次 CLI 退出 1,源端已 stopped 而全局仍 active,响应却报 written=false,未返回 partial_write 或 closeout。恢复后同一 stop 退出 0、projection_reconciled=true,账本和子进程调用次数仍为零。 在 activation owner 内保留源提交回执,将投影写入异常转换为独立故障。在释放锁后,对已提交的 stop 派发一次现有 hook。补测 EIO 首次失败与恢复重试,保留未提交及无配置对照。

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 <[email protected]>
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 <[email protected]>
…top receipts

The stop hook now uses the confirmed registry snapshot from the committing transaction instead of re-reading the source registry, resolves relative state_file values against the registry project root, and reports preparation failures in the hook result. Retire and archive apply the same absolute-path rule. Refs loopx-project#8918.

Signed-off-by: ChengLong GU <[email protected]>
Archive resolves a global registry's relative state_file from the Goal repo
instead of the runtime root, the orphaned-global stop route shares that
resolver, and the archive hook's fallible preparation now happens after the
canonical locks release so a disabled hook cannot mask a committed move.

Refs loopx-project#8918.

Signed-off-by: ChengLong GU <[email protected]>
The retire loop prepared hook arguments after the registry removal had
committed, so one unusable record turned a finished retirement into its own
error. Each record now prepares inside the best-effort boundary, an
unconfigured hook resolves nothing, and an alias that no longer expands
counts as a missing path instead of aborting the preflight.

Refs loopx-project#8918.

Signed-off-by: ChengLong GU <[email protected]>
A transient shared-registry projection failure leaves the source stop committed with partial_write=true. The stop hook previously required the combined readback to verify, so the configured closeout never ran and no retry could back-fill it. Gate the hook on the committed source transition and report the projection fault separately. Refs loopx-project#8918.

Signed-off-by: ChengLong GU <[email protected]>
The source stop commits before the shared registry is projected. A projection writer that raised an I/O error escaped the transaction, so the CLI reported written=false and the configured closeout never ran even after a retry reconciled both registries. Report the raising projection as a fixable failure receipt and keep the committed transition, its readback fault, and the single hook dispatch. Refs loopx-project#8918.

Signed-off-by: ChengLong GU <[email protected]>
@gcl-coder
gcl-coder force-pushed the codex/goal-closeout-hook branch from 58b1646 to b21f2f2 Compare November 21, 2026 14:31
Once the source transition commits, a read fault during the shared-registry readback is a reported verification failure rather than an exception that hides written=true and skips the terminal hook. Refs loopx-project#8918.

Signed-off-by: ChengLong GU <[email protected]>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

有意配置终态钩子的操作者需要在 Goal 停止、退役或归档后读到实际处理结果。 原命令各自处理终态,无需读取钩子命令或解析钩子专用的参数。 未配置命令的原生 stop,读取含过期用户别名的 state_file 时,候选把钩子状态报为 preparation_error。普通路径的对照是 not_configured。主干两种输入都正常停止。候选主操作也已成功写回,进程与账本数量均为零。 候选复用共享的受限子进程执行器,并为三个终态入口增加本机可选的钩子与账本。 只审 #8918 第一案的本机钩子与已有配置入口。真实安装版、Windows 进程树和自动清理工作树均未验收。

改动思路 / Approach

注册表提交继续拥有生命周期转换。现有机器配置拥有钩子启用和外部命令权限。 钩子只能在实际终态转换之后运行。只允许本机配置命令,工作区 HTTP 配置保留超时等受限字段。 复用退役和归档已采用的空配置短路,保留原停止路径的动作和可诊断性。

具体改动 / Changes

逐项检查当前头 b21f2f2 和 merge base b97818e,17 个文件,+2020/-11。核对终态转换、配置权限、共享进程管控、账本位置和旧 projection 错误的修复。当前头已修复上一轮 EIO,尚欠停用时的状态语义。configured-commit 已验证提交后只执行一次。disabled-no-preparation 未满足,停止时仍会解析未启用功能的路径。local-authority 已实现,本机配置可写命令,工作区 HTTP 禁止修改。 评审依据为 Issue #8918 方案一。 目标规范

关键代码讲解

  • 在 停止回执与钩子 确认源提交后,停止入口先解析 state_file。
  • 配置读取和账本 已有统一配置判断。退役和归档在无命令时跳过路径准备,避免历史别名影响未启用的路径。

对主干的风险 / Risks

[P2] 停用终态钩子时停止操作仍报告钩子准备失败。 未配置命令的原生 stop,读取含过期用户别名的 state_file 时,候选把钩子状态报为 preparation_error。普通路径的对照是 not_configured。主干两种输入都正常停止。候选主操作也已成功写回,进程与账本数量均为零。 在解析 state_file 前复用 goal_closeout_configuration 的未配置短路,与 retire 和 archive 一致。保留已配置路径的准备错误回执,再补一条禁用状态下过期别名的原生 stop 测试。 这是新引入的状态分支。历史 Goal 的状态文件只因旧账号别名出错,关闭钩子之后依然会收到账本未写的准备错误。

已配置钩子时,注入共享投影 EIO 或 EACCES,首次保留 written=true 和 partial_write=true,真实子进程执行一次。重试修复共享投影,账本仍只有一条。预检阶段拒绝的对照保持源注册表未写且不执行。 当前头本地定向 164 项通过,Ruff、7 文件 mypy 与 quick premerge 通过。独立双版本 CLI 夹具复现未配置状态的回执差异。 只审 #8918 第一案的本机钩子与已有配置入口。真实安装版、Windows 进程树和自动清理工作树均未验收。

我的整体评价 / Verdict

请求修改。注册表提交继续拥有生命周期转换。现有机器配置拥有钩子启用和外部命令权限。 钩子只能在实际终态转换之后运行。只允许本机配置命令,工作区 HTTP 配置保留超时等受限字段。 同一关闭状态在停止与退役、归档的可观测结果不一致。 请先让关闭钩子时的 stop 跳过钩子专有准备,并保持当前头正确的提交与投影重试回执。 通过真实 loopback HTTP 验证本机命令字段无法从工作区写入。 已打包界面和 Windows 未验证。

English verdict: REQUEST_CHANGES at b21f2f2. The previous EIO receipt and single-dispatch defect is fixed. An unconfigured stop still resolves a hook-only legacy state path and emits preparation_error. Apply the existing disabled gate before path resolution and preserve the recorded stop.

runtime_root_override,
registry_path=source_registry,
)
declared = goal_state_file_from_record(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 停用终态钩子时停止操作仍报告钩子准备失败。未配置命令的原生 stop,读取含过期用户别名的 state_file 时,候选把钩子状态报为 preparation_error。普通路径的对照是 not_configured。主干两种输入都正常停止。候选主操作也已成功写回,进程与账本数量均为零。 在解析 state_file 前复用 goal_closeout_configuration 的未配置短路,与 retire 和 archive 一致。保留已配置路径的准备错误回执,再补一条禁用状态下过期别名的原生 stop 测试。

@gcl-coder

Copy link
Copy Markdown
Contributor Author

Replied to review 6005590580. Fixed at ea8fc1ebc (rebased onto b97818e51).

[P2] A raising projection writer lost the committed stop. The post-commit boundary no longer lets an exception escape. _project_committed_transition runs the projection after the source commit and converts a raising sync_project_registry_to_global into a global_sync_failed receipt; _readback_committed_transition does the same for a raising readback with status="readback_failed". Both faults are reported in the existing ok / partial_write / error fields, so written=true and the hook result survive, and the hook still dispatches exactly once because it is gated on the committed source transition.

Two regressions, both fail on 58b164601 with the raw OSError escaping:

  • test_stop_runs_closeout_when_shared_registry_writer_raises_eio injects one EIO from the real shared-registry write_json and asserts written=true, ok=false, partial_write=true, global_sync.error_kind="global_sync_failed", closeout.status="success", one ledger row; the retry returns ok=true / projection_reconciled=true with no closeout key and still one ledger row and one payload line.
  • test_stop_runs_closeout_when_readback_raises covers the same rule for a read fault, asserting readback.status="readback_failed" with the hook result kept.

I also replayed your path through the real CLI handler: temporary File registry, real subprocess hook, one injected EIO on the shared registry. First stop exits 1 with written=true, partial_write=true, global_sync.error_kind=global_sync_failed, closeout.status=success, one hook payload; the retry exits 0 with projection_reconciled=true, no closeout key, still one payload line.

Verification on ea8fc1ebc: 135 tests across test_goal_closeout_terminal_hooks.py, test_goal_closeout_hook.py, test_goal_activation.py, test_runtime_archive.py, test_global_registry_write_serialization.py and test_chat_machine_configuration_api.py; ruff check clean; scoped mypy --no-incremental --follow-imports=silent clean on the four changed modules. The PR body carries the follow-up table for this head.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

有意配置终态钩子的操作者需要在 Goal 停止、退役或归档后读到实际处理结果。 原命令各自处理终态,无需读取钩子命令或解析钩子专用的参数。 未配置命令的原生 stop,读取含过期用户别名的 state_file 时,候选把钩子状态报为 preparation_error。普通路径的对照是 not_configured。主干两种输入都正常停止。候选主操作也已成功写回,进程与账本数量均为零。 候选复用共享的受限子进程执行器,并为三个终态入口增加本机可选的钩子与账本。 只审 #8918 第一案的本机钩子与已有配置入口。真实安装版、Windows 进程树和自动清理工作树均未验收。

改动思路 / Approach

注册表提交继续拥有生命周期转换。现有机器配置拥有钩子启用和外部命令权限。 钩子只能在实际终态转换之后运行。只允许本机配置命令,工作区 HTTP 配置保留超时等受限字段。 复用退役和归档已采用的空配置短路,保留原停止路径的动作和可诊断性。

具体改动 / Changes

逐项检查当前头 ea8fc1e 和 merge base b97818e,17 个文件,+2079/-11。核对终态转换、配置权限、共享进程管控、账本位置和旧 projection 错误的修复。相对上一受审头只有新增读回抛错测试,生产代码完全相同。该测试在当前精确头通过,补齐 EIO 读回支路。停止入口的未配置问题仍可用原生 CLI 独立复现。configured-commit 已验证提交后只执行一次。disabled-no-preparation 未满足,停止时仍会解析未启用功能的路径。local-authority 已实现,本机配置可写命令,工作区 HTTP 禁止修改。 评审依据为 Issue #8918 方案一。 目标规范

关键代码讲解

  • 在 停止回执与钩子 确认源提交后,停止入口先解析 state_file。
  • 配置读取和账本 已有统一配置判断。退役和归档在无命令时跳过路径准备,避免历史别名影响未启用的路径。

对主干的风险 / Risks

[P2] 停用终态钩子时停止操作仍报告钩子准备失败。 未配置命令的原生 stop,读取含过期用户别名的 state_file 时,候选把钩子状态报为 preparation_error。普通路径的对照是 not_configured。主干两种输入都正常停止。候选主操作也已成功写回,进程与账本数量均为零。 在解析 state_file 前复用 goal_closeout_configuration 的未配置短路,与 retire 和 archive 一致。保留已配置路径的准备错误回执,再补一条禁用状态下过期别名的原生 stop 测试。 这是新引入的状态分支。历史 Goal 的状态文件只因旧账号别名出错,关闭钩子之后依然会收到账本未写的准备错误。

已配置钩子时,注入共享投影 EIO 或 EACCES,首次保留 written=true 和 partial_write=true,真实子进程执行一次。重试修复共享投影,账本仍只有一条。预检阶段拒绝的对照保持源注册表未写且不执行。 当前头本地定向 165 项通过,Ruff、7 文件 mypy 与 quick premerge 通过。独立双版本 CLI 夹具复现未配置状态的回执差异。 只审 #8918 第一案的本机钩子与已有配置入口。真实安装版、Windows 进程树和自动清理工作树均未验收。

我的整体评价 / Verdict

请求修改。注册表提交继续拥有生命周期转换。现有机器配置拥有钩子启用和外部命令权限。 钩子只能在实际终态转换之后运行。只允许本机配置命令,工作区 HTTP 配置保留超时等受限字段。 同一关闭状态在停止与退役、归档的可观测结果不一致。 请先让关闭钩子时的 stop 跳过钩子专有准备,并保持当前头正确的提交与投影重试回执。 通过真实 loopback HTTP 验证本机命令字段无法从工作区写入。 已打包界面和 Windows 未验证。

English verdict: REQUEST_CHANGES at ea8fc1e. The new raising-readback test passes and the production code is unchanged from the previous review. An unconfigured stop still resolves a hook-only legacy state path and emits preparation_error. Apply the existing disabled gate before path resolution and preserve the recorded stop.

runtime_root_override,
registry_path=source_registry,
)
declared = goal_state_file_from_record(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 停用终态钩子时停止操作仍报告钩子准备失败。未配置命令的原生 stop,读取含过期用户别名的 state_file 时,候选把钩子状态报为 preparation_error。普通路径的对照是 not_configured。主干两种输入都正常停止。候选主操作也已成功写回,进程与账本数量均为零。 在解析 state_file 前复用 goal_closeout_configuration 的未配置短路,与 retire 和 archive 一致。保留已配置路径的准备错误回执,再补一条禁用状态下过期别名的原生 stop 测试。

This branch has not been deployed

No deployments
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.

Feature request: a terminal-state (closeout) hook so finished goal worktrees can be reclaimed

2 participants