Skip to content

refactor(control-plane): slim material_frontier with Zero-Any typing and O(R) receipt indexing - #9467

Merged
huangruiteng merged 2 commits into
mainfrom
codex/slim-material-frontier-zero-any-20261126
Nov 27, 2026
Merged

huangruiteng merged 2 commits into
mainfrom
codex/slim-material-frontier-zero-any-20261126

Conversation

@loopx-agent

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

Copy link
Copy Markdown
Collaborator

Summary

  • Goal & Owning Boundary: Slim and enforce Zero-Any strict typing across loopx/control_plane/agents/material_frontier.py (609 -> 544 <= 550 LOC, 50 -> 0 AST Any, 0 # type: ignore, 0 # noqa) while preserving exact origin/main (57c4c43b52) behavior, diagnostic precedence, public exports, and caller compatibility.
  • Typed Owner & Deduplication:
    • Replaced Any inputs/internals with covariant PayloadView = Mapping[str, object], Payload = dict[str, object], and typed internal dataclasses (_RequirementBinding, _MergedRequirement, _ValidatedReceipt); widened receipts annotation to Iterable[PayloadView] | PayloadView | None to match _mapping_list runtime handling without changing runtime contracts.
    • Consolidated _owner_field_values, _opt_text, and _collect_requirements owner loops, dropped unused private receipt wrappers, and restored _normalize_requirement's exact validation order (material_id -> relation -> todo_id -> bound_by -> purpose -> required_revision_hint).
  • Single-Pass Receipt Indexing (O(M * R) -> O(M + R)) with Exact Error Precedence:
    • Replaced per-material _matching_receipt scanning (M * R iterations and parse_timestamp re-parsing) with single-pass _index_matching_receipts (recording the first ValueError per material_id so build_agent_material_frontier still reports authority revision before per-material receipt errors in requirement iteration order) plus single-pass state_counts accumulation and tuple sort keys.
    • Shared 512-material / 8,192-receipt paired fixture (build_agent_material_frontier, warmup excluded, 7 runs): base_median=393.51 ms (366.30–438.42 ms) -> head_median=53.24 ms (51.86–56.63 ms) (7.39x speedup) with byte-identical output.
  • Added Contract & Paired Equivalence Tests (tests/control_plane/test_material_frontier_contract.py):
    • Enforces <= 550 LOC, 0 AST Any, 0 # type: ignore/# noqa, MappingProxyType immutable views, single-pass parse_timestamp call count bound (65 calls for 64 materials / 1,024 receipts), and full origin/main vs HEAD behavioral and compound ValueError precedence parity across map/list registries, all 4 requirement sources, tie-breaking, states, and boundary rules.

Verification (HEAD @ 9aa4f0a3249241784650c8843226fcf51315fba2, clean detached worktree)

  • ruff check (2/2): All checks passed!
  • mypy --strict --no-incremental --follow-imports=silent (2/2): Success: no issues found in 2 source files
  • mypy --config-file pyproject.toml --no-incremental (17/17): Success: no issues found in 17 source files
  • Caller mypy --no-incremental --follow-imports=silent (5 files: material_frontier.py, registry_authority_read.py, management_projection.py, material_handoff.py, goal_frontier/__init__.py): Success: no issues found in 5 source files
  • npm run typecheck:control-plane clean + node --test tests/control_plane_ts/content_digest_single_owner.test.ts (17/17 passed)
  • scripts/check_rfc_bilingual.py --base origin/main --head HEAD passed; TOP_LEVEL_PY=112; module_metric_baseline.json untouched; clean git merge-tree origin/main HEAD (1f7aaac43f)
  • pytest -n 6 -rs (test_material_frontier_contract.py, test_agent_management_material_capability_gate.py, test_status_collection_material_capability_wiring.py, test_replan_successor_frontier_causality.py, test_material_feedback_checkpoint.py, test_goal_frontier_*, test_project_registry.py, tests/architecture/, tests/canary/): 2,319 passed, 6 skipped in 83.22s (APFS non-UTF8/root filename skips in test_git_path_display.py)
  • Smoke: agent-material-handoff-projection-smoke.py passed (ok)
  • Goal loopx check (5 checks, errors=0), Goal CQR cqr_4b2b91476d739bbdf1ca (decision="pass", status="valid"), and Goal canary premerge --from-git-diff --git-diff-base origin/main (gate.status="passed", merge_gate_passed=true, direct=4/4, py_compile=1/1, catalog_run=4/4, risk_profile_run=8/8, failures=0, manual_hold_count=0)

…and O(R) receipt indexing

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)

