Skip to content

fix(steward): recover reports and monitor follow-ups after zero-write replan or pre-dispatch failures - #9513

Merged
loopx-agent merged 1 commit into
mainfrom
codex/fix-steward-morning-monitor-replan-20261127
Nov 27, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/fix-steward-morning-monitor-replan-20261127

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Steward periodic report .admission-resume recovery (steward_managed_mode.ts, steward_turn.py): Admit .admission-resume once a blocking autonomous_replan obligation has cleared (effective_action == "normal_run" and replan_action_packet == null) when the prior .replan governance probe failed pre-commit validation at validation_stage == "task_postcondition" (in addition to "host_result_contract") with zero durable writes (completed_phases == ["host_execute", "typed_result"], writeback/quota_spend/scheduler_ack == false). Preserve #9515's stopped-journal fail-closed checks and return None from report_selection_recovery while replan remains active or on non-recoverable failed probes.
  • Steward monitor follow-up retry & exhaustion (steward_monitor_turns.py): Recognize two zero-write failure shapes in _is_precommit_retryable_advancement_turn (and is_exhausted_zero_write_followup_todo) via _past_precommit_cooldown while staying within the 750-line module ceiling (746 lines):
    1. turn_todo_selection_deferred (reason_code == "autonomous_replan") where the inline .replan probe invoked the host (host_invoked == true) without durable writes (state_written == false, quota_spent == false, scheduler_acknowledged == false).
    2. Outer native_loopx Chat preparation failures (resume_failed, runtime_unavailable, model_auth_unavailable) that failed strictly before worker dispatch (started_at == null, first_event_at == null, upstream_turn_id == null, response == null, delta_count == 0). Unmapped execution_worker_exited / execution_worker_exited_before_dispatch and post-start failures fail closed.
  • Governance replan preview validator hardening (turn_run_once.py): Catch ValueError alongside ReplanWritebackRejected in validate_replan so invalid candidate fields produce a structured public-safe failed validator receipt rather than an unhandled inconclusive exception.
  • Test alignment (tests/test_native_steward_reports.py, tests/test_steward_report_recovery_and_validator.py, tests/control_plane_ts/steward_reports.test.ts): Align the pre-commit non-looping negative test on "settlement_postcondition", add negative fail-closed tests for execution_worker_exited / execution_worker_exited_before_dispatch / started turns, and cover TS/Python task_postcondition .admission-resume recovery and validator receipt handling.

Verification

  • node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/steward_reports.test.ts tests/control_plane_ts/steward_managed_mode.test.ts (31 passed, 0 failed)
  • npm run typecheck:control-plane (exit 0)
  • uv run --extra test python -m pytest -n 4 tests/capabilities/test_steward_monitor_contract.py tests/test_steward_report_recovery_and_validator.py tests/test_native_steward_monitor.py tests/test_native_steward_reports.py -q (408 passed)
  • uv run --extra test ruff check ..., uv run --extra test python scripts/check_rfc_bilingual.py --base origin/main --head HEAD, and uv run --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick (passed, 0 failures)

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

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

Exact head: 6b392476e549bf02334618c2d3a35d9addda9dda

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

[P2] 让原生监控跟进识别实际的派发前退出

已有监控跟进 Todo,真实 Codex worker 在 starting 检查点后、派发前退出。 实际运行 Codex worker,在写入 starting 后、调用派发前注入异常。ChatStore 对 native_loopx 不保存 pending 标记,随后只写入 execution_worker_exited,并保留 started_at。冷却后原生调度解析返回 None,原跟进没有 .precommit-retry。 在 Chat 的生产写入点为这类原生工作提供可核验的未派发凭证,并让重试分类按该凭证匹配带 started_at 的真实记录。保留无凭证或已派发时的拦截。如果本次只交付 worker 启动前的准备失败恢复,收窄允许列表和交付说明。 用真实 worker 和 SQLite Todo 复验,覆盖冷却期后恰好一次接续,以及已派发、凭证缺失时继续拦截。 改动位置 ChatStore 派发检查点 worker 退出恢复

[P2] 恢复 monitor 模块的仓库边界校验

