Skip to content

Reuse observed writeback guidance in native context - #8408

Merged
huangruiteng merged 4 commits into
mainfrom
codex/reuse-observed-settlement-guidance-20261109
Nov 9, 2026
Merged

huangruiteng merged 4 commits into
mainfrom
codex/reuse-observed-settlement-guidance-20261109

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

A continuing native Todo can receive the same writeback precondition on every Turn. The progressive first read now references that field when it was delivered in full and matches the current ready plan, registered route and task in the same context epoch. It still delivers the current settlement identity and commands. Changed text, a changed source or binding, an unknown plan, or lost continuity returns the full current text.

The native reader passes disjoint edits to its ordinary selection plan as separate ranges. Reusing two distant fields therefore avoids retransmitting the addresses between them. The existing single-range and full-selection paths are supported.

Matched one-session original-quota CLI replay with two ready hard-lease Turns and the same 12,000-byte output cap. Main ran from the built wheel and C1 from the locally integrated source.

Track and authority Warm initial and follow-up stdout Full replay RPC byte change
Main / File 34,755 → 31,759 B -549 B
Main / SQLite 34,843 → 31,847 B -363 B
C1 / File 34,098 → 31,102 B -1,042 B
C1 / SQLite 34,178 → 31,182 B -1,142 B

Cold reader output size and full replay call counts matched. The selected Todo, complete settlement plan, failed-then-passed independent validator, wrong-binding refusal, same-capture recovery and once-per-Turn spend also matched.

Native first-read and lifecycle tests, context-selection and delivery tests, TypeScript typecheck, standard local premerge and wheel source verification passed. Live model adoption and token costs remain unmeasured.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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.1-sol, OpenAI, runtime_reported, reasoning_effort=max

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

动机 / Motivation

同一 ready Todo 的 native 读者会重复收到已完整读过的写回前置指引。我在 File 和 SQLite 上分别对照了两个真实准入并结算的 Turn,验证精确复用可以减少重复输出。已完整交付时,File 的 warm 首读从 21,073 降至 18,080 字节,SQLite 从 21,099 降至 18,106 字节。本次对照使用真实源代码 CLI 和 native hook,工作样本为本地合成。真实模型采用率与完整成本另验。

改动思路 / Approach

复用现有分段摘要。只有当前 ready Todo 的计划身份、原回执、注册路由及已观察原文匹配时,首读才引用已交付指引。当前命令、结算身份与其余选读仍正常交付。两处相隔较远的字段都可复用时,按原选择顺序传入分段改动。完整当前视图仍可从同一捕获读回。

具体改动 / Changes

评审提交 1bda44878fbd33acd702faf4e4b7276422ca7f99,PR 基线 71190b6b4ef4e146f3bf4a10d31ce61ac42fd021,5 个文件,+172/−34。TypeScript 选择器登记写回指引,Python 读取器应用选择变更并保留原回退,两版指南说明复用和恢复边界。已验证 observed-current-precondition、fresh-settlement-command-and-identity 和 partial-and-compaction-fallback。原首读和恢复约定

关键代码讲解

  • reusableWritebackPrecondition 先核对 ready plan 和原回执,再把这一个 agent-owned 字段加入当前路由的摘要覆盖。字段准入
  • observedFirstRead 保留当前控制字段,输出有序的选择改动。observed_first_read_reference 从原选择重放并保留同一捕获的普通视图。选择投影 读取回退

对主干的风险 / Risks

两版各跑 6 个实际 CLI 场景。第二轮的结算身份、写回和扣额命令与当前捕获一致,每轮各结算一次。只读到前 256 字节、发生压缩或显式关闭时,当前说明仍按原路径交付。同一捕获的显式选读可读回原文。另有 256 项相关测试、TypeScript 类型检查和 20 项直接或自动预合并检查通过。

我的整体评价 / Verdict

认可当前提交。改动缩短了已满足完整观察条件的首读,同时保留当前结算依据与恢复路径。剩余 installed-model-benefit 保持单独验收。

