Skip to content

Reduce native hook replies to journal changes - #9336

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/native-journal-transfer-20261123T173711
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/native-journal-transfer-20261123T173711

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Motivation

A native context page hook reads its private journal under a lock. The lifecycle reducer previously sent the entire result back to Python for every verified page, even when only the byte range changed. Large section-digest maps made the return value scale with both journal size and page count.

Change

The Python hook requests the existing source-edit representation and reconstructs the journal before checkpointing. TypeScript still owns session identity, byte coverage, promotion and invalidation. Callers that request a full result keep the previous representation. An invalid edit takes the hook's existing recovery path under the lock, preserving the original capture.

Validation

  • Replayed identical captured pages through the real hook in a disposable native session on base and head. For a 13-page selection, the combined JSON-encoded lifecycle result fell from 8,387,099 to 50,488 bytes. The request bodies remained about 8.89 MB. On a nine-page complete read, the results fell from 5,675,143 to 614,732 bytes. These sizes measure the logical RPC values, excluding framing and storage overhead.
  • Matched final journals for partial selection, complete selection, duplicate terminal page, full read, damaged page and compaction. The comparison normalized only the newly generated epoch after invalidation. The full read established the same verified capture, and partial selection established no complete baseline.
  • Three alternating comparisons through the CLI in separate processes produced identical final journals. Wall-clock times varied widely on the shared host, so the result establishes a reduction in returned data volume. End-to-end latency needs a controlled run.
  • The opt-in wire check failed on base. The invalid-edit tests failed on the initial candidate and passed after routing malformed changes through locked invalidation. Run node --experimental-strip-types --test tests/control_plane_ts/context_delivery.test.ts and uv run --extra test python -m pytest -q tests/control_plane/test_codex_context_lifecycle.py.

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-astra · OpenAI · runtime_reported · xhigh

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

动机 / Motivation

逐页接收上下文的原生 Codex 钩子需要在两页之间保存已读范围。13 页读取过去每页都返回整本日志,候选版本只回传变更。累计结果从 8,387,099 降到 50,488 字节,六种场景的最终持久化日志与主干一致。改动只涉及本地日志的返回格式。模型用量、额度结算、派单和面向用户的读取规则都沿用原路径。

改动思路 / Approach

日志状态由同一个 TypeScript reducer 决定,Python 在已有锁内完成重建与写盘。改动只涉及本地日志的返回格式。模型用量、额度结算、派单和面向用户的读取规则都沿用原路径。原始捕获与摘要仍由原来的读取路径验证。局部范围只改变几个字段,直接复用现有的 source_edits 编码就可以省掉大部分返回数据。删减摘要会使后续恢复失去依据。

具体改动 / Changes

核对提交 6c02ff5 及完整远端补丁。验收依据为 docs/reference/required-work-context.md,基线版本 49881d5。coverage 对应读取覆盖,recovery 对应压缩上下文时的失效和原文恢复。

evaluateTurnEnvelope 在执行原状态机后选择返回格式,直接调用方仍可以取回完整结果。Python 的 update_native_context_lifecycle 对同一份输入重建状态。解码期间遇到损坏路径会进入持锁失效处理,后续还能重新读取原始捕获。

部分选择、完整选择、重复末页、全量读取、损坏页和压缩事件逐项对照,最终日志一致。关闭原生交付、普通工具事件和其他会话的压缩事件都保持了原日志。新增的格式断言在主干失败,三个损坏编辑用例在补上错误处理前失败,在当前提交通过。174 个 Python 用例、38 个 TypeScript 用例及 13 项预合并检查通过。

对主干的风险 / Risks

13 页选择的请求仍约 8.89 MB。每次计算差异和重建日志也需要 CPU。三组交替的真实 CLI 比较都生成相同日志,但共享主机的耗时波动较大,尚不能据此预测安装后的速度或模型费用。全量读取完成时仍需返回一份完整的已读索引,这个分支在九页回放中共返回约六十一万字节。持久化数据结构保持兼容,回退该提交即可恢复原传输方式。

我的整体评价 / Verdict

返回数据量下降已验证,选读没有误升为全读,坏回复能从原捕获恢复。下一个值得单独度量的开销是每页请求中重复携带的输入摘要。作者自评通过,独立批准与安装验收另行核对。

English verdict: APPROVE. Head 6c02ff5 reduces journal reply volume and preserves verified page coverage and recovery.

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