Repository navigation
Shorten heartbeat wakes for a bound Codex session - #9251
Conversation
Signed-off-by: LoopX Agent <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
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 边界)。
关键代码讲解
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。_verified_codex_resume与handle_heartbeat_prompt_command
CLI 在收到--resume-codex-session-id后并不信任调用方传入值,而是强制校验证书式条件(--thin、非--bootstrap、存在--turn-instance-id、generic_cliprofile、visible_goal_host is None)并用FirstPartyHostGoalAdmission+select_codex_cli_session重新读取本地绑定,确认session_id精确匹配且非operation_transport会话后才返回True。_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*.py272 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.
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
Validation
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.