From bd96861db64063350b74577dbcb751891899baaf Mon Sep 17 00:00:00 2001 From: "lusendong.6789" Date: Mon, 9 Nov 2026 00:24:51 +0800 Subject: [PATCH] refactor(todos): reuse validated complete source basis bytes Signed-off-by: lusendong.6789 Co-authored-by: TRAE CLI --- .../rfcs/monorepo-distribution-split-v0.md | 30 +++++++++++++++++++ .../monorepo-distribution-split-v0.zh-CN.md | 25 ++++++++++++++++ loopx/control_plane/todos/summary_item.py | 5 ++-- .../test_canonical_quota_projection.py | 9 ++++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.md index 4754501bf7..1b52a51908 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.md @@ -2822,3 +2822,33 @@ I3/minor-release, M1/#8011, full R0/V10/R1, D2/D5/D6/D3, context/model/split-install and historical failure qualifications remain open. The next useful boundary remains report subscription/construction loading after the combined proposal's review; the original task stays open. + + +### 2026-11-09 — Reuse validated complete source-basis bytes + +The existing Python Todo compatibility transport now retains its validated +canonical field bytes as the complete source basis. It previously encoded each +field twice, once for the basis and once for digest validation. The basis is +only decoded as JSON; mapping insertion order is not a source difference. Full +digest mismatch fallback, scalar-fact protection, request-scope provenance and +source/revision/lease/refusal/replay guards remain. No decoder, cache, provider, +configuration, protocol or competing decision owner is added. + +On the same real isolated SQLite field observation, the immutable original +encodes two fields four times and the candidate twice; both retain complete +values and empty source differences. The original passes two mapping-order and +scalar-protection characterization cases; the candidate passes all nine canonical +source cases across File/SQLite. Final `summary_item.py` SHA-256 `a8ca890eee547929060ac326fc8b85ca9c14a8fd5ec850deb2fe3e6586628513` +matches the isolated wheel. Four complete 101-Todo source/wheel × File/SQLite +CLI lifecycles preserve sum45, original completion time, four receipts, one debit, +restart and refusal/replay, with two normal native exits per lifecycle. +Validation uses macOS arm64, CPython3.13.5 and Node22.22.3. + +This is an encoding mechanism refinement, not matched-cost or full marginal-cost +and adoption qualification. Frozen cost, attribution and normal-bytecode +campaigns remain unchanged. PostgreSQL host factory absence is already recorded; +its store/service checks do not qualify a source/wheel host journey. Retain every +original acceptance and I3/minor-release, M1/#8011, full R0/V10/R1, D2/D5/D6/D3, +context/model/split-install, installed-host, full-cost/adoption and historical +failure gap. Exact-head review, CI/readiness and maintainer merge authority remain +separate gates. diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md index 086a8b0f2f..1cc885218e 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md @@ -2191,3 +2191,28 @@ Whole-path 成本收益、installed adoption、PostgreSQL host/wheel,以及 I3/minor-release、M1/#8011、完整 R0/V10/R1、D2/D5/D6/D3、 context/model/split-install 与历史失败资格继续开放。组合提案评审之后,下一段 有用边界仍是报告订阅/构造加载;原 Task 保持开放。 + + +### 2026-11-09 — 复用已验证的完整 source basis bytes + +现有 Python Todo compatibility transport 将已经通过 canonical field digest +验证的完整字节复用为 source basis;此前每个字段分别为 basis 和 digest 编码一次。 +basis 只作为 JSON 解码,mapping insertion order 不属于 source difference。 +完整 digest mismatch fallback、标量 fact 保护、request-scope provenance 与 +source/revision/lease/refusal/replay guards 均保留;未新增 decoder、cache、provider、 +配置、protocol 或竞争的决策 owner。 + +在同一次真实隔离 SQLite field observation 上,不可变原版对两个字段编码四次, +候选版编码两次;二者保留完整值与空 source differences。原版通过两个 mapping-order +与标量保护 characterization 用例,候选版通过 File/SQLite 全部九个 canonical source +用例。最终 `summary_item.py` SHA-256 `a8ca890eee547929060ac326fc8b85ca9c14a8fd5ec850deb2fe3e6586628513` +与隔离 wheel 一致。source/wheel × File/SQLite 四条完整 101-Todo CLI lifecycle +保留 sum45、原完成时间、四份 receipt、一次 debit、restart 和 refusal/replay, +每条均观测两次正常 native exit。验证环境为 macOS arm64、CPython3.13.5、Node22.22.3。 + +这是编码机制细化,不代表 matched-cost、完整边际成本或 adoption 资格。冻结的 cost、 +attribution 与 normal-bytecode campaign 保持不变。PostgreSQL host factory 缺失 +已有记录,其 store/service 验证不能成为 source/wheel host journey 资格。继续保留 +原完整验收以及 I3/minor-release、M1/#8011、完整 R0/V10/R1、D2/D5/D6/D3、 +context/model/split-install、installed-host、full-cost/adoption 与全部历史失败缺口。 +exact-head review、CI/readiness 和 maintainer merge authority 仍是独立门。 diff --git a/loopx/control_plane/todos/summary_item.py b/loopx/control_plane/todos/summary_item.py index 758b68c727..c2c9c0020d 100644 --- a/loopx/control_plane/todos/summary_item.py +++ b/loopx/control_plane/todos/summary_item.py @@ -53,15 +53,16 @@ def bind_canonical_todo_sources(result: dict[str, Any], read: dict[str, Any]) -> digest = metadata.get("field_digests", {}).get(field) if not isinstance(value, dict) or not isinstance(digest, str): continue - basis = json.dumps(value, ensure_ascii=False, separators=(",", ":")).encode("utf-8", "backslashreplace") observed = json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8", "backslashreplace") if sha256(observed).hexdigest() != digest: # A modified response or a numeric JSON spelling mismatch cannot # mint a native reference. Keep the complete supplied source codec. continue + # The basis is decoded as JSON; mapping insertion order is not a + # source difference. Retain the complete bytes already validated here. fields[field] = _CanonicalTodoSummary(value, read={key: value for key, value in metadata.get("replay_read", read).items() if key != "return_projection"}, expected=metadata["source"], field=field, digest=digest, - basis=basis, request_identity=identity, + basis=observed, request_identity=identity, evaluations=(result.get("field_evaluations") or {}).get(field), source_row_fields=tuple(metadata.get("source_row_fields", []))) diff --git a/tests/control_plane/test_canonical_quota_projection.py b/tests/control_plane/test_canonical_quota_projection.py index ba363973b0..d45bc4e0f1 100644 --- a/tests/control_plane/test_canonical_quota_projection.py +++ b/tests/control_plane/test_canonical_quota_projection.py @@ -25,6 +25,15 @@ def test_provider_projection_uses_complete_source_differences_and_scope_exit(tmp reference = canonical_todo_source_reference(source) assert reference is not None, "the real native read must supply a validated reference" assert reference["changes"] == [] + # Mapping insertion order is not a caller change. Reordering a complete + # native summary must retain its source without hiding scalar changes. + reordered = deepcopy(source) + entries = list(reordered.items()) + reordered.clear() + reordered.update(reversed(entries)) + assert canonical_todo_source_reference(reordered) == reference + reordered["items"][0]["done"] = 0 + assert canonical_todo_source_reference(reordered) is None copied = deepcopy(source) proof = {"agent_id": fixture.AGENT_ID, "state": "waiting", "evidence": {"revision": 9007199254740993, "ratio": -0.0}} copied["vision_wait_states"] = [proof]