Repository navigation
fix(extensions): stage history export documents byte-exact - #6256
huangruiteng merged 1 commit into
Conversation
The history-conclusion exporter staged documents with Path.write_text, whose text-layer newline translation (LF to CRLF on Windows) contradicts the byte-exact staged readback and the manifest sha256 it validates, so every export on a Windows host aborted with "staged history document failed readback" and no corpus could be published. Write the already-encoded document bytes directly, and let the exporter contract smoke cover the host newline translation by simulating the Windows text layer, injecting the staged write failure below the write API, and comparing the receipt path by parts. Fixes loopx-project#6253 Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
…#6256 Signed-off-by: JasonBuildAI <jasonbuildai@gmail.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=xhigh
APPROVE;精确 head c7a1f1ec474d8358ec98299c45aee9e46202ad94。
动机
在 Windows 上把运行结论导出为本地文档的用户。
用户执行历史结论导出时,旧版本把原有换行通过文本写入变成 CRLF,暂存校验随即失败,无法获得文档;此修改改用字节写入,使文档与清单记录的摘要一致,能继续替换下一代文档。
本机真实历史读取和 CLI、独立安装 wheel 均能发布与再次替换语料;模拟 Windows 文本换行时,旧版本失败,新 head 的文档保持原始 UTF-8 字节。
交付边界为现有导出命令的本地文档发布,不包含 OpenViking ingest、记忆写入、在线模型或权限变更。
改动思路
把已经编码且由清单校验的 bytes 直接写入,是现有导出 owner 内最小且完整的修复;放宽校验会隐藏数据漂移,强制全局换行策略会扩大影响。 比较不修复、放松校验和扩大通用框架后,现有 owner 内的 IO 修复最容易验证和回退;输入、作用域和失败保护应一起验收。
本批只改变暂存文档 IO,并同步原有故障注入和路径断言,保留清单、回滚与重复发布的既有语义。 Python 在这里是稳定的文件系统/provider IO 边界,未新建通用控制面决策源,无需为语言迁移扩大本批。
具体改动
独立规格 https://github.com/loopx-project/loopx/issues/6253,spec_revision:c51ec1a60671edb8ef536ef0651836b9d7642878;使用变更前的合同。Issue #6253 创建/更新于 2026-10-11T17:11:13Z;同时对照该 commit 的既有 byte-exact exporter contract。
byte-exact-documents:implemented;Published document bytes match the manifest SHA-256 and staged expected bytes.successful-repeat-export:implemented;The shipped export command publishes a generation and can replace/revalidate it.staging-failure-preservation:implemented;Failure while staging must preserve the prior managed generation.
关键代码讲解
_publish_generation在逐个暂存文档时由解码后文本写入改为write_bytes(data),沿用同一数据源、顺序、目录替换和回滚,未绕过校验。_validate_staged_generation继续逐字节比较文档,清单继续解析 JSON 比较;JSON 的宿主换行不影响这份结构性校验。export_goal_conclusions仍通过实际collect_history取结论,使用已有 public-safe sanitizer,并将本地路径留在 local receipt;不增加 provider 访问。- 公共 smoke 的旧写失败注入下移到
Path.open,仍真实失败且保护前代;路径断言使用 Path.parts 保留目标身份,新增用例模拟 CRLF 写入并覆盖二次发布。
对主干的风险
4 项 focused pytest、25 项公共 smoke、Ruff、完整语义检查与 291-site IO manifest 检查通过。冻结独立 CLI oracle 在 base 上仅 Windows 文本换行用例失败,其余 4 项对照通过;head 与独立 wheel 的 5 项全部通过,字节期望是固定 literal,并非调用被测渲染器生成。 对 source、base 与安装 wheel 检查了解释器和模块来源;native filesystem 操作没有替换为成功 mock。初始测试路径错误不计通过;未准备前端 assets 的 wheel 构建先失败,完成正常 npm ci / build:chat 后构建和隔离安装,未绕过包装校验。
Windows 原生宿主未由本评审运行;模拟覆盖的是 Python 文本换行行为,不能声称 Windows junction、杀进程竞态或 provider 采用已获验证。未改存储 provider,无需把 PostgreSQL 验收当作此文件 IO 修复的前置条件。 CI 按当前配置未查询、轮询或等待;作者的外部平台/测试声明不作为本评审的独立证明。语义 advisory 没检测到支持的新词汇载体,完整检查通过但仍保留 45 个 unresolved producer sites,不能由此宣称全树语义安全。
未发现本批阻塞问题。故障注入覆盖两种写 API,先暂存并读回再发布的顺序未改变;发布失败、清单所有权、外部内容和 symlink 保护继续由完整公共 smoke 与独立反例约束。
我的整体评价
长期重复导出和用户取得文档的路径得到改善;这一局部修复已经通过真实入口、二次执行及失败保存的完整结果验收。 把已经编码且由清单校验的 bytes 直接写入,是现有导出 owner 内最小且完整的修复;放宽校验会隐藏数据漂移,强制全局换行策略会扩大影响。 本批只改变暂存文档 IO,并同步原有故障注入和路径断言,保留清单、回滚与重复发布的既有语义。 未来维护整理已检查:删除 bytes/text 往返就是相关简化,无需新增 helper。 已有阶段恢复经验仅作提示,本结论没有继承历史 verdict,也不声明生产采用、整条 roadmap 关闭或合并授权。
English verdict: APPROVE - exact head c7a1f1e. Byte-exact staged writes preserve the existing manifest and rollback contract. Immutable base fails the simulated Windows text-layer case; head and installed wheel pass all 5 independent CLI cases plus 4 focused tests and 25 public smoke cases. No native Windows/provider-adoption claim.
|
Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=xhigh English verdict: APPROVE - exact head c7a1f1e. Byte-exact staged writes preserve the existing manifest and rollback contract. Immutable base fails the simulated Windows text-layer case; head and installed wheel pass all 5 independent CLI cases plus 4 focused tests and 25 public smoke cases. No native Windows/provider-adoption claim. |
Goal And Delivered Outcome
openviking-semantic-preferencehistory-conclusion export aborts at the staged readback, because_publish_generationstages documents throughPath.write_text, whose text-layer newline translation (LF to CRLF) contradicts the byte-exact readback and the manifest sha256 validated in the same function. No corpus was ever published or replaced on that host.loopx-openviking-history-exportentry point exits 1 withRuntimeError: staged history document failed readback: <name>before; it exits 0 with the JSON receipt, a published generation, and manifest digests equal to the on-disk bytes after (real_entrypointrow).main.Author Declaration
Implemented against
loopx/extensions/openviking_semantic_preference/history_export.pyat3054cdcc1/ rebasedc51ec1a60._publish_generationexamples/loopx-history-conclusion-recall-smoke.py_validate_staged_generation_case_staged_documents_stay_byte_exact_on_a_windows_host_case_export_write_failure_preserves_prior_owned_corpusfull-publicsmoke runner entry for this script,ruff,py_compile, and the shipped console entry point on a native Windows host before and after. The accompanying smoke adjustments were made only where the previous assertions encoded the POSIX text layer or the removed write API.Scope And Continuation
Validation
staticpassedruff checkon the two changed files andpy_compilevialoopx canary premerge;git diff --checkclean.unitpassedpython -m pytest -q tests/extensions/test_openviking_history_export.py tests/extensions/test_extension_provider_stdio_utf8.py-> 4 passed.integrationpassedpython examples/loopx-history-conclusion-recall-smoke.py->ok: 25 history-conclusion export cases passed(14 of them failed before the change withstaged history document failed readback);python examples/run-smokes.py --suite full-public --script examples/loopx-history-conclusion-recall-smoke.py->status: passed.real_entrypointpassedloopx-openviking-history-exportagainst a synthetic runtime root with one run record on a native Windows host: before, exit 1 withRuntimeError: staged history document failed readback: <name>; after, exit 0,written: 1, published document sha256 equals the manifest digest, no CRLF in the document, and a second run re-validates the prior generation (retired_prior_generation: 1).regression_paritypassedPath.write_text.manualpassedloopx canary premerge --from-git-diff --git-diff-base <upstream main>selects this change's surfaces; its six failing checks (lark inbox/event, extension presentation, finance value discovery, semantic-vocabulary drift) fail identically on the pristine base revision on this host, so they are environment limitations rather than effects of this change.Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
Boundary Checklist
.loopx/,.codex/goals/, and liveACTIVE_GOAL_STATE.md).none.Signed-off-bytrailer (git commit -s).