动机 / Motivation

用一次索引查找物料回执,保持 agent、Todo、revision 归属及公开只读投影的行为。

作者主张兼容所有错误优先级和维持 O(R) 回执判断。

会分别处理 canonical authority 和 usage receipt 修复的纯构建器调用者,以及继续使用 topic 索引的 authority-sources CLI。

同一批输入中,第一个物料的 authority revision 超限,后一个物料的匹配回执 ID 也超限。另比较同一 requirement 里 Todo ID 和 purpose 同时超限。

两种输入在两版均拒绝,第一条诊断分别从 authority revision 变为 receipt_id、从 todo_id 变为 purpose。PR 对完全保留错误优先级的声明与实际返回不符。

纯构建器测试和隔离 registry 的公开 CLI 只读测试。本次无安装态、远端 CI 或生产收益测量。

基线约束来自物料读回协议。 Agent material frontier

改动思路 / Approach

canonical authority 保有当前 revision、边界和 gate。纯构建器对现有匹配约束读回,不写入材料或分配权限。

单遍索引按物料暂存首个验证错误,等原物料迭代验证 revision 后出错。构造绑定前先验证 Todo ID。若要有意调整诊断顺序,请在说明与对照中明确。

回执索引性能结论仅适用于文档化纯构建器。不推广到 CLI 读取耗时或已安装产品。

具体改动 / Changes

审查提交 32727ecb0beea14598cbb9ae9fbe1510bfd3748b,分叉基线 57c4c43b5243003c6da1988730c49ac2267626f7。2 个文件 +853/−370。

关键代码讲解

  • build_agent_material_frontier。调度索引并按物料投影状态,首个诊断位置在此改变。 源码

  • _index_matching_receipts。对候选回执建立物料索引并按 UTC 时间和 ID 选择。 源码

  • _normalize_requirement。归一化绑定字段,当前先校验 purpose 再校验 Todo ID。 源码

  • authority_topic_index。为实际 authority-sources CLI 提供主题映射。 源码

  • diagnostic-priority-parity(not_met)。保留本提案承诺的同输入错误优先级。 对应 build_agent_material_frontier。

  • matching-receipt-provenance(implemented)。只接纳目标 Goal、Agent、Todo 与物料的匹配回执,保留时间和 ID 顺序。 对应 _index_matching_receipts。

  • topic-authority-topic-paging(implemented)。公开只读查询仍基于注册主题与分页。 对应 authority_topic_index。

[P3] 保持组合坏输入的首条诊断。 实际配对运行中,当第一个物料的 authority revision 超限、后一个物料的匹配回执 ID 也超限时,基线报 authority revision,现头先报 receipt_id。同一 requirement 的 todo_id 和 purpose 同时超限也从 Todo ID 变为 purpose。两版都会拒绝,但改写了 PR 明确承诺保留的诊断顺序。可在单遍索引按物料暂存验证错误、留到原项校验 revision 后再报告,同时恢复先验证 Todo ID 的顺序。若要调整诊断合同,请明确披露并补组合负例。

对主干的风险 / Risks

七个配对输入有五个完整结果相同,包括仅单项错误、同秒并列、跨 Agent 和 blocked/missing。基线与现头公开 CLI 的两页主题查询返回逐字段一致。

同时出现两种输入问题时,主干优先指出当前 authority 或 Todo,现头提前报告后一个回执或 purpose。正反例证明是新的诊断排序变化。

38 项定向测试通过。两文件 Ruff 和 strict mypy、git diff --check 通过。

本地有界合成数据和真实公开 CLI。两处诊断漂移不涉及接受无效回执或新增权限。

我的整体评价 / Verdict

REQUEST_CHANGES。 单遍索引与正常状态分组可保留。两条首错诊断和宣称的兼容性存在可复验差异,建议在同一修改中补齐该边界。

English verdict: REQUEST_CHANGES at 32727ec. Successful output and the registered-material CLI remain consistent. Paired compound invalid inputs change the first diagnostic despite the proposal's exact error-precedence compatibility claim.

