Skip to content

fix(benchmark): retire stale pending turn after frozen task_postcondition replay failure - #9603

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/fix-turn-frozen-validation-retry-spin-20261130
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/fix-turn-frozen-validation-retry-spin-20261130

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Retire stale benchmark-pending-turn.json after frozen task_postcondition replay failure (benchmark/runtime/worker.py):
    • When a first Turn wake fails task_postcondition (host_invoked=True), worker.py preserves pending["resume_turn_key"] so the next wake resumes the failed Turn cleanly.
    • On the resumed wake (had_resume_key == True), if reinvoke_host is False (effects.host_invoked is False) and task_postcondition still fails (result_kind == "validation_failed", validation_stage == "task_postcondition", validation.status == "failed"), worker.py now unlinks benchmark-pending-turn.json and records receipt["pending_turn_retired_reason"] = "frozen_task_postcondition_failed" instead of re-persisting the same resume_turn_key in an infinite no-Host replay spin.
    • Preserves first-failure resume_turn_key retention cleanly against origin/main.
  • Tests (benchmark/tests/test_worker_phase_budget.py, benchmark/tests/test_sforge_turn.py):
    • Verified end-to-end across 3 wakes: Wake 1 (host_invoked=True) fails task_postcondition and writes benchmark-pending-turn.json; Wake 2 (host_invoked=False) sees frozen task_postcondition fail, unlinks pending file, and records pending_turn_retired_reason="frozen_task_postcondition_failed"; Wake 3 allocates a fresh turn_instance_id, invokes Codex, and commits.

Verification

  • uv run --extra test ruff check ...: passed
  • uv run --extra test python -m pytest -vv benchmark/tests/test_worker_phase_budget.py benchmark/tests/test_sforge_turn.py benchmark/tests/test_shared_codex_runtime.py benchmark/tests/test_task_entry.py: non-sforge tests passed (including live test_turn_retires_frozen_task_postcondition_failed_pending_turn; test_sforge_turn.py skipped locally without sforge/harbor)
  • uv run loopx ... check --scan-path ...: clean (0 errors, 0 warnings across all 3 files)
  • uv run loopx --format json canary premerge --from-git-diff --git-diff-base origin/main: direct checks 5/5 passed, catalog_canaries 9/9 passed (0 failures; manual_review_required hold due to benchmark_sensitive surface)

…tion replay failure

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

无头调度器在 C1 Turn 模式下通过 benchmark-pending-turn.json 跨唤醒恢复尚未完成结算的 Turn。受影响主体是在无头 C1 Turn 模式下运行定时唤醒、并在 benchmark-pending-turn.json 中记录恢复键的外部 benchmark worker。

在变更前的场景中,当首次唤醒(host_invoked=true)因工作区未满足独立验证条件而在 task_postcondition 阶段失败时,worker.py 会写出 benchmark-pending-turn.json(含 resume_turn_key)。在下一次唤醒以 --resume-turn-key --retry-failed-turn 重试时,如果宿主无需重跑(effects.host_invoked=false)而工作区冻结状态下 task_postcondition 依然失败,worker.py 仍再次写入相同的 resume_turn_key,导致后续所有唤醒陷入无限无宿主重放死循环。本 PR 的可观测改进是:在恢复执行(had_resume_key 为真)且结果仍为 validation_failed / validation_stage=task_postcondition / effects.host_invoked=false / validation.status=failed 时,worker.py 立即删除过期的 benchmark-pending-turn.json 并记录 pending_turn_retired_reason='frozen_task_postcondition_failed',使下一轮能够重新分配新的 turn_instance_id 并唤醒宿主继续推进。本 PR 明确保留首次失败(had_resume_key 为假)时写入 benchmark-pending-turn.json 的行为,不干预非 task_postcondition 失败或 host_invoked 为真的正常恢复路径。

改动思路 / Approach