运行现有 steward monitor 合约测试。 同一仓库测试在基线以 741 行通过,在当前头以 794 行失败。既有断言对该模块设限 750 行,并在这之后检查导入 DAG。 复用 Chat 的派发证据判定,精简监控模块新增分类,恢复现有行数和导入约束。 python -m pytest -q tests/capabilities/test_steward_monitor_contract.py::test_steward_monitor_module_budgets_and_import_dag 改动位置 仓库模块合约

动机 / Motivation

使用管家定期报告和监控的操作者需要拿到原窗口报告,也需要在监控信号变化时完成对应的跟进。 当宿主重规划在提交前被拒绝,报告窗口可能留下零写入记录却未继续。监控跟进也可能在准备阶段退出,之后仍留在开放队列里。 隔离 SQLite 中,清除重规划阻塞后,原窗口只恢复一次并生成报告,次日正常运行。原生监控 worker 在派发前退出后,冷却到期依然没有跟进重试。 本次范围是原 Session 内的报告和监控恢复,沿用既有订阅、Todo、校验器和权限。

改动思路 / Approach

报告接续沿用 Chat 记录、Turn journal 和 TypeScript 原会话准入。监控恢复继续使用原 Todo 版本产生确定性载体 ID,派发前证据应由持久化派发状态的 Chat owner 提供。 当前提案需要保证零写入报告能够恢复,同时让声明支持的监控失败类型可由真实写入路径产生,并保留既有未知状态拦截。 Chat 现有处理只为 Lark 外部请求写入 pending,随后会用 committed 防止把已派发工作当成安全重试。原生跟进应沿用相同的证据强度。报告重规划回执则已能在原 journal 和新 guard 都合格时继续。 既有派发恢复合同 现有 Lark 恢复所有者

具体改动 / Changes

6 个文件,+303/-10。以 b6be7f6ab836bb91b416230b8147c027adfda5ba 的定期报告合同为基线。原报告窗口经 SQLite 验证,在清除阻塞后保持同一窗口并只恢复一次。原生准入仍核对宿主、身份、零写入和当前 guard。已证实未派发在监控边缺少对应的生产凭证。 定期报告合同

  • validate_replan 把语义预检抛出的 ValueError 写成结构化校验失败,可从原 Turn journal 回读。 校验器
  • report_selection_recovery 读取本次失败探针的 journal,TypeScript 准入在原窗口与授权成立时接纳 task_postcondition。 报告证明 准入
  • resolve_advancement_turn_id 在冷却后依据旧载体选择有界接续。worker 的 starting 检查点与新增错误分类发生在不同生产边界,测试必须连到同一份持久化记录。 跟进选择 调度调用

对主干的风险 / Risks

精确头 18 项 Python 和 31 项 TypeScript 聚焦测试通过,管理队列与监控兼容组额外 22 项通过,现有模块边界测试有 1 项失败。两条作者新增回归移植至基线均失败,验证报告恢复和既有准备阶段的改进。真实 native witness 在基线和精确头均读到相同退出形态,也均无重试,表示这项交付缺口仍未闭合。隔离环境用实际 SQLite 和 Chat worker,Codex app-server 用合成 transport,异常只注入派发前检查点。未查询托管 CI。 报告回归 既有模块校验

我的整体评价 / Verdict

报告恢复和新治理回执可以保留。缺少匹配凭证时,原信号的跟进会持续留在开放 Todo 中。相同条件下耗尽重试的判定也依赖同一分类。 补齐原生生产凭证或收窄到已验证的错误范围,并恢复 monitor 模块边界后再复核。改动涉及 Chat 本地记录、CLI 校验和原生准入,没有修改渲染代码。SQLite 回归核对报告输出和次日窗口。 实际模型及外部投递未验证。

English verdict: REQUEST_CHANGES. A real native worker exit before dispatch still leaves the follow-up without a retry, and the monitor module now fails the repository's 750-line gate. Original report-window recovery passed.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

