Skip to content

refactor(native-chat): modularize report_failure_proof to zero-Any with single-pass verification - #9455

Merged
huangruiteng merged 2 commits into
mainfrom
codex/slim-report-failure-proof-zero-any-20261126
Nov 26, 2026
Merged

huangruiteng merged 2 commits into
mainfrom
codex/slim-report-failure-proof-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Modularized loopx/capabilities/native_chat/report_failure_proof.py (728 -> 494 LOC, 82 -> 0 AST Any, 6 -> 0 mypy errors, 0 # type: ignore) into an acyclic three-module Zero-Any structure while preserving all exported symbols and atomic_write_json monkeypatch seams (loopx/*.py == 112, module_metric_baseline.json untouched):
    • loopx/capabilities/native_chat/report_failure_probe.py (369 LOC, 0 AST Any): narrow structural TurnLoader / ReportProofStore / ReportProofController Protocols, ProofMapping / ProofObject aliases, _is_completed_host_failure_report, valid_report_failure_proof, proof_targets_original_turn, probe_report_failure, _extract_antigravity_turn_cascade, _antigravity_trajectory_steps, _probe_antigravity_report_failure, and observe_antigravity_report_failure.
    • loopx/capabilities/native_chat/report_failure_ledger.py (237 LOC, 0 AST Any): report_failure_binding, _read_report_failure_record, _is_valid_retained_proof, _is_contradicted_proof, _is_exact_contradiction, _contradiction_ledger_path, _read_contradiction_ledger, _durable_contradiction_status, _binding_attempt_state, read_retained_report_failure, and is_report_failure_contradicted.
    • loopx/capabilities/native_chat/report_failure_proof.py (494 LOC <= 550, 0 AST Any): lock-guarded persistence (retain_report_failure, _invalidate_attempt_proof, contradict_report_failure), observe_report_failure, verify_report_window_failure, resolve_report_quota_observation, build_report_quota_request, build_report_timeout_request, and explicit re-exports of probe/ledger symbols.
  • Preserved exact main behavior (valid_report_failure_proof, contradicted, provider_thread_id key-presence vs explicit None, untrusted/corrupt ledger fail-closed handling, request builders) with safe I/O and scan reductions:
    • Coalesced post-probe ledger + attempt-record checks in verify_report_window_failure (proof is None fallback) into _binding_attempt_state (1+1 reads instead of 2+2 post-probe).
    • Deferred attempt-record pre-read in contradict_report_failure unless proof omits thread_id.
    • Collapsed _extract_antigravity_turn_cascade event checks into a single pass and shared _mapping / _is_completed_host_failure_report helpers.
  • Added tests/capabilities/test_report_failure_proof_contract.py (510 LOC, 0 AST Any, 0 # type: ignore) covering LOC/Zero-Any/export invariants, malformed inputs, key-presence vs explicit None, single-pass I/O counters, Antigravity retention/timeout builders, and paired origin/main vs HEAD behavioral parity.

Verification

  • pytest -n 2 -rs (tests/capabilities/test_report_failure_proof_contract.py, tests/test_steward_report_recovery_and_validator.py, tests/test_native_steward_reports.py, tests/test_native_steward_turn_host.py): 312 passed, 0 failed.
  • pytest -n 4 -rs (tests/capabilities/test_periodic_report*.py, tests/canary/, tests/architecture/): 2,578 passed, 6 skipped (6 APFS skips in test_git_path_display.py, 0 failed).
  • ruff check (4/4 clean), mypy --strict --follow-imports=silent (4/4 clean), repo mypy (17/17 clean), steward_turn.py caller mypy (59 pre-existing errors matching main, 0 regressions).
  • npm run typecheck:control-plane & node --test tests/control_plane_ts/content_digest_single_owner.test.ts (17/17 passed), check_rfc_bilingual.py passed, canary premerge (status=passed, 5/5 catalog smokes passed, manual_holds=0, receipt cqr_bc557e040b1e9d2d41c7).

…th single-pass verification

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@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

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

[P2] 接受保留证据前复核已提交的否定记录。generation.lock 挡住 attempt 清理,挡不住父账本提交。读到旧 positive record 后,候选核验返回 true,cadence 替换原窗口。相同 fixture 下基线返回 false 并保留原窗口。 保留单次 attempt proof 读取,并在接受旧证据前重新核验 durable contradiction。必要时使窗口替换和否定写入共享可验证的顺序。增加这组 interleaving 回归。 源码

动机 / Motivation

减少原始报告失败证据的重复读,同时维持同一窗口及否定证据的优先级。 基线的 history-outage 分支接连经过 contradiction 检查与 retained-proof 读取,后者再次读取父账本。 通过原会话等待本期报告和恢复的用户,以及在同一 cadence 上调度的 Steward。

单一同头窗口。在历史返回无有效证明且父账本无否定时,两版均可复用同一旧失败证据。父账本在核验前已有否定时,两版均保留原窗口。 已落盘的反证应保持原窗口。当前候选的窗口替换使后续工作在不同窗口上继续。 完整 diff 与 git diff --check 已核对。两版各跑 6 个独立场景,包含实际 Filesystem 锁、否定记录提交与读回,以及 cadence admission。候选新增 4 项契约测试通过,均未覆盖本次有序交错。 较宽的 24 项报告恢复对照中,基线 23 项通过、候选 22 项通过,差项均为等待 Chat Turn 超时。候选第一次独有的 SQLite 超时按同 selector 配对复跑后,两版均在准备原失败轮时超时。另一 SQLite 超时在两版的不同阶段出现,原因仍待归因。这类超时与本评审已稳定复现的 ledger/cadence 差异分别记录。 实测使用隔离运行目录与真实锁、正反证据写入和 cadence writer。只替换 provider 观察为无当前证据。未调用真实 provider、安装版或远程 CI。 基线契约

改动思路 / Approach

该改动沿用 StewardReports._frontier → admit_cadence_window → report_window_failure_verified → durable contradiction / attempt proof。保留一个否定账本和既有 cadence owner。持久态无需复制,但父账本写入不等 attempt 文件清理,必须把这些读按实际写入顺序核验。 父账本按原绑定先提交,attempt 文件随后在 generation fence 可用时清理。候选的合并读取丢掉后置 ledger 检查。 保留拆分和单次 attempt 文件读取,复核接受前的 ledger 状态,测试同一路径真实窗口是否保留。

具体改动 / Changes

精确提交 45e99b2,分叉基线 50aa5b4。4 个文件 +1,386 / −504。抽出 probe 与 ledger,保留 proof 门面及原恢复链,新增 contract 测试。

关键代码讲解

  • report_failure_binding。把 Session、Turn、窗口、订阅及结果摘要绑定到同一 proof。 源码

  • _binding_attempt_state。一次读取父否定账本和旧 attempt,正常情形减少 IO,交错时会漏读已提交否定证据。 源码

  • contradict_report_failure。先提交和复读父账本,随后尝试在原 generation lease 下清理 attempt。 源码

  • verify_report_window_failure。优先查当前 history。无当前证明时,retained proof 决定是否可替换原窗口。 源码

  • _extract_antigravity_turn_cascade。归并 Antigravity 原始事件检查,与本次 Codex history-outage 反例无关。 源码

  • durable-contradiction-holds-the-original-report(not_met)。父否定账本提交后,旧 attempt 即使尚在磁盘也不再授权替换原窗口。

对主干的风险 / Risks

在读取旧 attempt proof 的过程中,另一条正常写入路径已经提交并读回同一绑定的 durable contradiction。generation.lock 仍持有,attempt proof 暂未清除。基线拒绝,当前提交返回 true,真正的 cadence admission 因此把原窗口换成新窗口。 完整 diff 与 git diff --check 已核对。两版各跑 6 个独立场景,包含实际 Filesystem 锁、否定记录提交与读回,以及 cadence admission。候选新增 4 项契约测试通过,均未覆盖本次有序交错。 较宽的 24 项报告恢复对照中,基线 23 项通过、候选 22 项通过,差项均为等待 Chat Turn 超时。候选第一次独有的 SQLite 超时按同 selector 配对复跑后,两版均在准备原失败轮时超时。另一 SQLite 超时在两版的不同阶段出现,原因仍待归因。这类超时与本评审已稳定复现的 ledger/cadence 差异分别记录。 实测使用隔离运行目录与真实锁、正反证据写入和 cadence writer。只替换 provider 观察为无当前证据。未调用真实 provider、安装版或远程 CI。

语义与 CI 对齐

在读取旧 attempt proof 的过程中,另一条正常写入路径已经提交并读回同一绑定的 durable contradiction。generation.lock 仍持有,attempt proof 暂未清除。基线拒绝,当前提交返回 true,真正的 cadence admission 因此把原窗口换成新窗口。 保留单次 attempt proof 读取,并在接受旧证据前重新核验 durable contradiction。必要时使窗口替换和否定写入共享可验证的顺序。增加这组 interleaving 回归。

我的整体评价 / Verdict

REQUEST_CHANGES。 候选在否定证据已经提交时仍接受旧 proof,实际替换原窗口。修复后按同一 exact base 与新 head 复跑并发窗口和两个对照分支。 已落盘的反证应保持原窗口。当前候选的窗口替换使后续工作在不同窗口上继续。

English verdict: REQUEST_CHANGES at 45e99b2. A newly committed contradiction can be missed, allowing cadence to replace the original report window. Recheck durable contradiction before accepting retained proof.

…port failure record

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@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

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

动机 / Motivation

减少原始报告失败证据的重复读,同时维持同一窗口及否定证据的优先级。 基线的 history-outage 分支接连经过 contradiction 检查与 retained-proof 读取,后者再次读取父账本。 通过原会话等待本期报告和恢复的用户,以及在同一 cadence 上调度的 Steward。

三版的普通历史缺证场景均接受合法保留证据并推进窗口。在无反证的实际 cadence 路径,原基线读取 attempt 两次,当前一次。 已观察到的持久反证保留原窗口和后续恢复身份。 基线、旧头和当前各跑 6 项独立对照,检查真实锁、持久读写及实际 cadence admission。当前报告定向套件 212 项通过。完整差异的 git diff --check 和此次修订两文件的 Ruff 检查通过。 隔离运行使用真实本地账本、锁、attempt 文件和 cadence writer。原 Turn 由固定样例提供,历史 provider 返回无有效证据的测试响应。结论覆盖最终账本读取已经可见的提交。安装版、真实远程 provider、远程 CI 及最终读取之后才发生的提交留待适用验证。 基线契约

改动思路 / Approach

该改动沿用 StewardReports._frontier → admit_cadence_window → report_window_failure_verified → durable contradiction / attempt proof。父账本与 attempt 清理仍分两阶段。先取 retained attempt,再依父账本决定能否使用旧 proof,保留原 cadence 所有权。 父账本先落盘,attempt 清理可被 generation fence 推迟。新的读取顺序使核验时可见的反证覆盖尚存的旧 attempt。 已有 attempt 反证直接拒绝。否则读取一次父账本即可决策,普通分支无需读同一 attempt 两次。

具体改动 / Changes

精确提交 1d5dba6,分叉基线 50aa5b4。4 个文件 +1,445 / −504。保留 proof 门面,分出 probe 与 ledger。新修订调整读取顺序并加入真实 cadence 有序回归。

关键代码讲解

  • _binding_attempt_state。读取 attempt 后确认否定账本,再允许消费旧 proof。 源码

  • report_failure_binding。把 Session、Turn、窗口、订阅及结果摘要绑定到同一 proof。 源码

  • contradict_report_failure。先提交和复读父账本,随后尝试在原 generation lease 下清理 attempt。 源码

  • verify_report_window_failure。优先查当前 history。无当前证明时,retained proof 决定是否可替换原窗口。 源码

  • _extract_antigravity_turn_cascade。归并 Antigravity 原始事件检查,与本次 Codex history-outage 反例无关。 源码

  • durable-contradiction-holds-the-original-report(implemented)。在核验旧 attempt 后的最终账本读取里,已提交并可观察的同绑定反证必须阻止原窗口替换。

对主干的风险 / Risks

独立确定性交错先读取旧 positive attempt 字节,在字节交还读取方前通过正式写入者提交并读回同绑定的父账本反证。旧 attempt 此时仍在磁盘。旧头 45e99b2 接受并换窗,基线与当前均拒绝并保留原窗口。三版均拒绝核验前已提交的反证。 基线、旧头和当前各跑 6 项独立对照,检查真实锁、持久读写及实际 cadence admission。当前报告定向套件 212 项通过。完整差异的 git diff --check 和此次修订两文件的 Ruff 检查通过。 隔离运行使用真实本地账本、锁、attempt 文件和 cadence writer。原 Turn 由固定样例提供,历史 provider 返回无有效证据的测试响应。结论覆盖最终账本读取已经可见的提交。安装版、真实远程 provider、远程 CI 及最终读取之后才发生的提交留待适用验证。

我的整体评价 / Verdict

APPROVE。 实际窗口回归已修复,缺反证时的恢复推进保持,最终账本核验观察到反证时保留原窗口。 已观察到的持久反证保留原窗口和后续恢复身份。

English verdict: APPROVE at 1d5dba6. The real cadence regression is fixed. Baseline and current reject a contradiction committed while attempt bytes are outstanding, and the ordinary proof path still advances.

@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

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

动机 / Motivation

本轮重构旨在消除 report_failure_proof 模块超出大小与 Any 密度约束(728 行、82 处 Any、6 处 mypy 错误)的问题,并修复上一提交在并发否定写入时的窗口替换竞态。受影响的调用方与运维主体为:通过原会话等待定期报告恢复的用户,以及在 cadence 调度下复核历史故障证明的 Steward 守护进程。

在 history-outage 复核场景中,旧主干 50aa5b4fd1 会两次读取 attempt 记录和父账本,上一修订 45e99b2a90 先读父账本再读 attempt 记录,在 generation.lock 阻挡 attempt 清理时会漏掉刚提交的否定账本并替换原窗口;当前提交 1d5dba63d9 改为先读 attempt 记录再核验父否定账本,保留单次 attempt 读取并在并发否定后继续守住原窗口。若不做任何改动,原模块将持续保留 82 处 Any 与基线类型报错;若仅按上一提交方式合入,则会放行已否定窗口的替换。可观测改进为:verify_report_window_failure 在单次 attempt 文件读取下完成非否定旧证明复用,并在并发 durable contradiction 落盘时返回 False 且保持原 cadence 窗口不变。本 PR 边界明确收敛于:不更改 periodic_reports 调度策略、Codex/Antigravity 失败判定阈值或外部 CLI 参数,也不修改无关调用方或文档。

改动思路 / Approach

整体链路保持 steward_turn → admit_cadence_window → verify_report_window_failure → _binding_attempt_state 不变。方案复用既有的 native-terminal-failure.json 尝试记录与父目录 contradicted-report-failures.json 持久化否定账本,未引入额外状态存储或平行决策分支。

机制评估维持保留结论:将探测逻辑、否定账本状态机与持锁写入拆分为无环三模块,在单次读取优化的同时严格维持父账本先于清理、不可信即闭锁的既有边界。当前 PR 边界明确为:仅重构报告失败证明三模块的类型边界与 _binding_attempt_state 读取顺序,不改动周期调度策略、外部 CLI 或其他宿主模块。因为 contradict_report_failure 总是先提交且读回校验父否定账本、再获取 generation.lock 清理 attempt 文件,所以 _binding_attempt_state 只要先读 attempt 文件、再读父否定账本,无论并发否定落在锁前、读取前还是两次读取之间,都能保证不会错过已提交的否定状态。

具体改动 / Changes

精确审查提交 1d5dba63d99360c7ce22fa4c0a00ab51580628c5,基于主干 50aa5b4fd1c88b7225fc30e58423120e3ad5d426(4 个文件 +1,445 / -504;相对上一审查头 45e99b2a90 的增量修复已解决线程 PRRT_kwDOStEbEs68K09p)。按 docs/product/periodic-reports.md#original-private-report-settings-and-execution(修订 50aa5b4fd1c88b7225fc30e58423120e3ad5d426)逐项核对:

  • durable-contradiction-before-attempt-cleanup(implemented):父否定账本提交先于 attempt 清理,并发写入期间 _binding_attempt_state 先读 attempt 再复核账本,持续守住原窗口。
  • single-pass-outage-fallback(implemented):仅在 live 历史不可用且未否定/账本可信时复用旧证明;账本损坏或符号链接仍闭锁返回 False。
  • antigravity-codex-proof-parity(implemented):Codex 与 Antigravity 探测判定、所有公开/私有导出符号及 monkeypatch 兼容点保持等价。

关键代码讲解

  • _binding_attempt_state(report_failure_ledger.py#L202-L213):先调用 _read_report_failure_record 读取 attempt 记录一次并判定 _is_contradicted_proof,未否定时再检查 _durable_contradiction_status != "absent",既保持单次 attempt IO 又彻底消除 45e99b2a90 的并发漏读竞态。
  • contradict_report_failure(report_failure_proof.py#L177-L270):独占锁下提交且读回校验 contradicted-report-failures.json 后,再进入 _invalidate_attempt_proof 清理或覆写 attempt 文件,提交失败时先尽力清理正证明并向上报错。
  • verify_report_window_failure(report_failure_proof.py#L335-L377):入口先验账本非 untrusted,优先查实时历史,仅当 probe 返回 None 时走 _binding_attempt_state 单遍兜底。
  • valid_report_failure_proof(report_failure_probe.py#L64-L86):采用零 Any 的 ProofMapping 与 Protocol 契约校验 agy_turn_* 与 Codex 用户态故障证据,字段判定与基线一致。

对主干的风险 / Risks

未发现阻塞性回归风险。独立三臂交错反事实验证(真实文件系统锁、账本提交与 admit_cadence_window)实测结果:

基线/候选版本 并发否定交错结果 是否守住原窗口 attempt 读取次数
50aa5b4fd1 (main) mutated=False same_win=True 2
45e99b2a90 (上一修订) mutated=True(窗口被替换) same_win=False 1
1d5dba63d9 (当前 HEAD) mutated=False same_win=True 1

活跃生产调用方仅 steward_turn.py,未增设特权控制或 opt-in 开关,所有旧导出及 atomic_write_json 测试桩保持可用。本地完整验证结果:report_failure_probe.py 369 行、report_failure_ledger.py 239 行、report_failure_proof.py 494 行、test_report_failure_proof_contract.py 567 行(4 文件均 0 AST Any、0 # type: ignore、0 noqa);ruff check 4/4 PASS;mypy --strict --follow-imports=silent 4/4 PASS;仓库 [tool.mypy] 17/17 PASS;调用方与测试文件(steward_turn.py 与 3 个 Steward 报告测试文件)mypy 相对主干均为 +0 报错增量且 report_failure_proof.py 从 6 降至 0;npm run typecheck:control-plane 与 content_digest_single_owner.test.ts (17/17) PASS;check_rfc_bilingual.py PASS;loopx check 4/4 (errors=0, public boundary clean) PASS;pytest -n 4 -rs 覆盖合同测试、Steward 报告/恢复、tests/canary/ 与 tests/architecture/ 共 2,378 passed, 6 skipped(test_git_path_display.py 标准 macOS APFS 跳过,0 失败)PASS;本地 canary premerge(direct=6/6, catalog_run=5/5, manual_hold_count=0, exact-scope quality receipt valid)PASS。

我的整体评价 / Verdict

长程稳定性与用户体验评估:长程维度 preserved(并发否定提交与跨重启 outage 兜底均不会丢失或错替报告窗口);交互体验维度 preserved(无外部 CLI/UI 变更,既有报告恢复路径保持一致)。视觉审查(visual_review)因无界面渲染改动记为 not_applicable(已核对 loopx/capabilities/native_chat/report_failure_proof.py 纯后端失败证明模块,未验证范围为 none,无需截图)。

语义兼容性与代码体量:本轮行为与主干 50aa5b4fd1 等价(仅在未否定 outage 回退路径将 attempt 文件读取由 2 次降为 1 次),零 Any 无环三模块拆分合理、未新增任何注册表词汇或协议常量,所有既有导入与兼容语义按 retain 保留。精确头 1d5dba63d99360c7ce22fa4c0a00ab51580628c5 已通过全部本地门禁与并发反例实测,残余风险仅限于:所有测试与反例在隔离临时目录运行且实时 Codex/Antigravity 探针使用测试桩替代(未连外部进程,亦未咨询远端 CI)。

English verdict: APPROVE at 1d5dba6. The ordered read in _binding_attempt_state fixes the concurrent durable contradiction race while preserving single-pass outage verification, full export parity, zero AST Any, and all 2,378 local test passes.

@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

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

动机 / Motivation

本轮重构旨在消除 report_failure_proof 模块超出大小与 Any 密度约束(728 行、82 处 Any、6 处 mypy 错误)的问题,并修复上一提交在并发否定写入时的窗口替换竞态。受影响的调用方与运维主体为:通过原会话等待定期报告恢复的用户,以及在 cadence 调度下复核历史故障证明的 Steward 守护进程。

在 history-outage 复核场景中,旧主干 50aa5b4fd1 会两次读取 attempt 记录和父账本,上一修订 45e99b2a90 先读父账本再读 attempt 记录,在 generation.lock 阻挡 attempt 清理时会漏掉刚提交的否定账本并替换原窗口;当前提交 1d5dba63d9 改为先读 attempt 记录再核验父否定账本,保留单次 attempt 读取并在并发否定后继续守住原窗口。若不做任何改动,原模块将持续保留 82 处 Any 与基线类型报错;若仅按上一提交方式合入,则会放行已否定窗口的替换。可观测改进为:verify_report_window_failure 在单次 attempt 文件读取下完成非否定旧证明复用,并在并发 durable contradiction 落盘时返回 False 且保持原 cadence 窗口不变。本 PR 边界明确收敛于:不更改 periodic_reports 调度策略、Codex/Antigravity 失败判定阈值或外部 CLI 参数,也不修改无关调用方或文档。

改动思路 / Approach

整体链路保持 steward_turn → admit_cadence_window → verify_report_window_failure → _binding_attempt_state 不变。方案复用既有的 native-terminal-failure.json 尝试记录与父目录 contradicted-report-failures.json 持久化否定账本,未引入额外状态存储或平行决策分支。

机制评估维持保留结论:将探测逻辑、否定账本状态机与持锁写入拆分为无环三模块,在单次读取优化的同时严格维持父账本先于清理、不可信即闭锁的既有边界。当前 PR 边界明确为:仅重构报告失败证明三模块的类型边界与 _binding_attempt_state 读取顺序,不改动周期调度策略、外部 CLI 或其他宿主模块。因为 contradict_report_failure 总是先提交且读回校验父否定账本、再获取 generation.lock 清理 attempt 文件,所以 _binding_attempt_state 只要先读 attempt 文件、再读父否定账本,无论并发否定落在锁前、读取前还是两次读取之间,都能保证不会错过已提交的否定状态。

具体改动 / Changes

精确审查提交 1d5dba63d99360c7ce22fa4c0a00ab51580628c5,基于主干 50aa5b4fd1c88b7225fc30e58423120e3ad5d426(4 个文件 +1,445 / -504;相对上一审查头 45e99b2a90 的增量修复已解决线程 PRRT_kwDOStEbEs68K09p)。按 docs/product/periodic-reports.md#original-private-report-settings-and-execution(修订 50aa5b4fd1c88b7225fc30e58423120e3ad5d426)逐项核对:

  • durable-contradiction-before-attempt-cleanup(implemented):父否定账本提交先于 attempt 清理,并发写入期间 _binding_attempt_state 先读 attempt 再复核账本,持续守住原窗口。
  • single-pass-outage-fallback(implemented):仅在 live 历史不可用且未否定/账本可信时复用旧证明;账本损坏或符号链接仍闭锁返回 False。
  • antigravity-codex-proof-parity(implemented):Codex 与 Antigravity 探测判定、所有公开/私有导出符号及 monkeypatch 兼容点保持等价。

关键代码讲解

  • _binding_attempt_state(report_failure_ledger.py#L202-L213):先调用 _read_report_failure_record 读取 attempt 记录一次并判定 _is_contradicted_proof,未否定时再检查 _durable_contradiction_status != "absent",既保持单次 attempt IO 又彻底消除 45e99b2a90 的并发漏读竞态。
  • contradict_report_failure(report_failure_proof.py#L177-L270):独占锁下提交且读回校验 contradicted-report-failures.json 后,再进入 _invalidate_attempt_proof 清理或覆写 attempt 文件,提交失败时先尽力清理正证明并向上报错。
  • verify_report_window_failure(report_failure_proof.py#L335-L377):入口先验账本非 untrusted,优先查实时历史,仅当 probe 返回 None 时走 _binding_attempt_state 单遍兜底。
  • valid_report_failure_proof(report_failure_probe.py#L64-L86):采用零 Any 的 ProofMapping 与 Protocol 契约校验 agy_turn_* 与 Codex 用户态故障证据,字段判定与基线一致。

对主干的风险 / Risks

未发现阻塞性回归风险。独立三臂交错反事实验证(真实文件系统锁、账本提交与 admit_cadence_window)实测结果:

基线/候选版本 并发否定交错结果 是否守住原窗口 attempt 读取次数
50aa5b4fd1 (main) mutated=False same_win=True 2
45e99b2a90 (上一修订) mutated=True(窗口被替换) same_win=False 1
1d5dba63d9 (当前 HEAD) mutated=False same_win=True 1

活跃生产调用方仅 steward_turn.py,未增设特权控制或 opt-in 开关,所有旧导出及 atomic_write_json 测试桩保持可用。本地完整验证结果:report_failure_probe.py 369 行、report_failure_ledger.py 239 行、report_failure_proof.py 494 行、test_report_failure_proof_contract.py 567 行(4 文件均 0 AST Any、0 # type: ignore、0 noqa);ruff check 4/4 PASS;mypy --strict --follow-imports=silent 4/4 PASS;仓库 [tool.mypy] 17/17 PASS;调用方与测试文件(steward_turn.py 与 3 个 Steward 报告测试文件)mypy 相对主干均为 +0 报错增量且 report_failure_proof.py 从 6 降至 0;npm run typecheck:control-plane 与 content_digest_single_owner.test.ts (17/17) PASS;check_rfc_bilingual.py PASS;loopx check 4/4 (errors=0, public boundary clean) PASS;pytest -n 4 -rs 覆盖合同测试、Steward 报告/恢复、tests/canary/ 与 tests/architecture/ 共 2,378 passed, 6 skipped(test_git_path_display.py 标准 macOS APFS 跳过,0 失败)PASS;本地 canary premerge(direct=6/6, catalog_run=5/5, manual_hold_count=0, exact-scope quality receipt valid)PASS。

我的整体评价 / Verdict

长程稳定性与用户体验评估:长程维度 preserved(并发否定提交与跨重启 outage 兜底均不会丢失或错替报告窗口);交互体验维度 preserved(无外部 CLI/UI 变更,既有报告恢复路径保持一致)。视觉审查(visual_review)因无界面渲染改动记为 not_applicable(已核对 loopx/capabilities/native_chat/report_failure_proof.py 纯后端失败证明模块,未验证范围为 none,无需截图)。

语义兼容性与代码体量:本轮行为与主干 50aa5b4fd1 等价(仅在未否定 outage 回退路径将 attempt 文件读取由 2 次降为 1 次),零 Any 无环三模块拆分合理、未新增任何注册表词汇或协议常量,所有既有导入与兼容语义按 retain 保留。精确头 1d5dba63d99360c7ce22fa4c0a00ab51580628c5 已通过全部本地门禁与并发反例实测,残余风险仅限于:所有测试与反例在隔离临时目录运行且实时 Codex/Antigravity 探针使用测试桩替代(未连外部进程,亦未咨询远端 CI)。

English verdict: APPROVE at 1d5dba6. The ordered read in _binding_attempt_state fixes the concurrent durable contradiction race while preserving single-pass outage verification, full export parity, zero AST Any, and all 2,378 local test passes.

@huangruiteng huangruiteng 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-5 · OpenAI · self_reported

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

动机 / Motivation

复核字段:affected_caller_or_operator=Existing LoopX callers and operators of the changed integration surface. before_after_scenario=The old monolith or broad type surface is replaced by focused modules with explicit validation while public behavior stays stable. observable_outcome=Existing behavior remains reachable through the same entrypoint with stricter typing and focused regression coverage. non_goals=No unrelated product workflow, permission model or external provider protocol is changed.

本轮重构旨在消除 report_failure_proof 模块超出大小与 Any 密度约束(728 行、82 处 Any、6 处 mypy 错误)的问题,并修复上一提交在并发否定写入时的窗口替换竞态。受影响的调用方与运维主体为:通过原会话等待定期报告恢复的用户,以及在 cadence 调度下复核历史故障证明的 Steward 守护进程。

在 history-outage 复核场景中,旧主干 50aa5b4fd1 会两次读取 attempt 记录和父账本,上一修订 45e99b2a90 先读父账本再读 attempt 记录,在 generation.lock 阻挡 attempt 清理时会漏掉刚提交的否定账本并替换原窗口;当前提交 1d5dba63d9 改为先读 attempt 记录再核验父否定账本,保留单次 attempt 读取并在并发否定后继续守住原窗口。若不做任何改动,原模块将持续保留 82 处 Any 与基线类型报错;若仅按上一提交方式合入,则会放行已否定窗口的替换。可观测改进为:verify_report_window_failure 在单次 attempt 文件读取下完成非否定旧证明复用,并在并发 durable contradiction 落盘时返回 False 且保持原 cadence 窗口不变。本 PR 边界明确收敛于:不更改 periodic_reports 调度策略、Codex/Antigravity 失败判定阈值或外部 CLI 参数,也不修改无关调用方或文档。

改动思路 / Approach

复核字段:criterion=contradiction-before-window-advance architecture_reason=职责沿现有调用、provider 和持久化边界拆分,公共入口保持。 current_pr_boundary=仅 loopx/capabilities/native_chat/report_failure_ledger.py, loopx/capabilities/native_chat/report_failure_probe.py, loopx/capabilities/native_chat/report_failure_proof.py, tests/capabilities/test_report_failure_proof_contract.py。

整体链路保持 steward_turn → admit_cadence_window → verify_report_window_failure → _binding_attempt_state 不变。方案复用既有的 native-terminal-failure.json 尝试记录与父目录 contradicted-report-failures.json 持久化否定账本,未引入额外状态存储或平行决策分支。

机制评估维持保留结论:将探测逻辑、否定账本状态机与持锁写入拆分为无环三模块,在单次读取优化的同时严格维持父账本先于清理、不可信即闭锁的既有边界。当前 PR 边界明确为:仅重构报告失败证明三模块的类型边界与 _binding_attempt_state 读取顺序,不改动周期调度策略、外部 CLI 或其他宿主模块。因为 contradict_report_failure 总是先提交且读回校验父否定账本、再获取 generation.lock 清理 attempt 文件,所以 _binding_attempt_state 只要先读 attempt 文件、再读父否定账本,无论并发否定落在锁前、读取前还是两次读取之间,都能保证不会错过已提交的否定状态。

具体改动 / Changes

精确审查提交 1d5dba63d99360c7ce22fa4c0a00ab51580628c5,基于主干 50aa5b4fd1c88b7225fc30e58423120e3ad5d426(4 个文件 +1,445 / -504;相对上一审查头 45e99b2a90 的增量修复已解决线程 PRRT_kwDOStEbEs68K09p)。按 docs/product/periodic-reports.md#original-private-report-settings-and-execution(修订 50aa5b4fd1c88b7225fc30e58423120e3ad5d426)逐项核对:

  • durable-contradiction-before-attempt-cleanup(implemented):父否定账本提交先于 attempt 清理,并发写入期间 _binding_attempt_state 先读 attempt 再复核账本,持续守住原窗口。
  • single-pass-outage-fallback(implemented):仅在 live 历史不可用且未否定/账本可信时复用旧证明;账本损坏或符号链接仍闭锁返回 False。
  • antigravity-codex-proof-parity(implemented):Codex 与 Antigravity 探测判定、所有公开/私有导出符号及 monkeypatch 兼容点保持等价。

关键代码讲解

  • _binding_attempt_state(report_failure_ledger.py#L202-L213):先调用 _read_report_failure_record 读取 attempt 记录一次并判定 _is_contradicted_proof,未否定时再检查 _durable_contradiction_status != "absent",既保持单次 attempt IO 又彻底消除 45e99b2a90 的并发漏读竞态。
  • contradict_report_failure(report_failure_proof.py#L177-L270):独占锁下提交且读回校验 contradicted-report-failures.json 后,再进入 _invalidate_attempt_proof 清理或覆写 attempt 文件,提交失败时先尽力清理正证明并向上报错。
  • verify_report_window_failure(report_failure_proof.py#L335-L377):入口先验账本非 untrusted,优先查实时历史,仅当 probe 返回 None 时走 _binding_attempt_state 单遍兜底。
  • valid_report_failure_proof(report_failure_probe.py#L64-L86):采用零 Any 的 ProofMapping 与 Protocol 契约校验 agy_turn_* 与 Codex 用户态故障证据,字段判定与基线一致。

对主干的风险 / Risks

未发现阻塞性回归风险。独立三臂交错反事实验证(真实文件系统锁、账本提交与 admit_cadence_window)实测结果:

基线/候选版本 并发否定交错结果 是否守住原窗口 attempt 读取次数
50aa5b4fd1 (main) mutated=False same_win=True 2
45e99b2a90 (上一修订) mutated=True(窗口被替换) same_win=False 1
1d5dba63d9 (当前 HEAD) mutated=False same_win=True 1

活跃生产调用方仅 steward_turn.py,未增设特权控制或 opt-in 开关,所有旧导出及 atomic_write_json 测试桩保持可用。本地完整验证结果:report_failure_probe.py 369 行、report_failure_ledger.py 239 行、report_failure_proof.py 494 行、test_report_failure_proof_contract.py 567 行(4 文件均 0 AST Any、0 # type: ignore、0 noqa);ruff check 4/4 PASS;mypy --strict --follow-imports=silent 4/4 PASS;仓库 [tool.mypy] 17/17 PASS;调用方与测试文件(steward_turn.py 与 3 个 Steward 报告测试文件)mypy 相对主干均为 +0 报错增量且 report_failure_proof.py 从 6 降至 0;npm run typecheck:control-plane 与 content_digest_single_owner.test.ts (17/17) PASS;check_rfc_bilingual.py PASS;loopx check 4/4 (errors=0, public boundary clean) PASS;pytest -n 4 -rs 覆盖合同测试、Steward 报告/恢复、tests/canary/ 与 tests/architecture/ 共 2,378 passed, 6 skipped(test_git_path_display.py 标准 macOS APFS 跳过,0 失败)PASS;本地 canary premerge(direct=6/6, catalog_run=5/5, manual_hold_count=0, exact-scope quality receipt valid)PASS。

我的整体评价 / Verdict

长程稳定性与用户体验评估:长程维度 preserved(并发否定提交与跨重启 outage 兜底均不会丢失或错替报告窗口);交互体验维度 preserved(无外部 CLI/UI 变更,既有报告恢复路径保持一致)。视觉审查(visual_review)因无界面渲染改动记为 not_applicable(已核对 loopx/capabilities/native_chat/report_failure_proof.py 纯后端失败证明模块,未验证范围为 none,无需截图)。

语义兼容性与代码体量:本轮行为与主干 50aa5b4fd1 等价(仅在未否定 outage 回退路径将 attempt 文件读取由 2 次降为 1 次),零 Any 无环三模块拆分合理、未新增任何注册表词汇或协议常量,所有既有导入与兼容语义按 retain 保留。精确头 1d5dba63d99360c7ce22fa4c0a00ab51580628c5 已通过全部本地门禁与并发反例实测,残余风险仅限于:所有测试与反例在隔离临时目录运行且实时 Codex/Antigravity 探针使用测试桩替代(未连外部进程,亦未咨询远端 CI)。

本轮独立复核:113 passed; Ruff passed; strict mypy passed;premerge passed 5/5 with 0 manual holds。

English verdict: APPROVE at 1d5dba6. The ordered read in _binding_attempt_state fixes the concurrent durable contradiction race while preserving single-pass outage verification, full export parity, zero AST Any, and all 2,378 local test passes.

@huangruiteng
huangruiteng merged commit 6aa5202 into main Nov 26, 2026
38 of 49 checks passed
@huangruiteng
huangruiteng deleted the codex/slim-report-failure-proof-zero-any-20261126 branch November 26, 2026 12:19
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.

2 participants