Repository navigation
fix(turn): compact complete decision captures without changing recovery - #7104
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
There was a problem hiding this comment.
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机
结论:APPROVE,绑定 f7b74895b7dbf7f46b72fa87a005f4782cad0fba。本次没有新增 blocking finding。
需要通过原生 Turn 的详情文件补读完整决策,或在 Host 失败后恢复原事务的操作者和 Agent。
同一份约 52 KB 的完整决策,以前因缩进占用约 1360 行;当前只去除 JSON 的排版空白,约为 39.5 KB、单行加末尾换行,原字符串中的空格、换行及停止约束完整保留。
独立同输入对照显示文件字节减少 23.78%–23.92%,解码后的全部值和动作签名一致;原生 File/SQLite 路径在来源改变、失败恢复及重复执行后仍使用原观察,最终只结算一次。
本 PR 只改变新 capture 的 JSON 排版,并补齐既有原生恢复覆盖;不删字段或指令,不提高预算,不改变准入、quota、重试与原始观察的权限。
字节减少是这条存储/读取路径的可验证收益,不证明 token 减少、速度提升、模型质量或长期任务净收益。手工直接看文件会从多行变为单行;需要时可在本地用 JSON reader 格式化,不需要重新调用 guard、重新准入或新增确认轮次。
改动思路
复用现有共享文件 writer 是足够小的修复;JSON 编码留在 Python IO 适配层,观察绑定仍由既有 TypeScript owner 校验,原事务与 effect 仍归 journal 和结算 owner。
当前 PR 的边界是无损的详情文件编码与真实调用者恢复验证,没有新增状态、配置、CLI 开关、平台界面或第二套决策规则。
这里比较了不改动、提高大小限制、裁掉重复字段和另建编码层四种方案。不改保留无用排版成本;提高限制不减少成本;删字段可能删除动作约束;另建配置或 encoder 会扩大维护面。当前一个共享 writer 的参数变更即可保留完整信息,没有必要另起协议或迁移框架。旧缩进格式由现有 JSON reader 自然兼容,不引入按版本分叉的 parser。
独立规格取自实际 base 0f59ffaf7b80cd12a22af768fe63205221d5ac25 的 docs/reference/protocols/turn-envelope-v0.md,先读旧文再审本次对规格的增补。按原节名逐项映射:
- TurnEnvelope v0:保留完整未投影值、私有原子 capture、可选 quota capture、按 JSON 值计算的原签名及非新权限的 detail 语义;implemented,
capture_decision、共享 writer 和既有绑定 owner,由同输入 base/head、15 项边界检查及原生入口验证。 - Native Turn Host capture:执行前保存原观察,preview 只读,重试仍读原观察且不多结算;缺失/损坏不得重跑 Host 补造;implemented,由 File/SQLite × 首次成功/容量失败 × 新/历史缩进格式的真实 CLI/合成 Host 矩阵验证。该节已经明确把真实模型、打包 App/Lark 及整体收敛留作独立验收,本次不把它们升级为已通过。
两份 RFC 增补与协议说明只解释新的编码和已有恢复边界;它们没有被当成本次实现正确性的独立规格。中英文 RFC 同步,已执行提交 diff 的原生检查。
具体改动
完整 5 个文件:生产 1 增 1 删;测试 42 增 6 删;3 份文档 17 增。没有新模块、枚举、持久字段或指令模板。
关键代码讲解
write_decision_capture(loopx/control_plane/turn_driver/decision_capture.py:17)接收完整 payload。唯一生产变更把indent=2换为紧凑 separators;ensure_ascii=False、allow_nan=False、末尾换行、flush/fsync、临时文件和 finally 清理均保留。native 仍用硬链接原子发布且拒绝覆盖;quota wrapper 仍在自己新建的私有目录中用原有 replace 发布。prepare_turn_decision_capture(同文件 :33)先从原 journal 的 path 读 JSON,再交给原 typed owner 绑定;已有 capture 不写回。当前 Todo 变化不改原文件,旧 pretty 文件恢复后也必须逐字节不变。missing/corrupt/wrong original 分支不借当前 guard 重建。capture_decision(loopx/cli_commands/quota_capture.py:55,生产调用者quota.py:461)在无 capture 目录时立即返回;有显式目录才使用同一 writer。其错误仍提示 receipt 可能已经发生,应恢复原事务,不能把磁盘错误当作未准入。原生调用者是executor.py:1616,在原 journal 锁内准备 capture。test_real_host_reads_original_capture_after_source_change(tests/control_plane/test_turn_host_decision_capture.py:31)先确认普通未迁移读取拒绝、无 fallback 且原文件不变,然后显式初始化一次隔离的新 fixture。之后由真实 CLI 启动合成子进程,子进程收到的 detail 命令读到原观察;native CAS 改 Todo 后仍不含新来源,失败后恢复、终态重放和一次 spend 都有独立断言。这是新工作的 fixture 修复,没有把历史已提交事务的恢复要求改成先迁移。
两个共享 writer 用例另外逐值检查中文、双空格、字符串内换行/tab/引号、布尔、null、负零、浮点及停止文本。旧 pretty 用例重建的是合成观察的历史编码,不能代表全部历史发行版或旧模型结果。
正向与失败路径
正常执行先保存完整观察,再把同一私有文件绑定到 envelope;Host 从实际收到的 detail 命令补读。当前来源变化后,retry 仍读取原字节,恢复成功只结算一次,之后相同 Turn 返回无 effect 重放。preview 不分配 capture、不调用 Host。
反向检查覆盖 missing/corrupt original 的 Host 重试拒绝、原始字节恢复、无 capture 的旧 journal 拒绝补造、非有限数字写入失败、原子发布中断无半文件,以及 native 第二次发布不覆盖原观察。错误和恢复 owner 均未改变,文件存在不等于授权当前工作。
对主干的风险
主要风险是把去排版写成删内容,或在恢复时重写原文件破坏签名。独立探针固定 4 份真实合成 File/SQLite guard 的完整输入,分别调用实际 base/head 的 native 和 quota writer 共 8 对,全部值、字符串和动作签名逐项相等,0600 与末尾换行保留;原始文件字节有意不同。4 份 guard 都是 normal_run,省略 shell capability 的输入也没有被冒称 blocked/denial 验证。
本轮实际执行:
- 当前 head 原生 capture 套件 10 通过,包含 8 个真实 CLI/File/SQLite/合成子进程恢复组合与 2 个共享 writer 用例。
- 将同一当前恢复 oracle 应用于两个不可变源码:base 的 4 个新紧凑格式断言在读取原生 capture 后按预期失败,4 个历史格式恢复组合通过;head 的 8 个组合全部通过。这证明表示变化的回归敏感性,不能把 base 的旧排版称作原有业务缺陷。
- 未改动的边界子集两边均 15 通过、13 deselected:包括关闭 capture 不触盘、无效目标、私有权限、原子发布、symlink、完整 display 和本地 transport 错误。没有声称跑完 28 个 quota capture 用例。
- base 原有原生套件另有 4 失败,都在普通
todo list要求 canonical authority 的 fixture 初始化前;不是 writer 回归,也未被重标为通过。当前 fixture 显式初始化与上述同一 oracle 跨 base/head 的恢复结果补足有效验证。 - 标准
loopx canary premerge --from-git-diff:6 项直接检查 + 14 项所选 canary 通过,无 required skip/失败/manual hold,包含双语 RFC、语义词汇及 public boundary;两个改动 Python 文件 Ruff 通过。
未获取、轮询、等待或调度 GitHub CI。原生预览、quota capture 关闭路径和已有消费者没有多出字段要求、prompt、调度或 effect。该改动不触及 provider store 协议,所以没有为它启动真实 PostgreSQL 或付费模型任务;真实 Python/CLI/文件系统/TS 绑定路径已覆盖,模型 provider 明确是合成实现。
我的整体评价
这个完整切片的判断为 goal_achieved、proportionate:只减少可丢弃的文件排版,保留原有停止与恢复语义,产物、实际调用者和负例均已闭环。long_horizon 为 preserved;user_experience 为 accepted_tradeoff:原任务及恢复无需新增操作,直接手工读单行文件的代价以本地可选格式化为界。依据是旧协议仅承诺完整 JSON 观察,未承诺 pretty 排版;不能据此宣称完整 Agent 效率提升。
已检查 quota CLI、原生 executor、详情读取及既有捕获消费者;没有渲染页面变更,视觉评审 not_applicable。
真实模型、打包或现场 App/Lark、PostgreSQL、全部历史发行版、token/延迟及可比完整 Turn 成本均未由本轮认证。
没有发现必须扩大当前修复的相邻重构。既有共享 writer 已是单一修改点;为了少量编码差异新增服务、配置或请求版本反而更贵。公开批准、原生资格、人工授权、安装采用及完整目标验收分别成立;本评审不授予合并、dismiss、升级或新执行权限。
Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max.
English verdict: APPROVE — f7b74895b7dbf7f46b72fa87a005f4782cad0fba. The shared capture writer removes layout whitespace while retaining complete JSON values, strings, action signatures, private atomic publication and original-observation recovery. Exact-source File/SQLite native CLI tests and independent base/head probes pass within the disclosed synthetic Host boundary. Legacy fixture failures, unrun capture cases and broader model/platform/full-cost qualification remain explicit. No merge authority is implied.
Goal And Delivered Outcome
Complete native Turn decisions were stored as indented JSON. Layout bytes increased capture IO and the cost of reading the complete original observation. The shared writer now emits compact UTF-8 JSON with a final newline, retaining every decision value and all whitespace inside strings.
Existing indented observations remain readable and retain their original bytes during recovery. Atomic publication, private permissions, source signatures, admission, settlement and exactly-once replay keep their existing owners. Related to effect-interpreter M7.4, roadmap S2/S3/S6/S8; intended base:
main.Author Declaration
docs/reference/protocols/turn-envelope-v0.md, “Native Turn Host capture”, anddocs/architecture/rfcs/agent-loop-effect-interpreter-v0.md, convergence checkpoint, at0f59ffaf7b80cd12a22af768fe63205221d5ac25; this PR documents the encoding refinement.decision_capture.pywriter; lossless-value assertions for quota and native callersScope And Continuation
A one-line shared encoding change, native integration coverage and paired RFC/protocol notes. The fixture repair also restores the existing Host checks after ordinary legacy reads were retired. Reusing the existing writer avoids another reader, schema, configuration or projection owner.
The completed slice reduces lossless capture transport cost. Remaining heartbeat/Turn convergence, full/thin caller adoption, complete Turn cost and actual model behavior retain their existing acceptance. No Python projection is retired by this PR.
Validation
f7b74895b7dbf7f46b72fa87a005f4782cad0fba.0f59ffaf7b80cd12a22af768fe63205221d5ac25.uv run --extra test python -m pytest -q tests/control_plane/test_turn_host_decision_capture.py: 10 source cases passed before integrating the unrelated latest UI commit. Eight native File/SQLite × success/capacity-recovery × new/historical-format cases and two shared-writer cases.cqr_592b0d6525e237449ab7verified valid.The wheel build initially refused a stale Chat bundle; rebuilding through the existing frontend build and repeating the standard wheel build succeeded. An isolated test startup needed path canonicalization on macOS; the successful run retained the strict wheel-only import assertion.
Frontend / Visual Evidence
UI impact: none. The actual target-relative diff changes capture IO, tests and protocol/RFC text; it contains no presentation changes. Screenshots are not applicable.
Type of Change
LoopX Area
Shared-authority RFC fixture impact
No authority routing, provider promotion or compatibility-projection change. Real File/SQLite native capture coverage is described above. SQLite remains the formal default. PostgreSQL conformance and legacy authority migration are unchanged.
Boundary Checklist
Review and maintainer merge authorization remain separate; this author proposal does not certify merge readiness or installed adoption.