Skip to content

feat(control-plane,dsh-plugin): wire real Todo settlement semantic-unit fold - #9503

Open
loopx-agent wants to merge 4 commits into
mainfrom
codex/s1-wire-real-todo-settlement-fold-20261127
Open

loopx-agent wants to merge 4 commits into
mainfrom
codex/s1-wire-real-todo-settlement-fold-20261127

Conversation

@loopx-agent

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

Copy link
Copy Markdown
Collaborator

Follow-on to #9213 that wires Todo semantic-unit anchoring, verified settlement FoldToReceipt, KeepRaw fail-closed rollback, and subsequent-Todo prompt/surface replacement into the real Core Turn execution loop, Core CLI settlement readback, and DSH plugin driver.

Summary

  • Core CLI Opt-In Settlement Readback (loopx/cli_commands/quota_registration.py, loopx/cli_commands/quota_receipt.py):
    • Added opt-in --include-settlement flag to loopx quota receipt (strictly default-off; default receipt schema is unchanged).
    • Projected verified settlement readback via read_heartbeat_settlement (settlement_verified, completion_receipt backed by todo_complete, refresh_state durable writeback, quota_spend, conflict checks on refresh_recovery.decision == "reject" / replan / checkpoint recovery, and rollout-log source_ref SHA-256).
  • Turn-Driver / Codex & DSH Host Semantic-Unit Lifecycle (loopx/control_plane/turn_driver/todo_unit_settlement.py, epoch_prefetch.py, quiet_turn_store.py, executor.py, codex_cli.py, host_candidate.py, loopx/cli_commands/turn_registration.py, turn_run_once.py):
    • Anchors current Todo parent KV prefix digest inductively (compute_turn_parent_prefix_digest) at Turn launch via record_semantic_unit_anchor when opt-in semantic_unit_fold.enabled is configured (--semantic-unit-fold-json / Turn options / decision_capture_payload).
    • Commits FoldToReceipt + bounded read-only obs_next_cmd prefetch after real validated_completion durable writeback and quota spend settlement in dedicated locked File + SQLite state (semantic_unit_fold/ + turn_prefetch_state.sqlite), recording ordered SHA-256 item digests (covered_exploratory_digests) of the settled Turn-1 exploratory_context records while leaving immutable terminal Turn journal tombstones untouched.
    • Injects settled prior Todo [Semantic-Unit Fold Receipt ...] + --- obs_next_cmd --- swaps into subsequent Turn model requests via Stage-then-Swap's single-owner evaluate_epoch_prefetch_prompt_gate (_adjudicate_candidate_prompt_gate and _apply_prompt_gate_audit_fields), enforcing the active min_net_savings_tokens threshold (Turn override or settled Turn-1 fallback) against stabilized rendered prompts without inflating host wire JSON.
    • Extracted shared compact_semantic_unit_fold_wire_fields in todo_unit_settlement.py (composing strip_internal_semantic_unit_fold_audit_fields — which also strips covered_exploratory_digests — + _HOST_WIRE_EXCLUDED_FOLD_TEXT_FIELDS) and reused it in both codex_cli._render_prompt and host_candidate.render_prompt so host="dsh" strips all internal audit telemetry and preserves exact-equality net-savings thresholds.
    • Constrained _partition_for_covered_fold_span (sharing _is_bound_exploratory_item with _partition_exploratory_context_for_fold) so Turn-2 replacement collapses only the exact ordered contiguous span of exploratory_context records matching Turn 1's covered_exploratory_digests. Unbound items (lacking todo_id, blank todo_id, non-mappings, bare strings) and late post-settlement observations appended after a covered span stay verbatim; rewritten, reordered, uncovered, or missing-scope todo_id == folded_todo records fail closed to KeepRaw("source_digest_mismatch") (or KeepRaw("prefix_digest_mismatch") if parent prefix shifted).
    • Preserves strict default-off parity (0 extra flags/writes/render emissions when disabled).
  • DSH Real Driver Lifecycle & Mid-Prefetch Race Guard (packages/dsh-loopx-plugin/src/todo-unit-fold.ts, packages/dsh-loopx-plugin/src/driver.ts):
    • Gated extra /selected_todo capture read and --include-settlement Core readback strictly behind todoUnitFold.enabled === true.
    • Captures stable per-session todoUnitContextEpoch, tracks step/start / human user/message / turn/end (completedCleanly), anchors active Todo right before queueing continuation prompts (anchorTodoUnit), and runs tryFoldSettledActiveTodoUnit in buildPlan before dispatching the next Todo so settled exploratory spans (surfaceOp: replace) collapse cleanly into receipt + bounded obsNextCmd output with automatic fail-closed KeepRaw fallback.
    • Mid-prefetch interleaving safety & foldKey in-flight coalescing (54fe81a2fc, 4cbc2c4b5b, 817e67ab32, fixing PRRT_kwDOStEbEs68j78l, PRRT_kwDOStEbEs68kZte, and PRRT_kwDOStEbEs68kzjF):
      • captureTodoUnitPrefetchPin snapshots the active session, boundary, anchor, active Todo unit, step count, settled tail seqs, and event watermark before awaiting Core settlement readback or runObsCommand; detectTodoUnitPrefetchInterference re-verifies all pinned invariants (and applyTodoUnitFoldAndPrefetch independently enforces expectedTailSeqs) before committing FoldToReceipt. Any new user message, inbox interruption, active-unit switch, or segment advance during prefetch falls back atomically to KeepRaw, keeping both the new user correction and settled exploratory tail intact in deriveMessages() and the raw event log while running prefetch at most once.
      • onTodoUnitSettled checks committed todoUnitFolds and synchronously checks/registers a deferred execution Promise in todoUnitFoldsInFlight (inFlightMap.set(foldKey, execution)) before invoking executeTodoUnitSettled / runObsCommand, clearing inFlightMap.delete(foldKey) (only when inFlightMap.get(foldKey) === execution) before resolving or rejecting callers. Concurrent and synchronously re-entrant callers join the single in-flight runObsCommand, committed FoldToReceipt remains cached in todoUnitFolds, and errors or KeepRaw outcomes clear the in-flight entry so subsequent retries execute cleanly.
  • Tests (tests/control_plane/test_semantic_unit_fold_hooks.py, packages/dsh-loopx-plugin/tests/todo-unit-fold.spec.ts):
    • Covers dual-backend (file + sqlite) two-Todo run_loopx_turn_once threshold checks (min_net_savings_tokens=64, 10000, exact 1-token equality == vs +1, inherited Turn-1 thresholds, zero-amortization raw equality), host="dsh" wire audit stripping & exact-threshold render_dsh_host_prompt verification (file + sqlite), mixed [Todo A, unbound dict, blank todo_id, bare string, Todo B] + preceding-unbound KeepRaw preservation, Turn-1 covered_exploratory_digests span enforcement ([late A], rewritten A, [covered A + late A], empty Turn-1 scope, and wire non-leakage across file + sqlite), real DSH inbox + continuation interleavings with vs without mid-prefetch user corrections and segment advances (obsRunner called strictly once), concurrent same-foldKey in-flight coalescing, and synchronous re-entrant calls inside obsRunner before the outer promise returns (error -> KeepRaw -> FoldToReceipt -> cached replay, calling obsRunner once per attempt and aligning both callers on identical outcomes).

Local Verification (at exact head 817e67ab32a0b7c2535e699bb50c55d0fc167c77, based on origin/main@6915df67db6a8836df344a661f295006873a3ba8, zero CI waiting)

  • TS & DSH Plugin (817e67ab32):
    • packages/dsh-loopx-plugin: npm run typecheck (0 errors across tsconfig.host.json, tsconfig.client.json, tsconfig.tests.json), npm test / vitest run (16 passed (16) files / 415 passed (415) tests, 0 failed, 0 skipped, 80.62s, including 13/13 in tests/todo-unit-fold.spec.ts and 15/15 in tests/admission-closeout.integration.spec.ts), npm run smoke:peer-range (passed), npm run smoke:mcp-transport (passed).
    • npm run typecheck:control-plane: 0 errors.
  • Python Control Plane, Lint, Strict Mypy & Smokes (817e67ab32):
    • uv run --extra test python -m pytest tests/control_plane/test_semantic_unit_fold_hooks.py -v: 27 passed in 60.15s (0 skipped).
    • uv run --extra test python examples/loopx-turn-dsh-builtin-host-e2e-smoke.py: passed.
    • uv run --extra test ruff check (11 touched Python files): All checks passed!
    • uv run --extra test mypy --strict --follow-imports=silent loopx/control_plane/turn_driver/todo_unit_settlement.py: Success: no issues found in 1 source file.
    • git diff --check, git merge-tree --write-tree origin/main HEAD (36537491ff5601cbf20bd7710f24824e6a346d9d, 0 conflicts), and loopx check --scan-path ... (14 touched PR files: ok: true, errors: 0, warnings: 0).
  • Change-Quality Qualification & Premerge (817e67ab32):
    • Goal-bound Change Quality Receipt cqr_52307d2d90c98ee20f2c (decision: "pass", receipt_valid: true, blocking: false, scope_fingerprint: "52307d2d90c98ee20f2c3e49979de077b1d48d888f2987f99e561505aaee957a").
    • Goal canary premerge --tier standard: 6/6 direct checks (0 failures) + 8/10 catalog canaries + 5/8 risk-profile smokes passed (policy_failure_count: 0, manual_hold_count: 0, quality_receipt_failure_count: 0; the 2 catalog + 3 risk-profile failures are all examples/canary/dsh-loopx-plugin-validation.py exiting 2 with pnpm is required for DSH plugin validation, while direct DSH plugin tsc, 415/415 Vitest, smoke:peer-range, and smoke:mcp-transport passed above).

@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)

[P2] 后续 Todo 呈现应执行当前的最小收益门槛。 前一 Todo 已完成并可折叠,下一轮仍请求替换原始上下文,但实际呈现节省大于零且低于显式 min_net_savings_tokens。 请求 10,000 token 时,File 实际节省 1,519,SQLite 节省 1,539。两者仍执行 FoldToReceipt 并移除 Todo 1 的原始上下文。64 token 的正例均达到阈值。 在下一轮呈现路径复用既有净收益门槛判定,并用该轮实际呈现输入和当前生效阈值比较。低于阈值返回 KeepRaw,保留原始上下文。

动机 / Motivation