worker.py (execution.mode == "turn" and stage == "execute", head f4ac2f0c4362)
  |--> had_resume_key = bool(pending.get("resume_turn_key")) (在覆写前捕获)
  |--> 若 receipt["ok"] == True --> unlink pending_path
  |--> 否则若 had_resume_key && validation_failed && task_postcondition
  |      && effects.host_invoked is False && validation.status == "failed"
  |      --> pending_path.unlink(missing_ok=True)
  |      --> receipt["pending_turn_retired_reason"] = "frozen_task_postcondition_failed"
  |--> 否则若 result.get("resume_turn_key") --> 保留写入 pending["resume_turn_key"](含首次失败)

图示为基于 exact head 源码整理的说明性控制流图,非独立执行或渲染测试证据。

核心架构取舍在于仅在 benchmark/runtime/worker.py 的 Turn 执行收尾分支增加窄条件 frozen_postcondition_failed,避免触碰控制面 Turn journal 或与并行分支上的其他 pre-dispatch 退休条件冲突,保持与 origin/main 的独立最小可合入边界。当前 PR 边界严格限定在 benchmark/runtime/worker.py 对冻结 task_postcondition 复审失败后 pending-turn 指针的退休及其测试覆盖,不改变控制面 Turn 恢复语义或首次失败挂起行为。

具体改动 / Changes

关键代码讲解

  1. benchmark/runtime/worker.py (main Turn execute 收尾分支):在 pending["resume_turn_key"] 被覆盖之前采样 had_resume_key = bool(pending.get("resume_turn_key")),并校验 result_kind == "validation_failed"、validation_stage == "task_postcondition"、effects.get("host_invoked") is False 及 validation.get("status") == "failed" 四项前置条件全部成立时 unlink pending_path 并记录 pending_turn_retired_reason = "frozen_task_postcondition_failed"。首次失败时 had_resume_key 为 False,仍按原有路径写入 resume_turn_key。
  2. benchmark/tests/test_worker_phase_budget.py (test_turn_retires_frozen_task_postcondition_failed_pending_turn) & benchmark/tests/test_sforge_turn.py:通过真实 worker_command --once 与真实 SQLite Goal 端到端验证三轮唤醒流程:Wake 1 写标并首次 task_postcondition 失败(保留 resume_turn_key);Wake 2 在 host_invoked=False 下冻结重验仍失败,安全清理 benchmark-pending-turn.json 并标记 frozen_task_postcondition_failed;Wake 3 分配新 turn_instance_id、重新拉起 Codex 推进并成功提交。

按当前 exact head 对照需求:首次失败保留恢复键(implemented)、二次无宿主冻结 task_postcondition 失败退休 pending 文件并记入 receipt(implemented)、三轮唤醒重新推进提交(implemented)。

对主干的风险 / Risks

  • 误退休本可重放成功或宿主未结算的恢复指针风险:条件要求 had_resume_key 为真(绝不拦截首次失败恢复)、effects.host_invoked is False(未产生新宿主副作用)、validation_stage == "task_postcondition" 且 validation.status == "failed"(区别于瞬态 inconclusive/unavailable 或超时)。因此只有确定陷入冻结无宿主复验死循环的指针会被退休。
  • 验证边界与环境说明:本地 test_worker_phase_budget.py、test_shared_codex_runtime.py、test_task_entry.py 共 216 项全部 PASS(含真实 CLI + SQLite 三轮唤醒实测 test_turn_retires_frozen_task_postcondition_failed_pending_turn);test_sforge_turn.py 因本地未安装 sforge/harbor 跳过(133 skipped)。因修改触及 benchmark/runtime/worker.py,canary premerge 按策略提示 benchmark_sensitive manual hold(9/9 catalog canaries 与 5/5 direct checks 均通过,0 failures)。

我的整体评价 / Verdict

长期运行稳定性(long_horizon)显著改善(improved):消除无头 worker 在冻结 task_postcondition 复验失败时的无限重放死循环;用户体验(user_experience)保持无回归(preserved),visual_review 为 not_applicable(仅涉及 worker 运行时,无前端渲染改动,unverified_scope: none)。兼容与架构决策为 retain,代码体积 necessary(仅 +13 行生产代码),语义词表影响为 not_applicable,作用域隔离严格限制在 had_resume_key 且 host_invoked is False 的冻结 task_postcondition 失败。exact head f4ac2f0c4362c4cc13a049ee4bbb0f839af33842 本地验证全部 PASS。

