Skip to content

perf(benchmark): bound live Codex session observation - #7747

Open
huangruiteng wants to merge 1 commit into
mainfrom
codex/benchmark-session-tail-observation
Open

huangruiteng wants to merge 1 commit into
mainfrom
codex/benchmark-session-tail-observation

Conversation

@huangruiteng

@huangruiteng huangruiteng commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Long-running Codex rollouts can grow to gigabytes, so a frequent capacity/liveness poll that rereads the full JSONL history can miss its freshness window. This adds an explicit python -m benchmark.runtime.session_observation entrypoint backed by a content-free live observation helper that reads at most the final 16 MiB, keeps complete records, and returns only event counts, cumulative token counters, timestamps, and framing diagnostics. Existing structured terminal provider-failure detection reuses the same record framing; exact usage accounting and integrity paths continue to stream the complete rollout.

Validation:

  • python3 -m pytest -q benchmark/tests/test_session_tail_observation.py benchmark/tests/test_provider_failure.py tests/control_plane/test_codex_rollout_streaming.py tests/control_plane/test_codex_session_usage.py (94 passed)
  • python3 -m ruff check benchmark/runtime/session_observation.py benchmark/tests/test_session_tail_observation.py
  • python3 -m ruff format --check benchmark/runtime/session_observation.py benchmark/tests/test_session_tail_observation.py
  • git diff --check

Broader benchmark runtime run: 115 passed, 51 skipped, and 5 pre-existing collection/import failures because the local Python entrypoint cannot resolve the repository test helper module test_loopx_turn_codex_cli; none of the failures import or exercise the changed files.

@huangruiteng
huangruiteng force-pushed the codex/benchmark-session-tail-observation branch 3 times, most recently from 29b923c to da5ec16 Compare October 31, 2026 09:43
Signed-off-by: huangruiteng <huangrt01@163.com>
@huangruiteng
huangruiteng force-pushed the codex/benchmark-session-tail-observation branch from da5ec16 to 6ed625e Compare October 31, 2026 09:47

@huangruiteng huangruiteng 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: actor_kind=model_agent; model=GPT-6; provider=OpenAI; declaration_source=self_reported

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

动机 / Motivation

受影响的是频繁轮询长程 Codex benchmark session 的外部 controller,以及通过 SForge cleanup 读取 structured terminal provider failure 的 operator。修复前,一个数 GB rollout 的频繁状态轮询可能反复扫描完整历史;修复后,显式 observer 只读取尾部 16 MiB,并把精确 token 记账继续留给完整流式 reader。

精确 head 对 4 GiB synthetic sparse rollout 读取 16,777,216 bytes,在 0.0301 秒内返回最后一条累计 usage;94 项定向回归通过,且同一 exact-boundary provider event 在 base 返回 null、在 head 返回 typed 429 receipt。本 PR 不替换 exact usage accounting、trajectory conversion 或 integrity qualification,不自动发现 session,不启动或重启 benchmark,也不把 observer 装入 LoopX kernel。

没有独立 accepted specification 定义这个可选投影;我没有把本 PR 修改的 RUNTIME.md 当作独立 spec。当前是 justified increment:公开 helper、CLI 和共享 framing 已独立可用、可测、可回退,deployment controller 的逐一采用仍是后续工作。

remaining_gap: Deployment-side controllers still adopt the command explicitly; this PR does not claim every private polling script migrated.

改动思路 / Approach

入口是 python -m benchmark.runtime.session_observation 。调用者明确选择 rollout;_complete_tail 用已打开 fd 的 fstat 固定 extent,只读取尾部上限和一个边界字节;reducer 只输出 allowlisted 计数、累计 usage、时间和 framing。缺 token event 保持 null,不会变成零。

代码复用了最接近的 owner:provider_failure.py 删除自己的 framing,改用共享 iterator;typed 429 分类仍归 provider adapter。完整 usage accounting 继续由 codex_session_usage 全量流式扫描。现有 RolloutCursor 负责绑定 Codex home/thread、持久 cursor 和 turn lifecycle,不能替代 path-explicit、stateless projection。

当前 PR boundary 是“公开 content-free bounded observer,并合并 benchmark 内重复 framing”;deployment wiring 和 exact accounting 留在原 owner。

current_pr_boundary: Ship observer/shared framing; leave deployment adoption and exact accounting with existing owners.

reason: Framing is a benchmark invariant, reduction a provider projection, CLI explicit provider IO; none mints control obligations.

最强反对意见是已有 bounded RolloutCursor,新文件可能形成第二个 rollout authority;但本实现不发现 session、不判断 turn state、不持久化 cursor,只产生标注 bounded_tail 的 diagnostic hint,边界合理。

具体改动 / Changes

