Repository navigation
refactor(control-plane): slim material_frontier with Zero-Any typing and O(R) receipt indexing - #9467
loopx-agent wants to merge 2 commits into
Conversation
…and O(R) receipt indexing Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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-callermypy0错误),能力未声明隔离保持不变。 - 本地验证矩阵(精确头
9aa4f0a324):ruff2/2 PASS、mypy --strict2/2 PASS、[tool.mypy]17/17 PASS、5-callermypy0errors PASS、check_rfc_bilingual&git diff --checkPASS;TStypecheck:control-plane+content_digest_single_owner(17/17) +frontier_revision/material_wave_ranking(26/26) PASS;agent-material-handoff-projection-smokePASS;Goalloopx check0 errors PASS;canary premerge18/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.
Summary
Anystrict typing acrossloopx/control_plane/agents/material_frontier.py(609 -> 544 <= 550LOC,50 -> 0ASTAny,0 # type: ignore,0 # noqa) while preserving exactorigin/main(57c4c43b52) behavior, diagnostic precedence, public exports, and caller compatibility.Anyinputs/internals with covariantPayloadView = Mapping[str, object],Payload = dict[str, object], and typed internal dataclasses (_RequirementBinding,_MergedRequirement,_ValidatedReceipt); widenedreceiptsannotation toIterable[PayloadView] | PayloadView | Noneto match_mapping_listruntime handling without changing runtime contracts._owner_field_values,_opt_text, and_collect_requirementsowner 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).O(M * R) -> O(M + R)) with Exact Error Precedence:_matching_receiptscanning (M * Riterations andparse_timestampre-parsing) with single-pass_index_matching_receipts(recording the firstValueErrorpermaterial_idsobuild_agent_material_frontierstill reportsauthority revisionbefore per-material receipt errors in requirement iteration order) plus single-passstate_countsaccumulation and tuple sort keys.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.39xspeedup) with byte-identical output.tests/control_plane/test_material_frontier_contract.py):<= 550LOC,0ASTAny,0 # type: ignore/# noqa,MappingProxyTypeimmutable views, single-passparse_timestampcall count bound (65calls for64materials /1,024receipts), and fullorigin/mainvsHEADbehavioral and compoundValueErrorprecedence 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 filesmypy --config-file pyproject.toml --no-incremental(17/17):Success: no issues found in 17 source filesmypy --no-incremental --follow-imports=silent(5files:material_frontier.py,registry_authority_read.py,management_projection.py,material_handoff.py,goal_frontier/__init__.py):Success: no issues found in 5 source filesnpm run typecheck:control-planeclean +node --test tests/control_plane_ts/content_digest_single_owner.test.ts(17/17passed)scripts/check_rfc_bilingual.py --base origin/main --head HEADpassed;TOP_LEVEL_PY=112;module_metric_baseline.jsonuntouched; cleangit 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 intest_git_path_display.py)agent-material-handoff-projection-smoke.pypassed (ok)loopx check(5checks,errors=0), Goal CQRcqr_4b2b91476d739bbdf1ca(decision="pass",status="valid"), and Goalcanary 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)