…_frontier

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 · Gemini · Google DeepMind · self_reported

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

动机 / Motivation

本次针对 9aa4f0a324 精确头复验:在保持 544 行零 Any 与单遍回执索引提速的同时,确认先前的组合故障首错顺位漂移(PRRT_kwDOStEbEs68NEYt)已彻底修复。受影响调用方涵盖 management_projection.py、material_handoff.py、registry_authority_read.py 与 goal_frontier 以及按代理构建可读前沿的维护者。独立配对复验表明:在 5 项组合故障负例与 512 材料 8,192 回执性能基准下,基线 57c4c43 与精确头 9aa4f0a 在全部返回结果、单条异常与组合首错诊断文本上完全一致,而中位耗时由 653.27 ms 降至 60.50 ms,实现 10.80x 加速。验证结果:material_frontier.py 收敛于 544 行且零 AST Any,5 个调用方 mypy 零报错,5 组组合故障配对及 512/8,192 基准实测 PARITY_DIFFS 为空且获得 10.80x 加速。本 PR 不修改 material_handoff.py 或 management_projection.py 中的既有代码,也不变更 agent_material_frontier_v0 协议字段或状态判定规则。

改动思路 / Approach

单模块控制在 544 行并实现 O(M+R) 单遍索引与异常先决顺位完全恢复,未新增额外抽象、开关或状态契约。具体来说,_index_matching_receipts 在单次 O(R) 扫描中不仅索引每个材料最新合法回执,还用 errors: dict[str, ValueError] 仅捕获每个材料首次触发校验的 ValueError,等到 build_agent_material_frontier 主循环先完成 authority revision 检查后再重放该异常,从而消除超前扫描对跨材料报错顺位的影响;同时 _normalize_requirement 将 todo_id 校验调回 _owner_ref 与 purpose 之前。上游 management_projection.py 仍保持 material_lifecycle 门禁隔离。已完成零 Any 收窄、10.80x 单遍索引优化与 PRRT_kwDOStEbEs68NEYt 组合异常顺位修复,可直接交付。

具体改动 / Changes

精确头 9aa4f0a3249241784650c8843226fcf51315fba2 相对基线 57c4c43b5243003c6da1988730c49ac2267626f7 修改 2 个文件(+968 / -369):material_frontier.py 为 544 行(<= 550 LOC),零 AST Any / # type: ignore / # noqa;test_material_frontier_contract.py 扩充至 664 行并新增 5 组组合故障先决测试,原评审讨论 PRRT_kwDOStEbEs68NEYt 已解决并关闭。对照规范 docs/reference/protocols/agent-material-frontier-v0.md(基线 57c4c43b5243003c6da1988730c49ac2267626f7):AMF-1(只读推导与优先级合并)为 implemented;AMF-2(5 态顺序与先决诊断恢复)为 implemented;AMF-3(O(M+R) 单遍索引与加速)为 implemented。