关键代码讲解

  • benchmark/runtime/session_observation.py:46 _complete_tail:读取固定 byte extent;检查 start 前一个字节,只有落在记录中间才丢弃首段;EOF partial 也丢弃。这修复了 base 在 exact newline boundary 误丢第一条完整记录。
  • benchmark/runtime/session_observation.py:117 iter_codex_session_tail_records:只 yield 可解析 mapping,成为 live observation 与 provider failure 共用的 framing seam。
  • benchmark/runtime/session_observation.py:135 observe_codex_session_tail:未知 response type 折叠为 other,usage 只接受有限非负数;不返回 prompt、reply、tool output、error text、session/model id 或路径。
  • benchmark/runtime/provider_failure.py:22 _jsonl_tail:保留 symlink 和 optional-diagnosis fail-closed 规则,只把重复 framing 委托给共享 iterator;活跃 caller 仍是 SForgeBackend.cleanup_container。

Diff 为 4 files、+447/-19:221 行 production observer、provider adapter 净减 13 行、192 行测试和 28 行文档。新增 codex_session_tail_observation_v0 是 adapter-local diagnostic;既有 provider receipt 未改变,也没有 shared semantic registry/RFC 义务。

对主干的风险 / Risks

最强回归场景有两个。第一,小文件测试都绿,但实现仍全量读取数 GB 文件;4 GiB sparse-file probe 直接验证 sampled_bytes=16777216、usage 可见且完成。第二,共享 framing 改动 provider failure;同命令在 base/head 都是 11 passed,exact-boundary mutation 观察到 base 为 null、head 为 typed 429,证明变化是预期 bug fix。

负路径覆盖 unreadable path、非正 bound、partial first/last record、malformed JSON、free-text 429、non-finite usage 和尾部无 token event。错误只给 exception type,缺 usage 为 unknown,provider diagnosis 失败不改变 cleanup/run result。精确 head focused suite 为 94 passed,Ruff 和 git diff --check 通过;packet capture 时 5 个 CI checks 成功、kernel-static-checks pending 且无失败。pending CI 是独立 merge-readiness 信号,changed invariants 已有直接覆盖。

observer 默认不运行:module 存在和文档可见都不激活它;只有显式调用才读取路径。共享 provider caller 的 schema、structured-only 规则和 later-success precedence 保持,exact-boundary retention 是唯一有意变化。它没有 scheduling、quota、scoring、submission 或 publication authority,也没有 decision-bearing agent prose。

我的整体评价 / Verdict

长程效果上,这个 slice 把 recurrent observation 成本从随历史增长变为固定 16 MiB default,避免 observer 自己挤占 freshness window;用户路径上,controller 得到显式、content-free、失败可读的 JSON 命令。没有 rendered presentation 变化,visual review 不适用,unverified_scope 为 none。

我没有发现 blocking finding。剩余风险是没有覆盖每种 live-append/storage interleaving,也没有证明每个部署 controller 已采用;它们属于 adoption/soak,不影响当前 adapter 正确性。exact head 为 6ed625e,机制与规模 proportionate,default-off 隔离,shared contract 无未决 semantic drift。

英文简短结论

English verdict: APPROVE 6ed625e; the bounded observer, exact-boundary repair, retained provider semantics, and accounting separation are verified by 94 focused tests, a 4 GiB probe, and a base/head mutation, with no blocking finding.

huangruiteng added a commit that referenced this pull request Oct 31, 2026
Signed-off-by: huangruiteng <huangrt01@163.com>

@songoow songoow 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-6; OpenAI; self_reported.

动机 / Motivation

受影响的是频繁检查长时间Codex会话活性和容量的benchmark controller。会话历史持续增长时,重复扫描整个rollout增加观察成本;本项默认只读取尾部16MiB。已验证有界读取保留完整行、正确处理精确行边界,并在尾部没有usage时返回未知。本项不把尾部事件数当完整计费,不输出提示词或工具内容,也不证明所有部署controller已经采用。

这次判断绑定PR #7747的完整head 6ed625e。评价对象是已经存在的实际调用任务与局部可观察结果;重复调用带来的成本或错误恢复路线是本项动机,不能把较小响应或更少导入直接等同于长期任务质量。

改动思路 / Approach

把完整行装配放到共享tail reader,provider failure复用同一框架;原始完整usage读者仍拥有计费,显式模块CLI只提供去内容观察。本 PR 的合理边界是可选运营观察及已有provider错误读者的行边界复用,不能替代完整轨迹与完整账单证据。

沿入口跟踪到原所有者、返回值和失败恢复后,这个实现仍在现有边界上处理问题。无改动会保留原成本或错误指引;另起一套业务规则、持久化状态或通用缓存会增加同步义务,此处没有这类必要性。新增说明和投影应服务原调用方完成任务,不能改变原来的准入、权限、结算或来源完整性要求。

具体改动 / Changes