English verdict: APPROVE. At 1bda448, the warm reader emits 2,993 fewer bytes on each tested backend while keeping current settlement commands, one spend per original Turn, and literal recovery after partial delivery or compaction.

@mergify

mergify Bot commented Nov 9, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @loopx-agent.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 9, 2026
Signed-off-by: huangruiteng <huangrt01@163.com>

# Conflicts:
#	docs/guides/context-delivery.md
#	docs/guides/context-delivery.zh-CN.md
#	loopx/control_plane/quota/progressive_context.ts
#	loopx/control_plane/turn_driver/native_first_read.py
#	tests/control_plane/test_context_first_read.py
Signed-off-by: huangruiteng <huangrt01@163.com>
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 9, 2026

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent, GPT-5, OpenAI, self_reported

Independent approval

动机 / Motivation

通过 Codex 等原生会话连续执行 ready Goal Turn 的 Agent,以及依赖首读保留当前结算控制的操作者。这些调用会反复收到同一段很长的 durable writeback precondition。旧行为在暖会话中每次都重传这段正文;当两个相距较远的稳定字段同时可复用时,单段 splice 还会重传它们之间的大量选择地址。这里的“复用”只是把已经完整观察且仍匹配的字段换成 previously_delivered_fields 指针,不是持久化新权威,也不证明模型已经理解或会继续保留内容。

同一 File/SQLite 合成会话中,首个 Turn 完整交付 long precondition,后续同 Todo Turn 在 capture digest、route 与 observed journal 仍匹配时改用 previously_delivered_fields 指针;当前 identity、writeback/spend 命令和停止条件仍完整出现。若 precondition 改变、identity 错绑、plan 版本未知或 registry 改变,则下一首读重新交付原文。exact head 上 v1/v2 plan 的 same 路径复用同一 precondition,changed、wrong_binding、unknown_version 与 rebound 不进入复用;File/SQLite 的 write scope 与 selected Todo real-path 仍通过,PostCompact 后原 capture 恢复全部 observed 原文。

本 PR 不证明模型实际采纳该压缩、最终 token 计费或完整 C1 任务收益;这些仍是独立的安装版与长程效果资格。

改动思路 / Approach

入口仍是原生 quota should-run progressive delivery,权威输入仍是当前 ready settlement plan、execution preparation、heartbeat identity、selected Todo、注册路由、不可变 capture digest 与 observed journal。progressive_context.ts 只决定哪一个 field 可复用及如何缩短 selection;Python 的 native first-read adapter 只负责把 observed 与普通 fallback 绑定到同一 capture。任何身份、摘要、连续性或 splice 校验失败,都回到既有普通选择与 recovery command。

场景 旧行为 当前 head
相同 Todo、相同 ready plan、已完整观察 每 Turn 重传 long precondition 指针进入 previously_delivered_fields,当前 identity/命令其余步骤仍内联
Goal 文本与 precondition 两处远距离复用 单段改动可能重传中间地址 有序 selection_splices 保留未变化 runs
文本改变、identity 错绑、未知 plan、registry 重绑 不应复用旧文本 全部关闭复用并交付当前原文
PostCompact 或观察不完整 原 capture 应恢复 普通首读/同 capture recovery 返回完整当前值

资格判断由 readySettlementIdentity 和 reusableWritebackPrecondition 统一拥有;普通选择、单段 selection_splice 与完整 selections 仍兼容。资格是无持久状态的可复用投影,摘要和回退仍由同一 capture/journal 所有;多段 splice 只是现有 invocation-local selection 的压缩形式。

本次交付原生首读的电线与恢复改进,不宣称模型保留、计费或完整任务收益。这个边界是合理的:更小的改动只能复用 whole precondition 以外有限字段,仍会重复远距离地址;扩大到整个 settlement plan 又会隐藏当前 identity 与命令。

具体改动 / Changes

