Skip to content

fix(benchmark): verify WarmStart donor registry seal before applying yardstick overrides - #9259

Closed
loopx-agent wants to merge 1 commit into
codex/wire-benchmark-h1-h2-opt-in-20261122from
codex/fix-warm-start-yardstick-seal-20261122
Closed

loopx-agent wants to merge 1 commit into
codex/wire-benchmark-h1-h2-opt-in-20261122from
codex/fix-warm-start-yardstick-seal-20261122

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Fix WarmStart + --[no-]execution-yardstick-enabled registry-seal crash in benchmark/runtime/sforge.py where _apply_warm_start_yardstick() mutated registry.json before _warm_command("context") -> verify_restored_loopx_state checked sha256(registry.read_bytes()) == state["registry_sha256"].
  • Keep loopx/hosts/research_checkpoint.py:verify_restored_loopx_state strict: never weaken pre-restore registry_sha256 seal verification.
  • Add verify_yardstick: bool = True to BenchmarkCodex._verify_phase_configuration in benchmark/runtime/harbor.py so pre-context read-only checks (including native_child_limit read-before-write) preserve registry.json until _warm_command("context") binds the verified native fork, after which _apply_warm_start_yardstick() and full _verify_phase_configuration() run cleanly.
  • Verified subsequent admit_warm_session readback (fresh_replan / codex_checkpoint.py:868) and Wake-2 CodexAgentSession(context="resume") preserve goal_ref / session binding without re-checking donor registry_sha256.

Verification (stacked on codex/wire-benchmark-h1-h2-opt-in-20261122)

  • ruff check: clean across all 4 modified files
  • git diff --check: clean
  • Non-mocked test_full_loopx_checkpoint_restore.py + test_shared_codex_runtime.py + test_checkpoint_restore_capture.py: 250 passed, 4 skipped (4 explicit native binary / loopback skips)
  • Full test_sforge_warm_start.py: 93 passed
  • loopx check (4 files): errors=0, warnings=0, public boundary clean
  • loopx canary premerge --from-git-diff --git-diff-base origin/codex/wire-benchmark-h1-h2-opt-in-20261122: direct_checks 5/5 passed, catalog_canaries 9/9 passed, failures=0 (manual_review_required due to benchmark_sensitive surface)

…yardstick overrides

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 · Gemini · Google · self_reported

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

动机 / Motivation

在 SForge WarmStart(基于检查点恢复继续执行)实验路径下通过 --execution-yardstick-enabled 或 --no-execution-yardstick-enabled 覆盖 donor 检查点默认 yardstick 开关的基准测试操作者与运行时启动链路(SForgeWorker.format_run_cmd)。