显式启用语义单元折叠并设置最小收益的 Turn 调用者,以及接收原始上下文或精简回执的后续 Todo。 在 File 和 SQLite 完成第一个 Todo 后,保持同一个已验证折叠来源和父前缀,在第二轮比较 64 与 10,000 token 的最低收益请求。 请求 10,000 token 时,File 实际节省 1,519,SQLite 节省 1,539。两者仍执行 FoldToReceipt 并移除 Todo 1 的原始上下文。64 token 的正例均达到阈值。 测试使用确定性 host,真实模型效果、长期账单和缓存命中留待端到端验证。 已经验证结算的 Todo 可以移出可回读的探索材料,前提是实际交付的上下文达到使用者指定的收益。 通过既有结算和有界预读将已验收单元折叠,同时保留下一轮未达到最小收益时的原始材料。 对照契约 对照修订 50b4cc9de43498b57c8589c1bda03a787762416a。

  • S1 Stage-then-Swap 只有实际净 token 节省达到最小阈值才可回收原始跨度。 当前反例成立。
  • S2 折叠需要相同上下文、已验证结算和有界预读,重放不重复执行预读。 通过。
  • S3 无有效前提时保留 KeepRaw,功能关闭保持原始输入。 通过。

改动思路 / Approach

既有结算 owner 持有 Todo、效果与扣额。Turn 的下游呈现只可基于已验证回执和本轮输入选择是否替换。 复用首轮结算已有的预算判定可避免两个位置对同一最小收益指令作出不同决定。 原 Stage-then-Swap 契约要求有界预读成功且收益达到配置阈值才可回收原始上下文。 本轮按现头的实际两轮链路复核,分别核对真正结算、未重复预读与当前收益阈值。 对仓库经验采用其中的最小真实路径方法,分别核对正常操作、失败和恢复后的结果。

具体改动 / Changes

精确提交 8844d5757b6be78a889c17e6386fc685a38d7a85,14 个文件 +2505/−72。变化集中在结算观察、状态与两种 Host 接线。阈值可复用现有判据,避免各 Host 单独解释。

  • _apply_fold_to_next_request。重放按实际呈现计算节省,但只检查正数,之后直接替换原跨度。 代码
  • commit_turn_semantic_unit_fold_after_settlement。前一单元已验证完成、写回和扣额后才产生折叠回执。 代码
  • _evaluate_semantic_unit_fold。既有折叠 owner 可消费 min_net_savings_tokens,支持相同阈值规则。 代码
  • _verified_settlement_projection。可选回执读取保留默认格式,绑定精确结算和来源。 代码

18 项未改源码测试通过,原 CLI 回执用例因交付工作区未绑定而失败。使用该用例的登记工作区重跑,实际结算与回执成功。四组独立阈值观察得到结果。DSH 插件 411 项测试通过。 定向回归测试

对主干的风险 / Risks

双后端的低、高阈值都实际写入了已测量的 host 输入。高阈值配对反例仍替换材料,预读只执行一次。 标准本地预检 18 项执行检查均通过。 只读 merge-tree 和签署检查通过。外部模型、真实账单及远端 CI 未实测。

语义与 CI 对齐

在真实触发下保留调用方所选的范围。请求 10,000 token 时,File 实际节省 1,519,SQLite 节省 1,539。两者仍执行 FoldToReceipt 并移除 Todo 1 的原始上下文。64 token 的正例均达到阈值。 在真实 run_loopx_turn_once 双后端串联两个 Todo,比较 64、10,000 及阈值等于实测节省的情形,断言低于门槛时不移除原始上下文且不重复预读。 复用现有词汇,约束由既有源码拥有者执行。

我的整体评价 / Verdict

REQUEST_CHANGES。 在下一轮呈现路径复用既有净收益门槛判定,并用该轮实际呈现输入和当前生效阈值比较。低于阈值返回 KeepRaw,保留原始上下文。 真实链路已接好,但低于用户要求的节省也触发压缩,改变保留原始历史的条件。 保持现有回执、只读预读和 terminal journal。后续呈现复用既有 KeepRaw 和 FoldToReceipt 词汇。 原始 Pytest 回执用例暴露的工作区设置也应随回归夹具修正。

English verdict: REQUEST_CHANGES at 8844d57. The second Turn removes original exploration even though actual rendered savings of 1519 and 1539 tokens are below the explicit 10000-token minimum on File and SQLite. Bind the CLI receipt test to its delivery workspace.

@loopx-agent
loopx-agent force-pushed the codex/s1-wire-real-todo-settlement-fold-20261127 branch from 8844d57 to 703bb66 Compare November 26, 2026 19:27

@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 · self_reported
Reviewed exact head: 703bb66beee7470254382d43aa1866a427b1e8fb (author-owned PR; REQUEST_CHANGES, wait_for_ci=false)

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

结论先行(blocking [P2]):703bb66bee 已在 codex-cli、generic-cli、Core CLI --include-settlement 回读以及 dsh-loopx-plugin 端到端链路中扎实落地了 Todo semantic-unit 锚定、FoldToReceipt 与 KeepRaw 原子回退,并修复了 codex-cli 路径下 PRRT_kwDOStEbEs68hfD2(下一轮 min_net_savings_tokens 生效门槛,21/21 通过)。但 loopx/control_plane/turn_driver/host_candidate.py#L344-L356 的 render_prompt 未调用 strip_internal_semantic_unit_fold_audit_fields,导致 host="dsh" 在请求 JSON 中泄漏全部内部审计字段并破坏精确阈值边界(实测 1149 被次轮渲染推成 1148 并误回退 KeepRaw),需先补齐该 1 处剥离逻辑并补充 host="dsh" 回归测试再合入。


Actionable Findings

  • [P2] host_candidate.render_prompt 未剥离 semantic_unit_fold 内部 prompt-gate 审计字段,导致 DSH host 泄漏遥测并在精确净节省边界误回退 KeepRaw
    • 触发条件:在 host="dsh"(经 render_dsh_host_prompt -> render_prompt)下启用 semantic_unit_fold,于 Turn 1 结算 FoldToReceipt 后进入 Turn 2,使用默认或接近实测 amortized_net_savings_tokens 的 min_net_savings_tokens 阈值。
    • 代码路径:render_prompt 仅剔除了 replacement_text、receipt_mu、obs_next_cmd 等 6 个字段,未像同函数 epoch_prefetch 或 codex_cli._render_prompt 那样调用 strip_internal_semantic_unit_fold_audit_fields。
    • 可复现误判:在精确头 703bb66bee 通过 run_loopx_turn_once(host="dsh")端到端实测 Turn 1 -> Turn 2:
      • 当 min_net_savings_tokens=64 时,render_prompt 吐出的模型 Turn request JSON 直接包含 net_savings_tokens、rendered_prompt_delivered_bytes、tokenizer 等内部字段(amortized_net_savings_tokens=1149, cold_prefill_amortization_tokens=327);
      • 当随后在 Turn 2 显式传入精确相等门槛 min_net_savings_tokens=1149, cold_prefill_amortization_tokens=327 时,_apply_fold_to_next_request 第 2 轮重渲染因未剥离这些新增审计字段,将实测 amortized_net_savings_tokens 抬耗 1 token 压低至 1148 < 1149,直接返回 KeepRaw(fallback_reason="negative_net_savings") 而未替换旧 bloat。
    • 最小修复与回归验证:在 host_candidate.py#L344-L356 先调用 strip_internal_semantic_unit_fold_audit_fields(raw_fold) 再过滤上述 6 个载荷字段(与 codex_cli.py#L433-L450 对齐),并在 tests/control_plane/test_semantic_unit_fold_hooks.py 增加 host="dsh" 的 render_dsh_host_prompt 无遥测泄漏及精确 == amortized_net_savings_tokens 回归用例。

动机 / Motivation