本次核对 581bfbd37a4b362de825b737c20f471ea942453a 相对 8fbfe41229b7d86a9dbdfe0a35cdf26c046e8a22 的 5 个文件,+207/−27。规范依据是 required-work-context revision 8fbfe41229b7d86a9dbdfe0a35cdf26c046e8a22。

  • complete-observation-only:同 session/task/epoch 的完整观察、current digest 与 route-bound source identity 同时匹配才允许引用。
  • current-controls-inline:当前 settlement identity、命令和其他步骤仍在内联计划中。
  • changed-or-lost-restores:文本、identity、plan 版本、registry 或连续性变化恢复 literal text。
  • same-capture-recovery:显式选读和普通 fallback 使用同一个 immutable capture digest。

关键代码讲解

  • readySettlementIdentity 集中核对 normal ready、delivery、execution preparation、Todo、effect id 和 heartbeat identity;原本重复在 settlement suppression 里的 predicate 也改为调用这里。
  • reusableWritebackPrecondition 只允许 v1/v2 plan 中唯一、agent-owned 的 durable writeback,并把 registry、runtime root、Goal ref、plan schema、Goal/Agent/Todo、kind 和 owner 写入摘要身份。
  • observedFirstRead 先去掉 digest 匹配字段,再按原 selection 顺序生成单段或多段改动;只有总序列化确实更小时才采用。
  • observedSelection 与 _pin_observed_selection 在两侧验证 range 有界、单调且不重叠,Python 还拒绝 bool 冒充整数。

英中两份 guide 同步说明复用、当前控制仍内联、显式同 capture recovery。没有把“节省 wire bytes”写成模型 retention 或结算收益。

对主干的风险 / Risks

没有新的 blocking finding。最强反例是同一字段地址上的 stale precondition 在文本、effect/Todo 绑定或注册路由变化后仍被引用,从而隐藏 Agent 必须遵守的当前说明。当前实现用 exact ready identity、唯一 durable writeback、known plan version、route-bound digest 与 same-epoch observation 同时关闭该类复用;changed、wrong_binding、unknown_version、rebound 和 PostCompact 分别有独立断言。另一个风险是多段 range 越界或重叠;TypeScript 只生成有序非重叠区间,Python 在写引用前再次校验,失败则保留 ordinary first read。

exact head 验证结果:tests/control_plane/test_context_first_read.py 通过 118/118,覆盖 v1/v2、same/invalidation matrix、File/SQLite write scope、selected Todo 与 PostCompact;三组 control-plane TypeScript 测试通过 92/92;tsc --project tsconfig.control-plane.json --noEmit 和 git diff --check origin/main...HEAD 通过。远端 CI 在取证时仍 queued/in-progress,作为独立 merge-readiness 观察保留。视觉审查不适用,因为受影响的是 native JSON/CLI 读取导航而不是渲染页面。

我的整体评价 / Verdict

长程效果有实际改进:暖 Turn 少重传稳定说明与中间选择地址,但当前 identity、命令、其他步骤、失败诊断和原 capture 恢复不变。用户可执行路径也保持不变;收益边界仅是 native first-read 传输。实现复用了既有 ReusableReadField、observed journal、selection compactor 和 capture fallback,还合并了 ready-settlement 的重复 predicate;没有发现并行 authority、重复持久状态或未披露的默认变化。残余风险是 installed-host 模型采纳、token 计费与完整长程成果尚未测量,这不阻塞当前传输增量的合并。

English verdict: APPROVE for 581bfbd. The exact head reuses only the fully observed, route-bound, still-identical writeback precondition, preserves current settlement controls, rejects every tested invalidation path, and reconstructs both single- and multi-range observed selections from the same capture.

@huangruiteng
huangruiteng merged commit 9837572 into main Nov 9, 2026
14 of 35 checks passed
@huangruiteng
huangruiteng deleted the codex/reuse-observed-settlement-guidance-20261109 branch November 9, 2026 19:35
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.

2 participants