English verdict: APPROVE — exact head f4ac2f0 cleanly retires stale benchmark-pending-turn.json after a resumed no-host frozen task_postcondition failure in benchmark/runtime/worker.py (+13 prod LOC) while preserving first-failure resume_turn_key, verified by a real 3-wake SQLite worker test (216 passed, 133 sforge/harbor-gated skipped, canary premerge 0 failures).

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

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

通过外部 worker 执行带独立产物校验的 LoopX Turn 的 benchmark 操作者。 首次 task_postcondition 拒绝后,worker 按恢复键重试。持续失败且产物保持不变时,worker 会反复重验同一候选。 候选在第二次无宿主校验失败后删除恢复指针。下一次唤醒遵循当前准入启动新 Turn。 范围是Turn execute 收尾的 13 行生产逻辑及两组测试。 单次失败后仍有机会修复原产物,worker 需要保留这条同轮提交路径。

改动思路 / Approach

产品 Turn journal 和独立校验决定原轮能否结算。benchmark worker 持有调度指针与试验锁,并回读产品结果。 当前代码在已有恢复键、validation_failed、task_postcondition、host_invoked=false 和 validation.status=failed 同时出现时删除指针。候选的三次唤醒测试通过。产物未修复时,第二次移除指针,第三次新宿主更新产物并提交。若在首次失败后、第二次唤醒前修复,候选仍会用原 Turn 提交且不调用宿主。 这与已有同头评审的正例一致。 已有评审

具体改动 / Changes

关键代码讲解

  • pending_turn 保存原 instance 和验证命令摘要。turn_command 用恢复键定位原 journal。 待处理指针 原轮命令
  • run_once 在 Turn 执行收尾删除指针,并写入 frozen_task_postcondition_failed。原 journal 仍然保留原 Turn 的身份和校验失败结果。 退休条件
  • original-turn-revalidation 要求用原 Host 结果重验,产物修复后继续原结算。对持续失败可以限制重试。本 PR 的分支先撤掉了 worker 的原轮入口。规范修订为 811c1a1。 原轮重验合同

对主干的风险 / Risks

[P2] 第二次校验失败后,仍可继续的原轮失去自动恢复。 第二次校验失败只表明当时的验证拒绝,条件没有检查原轮是否还能在产物修复后继续结算。 以相同 worker CLI、验证命令和 SQLite fixture 跑对照,只在第二次失败后补齐原产物。主干按相同 instance 和 Turn key 提交,未调用宿主。候选已移除指针,第三次开启新轮,宿主将已达标的值从 2 改到 3,随后被同一校验器拒绝。 让恢复 owner 明确返回原轮可终止或不可重验的事实后再退休指针。若需限制重复失败,用有界暂停或适用的明确冻结策略,同时保留原恢复身份。 复跑应同时覆盖一直失败、第二次唤醒前修复、以及第二次失败后才修复。 worker 分支 三次唤醒测试

语义与 CI 对齐

本地测试 216 通过、133 跳过。Premerge 9 项选中、5 项直接检查无失败,保留 benchmark_sensitive 人工审阅。 未启动正式试验、在线 Codex、SForge/Harbor 或远端 CI。合成宿主是实际子进程,产品 CLI 与 SQLite 真实运行。

我的整体评价 / Verdict

REQUEST_CHANGES。 已验证能打断产物持续不变时的复验循环。先保留第二次校验失败后仍可恢复的原轮,并为持续失败设定明确退出条件。

English verdict: REQUEST_CHANGES at f4ac2f0. A second no-Host validation failure can still be repaired and settled under the original Turn. The candidate deletes its worker pointer, reinvokes the Host and fails a workspace that the same validator would have accepted on replay.

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