长程 Todo 执行过程中,代理在探索阶段产生的高冗余检索和中间工具输出会持续留在上下文里,不断拉高后续 Todo 唤醒时的冷启动和增量成本,而纯靠静态或口头总结又容易丢失失败事实与精确回读锚点。在此前的迭代(#9213)里,Todo semantic-unit 锚定、回执门控折叠(FoldToReceipt)和失败自动保持原文回退(KeepRaw)主要停留在离线或 Hook 辅助函数层,尚未接通真实执行闭环:Core Turn 执行器、loopx quota receipt 结算回读以及 DeepSeek Harness(DSH)插件驱动层都无法自动按已完成 Todo 折叠冗余探索区间并预取下一轮所需上下文,同时上一轮评审指出的下一轮净收益门槛(min_net_savings_tokens)校验缺口也需在真实提示词渲染后统一裁决。

本 PR 的核心目标是将 Todo semantic-unit 折叠与预取真正接入三条生产入口:首先,由外层调用方或 DSH 插件在启用 opt-in 策略后锚定每个活跃 Todo 的纯净前缀 Q;其次,仅当 Todo 通过 Core 的 validated_completion 持久化写回与配额扣减后才基于真实回执和只读探针 obs_next_cmd 提交 FoldToReceipt,否则无条件保持 KeepRaw 不删原文;最后,在下一轮 Todo 启动前结合真实宿主提示词长度复核净 token 收益后再决定是否替换旧 Todo 探索内容。关闭开关时所有既有路径、schema 和提示词字节均保持严格零漂移。需明确区分的是:目前在 codex-cli、generic-cli 与 DSH 驱动闭环中预期逻辑均已验证成立,但 host="dsh" 提示词投影路径仍残留审计字段泄漏缺陷,成为当前唯一未闭环阻塞项;此外本 PR 不更改既有默认行为、不新增跨节点备份迁移协议,也未改动前端页面,无后续隐含边界扩展。

改动思路 / Approach

整体实现沿用 Stage-then-Swap 双层职责分离架构:规范判定(锚定哈希校验、回执完整性、净节省与冷启动摊销门槛、obs_next_cmd 只读白名单)仍留在现有 turn_envelope / stage_then_swap.ts 单一决策 owner,本 PR 仅在 CLI、Turn Driver 与 DSH 宿主驱动三层编排生命周期、持久化双写与宿主渲染前剥离(参见 history-working-set-context-policy-v0.md)。

flowchart LR
  A["Turn 1 启用 opt-in semantic_unit_fold"] --> B["record_semantic_unit_anchor 锁定父前缀 Q"]
  B --> C{"结算结果 == validated_completion 且无恢复/replan 冲突?"}
  C -- "否" --> D["跳过或 KeepRaw: 保留原文"]
  C -- "是" --> E["执行只读 obs_next_cmd 并构建 FoldToReceipt 双写 File+SQLite"]
  E --> F["Turn 2 启动前 _apply_fold_to_next_request"]
  F --> G["调用 evaluate_epoch_prefetch_prompt_gate 复核稳定渲染 prompt"]
  G -- "codex-cli / generic-cli 剥离审计字段且通过门槛" --> H["FoldToReceipt: 替换 Todo1 原文为 mu + obs_next_cmd"]
  G -- "host=dsh 未剥离审计字段 / 收益不足" --> I["KeepRaw: 保留原文, dsh 精确边界误判 1149->1148"]
Loading

图示说明:基于 exact head 703bb66bee 的结构梳理图(非运行证据)。主要涉及 todo_unit_settlement.py、codex_cli.py、host_candidate.py、quota_receipt.py 与 dsh-loopx-plugin/src/driver.ts。

  1. 架构归属与边界判断(architecture_assessment):本 PR 将“已结算 Todo 的生命周期状态双写与次轮提示词裁决”置于 Python runtime 协调层 todo_unit_settlement.py,把纯计算决策(build_semantic_unit_fold_swap 与 evaluate_epoch_prefetch_prompt_gate)保留在 TypeScript stage_then_swap.ts;将外部结算真值验证放在已有 quota receipt(opt-in --include-settlement),由 DSH LoopXContinuationDriver 通过真实 CLI 子进程回读并结合本地 surfaceOp: replace 完成原子尾部 pop。当前边界合理、可独立评审与回滚,无需把 DSH 插件内存状态写入 Core,也不必重写旧 turn_envelope 解码器;唯独 host_candidate.py#L344-L356 漏调同一套剥离 helper 属于当前 PR 内部必须修平的不对称缺陷。
  2. 复用与状态推导核查:commit_turn_semantic_unit_fold_after_settlement 直接复用 Core 已写回的 validated_completion / writeback / spend 真相,不改写终态 Turn journal tombstone,而是将连续跨 Todo 折叠状态独立持久化在 semantic_unit_fold/(0600 原子替换)+ turn_prefetch_state.sqlite(BEGIN IMMEDIATE + 摘要防冲突),replay key 与 DSH 驱动内存去重键一致;quota receipt --include-settlement 直接投影 read_heartbeat_settlement,并在 replan、recovery_rejected 或 checkpoint_recovery_required 时 fail-closed。
  3. 默认关闭隔离与可逆性:--include-settlement 与 --semantic-unit-fold-json 以及 DSH todoUnitFold.enabled 均严格默认关闭;关闭状态下 CLI 零额外参数请求、Turn Driver 零状态目录创建且 semantic_unit_fold 键不出现在请求/结果/日志中。

具体改动 / Changes

规格对照(spec_basis)

  • 参考规格:docs/architecture/rfcs/history-working-set-context-policy-v0.md(spec_revision: eebc7b9d29646dc757b8c76ecb21b5742caa7201)与前序评审意见 PRRT_kwDOStEbEs68hfD2:
    • RFC-5.1-INV1(Stage-then-Swap 原子性:执行 next_command 并在计入冷启动摊销后以实际渲染输出校验净 token 节省门槛,异常或净节省不足时原子回退 KeepRaw):not_met — codex-cli、generic-cli 与 DSH 插件 applyTodoUnitFoldAndPrefetch 均已满足,但 host="dsh" 经 host_candidate.render_prompt 时未剥离审计字段,精确阈值边界稳定性失效。
    • RFC-5.1-INV2(同 epoch 前缀 KV-cache 局部性:FoldAndPrefetch 保持父前缀 Q 字节一致并在 DSH 与 Core Turn 边界连续替换):implemented(driver.ts#L1870、todo_unit_settlement.py#L777,由 test_semantic_unit_fold_hooks.py 与 todo-unit-fold.spec.ts 验证)。
    • RFC-5.1-INV3(回执门控提交、只读 obs_next_cmd 白名单、replay 幂等不重执行及严格默认关闭隔离):implemented(quota_receipt.py#L41、todo_unit_settlement.py#L777,经 CLI 默认关闭对照与双后端重放测试验证)。
    • PRRT-68hfD2(次轮呈现复用单 owner 净收益门槛并剔除门控审计字段对提示词长度的干扰):not_met — codex-cli 路径已修复并通过 21/21 用例,但同 PR 修改的 host_candidate.render_prompt 遗漏 strip_internal_semantic_unit_fold_audit_fields。

改动行分类与体量(14 files, +2755 / -72 relative to ff55255012)

类别 文件数 增/删 说明
生产代码 12 +1578 / -68 CLI 2 文件、Turn Driver 8 文件(含新建 todo_unit_settlement.py 888 行)、DSH 插件 2 文件
测试与夹具 2 +1177 / -4 tests/control_plane/test_semantic_unit_fold_hooks.py(+670/-1)、packages/dsh-loopx-plugin/tests/todo-unit-fold.spec.ts(+507/-3)
文档/生成物/机械迁移 0 0 / 0 无文档或自动生成物改动

关键代码讲解

  1. _verified_settlement_projection (loopx/cli_commands/quota_receipt.py#L41-L158)
    • 职责与改前/改后:原 quota receipt 仅返回 heartbeat_receipt 原始事件;新增 opt-in --include-settlement 后通过 read_heartbeat_settlement 交叉核验完成事件 completion_event、写回 writeback、配额扣减 spend 及日志 source_ref SHA-256。
    • 关键不变量:遇到 successor_replan_pending、replan_execution_pending、refresh_recovery.decision == "reject"、checkpoint_recovery_required 或 todo_id 不一致时均返回 settlement_verified=False 与显式冲突码;include_settlement=False 时零字段注入。
  2. _apply_fold_to_next_request (loopx/control_plane/turn_driver/todo_unit_settlement.py#L366-L518)
    • 职责与修复:在下一轮 Turn 启动时对比 context_epoch、父前缀摘要 prefix_digest 与恢复冲突,将上一 Todo 的探索条目折叠为 replaced_by_semantic_unit_fold 标记并注入回执与 obs_next_cmd;并按 PRRT_kwDOStEbEs68hfD2 替换旧字节数比较为 _adjudicate_candidate_prompt_gate(调用 TS evaluateEpochPrefetchPromptGate),在 3 轮内验证渲染输出收敛。
    • 边界缺口:算法本身成立,但依赖各宿主渲染器在序列化 JSON 时剥离 _PROMPT_GATE_AUDIT_FIELDS,目前已验证 codex_cli.py 与 executor.serialize_generic_cli_host_input 遵守该约定,而 host_candidate.render_prompt 未遵守。
  3. commit_turn_semantic_unit_fold_after_settlement (loopx/control_plane/turn_driver/todo_unit_settlement.py#L777-L888)
    • 职责:仅在 settled.ok is True、result_kind == "validated_completion"、写回成功、配额已扣减且无恢复/故障记录时获取文件锁并同时写入 JSON 与 SQLite 状态;若命中相同 replay_key 则直接返回 replayed=True, executed=False 避免重复执行 obs_next_cmd。
  4. render_prompt (loopx/control_plane/turn_driver/host_candidate.py#L324-L374)
    • 问题所在:L338-L343 对 epoch_prefetch 调用了 strip_internal_epoch_prefetch_audit_fields,但 L344-L356 对 semantic_unit_fold 仅做了 6 个正文大字段剔除而未调用 strip_internal_semantic_unit_fold_audit_fields,成为前述 [P2] 缺陷根因。
  5. tryFoldSettledActiveTodoUnit (packages/dsh-loopx-plugin/src/driver.ts#L1870-L1959)
    • 职责与生命周期:仅当 todoUnitFold.enabled === true 且上一轮明确 turn/end (completed)、无人类用户插话清空 activeTodoUnit、无 pendingSelection / attention_required 时,通过 quota receipt --include-settlement 验证真实结算并触发 onTodoUnitSettled,把探索尾段以 surfaceOp: replace 原地收拢;任何异常都记录日志并保持原文 KeepRaw 同时在 finally 清理 activeTodoUnit。

对主干的风险 / Risks

  1. host="dsh" 提示词稳定性与静默退化风险(已复现):如上方 P2 发现所述,当 host="dsh" 走 Python run_loopx_turn_once / render_dsh_host_prompt 路径启用 semantic_unit_fold 时,Turn request JSON 会把全部 11 个内部门控指标注入模型输入,且精确门槛 == amortized_net_savings_tokens 会发生 1 token 自举偏移而误触发 KeepRaw("negative_net_savings")。由于现有 test_semantic_unit_fold_hooks.py 所有 Turn 夹具均只传 host="codex-cli",该回退风险被测试盲区掩盖。
  2. File/SQLite 双写一致性与恢复冲突防护:todo_unit_settlement.py#_read_store_state 对两侧 SHA-256 不等返回冲突并锁定为 KeepRaw("store_digest_conflict"),在 validated_progress、obs_command_error、prefix_drift、recovery_conflict 与 negative_savings 五类异常路径下均保持 exploratory_context 原文不变(已在测试中验证)。需留意跨宿主边界的 host_candidate.py#L404 历史 turn_envelope(无 work_contract)路径不透传 request["semantic_unit_fold"],属既有 v0 兼容隔离,不影响主流 work_contract 路径。
  3. 本地全量验证与环境边界清单:
    • npm run typecheck:control-plane(exit 0)及 node --experimental-strip-types --test(stage_then_swap_telemetry, turn_envelope, content_digest_single_owner:104/104 passed);
    • packages/dsh-loopx-plugin: typecheck(exit 0)、vitest run(16/16 文件、411/411 用例通过,其中 todo-unit-fold.spec.ts 9/9 通过)、build、smoke:peer-range、smoke:mcp-transport 全部通过;
    • Python: ruff check(11 文件 0 错误)、mypy --strict(2 文件 0 错误)、scripts/check_rfc_bilingual.py(通过)、loopx check --scan-path(14 文件 0 错误/0 警告、边界扫描干净)、examples/semantic-vocabulary-drift-smoke.py & examples/control_plane/control-plane-maintainability-ratchet-smoke.py & examples/loopx-turn-dsh-builtin-host-e2e-smoke.py 全部通过;pytest -n 4 执行 test_semantic_unit_fold_hooks.py 等 6 个套件 636 passed,执行 test_loopx_turn_driver.py + test_core_distribution.py 214 passed, 57 skipped(57 个 skip 均为未设置 LOOPX_CORE_TEST_PYTHON 隔离轮子环境所致);
    • canary premerge --tier standard 环境局限说明:4/4 direct checks、1/1 py_compile、8/10 catalog canaries 及 5/8 risk smokes 全部通过;仅 dsh-loopx-plugin-validation.py(及 smoke:artifact、smoke:profile、smoke:runtime)因当前运行镜像的 PATH 未安装 pnpm 而报 spawn pnpm ENOENT(与本 PR 代码无关,上述 16/411 vitest、tsc、tsdown build、smoke:peer-range 与 smoke:mcp-transport 已直接通过 npm 独立覆盖)。

我的整体评价 / Verdict

本 PR 将 Todo semantic-unit 折叠与预取机制从孤立的原语打通到真实 Core Turn 驱动、quota receipt --include-settlement 回读以及 DSH 插件自动延续循环,对 codex-cli、generic-cli 与 dsh-loopx-plugin 的主路径工程完整度很高,默认关闭隔离干净,且已实际修掉上一轮 PRRT_kwDOStEbEs68hfD2 指出的 codex-cli 净节省门槛失效问题。唯一阻碍合入的实锤问题是 host_candidate.render_prompt(本 PR 新增支持 semantic_unit_fold 的 3 行核心缺口)遗漏了 strip_internal_semantic_unit_fold_audit_fields,导致 host="dsh" 在模型 JSON 中泄漏 11 个内部门控指标并在精确 == amortized_net_savings_tokens 边界把 1149 压成 1148 误触发 KeepRaw。 在作者补上该 3 行剥离逻辑与一条 host="dsh" 端到端回归测试后,即可快速复核并转为通过。

  • Architecture & Boundary Summary:本轮实现把规范判断保留在 TypeScript stage_then_swap.ts,由 todo_unit_settlement.py 和 DSH driver.ts 分别负责宿主侧 Turn 生命周期编排与外部回执验证,保持零侵入默认关闭边界。修复 host_candidate.py#L344-L356 漏调 strip_internal_semantic_unit_fold_audit_fields 后即可闭合多宿主渲染对称性;其余跨多轮 Turn 的状态持久化与 DSH 原地 surfaceOp: replace 边界均可保留原样、局部可逆。
  • Visual & Experience Assessment:本 PR 仅修改 CLI flags、Turn runtime 内部管道与 DSH 无头驱动逻辑,不涉及 Web/前端或渲染界面布局变更(visual_review 为 not_applicable);未验证范围仅限需要 pnpm 安装插件包的 DSH 打包集成脚本(smoke:artifact、smoke:profile、smoke:runtime)及真实外部模型 API 长程会话,已有单测与直接 npm 脚本覆盖核心契约。

English verdict: REQUEST_CHANGES

@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)

[P2] 前一 Todo 的折叠误删后续 Turn 的未绑定新证据。第一轮只记录并折叠 Todo A。下一轮在正常带 Todo B 标记的输入旁加入一条此前未出现、没有 todo_id 的新记录。低阈值仍通过,但 File 和 SQLite 的 host request 都丢掉这条新记录,同时保留带 B 标记的记录。上一 Todo 的 completion receipt 未覆盖新增记录。 只替换由原折叠证据明确绑定的记录。缺少 todo_id 的项保留原样,或在无法证明覆盖范围时走 KeepRaw。补充混合上一 Todo、下一 Todo 和未绑定新记录的双 provider 用例。 源码

动机 / Motivation

把已验证的 Todo 结算折叠成可安全复用的收据,并在后续 Turn 仅替换其覆盖的旧上下文。 此前精确候选未实际执行后续 Turn 的 token 阈值。这一版接入共享 Stage-then-Swap 判定,恢复阈值拒绝。 显式启用 Todo 折叠的 Core Turn 和 DSH 用户。

误删未纳入旧收据的新事实会让后继 Todo 在不完整证据上行动,净 token 节省也被这部分误删夸大。 上一轮 10,000-token 反例现已得到 KeepRaw,File 和 SQLite 都保留原文。低阈值、临界相等/加一和继承阈值通过。实际有界预取只执行一次。默认关闭的真实 File Turn 在 base/head 都正常结算且没有 fold 字段或持久目录。 Core fold、CLI receipt 和独立 threshold/off 共 24 项通过。base 默认关闭另有 1 项通过。DSH 插件完整 411 项通过。两种 provider 的新未绑定记录负例都复现。 运行真实 Core Turn 计划、生产执行器、File/SQLite 及真实有界预取。模型和结算回调由隔离夹具提供。另跑 DSH 专用插件套件。未实测生产模型计费、KV 节省或托管 CI。 同头另一份评审记录了 DSH host 渲染阈值的独立问题。 验收契约

改动思路 / Approach

该改动沿用 loopx turn plan → run_loopx_turn_once → host prompt;DSH driver → quota receipt --include-settlement → surface replacement。在 Turn 结束验证结算并阶段化预取,下一轮通过作用域及摘要匹配选择已有结果。DSH 监听会话步骤、读取旧轮回执并替换关闭的片段。 新的 token 门按实际 prompt 测量。替换的授权范围仍由 partition 决定,这一步把缺少 todo_id 的项归到上一 Todo。 只替换由原折叠证据明确绑定的记录。缺少 todo_id 的项保留原样,或在无法证明覆盖范围时走 KeepRaw。补充混合上一 Todo、下一 Todo 和未绑定新记录的双 provider 用例。

具体改动 / Changes

精确提交 703bb66,本次对照目标 f67d0c8。14 文件 +2755/−72。与上一版本的提交范围比较,主要增量是共享 prompt gate、host audit 字段裁剪及阈值测试。完整交付还包含 quota 回执、折叠持久化和 DSH 管线。

关键代码讲解

  • _partition_exploratory_context_for_fold。缺少 Todo 身份的行会被选入前一 Todo 的替换。 源码

  • _semantic_unit_prompt_gate_policy。读取当前与已结算的最低 token 节省量。 源码

  • quota receipt --include-settlement。显式核对原 Turn 的完成、写回与扣费。 源码

  • DSH Todo fold。对照已清洁结束的 Turn 并在插件中做隔离执行。 源码

  • settled-todo-fold-provenance(not_met)。前一 Todo 验证完成后,只替换其回执所覆盖的探索上下文。后续证据与未绑定材料保持可见。

对主干的风险 / Risks

第一轮只记录并折叠 Todo A。下一轮在正常带 Todo B 标记的输入旁加入一条此前未出现、没有 todo_id 的新记录。低阈值仍通过,但 File 和 SQLite 的 host request 都丢掉这条新记录,同时保留带 B 标记的记录。上一 Todo 的 completion receipt 未覆盖新增记录。 该误删仅在明确启用折叠后出现。高阈值的修复本身成立,无法代替来源完整性。 只替换由原折叠证据明确绑定的记录。缺少 todo_id 的项保留原样,或在无法证明覆盖范围时走 KeepRaw。补充混合上一 Todo、下一 Todo 和未绑定新记录的双 provider 用例。

我的整体评价 / Verdict

REQUEST_CHANGES。 上一轮 token 阈值发现已经关闭。当前仍需限制同一旧收据可以替换的输入范围。 每次折叠必须保留前缀和仍影响下一决定的证据,后续节省才可归因给已验收的旧工作。

English verdict: REQUEST_CHANGES at 703bb66. The earlier token-floor issue is fixed on File and SQLite. Both now lose a newly supplied unscoped context row during the previous Todo's successful fold. Preserve rows outside the prior receipt's proven scope.

@loopx-agent
loopx-agent force-pushed the codex/s1-wire-real-todo-settlement-fold-20261127 branch from 703bb66 to 3e4fa38 Compare November 26, 2026 20:12

@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)

[P2] 用原收据覆盖的记录范围约束折叠。File 与 SQLite 都执行 FoldToReceipt,保留 B 与未绑定行,删除结算后才出现的 A 观测。前缀和 token 通过,原 completion receipt 未覆盖该观测。 替换前核对旧收据的有序跨度或已验证内容指纹,保留晚到、改写和范围不明的记录。不能安全切换时 KeepRaw。 源码

动机 / Motivation

把已验证的 Todo 结算折叠成可安全复用的收据,并在后续 Turn 仅替换其覆盖的旧上下文。 此前精确候选未实际执行后续 Turn 的 token 阈值。这一版接入共享 Stage-then-Swap 判定,恢复阈值拒绝。 显式启用 Todo 折叠的 Core Turn 和 DSH 用户。

误删未纳入旧收据的新事实会让后继 Todo 在不完整证据上行动,净 token 节省也被这部分误删夸大。 相同两轮夹具在 File 与 SQLite 都保留首次出现的无归属观测和 Todo B 记录。官方回归覆盖上轮的阈值等于/大于、10,000-token KeepRaw、DSH 渲染字段与真实结算回读。默认关闭时,base/head 的同一对 fixture 均正常结算,无 fold 字段和持久目录。 完整 Core 定向 25/25、默认关闭 base/head 各两个 provider、内置 DSH 本地 runner smoke 通过。原反例两例通过;扩大同 Todo 新观测反例在 File/SQLite 两例失败。 隔离 File/SQLite、实际 Turn planner、生产 executor、CLI 回执路径和真实有界预取;模型及结算回调使用夹具,DSH 入口为本地 runner,尚未测量线上模型计费或 KV 收益。未查询托管 CI。 验收契约

改动思路 / Approach

该改动沿用 loopx turn plan → run_loopx_turn_once → host prompt;DSH driver → quota receipt --include-settlement → surface replacement。复用 Todo settlement、语义单元状态和 Stage-then-Swap。折叠记录继续由原收据 owner 验证,只有已证明的连续片段适合替换。 用现有 Stage-then-Swap 门计算真实渲染收益,作用范围由分区负责人界定。新实现按 todo_id 筛选,前缀指纹只核对第一条匹配之前的输入,未核对匹配记录是否在原回执覆盖的快照。 不需要另建调度层。用已结算跨度或内容指纹限定受覆盖记录,在证据不足时复用 KeepRaw。

具体改动 / Changes

精确提交 3e4fa38,本次对照目标 6915df6。14 文件 +3076/−72,主要改动为届时结算回读、折叠持久化、实际 prompt 阈值门、Codex/DSH 渲染和插件调度。此次修订收窄分区并共享 DSH/Codex wire 裁剪。

关键代码讲解

  • _partition_exploratory_context_for_fold。同一 Todo ID 的任意现有记录都会进入替换组。 源码

  • _apply_fold_to_next_request。验证前缀后应用分区,未比较该组和旧折叠覆盖的输入。 源码

  • _semantic_unit_prompt_gate_policy。读取当前与已结算的最低 token 节省量。 源码

  • quota receipt --include-settlement。通过显式 opt-in 核对原 Turn 的完成、写回与扣费。 源码

  • DSH Todo fold。插件从同一结算口核对已完成 Todo,并在原驱动提供 fold 或 KeepRaw。 源码

  • settled-todo-fold-provenance(not_met)。最多替换用结算收据与源跨度证明覆盖的旧探索记录,保留此后新到的可执行观测,收益低于门槛时保留原文。

对主干的风险 / Risks

仅改变第二轮输入,增加一条第一次观察到、但正确关联上一 Todo A 的新结果。File 和 SQLite 都返回 FoldToReceipt,保留无归属及 Todo B 记录,却把这条后来结果和 A 的原历史一起删掉。上一轮结算与预取成功时这条记录还不存在,预取也只执行了一次。 误删只出现在显式启用折叠的路径。门槛与上一轮无归属问题的修复成立,真实结算身份也成立。它们无法证明同一 Todo 的全部后续信息已由原收据覆盖。 只替换由原回执锚定的那段记录,核对捕获时的有序范围或内容指纹。追加、改写或范围不明的项应保留,必要时 KeepRaw。

我的整体评价 / Verdict

REQUEST_CHANGES。 请以原回执覆盖的记录范围限定替换。仅按 todo_id 判断会丢掉后来到达、正确归属同一 Todo 的观测。 每次折叠必须保留前缀和仍影响下一决定的证据,后续节省才可归因给已验收的旧工作。

English verdict: REQUEST_CHANGES at 3e4fa38. The earlier unscoped-row loss is fixed. File and SQLite still discard a new observation tagged with the previously settled Todo ID. Bind replacement to the recorded source span.

…it fold

Wires opt-in Todo semantic-unit anchoring, verified settlement FoldToReceipt commitment, KeepRaw fail-closed rollback, and subsequent-Todo prompt/surface replacement across Core Turn execution, Core CLI --include-settlement receipt readback, and the DSH driver. Reuses Stage-then-Swap's evaluate_epoch_prefetch_prompt_gate and audit stripping helpers so subsequent-Todo replacement enforces the active min_net_savings_tokens floor against stabilized rendered prompts without inflating host wire payloads.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/s1-wire-real-todo-settlement-fold-20261127 branch from 3e4fa38 to 73aaf8b Compare November 26, 2026 20:50

@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 · self_reported

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

Verdict: APPROVE (author-owned exact-head review at 9503@73aaf8b4dcdb9e478a76b0a4688fa6f79708d90f).
No blocking findings remain on exact head 73aaf8b4dcdb9e478a76b0a4688fa6f79708d90f (merge_base=6915df67db6a8836df344a661f295006873a3ba8, OPEN, MERGEABLE, 4/4 resolved threads: PRRT_kwDOStEbEs68hfD2, PRRT_kwDOStEbEs68iiGV, PRRT_kwDOStEbEs68ilpt, and PRRT_kwDOStEbEs68jPI2). All prior review findings—shared wire-field sanitization for host="dsh" in host_candidate.render_prompt, retention of unbound/blank/other-Todo records, and the newest Turn-1 covered-span SHA-256 digest binding (_covered_exploratory_digests + _partition_for_covered_fold_span + "source_digest_mismatch" fail-closed KeepRaw, preventing post-settlement todo_A records or empty Turn-1 scopes from being silently pruned)—are fixed cleanly and verified across TS, Python, Core CLI, DSH plugin, and real [file, sqlite] stores (wait_for_ci=false). Because this PR is author-owned (loopx-agent), GitHub blocks formal self-approval; this COMMENT review records the exact-head approval conclusion while leaving the PR OPEN.


动机 / Motivation

当智能体在一个持续运行的 Goal 下按步骤执行多个 Todo 工作单元时,前一轮围绕旧 Todo 积累的探索性工具日志与原始上下文(exploratory_context)如果直接无差别保留到下一轮输入,会导致上下文随轮次单调膨胀、拉低前缀缓存复用并增加注意力噪声;而如果绕开结算事实校验或未核对旧收据覆盖的精确源记录快照就直接裁剪,又会把尚未结算、与重规划冲突、未绑定或结算之后新到达的观测一并误删,破坏恢复锚点与可审计性。

Affected caller / operator: Operators and autonomous LoopX Turn loops running multi-Todo continuations across Core turn run-once, Core quota receipt, and the opt-in dsh-loopx-plugin driver.

Before / after scenario: Before this PR, runtime Turn execution and DSH continuation only had standalone Stage-then-Swap / fold hook building blocks (#9213), without live Turn lifecycle anchoring, verified quota-settlement readback gating, Turn-1 covered-span SHA-256 binding, fail-closed KeepRaw prefix/source verification, or downstream prompt/exploratory-context replacement on the real Core Turn + DSH execution paths. After this PR, opting in anchors each admitted Todo semantic unit, verifies authoritative settlement via quota receipt --include-settlement or post-settlement journal/store commit, records covered Turn-1 item digests (covered_exploratory_digests), executes bounded obsNextCmd / Stage-then-Swap prefetch before eviction, and replaces only the exact Turn-1 covered span on clean FoldToReceipt while falling back deterministically to KeepRaw on conflict, prefix/source digest mismatch, late post-settlement observations tagged with the settled Todo, or negative token savings.

Observable outcome: Opt-in multi-Todo continuations replace only the verified Turn-1 covered exploratory span with compact receipt-backed summaries and bounded next-step observations when net token savings pass the gate, preserve late/unrelated/unbound/active records and original source_ref hashes intact, strip internal digests/telemetry on host wire rendering, and leave default-off callers completely unchanged.

Non-goals: Enabling semantic-unit folding by default, removing or compacting raw source rollout logs/journals on disk, altering authoritative Todo/quota/settlement rules, or migrating every remaining TypeScript projection policy owner into a single unified cross-runtime rewrite in this PR.


改动思路 / Approach

本 PR 在既有 Turn 生命周期与外部主机封装之上,按“先锚定与记录 Turn-1 快照摘要、再基于权威结算凭证核验、精确比对已覆盖跨度与收益门槛后替换、其余异常一律回退 KeepRaw”的闭环将语义单元折叠接通到三条实际链路:

  1. Core Turn 运行与精确跨度绑定(epoch_prefetch.py -> todo_unit_settlement.py -> quiet_turn_store.py):
    • Turn 启动前,由 prepare_turn_execution_epoch_context 检查显式开启配置后调用 prepare_turn_semantic_unit_context,按 goal_id + agent_id + turn_key 为当前选中 Todo 记录不可变前缀摘要、语义单元锚点(复用 turn_envelope.record_semantic_unit_anchor)及有序的绑定记录基线(anchor_baselines)。
    • Turn 结算后,由 commit_turn_quiet_state_after_success 调用 commit_turn_semantic_unit_fold_after_settlement,在 File + SQLite 双写存储(loopx_semantic_unit_settlement_store_v0)中校验 settlement_verified、无挂起 replan 冲突且目标 Todo 一致,构造 FoldToReceipt 并写入有序的 covered_exploratory_digests SHA-256 列表。
    • 当上一 Todo 的 FoldToReceipt 进入下一 Turn 的 _apply_fold_to_next_request 时,先通过 _partition_for_covered_fold_span 逐项验证连续待折叠片段的 SHA-256 与 Turn-1 covered_exploratory_digests 完全吻合(以及前置前缀摘要与实时净 token 门槛均达标),方才仅剔除 Turn-1 锚定片段;任何晚到的同 todo_id 后置观测、重写/重排、中间注入非绑定项或空 Turn-1 基线均保留或直接触发 KeepRaw("source_digest_mismatch") / KeepRaw("prefix_digest_mismatch")。
  2. Core CLI 只读回读链路(quota_registration.py -> quota_receipt.py):
    • 在 loopx quota receipt 上新增默认关闭的 --include-settlement 开关。开启时 _verified_settlement_projection 对齐 heartbeat_receipt 绑定身份与 read_heartbeat_settlement、rollout 事件日志 sha256、completion_event、writeback、spend、replan 状态及 checkpoint 恢复标志,输出结构化 settlement_verified、settlement_conflict_reason 与 completion_receipt。
  3. DSH 插件与多主机出线契约(driver.ts + todo-unit-fold.ts / host_candidate.py / codex_cli.py / executor.py):
    • packages/dsh-loopx-plugin 仅在显式配置 todoUnitFold.enabled === true 时启用,先检查恢复状态再调用 quota receipt --include-settlement 与 decodeQuotaSettlementReadback,通过后执行有界 obsNextCmd 并调用 onTodoUnitSettled 替换尾部上下文。
    • 出线清理统一由 strip_internal_semantic_unit_fold_audit_fields(已包含 covered_exploratory_digests、persistence、anchor_recorded 与 17 个预取内部字段)及 compact_semantic_unit_fold_wire_fields(额外剥离 6 个大文本字段)共享提供给 executor.py、codex_cli.py 和 host_candidate.render_prompt(服务 host="dsh")。
执行载体 触发条件(默认均关闭) 权威核验与跨度来源 失败与晚到观测回退边界 线协议剥离边界
Core Turn (prepare_turn_execution_epoch_context / commit_turn_quiet_state_after_success) --semantic-unit-fold-json 或显式 options / capture 启用 File + SQLite settlement store、prefix_digest 与 Turn-1 covered_exploratory_digests 后置同 Todo 新观测保留在折叠片段之外;改写、重排或无 Turn-1 覆盖时直接退回 KeepRaw("source_digest_mismatch") executor.py、codex_cli.py 与 host_candidate.py 统一剥离 covered_exploratory_digests 及内部审计/大文本字段
Core CLI (loopx quota receipt --include-settlement) 显式传 --include-settlement read_heartbeat_settlement、completion_event、writeback、spend、rollout sha256 只读不写,缺失或不一致返回 settlement_verified: false + 精确原因码 未传开关时零扩展字段,输出结构与基线一致
DSH Plugin (LoopXContinuationDriver) todoUnitFold.enabled === true CLI quota receipt --include-settlement + decodeQuotaSettlementReadback attention_required 或核验失败即清除活跃态并不折叠;obsNextCmd 失败回退 共享 DSH host_candidate.render_prompt 线协议紧凑契约

Architecture assessment (retain): Core runtime anchoring, settlement projection verification, File+SQLite store persistence, Turn-1 covered-span SHA-256 validation, and fail-closed KeepRaw/FoldToReceipt transitions naturally live alongside existing turn-driver epoch prefetch and quiet-turn persistence while DSH handles contiguous tail replacement. Keeping the projection readback deterministic in Core CLI (quota receipt --include-settlement), Turn lifecycle hooks and span-digest gating in todo_unit_settlement.py, and contiguous-tail eviction in dsh-loopx-plugin preserves existing runtime boundaries with opt-in isolation and clean rollback. The current PR boundary covers opt-in Todo semantic-unit lifecycle wiring across Turn runner hooks with Turn-1 covered-span digest verification, quota receipt --include-settlement projection, wire stripping for Codex/DSH/generic-cli hosts, and DSH plugin driver integration, deferring global default-on rollout and future TypeScript owner consolidation cleanly.


具体改动 / Changes

  • 精确 Diff 分类:共修改 14 个文件,总计 +3355 / -72 行:
    • 产品代码(12 个文件,+1672 / -68):loopx/cli_commands/quota_receipt.py (+164/-6)、loopx/cli_commands/quota_registration.py (+5/-0)、loopx/cli_commands/turn_registration.py (+6/-0)、loopx/cli_commands/turn_run_once.py (+1/-0)、loopx/control_plane/turn_driver/codex_cli.py (+23/-0)、loopx/control_plane/turn_driver/epoch_prefetch.py (+58/-19)、loopx/control_plane/turn_driver/executor.py (+13/-20)、loopx/control_plane/turn_driver/host_candidate.py (+29/-7)、loopx/control_plane/turn_driver/quiet_turn_store.py (+32/-2)、loopx/control_plane/turn_driver/todo_unit_settlement.py (+999/-0)、packages/dsh-loopx-plugin/src/driver.ts (+223/-14)、packages/dsh-loopx-plugin/src/todo-unit-fold.ts (+119/-0)。
    • 测试(2 个文件,+1683 / -4):tests/control_plane/test_semantic_unit_fold_hooks.py (+1176/-1)、packages/dsh-loopx-plugin/tests/todo-unit-fold.spec.ts (+507/-3)。
    • 文档 / 生成物 / 机械搬移:0 个文件(+0/-0)。

关键代码讲解

  1. _covered_exploratory_digests 与 commit_turn_semantic_unit_fold_after_settlement(loopx/control_plane/turn_driver/todo_unit_settlement.py#L353, #L880):在 Turn-1 锚定期间将 bound 条目持久化到 anchor_baselines,并于结算提交 FoldToReceipt 时提取有序 SHA-256 列表 covered_exploratory_digests(同步写入 File/SQLite 并在回放时保留);strip_internal_semantic_unit_fold_audit_fields(#L293)同时将该摘要列表列入内部剔除集合,防止泄漏至 host stdin/prompt 线协议。
  2. _partition_for_covered_fold_span 与 _apply_fold_to_next_request(todo_unit_settlement.py#L377, #L465):在 Turn-2 仅匹配到精确从 bound_positions[0] 起算且长度与有序哈希均与 covered_exploratory_digests 一致的连续跨度时才折叠该片段,完整保留其后的后置同 todo_id 新观测、其他 Todo 及非绑定项;任何重写、空 Turn-1 基线、跨度断裂或前置错位均触发 KeepRaw("source_digest_mismatch") 或 KeepRaw("prefix_digest_mismatch")。
  3. prepare_turn_semantic_unit_context(todo_unit_settlement.py#L624):Opt-in 开启后加载双写存储状态、消费待生效 FoldToReceipt(否则保持 KeepRaw),并通过 record_semantic_unit_anchor 与 _partition_exploratory_context_for_fold(#L330)为新单元记录不可变基线快照;未开启时零开销直返 (None, dict(request))。
  4. compact_semantic_unit_fold_wire_fields 与 _verified_settlement_projection(todo_unit_settlement.py#L310 / quota_receipt.py#L41 / host_candidate.py#L345):codex_cli.py(#L437)与 host_candidate.render_prompt(服务 host="dsh")统一复用同一精简器剥离全部内部遥测和大块 prose,而 quota receipt --include-settlement 通过 completion_event、spend、writeback、rollout SHA-256 与 replan 检查向 CLI/DSH 输出严格核验结论。
  5. tryFoldSettledActiveTodoUnit 与 decodeQuotaSettlementReadback(packages/dsh-loopx-plugin/src/driver.ts#L1870 / todo-unit-fold.ts#L719):仅当 todoUnitFold.enabled === true 且无恢复阻塞时拉取 quota receipt --include-settlement,严格校验 goalId/agentId/turnInstanceId/todoId 与 settlementVerified === true,执行有界 obsNextCmd 后再在 DSH 会话中执行尾部折叠,失败则重置 activeTodoUnit。

规范对齐与逐条核验

对照已接受规范 docs/architecture/rfcs/history-working-set-context-policy-v0.md(评审基准固定版本 eebc7b9d29646dc757b8c76ecb21b5742caa7201 第 5.1–5.2 节,本 PR 未修改该规范文件),逐条对应如下:

  • RFC-5.1-Inv1(Stage-then-Swap 原子性——先执行有界观测/预取并在净节省满足门限后提交折叠,异常回退 KeepRaw):implemented(todo_unit_settlement.py::commit_turn_semantic_unit_fold_after_settlement、_apply_fold_to_next_request、driver.ts::tryFoldSettledActiveTodoUnit;由 test_semantic_unit_fold_hooks.py 与 todo-unit-fold.spec.ts 覆盖)。
  • RFC-5.1-Inv2(前缀 KV-cache 局部性——保留公共前缀与精确连续已覆盖片段,禁止散落删改):implemented(todo_unit_settlement.py::compute_turn_parent_prefix_digest、_partition_for_covered_fold_span、driver.ts::anchorTodoUnit;含 prefix_digest_mismatch 与 source_digest_mismatch 负向测试)。
  • RFC-5.1-Inv3(调用方权限与回放幂等——通过只读回读与有界预取,重放复用既有 folds_map[replay_key] 含 covered_exploratory_digests):implemented(quota_receipt.py::_verified_settlement_projection、todo_unit_settlement.py::commit_turn_semantic_unit_fold_after_settlement、epoch_prefetch.py、todo-unit-fold.ts::createDefaultDshObsRunner)。
  • RFC-5.1-Inv4(源跨度与配对完整性——只替换 Turn-1 覆盖快照且线协议保留 source_ref + sha256 可追溯性):implemented(todo_unit_settlement.py::_covered_exploratory_digests、_partition_for_covered_fold_span、compact_semantic_unit_fold_wire_fields、codex_cli.py、host_candidate.py::render_prompt、executor.py;由 27 项集成单测 + 7 项跨度反事实 + render_prompt 探针验证)。
  • RFC-5.1-Inv5(反漂白客观收据头——保留退出码、未决失败/义务事实与来源哈希):implemented(quota_receipt.py::_verified_settlement_projection、host_candidate.py::render_prompt)。
  • RFC-5.2-Eligibility(严格准入与覆盖边界——必须完整结算、无重规划冲突、且精确匹配 Turn-1 锚定快照):implemented(quota_receipt.py::_verified_settlement_projection、todo_unit_settlement.py::_partition_for_covered_fold_span、todo-unit-fold.ts::decodeQuotaSettlementReadback)。

对主干的风险 / Risks

  • 无阻断性回归发现(No blocking findings):全部 4 处先序评审阻塞项在精确提交 73aaf8b4dcdb9e478a76b0a4688fa6f79708d90f 上均已修复并关闭(4/4 resolved):
    1. PRRT_kwDOStEbEs68iiGV(host_candidate.py:345 shared compact_semantic_unit_fold_wire_fields)与新增 covered_exploratory_digests 剔除已通过双后端 [file, sqlite] 测试与 render_prompt 探针验证(17 个预取键 + 6 个大文本字段 + covered_exploratory_digests/persistence/anchor_recorded 零泄漏)。
    2. PRRT_kwDOStEbEs68ilpt 与 PRRT_kwDOStEbEs68jPI2(_covered_exploratory_digests + _partition_for_covered_fold_span)经 [file, sqlite] 双后端回归与 7 组独立反事实验证:仅精确替换 Turn-1 已覆盖的连续 span;后置同 todo_id 观测、其他 Todo 与非绑定记录完整保留;重写/插入前置/中段掺杂/空 Turn-1 基线一律 fail closed 至 KeepRaw("source_digest_mismatch") 或 KeepRaw("prefix_digest_mismatch")。
  • Default-off 隔离性证明(isolated):三条入口默认关闭——无 --semantic-unit-fold-json 或对应 options 时 prepare_turn_semantic_unit_context 返回 (None, dict(request)) 且工作目录零落盘;quota receipt 未传 --include-settlement 时不附带结算扩展字段;dsh-loopx-plugin 仅在 todoUnitFold.enabled === true 时触发。
  • 调用点与作用域契合(scope_fit):所有新增代码均连接在活跃生产入口(epoch_prefetch.py:1587、quiet_turn_store.py:1104、executor.py:905、codex_cli.py:437、host_candidate.py:348、quota_receipt.py:194、driver.ts:1651,1870,2171),状态判定基于强类型与 SHA-256 指纹而非字符串启发式,保持领域中立并无多余权限扩展(authority_semantics: not_applicable,semantic_alignment: aligned / reuse_existing)。
  • 合并前验证结果汇总(全部在精确提交 73aaf8b4dc 上实测,未等待远程 CI,wait_for_ci=false):
    • PASS 静态检查与 RFC Gate:ruff check(11 个变更 Python 文件 0 errors)、mypy --strict todo_unit_settlement.py (0)、仓库 [tool.mypy] 17/17 个核心文件通过、scripts/check_rfc_bilingual.py 通过、loopx check --scan-path ...(14 文件 0 errors / 0 warnings,public_boundary_scan.ok=true)。
    • FAIL(非阻断基线噪音)其余 9 个变更 Python 文件 mypy --follow-imports=silent:quota_receipt.py / quota_registration.py / codex_cli.py / quiet_turn_store.py 为 0 错误;5 个文件共 66 处错误(turn_registration.py:2、turn_run_once.py:29、epoch_prefetch.py:15、executor.py:19、host_candidate.py:1)在主干基线 6915df67db6a8836df344a661f295006873a3ba8 上执行相同命令完全相同(66 == 66,pre_existing_unrelated,0 新增回归)。
    • PASS TypeScript 控制面与 DSH 插件:npm run typecheck:control-plane (0)、stage_then_swap_telemetry.test.ts (13/13) + turn_envelope.test.ts + content_digest_single_owner.test.ts (92/92,合计 105/105);packages/dsh-loopx-plugin typecheck (0)、Vitest 16 files / 411 passed、smoke:peer-range、smoke:mcp-transport 全部通过。
    • PASS Python 定向与集成/架构套件:test_semantic_unit_fold_hooks.py 27 passed in 56.07s(覆盖 Turn-1 span 绑定与 File/SQLite 双后端);pytest -n 4 横跨 6 个控制面/DSH/Turn 宿主套件 + test_cli_entrypoint.py + 3 个架构预算/边界/棘轮套件共 1372 passed (0 skipped, 0 failed);test_core_staging 2 passed;examples/loopx-turn-dsh-builtin-host-e2e-smoke.py 通过;CLI_HELP_FLAGS_OK 验证 --include-settlement 与 --semantic-unit-fold-json 注册。
    • PASS 独立反事实与剥离探针:SPAN_DIGEST_COUNTERFACTUALS_7_7_OK(覆盖正常增量/后置保留/前插错位/中段注入/篡改/空 Turn-1 基线/covered_exploratory_digests 剥离 7 种情形)与 HEAD_73AAF8_RENDER_PROMPT_STRIP_AND_DEFAULTOFF_OK(host="dsh" prompt 剥离全部 17 项预取与 6 项折叠大文本/内部字段 + default-off 零落盘)全过。
    • FAIL(外部工具环境限制)Goal canary premerge --tier standard --from-git-diff --git-diff-base origin/main:direct_checks 4/4、python_compile 1/1、catalog_canaries 8/10、risk_profile_smokes 5/8 通过(manual_hold_count=0);5 次 dsh-loopx-plugin-validation.py 失败仅因容器 PATH 缺少 pnpm 二进制(external_unrelated),插件自身的 TypeScript/Vitest/smoke 已独立全过。
  • 残余风险(Residual risk):turn run-once 开启折叠及 DSH 长会话的真实模型端到端 KV-cache 命中节省比例仍待后续开启实验期间通过遥测观察;当前头的所有确定性行为、跨度安全与默认关闭隔离性均已充分实测。

我的整体评价 / Verdict

  • Long-horizon (improved) & User experience (improved): 既把跨 Todo 上下文折叠、结算回读核验与前置/源跨度安全门控真正接入了 Core Turn、CLI 与 DSH 主路径,又通过 covered_exploratory_digests 彻底杜绝了误删结算之后新到达事实的风险;默认关闭时与基线行为完全等价。
  • Observable semantics & Compatibility (aligned / code_volume=necessary / compatibility=retain): 未破坏任何默认关闭调用路径;仅新增 opt-in 开关、双写锚点/跨度字段与清晰可观测回退原因码;实现紧凑聚焦(14 文件 +3355/-72,核心变更集中于 todo_unit_settlement.py、quota_receipt.py、driver.ts/todo-unit-fold.ts 及双端单测),无需拆改(change_proportionality=proportionate)。
  • Architecture boundary (retain): Core runtime anchoring, settlement projection verification, File+SQLite store persistence, Turn-1 covered-span SHA-256 validation, and fail-closed KeepRaw/FoldToReceipt transitions naturally live alongside existing turn-driver epoch prefetch and quiet-turn persistence while DSH handles contiguous tail replacement. Keeping the projection readback deterministic in Core CLI (quota receipt --include-settlement), Turn lifecycle hooks and span-digest gating in todo_unit_settlement.py, and contiguous-tail eviction in dsh-loopx-plugin preserves existing runtime boundaries with opt-in isolation and clean rollback. The current PR boundary covers opt-in Todo semantic-unit lifecycle wiring across Turn runner hooks with Turn-1 covered-span digest verification, quota receipt --include-settlement projection, wire stripping for Codex/DSH/generic-cli hosts, and DSH plugin driver integration, deferring global default-on rollout and future TypeScript owner consolidation cleanly.
  • Visual review (not_applicable): Inspected changed files across Core Turn Python modules, Core CLI quota commands, and headless DSH plugin driver TS modules; no UI components, rendered pages, or frontend styles were modified. (unverified_scope: none).
  • Vocabulary & Freshness: 复用了已接受 RFC 第 5.1–5.2 节的 FoldToReceipt / KeepRaw 原语及 quota_receipt_readback_v0 模式,covered_exploratory_digests 严格局限在持久化与回放验证内部并在出线时剔除;已核对远端分支位于精确提交 73aaf8b4dcdb9e478a76b0a4688fa6f79708d90f(OPEN, MERGEABLE, 4/4 已解决讨论串)。因本 PR 为作者自有提交且关闭 CI 阻塞等待(wait_for_ci=false),记录独立审校通过结论并保留 OPEN 状态等待维护者合并决策。

English verdict: APPROVE

@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)

[P2] 自动折叠会覆盖预读期间的新用户消息。

动机 / Motivation

显式启用 Todo 折叠的 DSH 会话,及使用 Core Turn 净节省门槛和结算回执的调用者。 已结算 Todo 的探索尾段可以收起。预读等待期间新到的用户输入属于后续工作,须保持可见。 只折叠已验证结算、安静边界内的有界尾段,并让下一轮达到实际最小收益。未满足条件时完整保留输入。 对照契约

用真实 DSH Session 走续跑事件,读取同一已结算回执形状。将只读预读暂停,在此期间向会话追加一条普通用户纠正,再让预读返回。 预读执行一次。用户纠正仍在原始事件日志,下一次 deriveMessages() 中却已消失。Driver 同时把原探索尾段换成 FoldToReceipt。

本轮用真实 DSH SessionStore 与 Driver,控制 CLI 回执传输和只读预读的返回时机。Core 回执与阈值由实际隔离 File/SQLite 入口另行验证。生产宿主、模型账单、KV 命中率和远端 CI 未测。

  • S1 实际渲染收益低于当前阈值时保留原文。 通过。
  • S2 已结算回执才可触发归集,默认关闭不触发预读或替换。 通过。
  • S3 在同一安静边界原子替换旧尾段,新用户输入始终可见。 当前反例成立。

改动思路 / Approach

Core 持有原结算、效果和扣额。DSH 只能对绑定原回执的历史范围做会话投影,Driver 不能把后续输入归给旧 Todo。 原来 DSH helper 的局部接口已具备 KeepRaw。本次自动调用要在预读完成后验证同一候选仍可提交,沿现有 owner 保留单一条件。 基线拥有可调用的折叠 helper,常规 DSH 续跑不自动调用它。本提案让完成的 Todo 在下一次 Driver 调度时触发该 helper。 按实际入口执行并读回结果。

具体改动 / Changes

精确提交 73aaf8b4dcdb9e478a76b0a4688fa6f79708d90f,14 个文件 +3355/−72。改动集中于 Core 结算、Codex 下一轮判断、DSH 会话接线及配套测试。

  • tryFoldSettledActiveTodoUnit。常规 Driver 读取原结算后首次自动触发已有回收方法。 代码
  • onTodoUnitSettled。跨 await 持有旧的安静状态,预读回来时直接提交到当前会话。 代码
  • applyTodoUnitFoldAndPrefetch。用当下的完整 tail 决定 surface replace 范围。 代码
  • _covered_exploratory_digests。绑定 FoldReceipt 覆盖的具体原文。保留同一个 Todo 后到的探索补充。 代码
  • compact_semantic_unit_fold_wire_fields。Codex 与 DSH 复用同一序列化边界。 代码

Core 定向 27 项通过,包含 File/SQLite、同一 Todo 的后到探索记录、DSH wire 与默认关闭。共享 TypeScript 向量 105 项通过。DSH 插件 411 项通过。普通续跑能够折叠。预读交错在当前提交失败,在增加尾端复核的隔离对照通过。 定向回归测试

对主干的风险 / Risks

标准本地预检 18 项执行检查通过。 针对 PR 基线和复核时主干的只读 merge-tree 及签署检查通过。标准预检从干净提交运行。异步交错另用生产 Driver 和真实 SessionStore 验证。

语义与 CI 对齐

隔离对照在预读前记住 Session 尾端,返回后只在尾端相同的情况下提交。原纠正和探索记录都保持可见,正常无新输入的折叠仍通过。

我的整体评价 / Verdict

REQUEST_CHANGES。 Core 保留同一 Todo 后到探索记录的修复已核验。请让 DSH 在提交替换前核对同一会话和已结算尾段,并把并发输入用例留作回归。原始日志仍可读,正常模型入口也需要保留纠正。

English verdict: REQUEST_CHANGES at 73aaf8b. Core now retains new exploratory records outside the original fold receipt, even when they share the settled Todo ID. In a production-code DSH session, a user message arriving during the awaited prefetch stays in the raw journal but disappears from the next derived model view. Revalidate the settled suffix and quiescence immediately before replacing it.

Comment thread packages/dsh-loopx-plugin/src/driver.ts Resolved
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)

[P2] 同一结算回执的并发重试仍执行两次预取。真实 DSH Session 夹具中,同一 Todo、Turn、receipt 和 epoch 通过两个公开入口同时执行。surface 最终只写入一个 FoldToReceipt,另一调用 KeepRaw。预取执行器实际启动两次,按一次调用的断言失败。完成后串行重放仍复用一份结果。 在第一个 await 前用现有精确 foldKey 合并同一回执的执行请求,使重试等待同一个 in-flight 结果。保留新加的事件及尾部核验,失败时给该轮可重试路径明确收尾。 源码

动机 / Motivation

把已验证的 Todo 结算折叠成可安全复用的收据,并在后续 Turn 仅替换其覆盖的旧上下文。 上轮 Core 已保留同一已结算 Todo 的新证据,DSH 在异步预取期间收到新用户消息时曾丢失该消息的模型视图。 显式启用 Todo 折叠的 Core Turn 和 DSH 用户。

在请求重试或重叠期间,两次相同 readback 浪费时延和调用预算,回执幂等只能阻止目前的第二次 surface 变更。 此前 Core 反例在 File 和 SQLite 重放后,都能折叠旧记录并保留后追加的 A、B 及无归属记录。DSH 当前的标准 inbox/continuation 测试覆盖中途插话,回读保留原尾部和新用户消息。默认关闭在主线和候选均正常结算、无额外字段或存储。 候选 Core 29 项通过,独立双 provider 复跑保留旧 Todo 的后到证据。基线和候选默认关闭测试各 2 项通过。DSH 固定锁安装、typecheck、16 文件 413 项及插件 build 通过,真实内置 DSH host smoke 通过。另一个期望预取一次的独立反例明确失败为两次。 并发反例在公开 Driver 结算入口中的真实 Session 夹具复现。常规内部 buildPlan 有自己的节流,尚未观察到该入口的真实生产重复调用。独立验证范围限本地 File、SQLite、DSH 和固定源码。 验收契约

改动思路 / Approach

该改动沿用 loopx turn plan → run_loopx_turn_once → host prompt;DSH driver → quota receipt --include-settlement → surface replacement。继续沿用权威结算回执和 DSH 宿主本身。新增 pin 对读回和预取中的 interleaving 重新验证。保持同一 foldKey 的单次执行仍需与回执缓存一起处理。 前驱源码跨度与 DSH 入口真实回执提供独立证明。并发两次在同一 await 前各自看到缓存缺失,两次预取都开始执行。 将相同 foldKey 的执行约束放在现有缓存 owner,复用提交核验和现有结果。

具体改动 / Changes

精确提交 54fe81a,本次对照目标 6915df6。14 文件 +3862/-96。相比 73aaf8b,修订集中在 DSH driver 的异步快照、结构化尾部校验与真实 Session 竞态回归。

关键代码讲解

  • _partition_for_covered_fold_span。按有序摘要,仅选择真正覆盖的旧记录。 源码

  • onTodoUnitSettled。以 foldKey 分派异步预取并提交。 源码

  • foldAndPrefetch。调用同一公开结算入口。 源码

  • tryFoldSettledActiveTodoUnit。由实际 continuation 读回 settlement 并建立 pin。 源码

  • settled-todo-fold-provenance(not_met)。只折叠已结算源跨度,保护后到证据及用户消息,同一结算回执上的重试最多触发一次预取。

对主干的风险 / Risks

真实 DSH Session 的同一回执并发重试命中同一个 foldKey,缓存只在预取结束后写入。异步窗口内两次调用均执行预取,再由尾部核验阻止第二次替换。 常规 pin 能保护派生视图、阻止重复 commit,重复执行的读操作仍影响耗时与预算。 为同一精确回执合并在途预取,再按既有竞态保护提交。

我的整体评价 / Verdict

REQUEST_CHANGES。 Core 上轮反例及 DSH 消息竞态已有针对性修复,仍需合并同一结算回执的在途预取。 可验证的上下文收益需要算入重试消耗并保存用户最新指令。

English verdict: REQUEST_CHANGES at 54fe81a. The revised Core span and DSH interruption guards pass. Concurrent retries via the public DSH Driver start the same observation twice before the receipt is cached, despite a single surface commit.

Comment thread packages/dsh-loopx-plugin/src/driver.ts Resolved
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)

[P2] 同步重入时在途登记晚于第一次预取。在途 Map.set 发生于异步执行体启动之后。同步重入仍发起两次观察,首调用返回 KeepRaw,重入返回 FoldToReceipt。只看到一次替换无法证明同一回执只预取一次。按真实 Session 隔离运行,先登记再启动的对照恢复了一次观察与一致结果。 先注册在途 Promise,随后才调用可重入的 observation adapter。保留现有失败清理、成功缓存及尾部核验。 源码

动机 / Motivation

把已验证的 Todo 结算折叠成可安全复用的收据,并在后续 Turn 仅替换其覆盖的旧上下文。 上轮 Core 已保留同一已结算 Todo 的新证据,DSH 在异步预取期间收到新用户消息时曾丢失该消息的模型视图。 显式启用 Todo 折叠的 Core Turn 和 DSH 用户。

同一个已结算 Todo 的入口重试仍会重复预取,且调用方对同一回执得到相反的 fold 结果。 作者新增的真实 Session 回归在两个普通并发入口、runner 抛错、非零退出、成功和串行缓存时均通过。之前的 File/SQLite 前驱证据及内置 DSH 入口烟测保持通过。 候选 Core 定向回归和默认关闭校验、pnpm typecheck、插件 build、普通同回执新用例与内置 DSH host smoke 均完成。两提交的重入反例都给出两次观察。局部排序对照同时通过普通并发与重入用例。 对固定源码的真实 DSH Session 注入 observation adapter,未在默认生产 runner 或常规 buildPlan 中观测到同步重试。未核验远程 CI。文件与 SQLite 使用同一 Core 源,验证限本地。 验收契约

改动思路 / Approach

该改动沿用 loopx turn plan → run_loopx_turn_once → host prompt;DSH driver → quota receipt --include-settlement → surface replacement。核心文件与上一评审的已验证版本逐字节一致。DSH 继续使用现有回执、Session pin、原尾部确认与已提交结果缓存。 前一候选仅缓存成功结果,本次在同 Session 维护相同 foldKey 的在途 Promise。异步执行体会在登记前同步调用 observation adapter,执行入口仍有可重入间隙。 将相同 foldKey 的执行约束放在现有缓存 owner,复用提交核验和现有结果。

具体改动 / Changes

精确提交 4cbc2c4,本次对照目标 6915df6。14 文件 +3991/-99。相较上一候选,生产变化限定在 DSH driver 的同回执在途去重,测试新增成功、异常、KeepRaw 和重放对照。

关键代码讲解

  • _partition_for_covered_fold_span。按有序摘要只替换回执覆盖的旧记录。 源码

  • onTodoUnitSettled。按照当前 Session 和回执键找已提交与在途结果。 源码

  • executeTodoUnitSettled。调用 observation adapter 后继续验证尾部与活动 segment。 源码

  • foldAndPrefetch。第二个公开入口仍调用同一个结算方法。 源码

  • settled-todo-fold-provenance(not_met)。只折叠已结算源跨度,保护后到证据及用户消息,同一结算回执上的重试最多触发一次预取。

对主干的风险 / Risks

真实 DSH Session 里,第一个 observation adapter 在返回 Promise 前同步通过另一公开入口重入同一 receipt。候选和上一提交均启动两次观察,初始调用返回 KeepRaw,重入返回 FoldToReceipt,Session 仅暴露一个 FoldToReceipt。隔离对照把 Promise 登记完成再调用 runner,两次入口共享 FoldToReceipt,观察一次,既有重试回归也通过。 默认 DSH runner 的自动调度或生产事件尚未观察到同步重入。确定反例位于公开 driver API 与支持的 observation adapter 边界。 在进入外部 runner 前先登记在途 Promise,再启动执行体。保留失败清理、成功缓存和实际尾部确认。

我的整体评价 / Verdict

REQUEST_CHANGES。 普通异步并发的原问题已修复。请在 observation adapter 可能同步回调之前登记在途状态,再按同一 receipt 验收单次观察和结果一致。 可复用的结算回执要同时限定后续上下文替换与外部观察次数,使重试成本和结果可预测。

English verdict: REQUEST_CHANGES at 4cbc2c4. Ordinary concurrent retries now share one prefetch. A supported observation adapter that synchronously re-enters the public driver before returning still starts two observations for the same receipt and returns conflicting outcomes. Register the in-flight operation before invoking the adapter.

Comment thread packages/dsh-loopx-plugin/src/driver.ts Resolved
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

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

动机 / Motivation

把已验证的 Todo 结算折叠成可安全复用的收据,并在后续 Turn 仅替换其覆盖的旧上下文。 上轮 Core 已保留同一已结算 Todo 的新证据,DSH 在异步预取期间收到新用户消息时曾丢失该消息的模型视图。 显式启用 Todo 折叠的 Core Turn 和 DSH 用户。

回执重试不应增加观察成本,也不应让两个调用方把相同 Turn 向不同方向投影。 上一轮独立重入夹具在当前提交只观察一次。两个公开入口均获同一个 FoldToReceipt,实际 Session 仅有一个 replacement。普通并发同样合并。 Core 27 项通过。DSH 16 文件 415 项、typecheck、插件 build、内置 DSH host smoke 均通过。沿用上一轮 独立验证的 Core 后到证据对照,并确认 Core 源在两提交间逐字节相同。 验证覆盖精确源码、隔离的 File/SQLite、真实 DSH Session 与内置 DSH host smoke。远程 CI、付费模型和生产缓存收益仍未测量。 验收契约

改动思路 / Approach

该改动沿用 loopx turn plan → run_loopx_turn_once → host prompt;DSH driver → quota receipt --include-settlement → surface replacement。复用 DSH Session 的现有 foldKey、权威结算回执、tail pin 与已提交结果缓存。Core 使用现有 durable Turn record 与 prompt owner。 创建同一 foldKey 的在途 Promise 后立即登记,再进入可同步回调的 adapter。成功的折叠进入现有缓存,失败或 KeepRaw 清理在途状态并允许重试。 将相同 foldKey 的执行约束放在现有缓存 owner,复用提交核验和现有结果。

具体改动 / Changes

精确提交 817e67a,本次对照目标 6915df6。14 文件 +4090/-99。相对上轮仅 DSH driver 与其真实 Session 回归变化,新增 107 行、删除 8 行。

关键代码讲解

  • _partition_for_covered_fold_span。按有序摘要只替换回执覆盖的旧记录。 源码

  • onTodoUnitSettled。基于现有回执键先登记 Promise,再调用可重入观察。 源码

  • executeTodoUnitSettled。以原有载入 pin、用户消息和尾部校验决定是否替换。 源码

  • foldAndPrefetch。第二公开入口进入相同结算 owner。 源码

  • settled-todo-fold-provenance(implemented)。只折叠已结算源跨度,保护后到证据及用户消息,同一结算回执上的重试最多触发一次预取。

对主干的风险 / Risks

真实 Session 同步重入发生在异常、非零退出和成功阶段时,每个实际尝试只调用观察一次。失败继续可重试。成功后重放不增加调用数。上轮同一独立夹具两次观察并返回 KeepRaw / FoldToReceipt,当前已修复。 验证在真实 DSH Session 和其可注入 adapter 边界复现并关闭。未启用发布环境、远程模型付费调用和实际 KV 缓存测量。 在调用 adapter 前登记同一回执,在 settled/failed 后清理对应键,成功继续复用现有 FoldToReceipt 缓存。

我的整体评价 / Verdict

APPROVE。 本轮修订关闭了已验证的同步重入问题。针对已有 File/SQLite 与 DSH 验收,通过这次提交的独立评审。 经回执锚定的上下文裁剪减少重复加工,同时留下追踪历史和后续用户输入。

English verdict: APPROVE at 817e67a. The exact head registers the in-flight promise before entering the observation adapter. The original synchronous re-entry oracle now observes one prefetch, one replacement and equal results. Ordinary concurrency, rejection and KeepRaw retry, successful replay and default-off behavior were rechecked.

This branch has not been deployed

No deployments
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.

1 participant