补充一项独立复验的现有回归,绑定 6b392476e549bf02334618c2d3a35d9addda9dda。同一个 test_resolve_advancement_turn_id_handles_selection_deferral_and_precommit_retries 在基线 b6be7f6ab836bb91b416230b8147c027adfda5ba 通过,在候选失败。旧用例要求宿主已调用、其余 effect 均为 false 的自主重规划拒绝返回 None,新实现返回 .precommit-retry。如果保留这项有意的行为变化,请同步更新旧断言,并另保留实际写入、拒绝原因不匹配或派发状态未知时不得重试的负例。复验命令为 python -m pytest -q tests/test_steward_generic_monitor_todo.py -k handles_selection_deferral_and_precommit_retries。 现有断言

@mergify

mergify Bot commented Nov 27, 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, @loopx-agent.

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 27, 2026
… replan or pre-dispatch failures

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/fix-steward-morning-monitor-replan-20261127 branch from 6b39247 to d34c384 Compare November 27, 2026 15:10
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 27, 2026

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

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 · self_reported

注:pr-review 包在当前无绑定会话中返回 reviewer_execution.status = "unavailable" (session_not_bound),因此按 reviewer_declaration 规则以 self_reported 标明审阅身份。

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

本次改动面向通过 Steward 接收定时报告和持续 PR 监控推进汇报的用户,以及负责故障自恢复与模块契约门禁的 Steward 运行时维护者。

改造前,当 autonomous_replan 触发的 .replan 治理探针因候选改写无效在提交前阶段 task_postcondition 零写入失败时,周期报告在 replan 解除后仍卡死、监控跟进 todo 不在冷却后重试、validate_replan 遇到 ValueError 会抛未处理异常,且上轮基线存在两项 [P2] 缺陷;改造后,TS 与 Python 放行 task_postcondition 零写入恢复并将负测对齐到 settlement_postcondition,监控跟进抽共用 _past_precommit_cooldown 使模块回到 746 行并将预派发错误码收窄为三项,validate_replan 输出结构化 failed 回执。

细项改进(head d34c38497748a499e338f0bf9a463967c3f61189):

  1. TS 控制面 admitReportSelectionRecovery 与 Python StewardTurnHost.report_selection_recovery 在保留 #9515 stopped 日志拦截的基础上,统一放行 task_postcondition(completed_phases == ["host_execute", "typed_result"],writeback/quota_spend/scheduler_ack == false)零写入阻断后的单次 .admission-resume 恢复,并同步将 #9515 的非循环负向测试对齐到 settlement_postcondition。
  2. steward_monitor_turns.py 抽取 _past_precommit_cooldown 并精简辅助判断,将文件控制回 746 行(<= 750 通过 test_steward_monitor_contract.py),并将 _PRE_DISPATCH_ADVANCEMENT_ERROR_CODES 收窄为确实由外层准备拒绝到达的 {"resume_failed", "runtime_unavailable", "model_auth_unavailable"},移除未有生产到达证据的 "execution_worker_exited_before_dispatch",同时补充 execution_worker_exited(已设 started_at)及 execution_worker_exited_before_dispatch 的 fail-closed 负向测试。
  3. validate_replan 新增 except ValueError 分支,输出公开发布安全的 "failed" / "repair_required" 回执。

可观测结果:一旦 autonomous_replan 阻塞解除,卡在 task_postcondition 零写入失败上的周期报告通过一次 .admission-resume 恢复投递,监控跟进 todo 在冷却后按上限安全重试且不会越界重试已派发/不可达状态。

边界与非目标:本 PR 仅处理零写入预提交失败的受控恢复与 validate_replan 异常收敛;不放开已派发、已写入状态或未知退出码的重试,不放宽任何模块行数预算。

改动思路 / Approach

设计取舍:将是否允许 .replan 后 .admission-resume 的最终裁决权继续放在 TS 权威控制面 admitReportSelectionRecovery,监控推进重试逻辑在既有 steward_monitor_turns.py 内通过共用 _past_precommit_cooldown 完成复用并严格收敛预派发错误码,既零新增模块或外部存储,又把模块控制在 746 行符合 750 行合约。当前 PR 边界:仅涵括零写入 task_postcondition .replan 后报告恢复、内联拒单及三类未派发准备态重试、与 validate_replan 的 ValueError 收敛,不放宽模块行数上限或已派发退出码拦截。

