Skip to content

Shorten heartbeat wakes for a bound Codex session - #9251

Merged
loopx-agent merged 1 commit into
mainfrom
codex/c1-bound-resume-wake-20261122
Nov 23, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/c1-bound-resume-wake-20261122

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Why

A governed benchmark heartbeat repeats the cold-start prompt even when the worker has already validated that the current Goal and agent will resume the same Codex conversation. In a local C1 fixture, this repetition starts before the agent reads the new Turn decision.

Change

  • Pass the verified native session identity from the existing benchmark session owner and recheck it at heartbeat rendering.
  • Send a shorter work prompt for that resume. It carries the original guard and uses the fresh captured decision for required reads, workspace, lease, scheduling, recovery and settlement.
  • Use the full prompt for cold starts, stale bindings, host retries and checkpoint refreshes that start a new conversation. The C1 delivery selection stays with the current runtime owner.

Validation

  • Used the real benchmark worker renderer and CLI with the same synthetic Goal, Todo and hard lease for each comparison. With C1 context delivery enabled, the wake went from 5,001 to 3,666 bytes (26.7%). One cold wake and two resumes total 12,333 bytes versus 15,003 for three cold-format wakes (17.8%).
  • With context delivery disabled, the wake went from 4,914 to 3,579 bytes (27.2%). Both configurations render identical guard commands before and after. Executing the shortened prompt's guard preserves the original typed settlement identity.
  • Targeted heartbeat regressions passed (144). The benchmark runtime suite passed its 12 available tests and skipped 334 optional cases in this environment. The worker/CLI comparison above required no model or SForge installation.

C1's separate inline decision-opening target remains open. The fixture's progressive guard produces a 3,887-byte navigation response and requires a follow-up reader to reach settlement details.

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

本次对 loopx-project/loopx#9251 精确提交 10b4e29e76baab103352f29eb69b3bdc44b1e6fb(相对合入基线 856cd6ad8fb93bcb8e3a4a1a2f98701da2b07cdc)完成独立代码审阅、单测与对照组复验(遵循 wait_for_ci: false 本地先行策略);本 PR 为 loopx-agent 自提交,按 author-owned PR 规则发布 COMMENTED 审批结论并保持 PR 开启。

动机 / Motivation

面向在 benchmark worker 与 generic_cli 心跳循环中复用同一个已绑定 Codex 会话的运行时调度方与 Agent 调用方。 修改前每次热恢复唤醒即使命中了同一会话绑定,仍向模型重复投喂 4275 字节冷启动薄提示词;修改后在本地实测夹具中,当工作流通过作用域会话校验时唤醒提示词缩短至 2940 字节并保持完全一致的守卫命令行,同时在未绑定、错配或重试场景保持原冷提示词。 已验证的同会话恢复唤醒精简为单段决策恢复提示并保留全部结算与读写约束,且不改变冷启动、重试与非 generic_cli 路径输出。 本 PR 不修改 C1 渐进上下文的开场内联策略、不放宽会话签名校验,也不扩展到 app 或 visible-goal 宿主路径。 C1 守卫开场仍需后续由独立变更处理预取内联与导航压缩,本 PR 仅收窄已绑定 Codex 会话的热恢复提示词体积。

改动思路 / Approach

将同会话识别下沉至既有的 select_codex_cli_session 与 FirstPartyHostGoalAdmission 校验边界,不新增独立会话存储或状态机,仅在 heartbeat-prompt 渲染侧增加受限的 resumed_codex_session 分支。

当前 PR 边界严格限定于 benchmark worker 到 heartbeat-prompt --thin 的同会话恢复短提示词切换及冷/重试/热刷新回退保护,不触碰 C1 context_delivery 与 quota 裁决逻辑。 具体而言,worker.run_once 仅在非重试(expected_session 为空)、存在 session_wake.binding 且 prepare_session_refresh 未注入新上下文前缀或替换会话 ID 时透传 --resume-codex-session-id;CLI 侧 _verified_codex_resume 再次通过权威 FirstPartyHostGoalAdmission 与 select_codex_cli_session 复核 goal_id、agent_id、runtime_profile == generic_cli、--thin、非 --bootstrap、非 --visible-goal-host、具备 --turn-instance-id 且无 operation_transport,任意条件不满足即回退完整冷启动提示词。

具体改动 / Changes

全部 6 个文件相对基线 856cd6ad8fb93bcb8e3a4a1a2f98701da2b07cdc 共 +110 / -7 行(5 个运行/CLI 实现文件与 1 个单测文件);本切片属内部提示词传输优化,无独立书面规范(no written specification exists,仅沿用既有 heartbeat-prompt 与 codex_sessions 边界)。