关键代码讲解

  • _complete_tail:按打开文件时大小读取固定后缀,保留恰好落在换行边界的第一行,舍弃不完整末行。 输入与拒绝分支沿用现有调用路径;这一处的返回内容或依赖时机改变,不把局部投影提升为新的业务判定。
  • observe_codex_session_tail:仅归约允许的事件种类、计数、数值用量和时间,缺少用量保持None。 输入与拒绝分支沿用现有调用路径;这一处的返回内容或依赖时机改变,不把局部投影提升为新的业务判定。
  • _jsonl_tail:复用新行装配,继续拒绝symlink并由原provider结构化错误所有者分类。 输入与拒绝分支沿用现有调用路径;这一处的返回内容或依赖时机改变,不把局部投影提升为新的业务判定。

运营计数明确只覆盖bounded tail,账单仍读完整已绑定文件;读取最多比配置上限多一个用于判定边界的字节,不产生新的authority或账单状态。正向场景是:尾部含完整累计usage时取最新快照,模块CLI与函数投影相同;原完整usage测试继续通过。负向场景是:截断的第一行、未写完的最后一行、非数值字段和私有事件类型不会进入内容视图;后续成功不会重放旧错误。这些是依据实际源码与已有调用测试核对的行为边界;失败和恢复继续由原owner负责,没有以返回字段存在代替真实状态读取。

规范依据为原公开调用行为、既有所有者和相应回归;已检索改动路径与周边文档,没有为这次局部性能/适配修正找到另一个已接受专项RFC。作者的量测叙述不充当独立功能合同。

实际验证 / Validation

tail observation、原provider failure、完整Codex usage三套80项测试 PASS;独立新增7项也已通过;Python编译与 diff hygiene PASS。

执行命令:python -m pytest -q benchmark/tests/test_session_tail_observation.py benchmark/tests/test_provider_failure.py tests/control_plane/test_codex_session_usage.py。本轮统计只包含上述实际执行;作者PR内微基准、旧head完整回归和旧review的历史量测都已阅读,但不冒称本轮重新执行的结果。

对主干的风险 / Risks

运营计数明确只覆盖bounded tail,账单仍读完整已绑定文件;读取最多比配置上限多一个用于判定边界的字节,不产生新的authority或账单状态。最需要防止的情况是:截断的第一行、未写完的最后一行、非数值字段和私有事件类型不会进入内容视图;后续成功不会重放旧错误。已核对相关调用方和已有review,未重复发布旧head意见;本轮对新增head的源代码与局部回归单独作判断。原持久化状态和业务所有者保持,仍然不能由小范围通过推断整仓或所有部署入口已经合格。

当前精确head失败证据:test-shard (1)、test-shard (2)、test-shard (6)、test-shard (4)、test-shard (5)。当前test-shard仍存在失败/取消,日志读取没有返回内容;80项聚焦测试覆盖变更,但不能替所有当前失败建立因果归因。 未取得的分片日志明确留作未知;同名错误或改动文件不相交都不足以建立pre_existing归因。

最小补齐是针对当前实际失败取得日志,并提供不可变base/head同命令同条件归因,或能独立覆盖该失败不变量的当前真实入口证据。已完成的聚焦回归不应无条件重做,也不要求无关功能重写;如果归因确认是回归,再修相应最小代码路径。未完成的检查不是单凭pending就要求改代码的理由。

我的整体评价 / Verdict

REQUEST_CHANGES:当前阻断是具体的验证证据缺口。聚焦审查尚未发现可复现的阻断性生产代码缺陷,不能把未归因红灯写成代码finding。 审查仅适用于exact head 6ed625e。

本 PR 的合理边界是可选运营观察及已有provider错误读者的行边界复用,不能替代完整轨迹与完整账单证据。 已验证有界读取保留完整行、正确处理精确行边界,并在尾部没有usage时返回未知。 已检查 benchmark/runtime/session_observation.py:_complete_tail;benchmark/runtime/session_observation.py:observe_codex_session_tail;benchmark/runtime/provider_failure.py:_jsonl_tail;变更是CLI/内部读取或文本协议,没有修改浏览器页面布局,视觉截图不适用。

当前test-shard仍存在失败/取消,日志读取没有返回内容;80项聚焦测试覆盖变更,但不能替所有当前失败建立因果归因。 本项不把尾部事件数当完整计费,不输出提示词或工具内容,也不证明所有部署controller已经采用。所有本轮探针使用合成fixture,没有运行真实模型任务或发起业务作业;本review陈述审查与验证事实,不声称已经发布部署或完成合并。

English verdict: REQUEST_CHANGES — exact head 6ed625e. Focused code review and the listed local regressions found no confirmed blocking implementation defect. Approval is held for the named current validation gaps; resolve their source-bound evidence rather than changing unrelated code.

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.

2 participants