维度 改造前 / 上轮问题 本次修复后(d34c38497748a499e338f0bf9a463967c3f61189)
task_postcondition 零写入 .replan 后报告恢复 TS/Python 仅允许 host_result_contract,阻塞解除后仍永久无法 .admission-resume TS 与 Python 统一放行且要求无写/无配额消耗/无调度确认且 replan 已清除,settlement_postcondition 仍 fail-closed
监控跟进预派发与内联 .replan 重试 未识别内联 .replan 拒绝与预派发准备失败;上轮 [P2] 含 execution_worker_exited_before_dispatch 且模块达 794 行 收窄为 resume_failed / runtime_unavailable / model_auth_unavailable 并补充负向断言;抽共用 _past_precommit_cooldown,模块回落至 746 <= 750 行
validate_replan 非法候选处理 ValueError 未捕获导致校验回执退化为异常 inconclusive 返回确定性 status: "failed", recovery_kind: "repair_required" 回执
  • 入口与权威状态:报告恢复准入由 TS steward_managed_mode.ts#L301-L387 的 admitReportSelectionRecovery 持有权威判断;监控重试与耗尽判定由 steward_monitor_turns.py 读取 ChatStore 与 NativeLoopX Turn 状态;预览校验由 turn_run_once.py#L366-L392 承担。
  • 已有能力复用:直接复用现有 admitReportSelectionRecovery、_cleared_replan_guard、_is_precommit_retryable_advancement_turn 与 is_exhausted_zero_write_followup_todo,无新增外部存储或状态机。

具体改动 / Changes

  • 规范基准(Spec Basis):本次修复针对线上真实发生的 .replan task_postcondition 零写入卡死与上轮两项 [P2] 缺陷(spec_basis.decision = no_spec),改动语义与正负边界均由 TS 控制面单测与 Python 单元/合约回归直接验证。