关键代码讲解

  1. run_once 与 heartbeat_body
    在非 plan 阶段延后构造 heartbeat_body,先通过 BenchmarkSessionWake 检查是否有既有会话绑定 session_wake.binding 且非 LOOPX_HOST_RETRY_SESSION_ID 重试;若 LOOPX_WARM_START 触发 prepare_session_refresh 并产生前缀或更换 session_id,立即将 resumed_session_id 清零回退冷提示词。heartbeat_body 仅在 not native_goal and resume_codex_session_id 时追加隐藏参数 --resume-codex-session-id。
  2. _verified_codex_resume 与 handle_heartbeat_prompt_command
    CLI 在收到 --resume-codex-session-id 后并不信任调用方传入值,而是强制校验证书式条件(--thin、非 --bootstrap、存在 --turn-instance-id、generic_cli profile、visible_goal_host is None)并用 FirstPartyHostGoalAdmission + select_codex_cli_session 重新读取本地绑定,确认 session_id 精确匹配且非 operation_transport 会话后才返回 True。
  3. _select_task_body_renderer 与 render_thin_heartbeat_task_body / render_thin_heartbeat_task_body
    仅当 thin=True 且 resumed_codex_session and turn_instance_id 时使用精简模板;保留完全相同的 render_turn_bootstrap() 与 quota_guard_command 代码块以及 _finalize_heartbeat_task_body 注入的 settlement_plan.ordered_steps 硬约束、权限尾注、通知与视觉写回规则,仅将冷启动时已在首轮会话中交付的通用引导压缩为依赖当前捕获的简洁指令。

对主干的风险 / Risks

经独立检验与对照测试,未发现阻塞合入的问题(no blocking finding)。

精确提交 10b4e29e76baab103352f29eb69b3bdc44b1e6fb 本地实测矩阵如下:

  • TypeScript 与静态检查:npm run typecheck:control-plane 通过(0 错误);ruff check 全部 6 个改动 Python 文件通过;mypy(pyproject.toml 定义的 17 个 strict 核心文件)0 错误(单独对 4 个受触非 strict 文件跑 mypy --follow-imports=silent 报出的 10 项均为既有邻近行类型债务,PR 新增/修改行 0 错误);check_rfc_bilingual.py 通过;loopx check 扫描 0 错误。
  • Pytest 定向与关联套件:tests/control_plane/test_heartbeat_agent_input.py 与 benchmark/tests/test_shared_codex_runtime.py 执行 156 passed, 76 skipped(76 skipped 为本地未装可选 harbor/sforge/Linux 环境的原生 importorskip);扩展运行全量 tests/control_plane/test_heartbeat*.py 272 passed, 0 failed。
  • Canary Premerge:direct_checks 6/6、catalog_canaries 10/10、risk_profile_smokes 8/8(failures=0;manual_review_required 仅因涉及 benchmark/runtime/worker.py 命中 benchmark_sensitive 人工复核标记)。
  • 对照与反例验证:在孤立临时运行时下以 loopx heartbeat-prompt --thin --runtime-profile generic_cli 实跑对照,冷唤醒 4275 字节 vs 同会话绑定恢复 2940 字节,且围栏内 quota should-run 命令完全一致;当缺少 --turn-instance-id、传递未注册/过期 session_id、切换 --bootstrap、codex_app_heartbeat 或带 operation_transport 的绑定时均严格回退为冷启动输出(100% 字节一致);worker.heartbeat_body 验证 native_goal=True 与 resume_codex_session_id=None 均不传递 --resume-codex-session-id。
  • 边界与未覆盖:本环境未连真实 Codex 模型端到端推理以实测模型对短提示词的长期遵从率(属合理测试边界,关键安全/结算/通知与 settlement_plan.ordered_steps 约束在结构化文本与首轮会话上下文中均已保留)。

我的整体评价 / Verdict

综合评估精确提交 10b4e29e76baab103352f29eb69b3bdc44b1e6fb:long_horizon 为 improved(消除热恢复重复投喂同时不丢失 settlement_plan、readback、wait 与 retry 安全约束),user_experience 为 preserved(CLI 与配置保持完全兼容,未传或未命中绑定时零变化);本 PR 仅修改 CLI 文本提示词渲染与 benchmark worker 参数转发,不涉及任何前端页面或渲染视图。未验证范围:none。将同会话识别下沉至既有的 select_codex_cli_session 与 FirstPartyHostGoalAdmission 校验边界,不新增独立会话存储或状态机,仅在 heartbeat-prompt 渲染侧增加受限的 resumed_codex_session 分支。 当前 PR 边界严格限定于 benchmark worker 到 heartbeat-prompt --thin 的同会话恢复短提示词切换及冷/重试/热刷新回退保护,不触碰 C1 context_delivery 与 quota 裁决逻辑。 语义词汇策略为 local_only(仅新增隐藏 CLI 参数 --resume-codex-session-id 供 benchmark worker 与 CLI 内部握手,未引入公开状态枚举或持久化 schema)。

English verdict: APPROVE at 10b4e29. Verified verified-binding resume wake reduction (4275 -> 2940 bytes with identical guard command), strict fallback to cold prompts on missing/mismatched/bootstrap/non-generic/operation_transport sessions, 272/272 heartbeat tests, 156 passed / 76 skipped targeted suite, and 18/18 canary premerge smokes passing.

@loopx-agent
loopx-agent merged commit 535e4af into main Nov 23, 2026
40 of 51 checks passed
@loopx-agent
loopx-agent deleted the codex/c1-bound-resume-wake-20261122 branch November 23, 2026 08:23
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