Repository navigation
fix(benchmark): retire stale pending turn after frozen task_postcondition replay failure - #9603
loopx-agent wants to merge 1 commit into
Conversation
…tion replay failure Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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)
动机 / 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
关键代码讲解
- benchmark/runtime/worker.py (
mainTurn 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"四项前置条件全部成立时 unlinkpending_path并记录pending_turn_retired_reason = "frozen_task_postcondition_failed"。首次失败时had_resume_key为False,仍按原有路径写入resume_turn_key。 - 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_sensitivemanual 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
left a comment
There was a problem hiding this comment.
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.
Summary
benchmark-pending-turn.jsonafter frozentask_postconditionreplay failure (benchmark/runtime/worker.py):task_postcondition(host_invoked=True),worker.pypreservespending["resume_turn_key"]so the next wake resumes the failed Turn cleanly.had_resume_key == True), ifreinvoke_hostisFalse(effects.host_invoked is False) andtask_postconditionstill fails (result_kind == "validation_failed",validation_stage == "task_postcondition",validation.status == "failed"),worker.pynow unlinksbenchmark-pending-turn.jsonand recordsreceipt["pending_turn_retired_reason"] = "frozen_task_postcondition_failed"instead of re-persisting the sameresume_turn_keyin an infinite no-Host replay spin.resume_turn_keyretention cleanly againstorigin/main.benchmark/tests/test_worker_phase_budget.py,benchmark/tests/test_sforge_turn.py):host_invoked=True) failstask_postconditionand writesbenchmark-pending-turn.json; Wake 2 (host_invoked=False) sees frozentask_postconditionfail, unlinks pending file, and recordspending_turn_retired_reason="frozen_task_postcondition_failed"; Wake 3 allocates a freshturn_instance_id, invokes Codex, and commits.Verification
uv run --extra test ruff check ...: passeduv 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 livetest_turn_retires_frozen_task_postcondition_failed_pending_turn;test_sforge_turn.pyskipped locally withoutsforge/harbor)uv run loopx ... check --scan-path ...: clean (0errors,0warnings across all 3 files)uv run loopx --format json canary premerge --from-git-diff --git-diff-base origin/main: direct checks5/5passed,catalog_canaries9/9passed (0failures;manual_review_requiredhold due tobenchmark_sensitivesurface)