关键代码讲解

  1. admitReportSelectionRecovery 与 StewardTurnHost.report_selection_recovery(loopx/control_plane/collaboration/steward_managed_mode.ts#L365-L387, loopx/capabilities/native_chat/steward_turn.py#L574-L586)

    • 职责与变更:在原有 "host_result_contract" 之外把 "task_postcondition" 纳入合法的前置治理零写入失败阶段;保留 #9515 对 journal_status != "stopped" 的严格 fail-closed 检查,仍要求 completed_phases == ["host_execute", "typed_result"]、零写回/零配额/零调度确认且当前 effective_action == "normal_run"。
    • 测试对齐:原 #9515 在 tests/test_native_steward_reports.py#L2740-L2831 以 "task_postcondition" 作为不可恢复探针样例,已对齐为 "settlement_postcondition"(与 steward_reports.test.ts 一致),继续验证不可恢复阶段不会循环重试。
  2. 预派发收窄与 750 行模块收敛(loopx/capabilities/native_chat/steward_monitor_turns.py#L428-L502)

    • 职责与变更:移除 [P2] 指出的 "execution_worker_exited_before_dispatch",将 _PRE_DISPATCH_ADVANCEMENT_ERROR_CODES 限定为 frozenset({"resume_failed", "runtime_unavailable", "model_auth_unavailable"});要求 status == "failed"、origin == "native_loopx"、loopx_execution is True、四个关键执行字段(response/upstream_turn_id/started_at/first_event_at)全为 None、delta_count == 0 且通过 _past_precommit_cooldown。同时在 turn_todo_selection_deferred 分支支持内联 .replan autonomous_replan 零副作用失败的冷却后重试。抽取 _past_precommit_cooldown 并紧凑化相关分支后模块为 746 行,通过 750 行预算检查。
    • 负向覆盖:tests/test_steward_report_recovery_and_validator.py#L1647-L1755 验证已设 started_at 的 execution_worker_exited 以及 execution_worker_exited_before_dispatch 均 fail-closed(_is_precommit_retryable_advancement_turn 返回 False、耗尽判断返回 False)。
  3. validate_replan ValueError 收敛(loopx/cli_commands/turn_run_once.py#L366-L392)

    • 职责与变更:在 except ReplanWritebackRejected 之外新增 except ValueError,返回明确且不泄露私有路径的 "status": "failed"、"recovery_kind": "repair_required" 结构化回执。

对主干的风险 / Risks

  • 负向边界与恢复分析:若 autonomous_replan 依然处于激活态、validation_stage 为 "settlement_postcondition" 或任何非零写/已设 started_at 的 Turn 记录,两端均拒绝 .admission-resume 与自动重试;已超过重试上限的零写入跟进任务受 is_exhausted_zero_write_followup_todo 约束停止循环。
  • 隔离性、权限语义与默认行为披露:本 PR 属于既有 Steward 故障恢复路径的缺陷修复(default_off_isolation = not_applicable,authority_semantics = not_applicable);未更改共享枚举词表(semantic_alignment = not_applicable);已披露默认行为变化:task_postcondition 零写入 .replan 阻断解除后允许一次 .admission-resume,监控跟进在冷却后可针对内联 .replan 零副作用拒单与三类未派发错误重放,且 validate_replan 的 ValueError 收敛为确定性 failed 回执。
  • 本地验证矩阵(wait_for_ci: false,不依赖远端 CI;已包含对两项 [P2] 及 #9515 对齐测试的完整复验):
    • node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/steward_reports.test.ts tests/control_plane_ts/steward_managed_mode.test.ts -> PASS(31 passed, 0 failed)
    • npm run typecheck:control-plane -> PASS(exit 0)
    • uv run --extra test python -m pytest -n 4 tests/capabilities/test_steward_monitor_contract.py tests/test_steward_report_recovery_and_validator.py tests/test_native_steward_monitor.py tests/test_native_steward_reports.py -q -> PASS(408 passed in 452.87s)
    • uv run --extra test ruff check loopx/capabilities/native_chat/steward_monitor_turns.py loopx/capabilities/native_chat/steward_turn.py loopx/cli_commands/turn_run_once.py tests/test_steward_report_recovery_and_validator.py tests/test_native_steward_reports.py -> PASS(All checks passed!)
    • uv run --extra test python scripts/check_rfc_bilingual.py --base origin/main --head HEAD -> PASS
    • uv run --extra test loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick -> PASS(selected=3, failures=0, warnings=0)

我的整体评价 / Verdict

  • 长程与用户体验影响:long_horizon = improved(恢复被 task_postcondition 零写入 .replan 与预派发失败长期锁死的每日定时汇报与跟进监督链路,防止人工反复兜底);user_experience = improved(监控汇报恢复准时投递;visual_review = not_applicable,原因:仅涉及 TS 控制面校验、Python 后端运行时与测试,无前端 UI 渲染改动,unverified_scope = none)。
  • 代码体量、可观测语义与词表归属:全 diff 7 个文件 +316 / -63(生产改动 4 文件仅 +72 / -60,steward_monitor_turns.py 为 746 行符合 <= 750 契约),code_volume = necessary,change_proportionality = proportionate;observable_semantics = intentional_change_validated。
  • 残余风险与最终结论:单元与合约回归使用可控替身模拟 .replan 探针日志及外层准备拒绝;两项 [P2] 均已在 exact head d34c38497748a499e338f0bf9a463967c3f61189 修复并通过全量本地门禁,可关闭未决审阅线程并完成合入。

英文简短结论
English verdict: APPROVE at exact head d34c384 — resolves both [P2] findings by narrowing _PRE_DISPATCH_ADVANCEMENT_ERROR_CODES to verified pre-dispatch errors (resume_failed, runtime_unavailable, model_auth_unavailable) with fail-closed tests for execution_worker_exited / execution_worker_exited_before_dispatch and refactoring _past_precommit_cooldown so steward_monitor_turns.py stays at 746 lines (<= 750); 31 Node TS tests, typecheck, 408 pytest regressions (including test_steward_monitor_contract.py and aligned settlement_postcondition), ruff, bilingual RFC check, and quick canary premerge all passed locally with zero findings.

@loopx-agent
loopx-agent merged commit 2302e42 into main Nov 27, 2026
27 of 48 checks passed
@loopx-agent
loopx-agent deleted the codex/fix-steward-morning-monitor-replan-20261127 branch November 27, 2026 15:16
loopx-agent added a commit that referenced this pull request Nov 27, 2026
…it modules to loopx-workspace, fix contract test

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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.

1 participant