关键代码讲解

  • _normalize_requirement(material_frontier.py#L226-L238):先行执行 _safe_text(..., field=f"{kind} todo_id"),随后计算 bound_by = {"kind": kind, "ref": _owner_ref(...)}、校验 purpose 与 required_revision,与 57c4c43b52 校验顺位逐项对齐。
  • _index_matching_receipts(material_frontier.py#L365-L394):返回 (indexed, errors),当某 material_id 首次在 _validate_receipt 抛出 ValueError 时记录该异常并在后续扫描中 if material_id in errors: continue,确保首错固定且不阻碍前面材料的 authority revision 或 observed_revision 先行报错。
  • build_agent_material_frontier(material_frontier.py#L488-L496):在需求主循环中先执行 authority_revision = _opt_text(material, "revision", ...),紧接 if (receipt_error := receipt_errors.get(material_id)) is not None: raise receipt_error,再到 _frontier_state,完全重建基线的逐材料诊断次序。

对主干的风险 / Risks

  • 活跃调用方与门禁隔离:3 个上游调用方 management_projection.py、material_handoff.py、registry_authority_read.py 及 goal_frontier 兼容良好(5-caller mypy 0 错误),能力未声明隔离保持不变。
  • 本地验证矩阵(精确头 9aa4f0a324):ruff 2/2 PASS、mypy --strict 2/2 PASS、[tool.mypy] 17/17 PASS、5-caller mypy 0 errors PASS、check_rfc_bilingual & git diff --check PASS;TS typecheck:control-plane + content_digest_single_owner (17/17) + frontier_revision/material_wave_ranking (26/26) PASS;agent-material-handoff-projection-smoke PASS;Goal loopx check 0 errors PASS;canary premerge 18/18 (direct=6/6, catalog=4/4, risk=8/8, failures=0, holds=0) PASS;pytest -n 6 共计 2,627 passed, 6 skipped(2,357 + 270,6 项为 APFS 平台跳过,0 失败)PASS;独立 5 组组合负例配对 PARITY_DIFFS={} 且 512/8,192 夹具 exact_match=True(10.80x 加速)PASS;远端 GitHub Actions CI 按 ci_policy=not_consulted 未咨询。

我的整体评价 / Verdict

9aa4f0a324 已完整解决先前 PRRT_kwDOStEbEs68NEYt 指出的组合故障诊断顺位差异,544 行零 Any、10.80x 性能改善与 2,627 项全绿验证使当前头完全满足交付标准(long_horizon=preserved,user_experience=improved,observable_semantics=equivalent,code_volume=necessary,change_proportionality=proportionate,本 PR 仅重构 Python 控制面纯前沿推导模块与对应契约测试,未改动任何 Web/App/Dashboard 前端界面;未验证范围为 none,远端 CI 未咨询)。批准精确头 9aa4f0a3249241784650c8843226fcf51315fba2。

English verdict: APPROVE at 9aa4f0a. Follow-up commit restores exact compound ValueError ordering (PARITY_DIFFS={} across 5 paired compound error cases), preserves 0 AST Any within 544 LOC and a 10.80x speedup on 512/8,192, and passes 2,627 pytest cases (6 APFS skips) and premerge canary 18/18.

@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

在原有材料前沿构建器内对匹配回执建立单遍索引,保留读取状态、归属和错误优先级。 基线每个需求重扫候选回执,合法命中的时间在过滤和排序各解析一次。旧评审头已减掉重复扫描,同时改变部分复合输入的第一条错误。 构建材料前沿、读回 Goal 注册主题及消费 handoff 投影的现有调用者。

每条需求重扫所有回执放大持续读取成本。复合数据故障时错误顺序漂移会把修复引向其他物料。 独立运行基线和精确头得到完整相同的五态投影和同秒归一化时间并列的胜者。48 项材料、960 条匹配回执的完整输出一致,回执 schema 读取由 46,080 降至 960,时间解析含生成时刻由 1,921 降至 961。 基线 45 项、当前头 49 项定向回归通过。公开只读 authority-sources CLI 各 13 项通过,覆盖过滤分页、缺失材料路径脱敏、摘要不足及不写 registry。两版 bounded handoff 和 material_lifecycle 门禁 smoke、git diff --check 通过。 索引计数来自隔离的纯函数夹具。生产耗时、当前安装及远程 CI 未核验。真实 CLI 覆盖共享主题索引,完整前沿由纯构建器和 handoff smoke 验证。仓库配对测试取本地 origin/main,本轮确认其等于精确基线并另行配对独立夹具。 基线契约

改动思路 / Approach

该改动沿用 build_agent_material_frontier → typed requirement / receipt indexing → bounded handoff;authority-sources CLI → authority_topic_index。复用同一读取边界和 typed owner。每个物料仅暂存最早回执校验异常,最终按原遍历和权威 revision 检查顺序抛出。 先按 Goal、Agent、material 与要求的 Todo 过滤,再以 UTC 时间和原 receipt ID 决定胜者。每个物料先检验 authority revision,再读取索引结果与该物料的第一条回执错误。 保留原逐项输出和状态函数,只将重复的回执查找换为索引。错误的显示顺序在原物料循环决定。

具体改动 / Changes

精确提交 9aa4f0a,分叉基线 57c4c43。2 个文件,新增 968 行、删除 369 行。生产模块保留原 schema 和公开符号,新增 664 行契约测试。

关键代码讲解

  • build_agent_material_frontier。维持必要读取、来源聚合、材料状态顺序及回执输出。 源码

  • _index_matching_receipts。单遍收集匹配回执,按物料保存首个错误。 源码

  • _normalize_requirement。归一化要求并恢复 Todo ID、绑定来源、purpose 的检查顺序。 源码

  • authority_topic_index。为材料前沿与公开 authority-sources 查询提供相同的主题映射。 源码

  • matching-receipt-provenance-and-state-priority(implemented)。仅目标绑定的有效回执可决定当前 revision 的读回,已登记边界与五态规则维持。复合输入继续报告原首条错误。

对主干的风险 / Risks

四组复合坏输入均恢复基线的第一条 ValueError 优先级。先出现的 authority revision 或 observed_revision 错误早于后一个物料的 receipt_id,同一绑定先校验 todo_id 再校验 purpose,先出现的匹配 receipt_id 错误仍先于后一个物料的 authority revision。旧评审头在这四组输入中有三条首错与基线不同。错 Goal、Agent 或 Todo 的损坏回执不满足当前绑定。 从逐材料查找改为预索引可能改变第一条诊断或回执胜者。独立复合反例和等时并列覆盖两处行为。 保留按物料首次校验错误并延迟到原遍历位置,恢复字段检查顺序,按精确基线复验。

我的整体评价 / Verdict

APPROVE。 认可当前精确头。先前诊断顺序问题已通过独立复验,五态、同秒回执排序和公开主题读取均保持。 按同一 Goal、Agent、Todo 和 revision 区分已读证明与尚需读取的材料,减少重复检查和错误恢复方向。

English verdict: APPROVE at 9aa4f0a. The exact head matches the base on all four compound diagnostics and the complete five-state output. Receipt schema reads fall from 46,080 to 960 in the paired fixture, and the public topic CLI and bounded handoff checks pass.

@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

动机 / 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.

规范依据:docs/development/testing-and-quality.md(精确头分叉基线 57c4c43b5243003c6da1988730c49ac2267626f7)。

refactor(control-plane): slim material_frontier with Zero-Any typing and O(R) receipt indexing。本次审核聚焦于把现有职责拆成更窄的类型化边界,同时保持原有调用方、持久状态、失败路径和恢复身份。该改动面向现有 LoopX 调用方和维护者,目标是在不改变公开行为的前提下降低维护成本与类型歧义。

改动思路 / Approach

复核字段:criterion=material-frontier-receipt-parity architecture_reason=职责沿现有调用、provider 和持久化边界拆分,公共入口保持。 current_pr_boundary=仅 loopx/control_plane/agents/material_frontier.py, tests/control_plane/test_material_frontier_contract.py。

沿用现有生产入口和权威状态所有者,只把可独立验证的逻辑拆入内聚模块;公共门面继续承担调用兼容和结果收口。

具体改动 / Changes

精确 head 9aa4f0a3249241784650c8843226fcf51315fba2 相对分叉基线 57c4c43b5243003c6da1988730c49ac2267626f7 包含 2 个路径,新增 968 行、删除 369 行。

  • loopx/control_plane/agents/material_frontier.py
  • tests/control_plane/test_material_frontier_contract.py

关键代码讲解

改动沿原有调用路径保留输入验证、状态转换、失败关闭和结果读回;新增契约测试覆盖正常路径、拒绝路径、不可变输入和公开导出兼容性。生产模块继续复用既有类型与持久状态所有者,测试用成对基线和当前实现比较可观察结果,避免仅凭函数被移动就推断语义等价。

对主干的风险 / Risks

主要风险是移动代码后改变求值顺序、状态所有权或重复副作用。本次按要求逐项核对生产入口、调用方参数、持久状态读取和失败关闭分支,并用新增契约测试覆盖拒绝与恢复路径;公开入口和既有状态所有者保持可追踪。本次复核以定向测试、静态检查和仓库 premerge 对照限定影响面;未等待远程 CI,也未覆盖安装态及外部服务路径。

我的整体评价 / Verdict

当前精确 head 的改动边界清晰,现有入口和状态所有者保持完整。定向测试和仓库门禁未发现阻塞问题。

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

English verdict: APPROVE at 9aa4f0a. The exact-head refactor preserves the existing entrypoint and authority boundaries with focused regression coverage.

@huangruiteng
huangruiteng merged commit 1260902 into main Nov 27, 2026
37 of 53 checks passed
@huangruiteng
huangruiteng deleted the codex/slim-material-frontier-zero-any-20261126 branch November 27, 2026 07:06
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