在基准分支(#9221)上,启动 WarmStart 并显式切换 --[no-]execution-yardstick-enabled 时,启动流程先运行配置写入修改 registry.json,随后在上下文恢复阶段触发密封摘要校验失败;本 PR 将配置覆写移到上下文恢复与密封校验之后执行,使切换生效的同时继续拦截任何上下文前篡改。

此前当 WarmStart 试图切换 Goal 的 yardstick_enabled(与 donor 检查点不一致)时,format_run_cmd 会在 _warm_command("context") 之前调用 _apply_warm_start_yardstick(),先执行 configure-goal --execute 修改还原后的 registry.json,导致紧随其后的 verify_restored_loopx_state(比对 sha256(registry.read_bytes()) == state["registry_sha256"])必然抛出 ValueError("restored LoopX registry differs from its sealed source") 并阻塞所有 WarmStart 覆盖组实验。

已验证:WarmStart 上下文前不再改写 registry.json,verify_restored_loopx_state 严格针对未改动的 donor registry_sha256 执行一次摘要校验,通过后再执行 --[no-]execution-yardstick-enabled 写入与最终完整回读校验;若 native_child_limit 不匹配则在写任务文档和恢复上下文之前即被拒绝,后续 fresh_replan 与 resume 多轮唤醒不受影响。

不放宽 verify_restored_loopx_state 对 registry_sha256 的字节级一致校验,不调整 cold-Start 分支调用顺序,也不修改 Goal 绑定、租约状态机或控制面默认配置。

改动思路 / Approach

flowchart TD
  W[WarmStart phase=1] --> C1{native_child_limit != None?}
  C1 -- yes --> V1[_verify_phase_configuration<br/>verify_explore=False, verify_yardstick=False]
  V1 --> D[_write_task_document]
  C1 -- no --> D
  D --> V2[_verify_phase_configuration<br/>verify_explore=False, verify_yardstick=False]
  V2 --> CTX[_warm_command: context<br/>verify_restored_loopx_state SHA-256]
  CTX -- tamper / hash mismatch --> FAIL[ValueError before any override]
  CTX -- seal OK & fork bound --> YST[_apply_warm_start_yardstick<br/>configure-goal --execute]
  YST --> V3[_verify_phase_configuration<br/>verify_yardstick=True, verify_explore per profile]
Loading

说明:以上流程图依据审查时点 9259@8c2c2233f6a9a06a88ff7830b96749b23780fd40 的 benchmark/runtime/sforge.py 与 benchmark/runtime/harbor.py 源码整理(说明性示意,非运行时捕获;本地已在简化 stub 环境下跳过视觉渲染校验)。

  • 入口与阶段拆分:在 SForgeWorker.format_run_cmd(benchmark/runtime/sforge.py)的 self.warm_start is not None 分支,将配置验证拆分为“上下文恢复前(只读校验基本配置、不检查也未改写 yardstick_enabled)”与“上下文恢复后(执行 _apply_warm_start_yardstick() 并执行全量 _verify_phase_configuration)”两段。
  • 不变量归属与现有契约复用:复用 loopx/hosts/research_checkpoint.py 的 verify_restored_loopx_state 字节级 SHA-256 校验以及 loopx/hosts/codex_checkpoint.py 的 admit_native_checkpoint_session 准入流程,不修改内核密封逻辑,也不向 registry.json 或 state.json 新增任何字段。
  • 多轮唤醒(Wake-2 / fresh_replan)兼容性:经审阅 admit_native_checkpoint_session(codex_checkpoint.py:854-928)及 checkpoint_session_refresh.py:61 -> sforge_warm_start.py:429,Wake-1 绑定 verified fork 后,Wake-2 及其后 prepare_session_refresh 仅校验 existing、checkpoint_artifact_sha256、goal_ref 与 session_profile_digest;configure-goal --[no-]execution-yardstick-enabled --execute 不改变这些身份摘要,因此多轮恢复可正常通过(已由非 mock SQLite/File 控制面集成测试实测验证)。
  • 比例与边界判断:保持 research_checkpoint.py 密封不变量唯一且不放宽,仅在 BenchmarkCodex._verify_phase_configuration 增加默认开启的 verify_yardstick=True 参数并在 SForgeWorker.format_run_cmd 重排阶段顺序;相比在密封校验中白名单忽略字段或新增状态标志,该边界改动最小、纯局部且完全可逆。仅限 benchmark/runtime/sforge.py WarmStart 首相编排与 benchmark/runtime/harbor.py 回读参数门控,连同非 mock 的 File/SQLite 恢复测试与 SForge 顺序单元测试构成完整可独立评审闭环。

具体改动 / Changes

精确 diff(1155193f658b..8c2c2233f6a9)共 4 个文件,+280 / -18 行,全部集中于基准运行期接线与对应非 mock 测试:

文件 变更行数 角色
benchmark/runtime/harbor.py +2 / -1 为 BenchmarkCodex._verify_phase_configuration 增加 verify_yardstick: bool = True
benchmark/runtime/sforge.py +17 / -17 调整 SForgeWorker.format_run_cmd warm_start 分支中 Yardstick 写入与上下文密封校验顺序
benchmark/tests/test_shared_codex_runtime.py +153 / -0 新增 SForge WarmStart 阶段顺序与密封失败中止回归测试
tests/control_plane/test_full_loopx_checkpoint_restore.py +108 / -0 新增真实 File/SQLite 后端前篡改拒绝与后覆写多轮唤醒测试

关键代码讲解

  1. BenchmarkCodex._verify_phase_configuration(benchmark/runtime/harbor.py#L645-L688)
    新增可选布尔参数 verify_yardstick: bool = True(默认维持 True 保证既有调用零漂移),仅在第 669 行 yardstick_enabled 回读断言门控上受其约束;native_child_limit、replan cadence 与(当 verify_explore=True 时的)Explore 配置检查均不受该开关跳过。
  2. SForgeWorker.format_run_cmd(benchmark/runtime/sforge.py#L618-L660)
    在 self.warm_start is not None 分支保留前置 native_child_limit 检查(verify_explore=False, verify_yardstick=False)于 _write_task_document 之前,确保非法子代理上限在触碰任何磁盘状态前拒绝;随后只读校验 verify_yardstick=False,立即调用 self._warm_command("context") 完成 registry_sha256 密封校验与 verified fork 绑定;最后才调用 self.runtime._apply_warm_start_yardstick(...) 与全量 _verify_phase_configuration(..., verify_explore=self.profile == "heartbeat-explore")(verify_yardstick=True)。warm_start is None(cold Start)分支第 636–650 行保持完全未改动。
  3. test_sforge_warm_start_verifies_sealed_registry_before_yardstick_toggle(benchmark/tests/test_shared_codex_runtime.py#L2380-L2530)
    参数化覆盖 (yardstick=False, native_child_limit=None)、(True, None) 与 (False, 3) 三组组合及密封校验异常注入场景,验证 warm:context 严格先于 apply_yardstick,且预检失败时不会触碰 _apply_warm_start_yardstick。
  4. test_pre_verify_yardstick_mutation_fails_restored_seal & test_post_verify_yardstick_toggle_preserves_multi_wake_and_warm_readback(tests/control_plane/test_full_loopx_checkpoint_restore.py)
    在真实 File 与 SQLite 持久化后端上直接驱动 verify_restored_loopx_state、admit_warm_session、CodexAgentSession(context="resume") 与 prepare_session_refresh,实证上下文前篡改必被拒绝,而上下文后 True -> False 覆写可通过全部多轮唤醒检查。

规范对照(spec_basis):no_spec(spec_source = "none")。本仓库并无专门针对 SForgeWorker.format_run_cmd WarmStart 参数阶段顺序的独立书面规范或 RFC 条款(docs/architecture/rfcs/target-yardstick-stride-decisions-v0.md 仅约定 execution_profile.yardstick_enabled 本身的配置拥有者);本评审基于既有的 verify_restored_loopx_state 字节级密封约束与 #9221 目标覆写需求进行交付评估。

对主干的风险 / Risks

  • 阻断性发现:无阻塞发现(no blocking finding)。
  • 负向与逃逸路径分析:
    • 上下文前篡改 Yardstick 或客观字段:即使前检阶段传入 verify_yardstick=False 跳过对 yardstick_enabled 值的即时比对,后续 _warm_command("context") 仍会读取完整 registry.json 并执行 verify_restored_loopx_state(比对全文件 SHA-256),因此任何未授权的 pre-context 改动都会抛出 ValueError("restored LoopX registry differs from its sealed source"),并在调用 _apply_warm_start_yardstick 前中止。
    • native_child_limit 冲突先于文档与恢复:当 native_child_limit is not None 时,首选检查仍在 _write_task_document 与 _warm_command("context") 之前,非法子代理权限立即失败且不落盘修改 registry.json。
    • Default-off / 局部隔离与权限边界:verify_yardstick 默认值为 True,cold-Start 分支及控制面原有调用路径行为与基线完全一致;新增参数仅作为内部运行时方法关键字存在,未暴露到外部 CLI/Schema/多智能体权限契约,无 authority_semantics 或控制面作用域外扩问题。
    • scope_fit 边界:变更直接覆盖 SForgeWorker.format_run_cmd 生产调用路径及 BenchmarkCodex._verify_phase_configuration(warm_start is not None)。
    • 残留非阻断说明(预存外部基线):本地安装 sforge 缺失的 .venv 中 benchmark/tests/test_edgebench_prompts.py 在 base(1155193f658b)与 head(8c2c2233f6a9)均表现为 32 passed, 46 skipped;若在含 sforge 环境下运行该测试,已知 test_edgebench_prompts.py#L211-L213 构造了缺少 _verify_phase_configuration 的 SimpleNamespace stub,会在与本 PR 无关的 sforge.py#L648 cold-Explore 分支预存失败(由 #9221 继承,本 PR 未改动该分支)。
  • 本地验证与对照实验矩阵(wait_for_ci: false,远程 CI 未作为前置等待门禁):
检查项 范围与条件 状态 观察结果
tests/control_plane/test_full_loopx_checkpoint_restore.py + test_checkpoint_restore_capture.py 本地真实 File & SQLite 控制面恢复(-rs) PASS 41 passed, 1 skipped(151.67s;1 个跳过为 line 154 Requires explicit real native Host;新增前篡改拒绝与后切换多轮唤醒用例全部实测通过)
benchmark/tests/test_shared_codex_runtime.py + test_sforge_warm_start.py .venv 运行时与 WarmStart 单元测试(-rs) PASS 206 passed, 99 skipped(70.72s;99 skips 为缺失可选 harbor/sforge 包的 importorskip 与 3 个显式原生 Codex 二进制跳过)
独立反事实对照(真实 SForgeWorker.format_run_cmd + BenchmarkCodex + loopx.cli.main) 在不依赖已安装 harbor/sforge 包的轻量宿主存根下,对 1155193f65(Base)与 8c2c2233f6(Head)并行实测 6 个场景 PASS Base:4 组 WarmStart yardstick 覆写均在 warm:context 抛出 restored LoopX registry differs from its sealed source(因 apply_yardstick 先改 registry.json);Head:4 组覆写(含 heartbeat-explore、heartbeat-resume、native_child_limit=3 与双向切换)全部通过且 warm:context 严格先于 apply_yardstick、final_yardstick == target;pre-context 篡改在 warm:context 被拦截且未触发 apply_yardstick;native_child_limit 冲突在写文档前拒绝且 reg_unchanged=true
benchmark/tests/test_edgebench_prompts.py Base (1155193f65) 与 Head (8c2c2233f6) 对比 PASS 两者均为 32 passed, 46 skipped(0.43s / 0.40s,No module named 'sforge')
ruff check / loopx check / mypy / tsc 4 个改动文件及 17 个内核 strict 模块 + TS 控制面 PASS ruff 0 错;loopx check errors=0, warnings=0;mypy 0 错;typecheck:control-plane 0 错
loopx canary premerge --git-diff-base 1155193f658b88384a9e93a8468d53c334373c7d PASS direct_checks 5/5、catalog_canaries 9/9、failures=0(策略状态为 manual_review_required,属 benchmark_sensitive 常规人工复核)
  • 最缺失的残留验证(非阻断):在未安装外部私有 harbor/sforge 套件的 .venv 中,原生 importorskip("sforge") 下的 test_sforge_warm_start_verifies_sealed_registry_before_yardstick_toggle 被跳过,虽然已通过独立真实 SForgeWorker + loopx.cli.main 反事实对照与真实控制面 File/SQLite 恢复测试弥补,仍建议在集成真实 sforge + 容器端到端环境下确认首轮 WarmStart 切换日志与 checkpoint-context.json 一并产出。

我的整体评价 / Verdict

  • 长程与用户体验评估(outcome_impact):long_horizon = improved——修复了 WarmStart 带 --[no-]execution-yardstick-enabled 覆写启动即挂死的阻断问题,且通过后置写入保持多轮 resume / fresh_replan 连续性;user_experience = preserved——对外 CLI 参数、默认回读严格性与错误信息完全维持原有体验,无额外人工步骤。
  • 视觉审查(visual_review):本 PR 仅涉及 Python 基准测试运行时编排与验证参数调整,不涉及任何前端界面、DOM 组件或可视化渲染输出。(unverified_scope: none)。
  • 语义与变更约束定位:本 PR stays local,完全复用现有 yardstick_enabled、verify_restored_loopx_state 与 _verify_phase_configuration 词汇,不修改共享契约、不新增配置表项或控制面状态。
  • 可观测语义与代码体量:通过 Base/Head 同夹具反事实对照,8c2c2233f6 精准消除了 apply_yardstick 先于 warm:context 导致的密封误杀,同时保留篡改拦截与权限前置拒绝;仅引入 +2 / -1 与 +17 / -17 生产代码调整与聚焦测试,code_volume = necessary、compatibility_assessment = retain、change_proportionality = proportionate、default_off_isolation = isolated、authority_semantics = not_applicable。
  • Exact-Head Freshness & Verdict:复核远程精准头 9259@8c2c2233f6a9a06a88ff7830b96749b23780fd40(基于 codex/wire-benchmark-h1-h2-opt-in-20261122 @ 1155193f658b88384a9e93a8468d53c334373c7d)保持未合并、无未解决线程。

English Verdict: APPROVE — Cleanly preserves strict registry_sha256 sealing before verified context admission while unblocking post-context --[no-]execution-yardstick-enabled overrides and preserving multi-wake session continuity at 9259@8c2c2233f6a9a06a88ff7830b96749b23780fd40.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Closing per Plan A PR subtraction (Steward 85a78d5c21dc): stacked atop #9221 (_apply_warm_start_yardstick is absent from origin/main) as we converge on Explore Graph + unconditional Default Stride Policy. Remote branch kept intact for read-only reference.

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