Skip to content

実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する - #2754

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-2742-cold-restart-resume-candidate-discovery
Sep 25, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-2742-cold-restart-resume-candidate-discovery

Conversation

@squne121

@squne121 squne121 commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

cold restart 時の resume candidate discovery(scripts/task-context/task_context_cold_restart_startup.py)が持っていた 2 系統の production defect を解消する(Issue #2570 の runtime acceptance fact-check で発見された follow-up)。

  1. discover_resume_candidates() の DB query が runtime_health = 'ACTIVE' のみをフィルタしていたため、記録済み herdr_locator が現在 live な pane に存在しない ACTIVE Binding は、候補が単に無い場合と区別できない形で黙って drop されていた(false green)。本 PR で unresolved_target として明示的に discovery 結果へ残すようにした。
  2. 同じフィルタのため RESTORING のまま停止した stale Binding が discovery 対象から永久に除外され、ACTIVE -> RESTORING commit -> ACK 前に停止 -> 再度 cold restart という中断シナリオで orphan RESTORING 状態が解消されなかった。本 PR で RESTORING も discovery 対象に含めるようにした。Contract Reconciliation(2026-09-25、PR 実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する #2754 OWNER レビュー、issuecomment-5828693174): 既存の guarded primitive mark_restore_blocked_if_pending()(task_context_resume_dispatcher.py、変更なし)のガード条件(runtime_health == "RESTORING" AND execution_run.ended_at IS NULL)は「pending restore がまだ ACK されていない」ことしか確認できず、対応する pane/process が実際に死んでいることの証明にはならない(Herdr の live handoff 中の正常な RESTORING でも同じ DB state になり得るため)。この guard 成立を staleness の証明として扱い自動的に RESTORE_BLOCKED へ収束させる設計は、生存中の pane を誤って RESTORE_BLOCKED にしてしまうリスクがあると判明したため、安全側に単純化した。discover_resume_candidates() は mark_restore_blocked_if_pending() を一切呼び出さず、RESTORING の Binding は常に DB state を変更せず unresolved_target(restoring_not_provably_stale)として報告する。

同一 herdr_locator を複数の ACTIVE Binding が claim している場合(runtime_locations は UNIQUE(binding_id) WHERE released_at IS NULL のみを保証し locator 自体の Binding 間 uniqueness は保証しない)も、いずれか1件を恣意的に選ばず全 claimant を unresolved_target として報告し dispatch しない挙動にした。

run_startup_orchestrator() の any_failed 判定も、dispatch_status != "restored" の場合すべてを失敗として扱うよう修正した(従来は not_dispatched を失敗扱いしない false green 経路があった)。

AC対応

  • AC1(locator mismatch -> unresolved_target + any_failed=true): test_locator_mismatch_binding_reported_as_unresolved_target_and_any_failed_true — PASS
  • AC2(RESTORING の Binding は常に unresolved_target として報告し DB state を変更しない): mark_restore_blocked_if_pending() の guard 成立を staleness の証明として扱わない(Contract Reconciliation 2026-09-25)。RESTORING の Binding は常に unresolved_target(restoring_not_provably_stale)として報告され、discover_resume_candidates() は当該 Binding の DB state を一切変更しない。同一シナリオを2回連続で実行しても結果・DB state が変化しない(idempotent)ことを含めて test_restoring_binding_always_reported_as_unresolved_target_without_db_mutation で検証する — PASS
  • AC3(既存正常系の回帰なし): test_given_active_binding_dispatched_and_acked_when_orchestrating_then_reported_restored_and_no_failure を含む full suite — PASS
  • AC4(同一 pane への複数 ACTIVE claim -> 全件 unresolved_target): test_duplicate_binding_claims_on_same_live_pane_are_all_unresolved_and_not_dispatched — PASS

task_context_resume_dispatcher.py は import/call のみで、state machine・guard 条件は一切変更していない(Issue Stop Conditions 遵守)。

Checks

uv run pytest tests/task-context/test_cold_restart_startup.py::test_locator_mismatch_binding_reported_as_unresolved_target_and_any_failed_true -v
uv run pytest tests/task-context/test_cold_restart_startup.py::test_restoring_binding_always_reported_as_unresolved_target_without_db_mutation -v
uv run pytest tests/task-context/test_cold_restart_startup.py -v
uv run pytest tests/task-context/test_cold_restart_startup.py::test_duplicate_binding_claims_on_same_live_pane_are_all_unresolved_and_not_dispatched -v

すべて PASS(test_cold_restart_startup.py 全体は 13/13 PASS)。加えて tests/task-context/ 全体も PASS しており、既存 primitive(task_context_resume_dispatcher.py / task_context_service.py)への回帰がないことを確認した。ruff check scripts/task-context/task_context_cold_restart_startup.py は 0 issues。

Allowed Paths 遵守: scripts/task-context/task_context_cold_restart_startup.py / tests/task-context/test_cold_restart_startup.py / docs/dev/task-context.md の3ファイルのみ変更。

Runtime Verification Applicability

Schema Change Applicability

  • decision: not_schema_change
  • reason: DB スキーマ(tab_bindings / runtime_locations / execution_runs)自体は変更していない。discover_resume_candidates() の戻り値型を list[tuple] から dict へ拡張したが、このモジュール内部の呼び出し元(run_startup_orchestrator()、同 PR で追従済み)以外に consumer は存在しない(他ファイルからの import 呼び出しなし)。

Schema Consumer Inventory

N/A
reason: 上記 Schema Change Applicability の通り、外部 consumer が存在しない内部戻り値型の拡張のため。

Safety Claim Matrix

N/A
reason: 変更対象パス(scripts/task-context/, tests/task-context/, docs/dev/)は safety-sensitive パターン(transport / permission / sandbox / auth / mcp / .claude/skills/ / .github/workflows/)に該当しない。

Notes

  • task_context_resume_dispatcher.py は import/call のみで一切変更していない(Stop Conditions 遵守)。
  • docs/dev/task-context.md の discovery 成果物チェーン図(旧 1006-1018 行目付近)を新しい分類語彙(restored / unresolved_target。restore_blocked は常に空で将来の独立した liveness 機構のために予約)・RESTORING を常に unresolved_target として扱い DB state を変更しない設計・duplicate-pane conflict 処理に合わせて更新した。
  • Contract Reconciliation(2026-09-25、PR 実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する #2754 OWNER レビュー、issuecomment-5828693174): 当初案は mark_restore_blocked_if_pending() の guard 成立を stale RESTORING の証明として扱い RESTORE_BLOCKED へ自動収束させる設計だったが、その guard は「pending restore が未 ACK」であることしか確認できず、live Herdr handoff 中の正常な RESTORING でも同じ条件が成立し得るため、生存中の pane を誤って RESTORE_BLOCKED にするリスクがあると判明した。安全側に単純化し、RESTORING の Binding は常に unresolved_target として報告し DB state を変更しない設計に変更した。真の stale-RESTORING 自動収束には独立した liveness 機構(世代カウンタや pid liveness check 等)が必要であり、これは本 PR のスコープ外として別途 follow-up で扱う。
  • Related issue: Closes 実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する #2742
  • 実装は Claude Code(claude-sonnet-5)による自動化エージェントが行いました。🤖 Generated with Claude Code
IMPLEMENTATION_SCOPE_COVERAGE_V1:
  schema_version: "IMPLEMENTATION_SCOPE_COVERAGE_V1"
  issue_number: 2742
  issue_body_sha256: "sha256:6b6080ca6cbc54b01a8ee65c764f8ed8ca6a810f90158ee3a5e0e395aeae2d2d"
  normalized_scope_manifest_sha256: "sha256:3c847081d0b2998738fe3b2bf647109ecc4aa6d34af1edfe544a2c7faffca120"
  pr_head_sha: "c8cc6e23c3ab3571d5d9f6aabd8c5b10940cda3d"
  scope_manifest: {"acceptance_criteria": ["(a) mark_restore_blocked_if_pending() のguard条件が成立する(staleと確定できる)場合: 再度の discovery呼び出しが当該Bindingを検出し、guarded transitionにより RESTORE_BLOCKED へ収束させ、重複resume commandを発行しない。同一シナリオを2回連続で実行してもDB状態・結果が変化しない(idempotent)ことを示す", "(b) guard条件が成立しない(staleと確定できない。例: 対応する execution_run がまだ ended_at IS NULL でない、または既にACKにより解消済み)場合: DB stateを変更せず、当該Bindingを unresolved_target として報告し、any_failed=true になることを示す", "ACTIVE -> RESTORING commit -> ACK前停止 -> 再cold restart のシナリオで、以下の2通り(両方とも AC2 の VC で検証する)をそれぞれテストで示す", "locatorが live_pane_ids に含まれない ACTIVE Binding について、discover_resume_candidates()(またはその戻り値を消費する run_startup_orchestrator() の結果)が、当該Bindingを binding_id / session_id / 理由を伴う unresolved_target エントリとして結果に残し、resume commandを発行せず、any_failed=true かつ main() の戻り値(プロセス終了コード相当)が非0になることをテストで示す", "同一 live pane(同一 herdr_locator)を2件以上の ACTIVE Binding が claim している場合、discoveryがいずれか1件を選ばず、該当する全Bindingを unresolved_target として報告し、いずれもdispatchしないことをテストで示す", "既存の正常系(locator一致・ACTIVE Binding が発見されdispatchされ、restored として報告されるケース)が回帰しないことをテストで示す"], "allowed_paths": ["docs/dev/task-context.md", "scripts/task-context/task_context_cold_restart_startup.py", "tests/task-context/test_cold_restart_startup.py"], "change_kind": "code", "goal_ref": "cold restart時のresume candidate discoveryでlocator不一致candidate lossとorphan RESTORING状態を解消する", "in_scope": ["discover_resume_candidates() において、DB上 runtime_health='ACTIVE' かつ current_claude_session_id IS NOT NULL のBindingのうち、記録済み herdr_locator が現在の live_pane_ids に含まれないケースを unresolved_target として区別可能な形で返すようにする(戻り値型の拡張、または追加のresult entryとして返す)", "discover_resume_candidates() の DB query が runtime_health='ACTIVE' のみをフィルタしているために、ACTIVE -> RESTORING commit -> launch/SessionStart ACK前に停止 -> 再度cold restart という中断シナリオで stale RESTORING Binding が永久に取り残される問題を修正する。具体的には、RESTORING のBindingも discovery対象に含め、該当Bindingについて既存の mark_restore_blocked_if_pending(binding_id, execution_run_id)(task_context_resume_dispatcher.py、変更しない)を呼び出し、guarded transitionが成立すれば restore_blocked として結果に残し、成立しなければ(staleと確定できない)DB stateを変更せず unresolved_target として結果に残す", "discovery結果・summary出力の分類語彙を、Issue #2570 の結果語彙(restored / expected_skip_suspended / restore_blocked / unresolved_target)に合わせる", "docs/dev/task-context.md の該当記述(1006-1018行目付近の成果物チェーン図。現状は「ACTIVE かつ ... herdr_locator が現在live な pane として存在するものを列挙」とのみ記載しており、上記の新しい分類・stale RESTORING収束経路・duplicate-pane conflict処理を反映していない)を実装内容に合わせて更新する", "run_startup_orchestrator() の any_failed 判定を、新しい discovery分類(unresolved_target / restore_blocked を含む)に対応させ、unresolved_target および restore_blocked を含む結果は any_failed=true として扱う(現状は dispatch_status not in (\"restored\", \"not_dispatched\") のみを失敗とみなし、not_dispatched はfalse green経路になっている)。main() の exit code (return 1 if summary[\"any_failed\"] else 0) はこの修正後の any_failed をそのまま使用する(main() 自体の変更は不要)", "上記に対応する tests/task-context/test_cold_restart_startup.py のテストケース追加", "同一 live pane(同一 herdr_locator)を複数の Binding が claim している場合、discovery時点で該当する全Bindingを unresolved_target として扱い、いずれもdispatchしない(runtime_locations は UNIQUE(binding_id) WHERE released_at IS NULL のみを保証し、herdr_locator 自体のBinding間uniquenessは保証しないため、schema変更なしにアプリケーション側で検出する)"], "schema_version": "IMPLEMENTATION_SCOPE_MANIFEST_V1"}

…e loss と orphan RESTORING を解消 (#2742)

discover_resume_candidates() を拡張し、次を discovery 結果へ明示的に残す:
- AC1: 記録済み herdr_locator が現在 live な pane に存在しない ACTIVE
  Binding を unresolved_target として報告する(従来は候補なしと区別
  できない形で黙って drop していた false green)。
- AC2: RESTORING の Binding も discovery 対象に含め、既存の guarded
  primitive mark_restore_blocked_if_pending()(task_context_resume_
  dispatcher.py、変更なし)へ staleness 判定を委譲する。guard 成立時は
  restore_blocked へ収束(冪等)、不成立時は DB を変更せず
  unresolved_target として報告する。
- AC3: 既存の正常系(locator一致 ACTIVE Binding の dispatch/restored)
  が回帰しないことを新規テストで確認。
- AC4: 同一 herdr_locator を複数の ACTIVE Binding が claim している
  場合、いずれか1件を選ばず全 claimant を unresolved_target として
  報告し dispatch しない。

run_startup_orchestrator() の any_failed 判定を "restored" 以外を全て
失敗として扱うよう修正し、既存の not_dispatched false green を解消。

docs/dev/task-context.md の discovery 成果物チェーン図を新しい分類語彙
(restored / restore_blocked / unresolved_target)と stale RESTORING
収束経路・duplicate-pane conflict 処理を反映して更新。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2754 closed).

@squne121

Copy link
Copy Markdown
Owner Author

結論

PR #2754 は現 head 7c389e9bac74a0096c0a354c4b9d87e3e277d897 に対して REQUEST_CHANGES 相当です。

CI は ci / Check Japanese Content / check-hook-integrity / agent-session-manifest / deploy-pages まで全て success、変更パスも #2742 の Allowed Paths 内、既存レビューthreadもありません。locator mismatch の false green 解消と duplicate ACTIVE claim の処理は妥当です。

ただし AC2 の中心である「RESTORING が本当に stale か」の判定が成立していません。これはテスト不足ではなく、本番状態遷移を誤る production correctness blocker です。

Findings

優先度 | Finding | 影響 -- | -- | -- P1 / blocker | mark_restore_blocked_if_pending() を「staleを証明するprimitive」と誤解している | 正常に進行中の restore を RESTORE_BLOCKED に落とせる P2 | AC2テストが「process が死んだ」という証拠を一切作らず RESTORING を stale と仮定している | P1を検出するどころか誤った仕様を固定している P2 | expected_skip_suspended と any_failed の語彙が #2570 契約と十分整合していない | 将来その状態をsummaryへ載せると expected skip まで failure になる P2 / hardening | JOIN runtime_locations のため current location 行自体が欠けた ACTIVE/RESTORING は依然 silent drop | 同系統の false green が残る

P1: mark_restore_blocked_if_pending() は stale detector ではない

PR の核心はここです。

scripts/task-context/task_context_cold_restart_startup.py:224

WHERE tb.runtime_health IN ('ACTIVE', 'RESTORING')

そして全 RESTORING に対し、同ファイル 287–290行付近で、

_task_id, _activity_id, execution_run_id = ...guard_applied = dispatcher.mark_restore_blocked_if_pending(    binding_id, execution_run_id)

を無条件に呼んでいます。

しかし既存 primitive の実装を見ると、task_context_resume_dispatcher.py:343-378 が検証しているのは実質、

Binding がまだ RESTORING
AND
old execution_run がまだ ended_at IS NULL

だけです。成立するとその場で RESTORE_BLOCKED にします。

この条件は 「staleである証拠」ではありません。むしろ正常な、

ACTIVE
→ prepare_managed_resume()
→ RESTORING
→ launch済み / ACK待ち

の最中も完全に同じ状態です。

既存 primitive のdocstring自体も、これは late launch failure / timeout が ACK と競合したとき「まだ同じ pending restore なら failure を適用してよいか」を確認するための guard と説明しています。pendingness の確認であって liveness/staleness の確認ではありません。

SQLite の BEGIN IMMEDIATE が保証するのも、即座にwrite transactionを取得して競合するwriterとの原子性を確保することです。「この restore process は死んだ」という時間的・外部runtime的事実は何も証明しません。SQLite

そして Herdr 側では、この区別が実際に必要です。Herdr 0.9.1 の live handoff は pane process を生存させ得ます。さらに [[startup]] hook は通常startupだけでなく、live handoffで新serverがtake overした際にも再実行されます。GitHub

したがって次が成立します。

restore が正当に進行中
Binding = RESTORING
old run.ended_at = NULL
    ↓ live handoff

pane/process は生存
[[startup]] が再発火

    ↓ PR #2754

mark_restore_blocked_if_pending()
↓
RESTORE_BLOCKED

これは #2742 本文に明記されている、

staleと確定できない場合(例: Herdr live handoff等でpane processが生存している可能性を排除できない場合)はDB stateを変更しない

という Outcome と直接矛盾します。

さらに #2742 の anchor review issuecomment-5827586250 も、まさに 「RESTORING を無条件でstale扱いしてはいけない」 と指摘しています。refinement時にその指摘を契約へ取り込んだのに、実装段階で guard succeeded == stale proved と読み替えてしまっています。

テストも同じ誤りを固定しています

tests/task-context/test_cold_restart_startup.py:373 の

test_stale_restoring_binding_converges_to_restore_blocked_idempotently

では、394行付近で、

decision = dispatcher.prepare_managed_resume("stale-s1")

として RESTORING にしたあと、process death、cold restart generation、handoff/non-handoff、lease expiry、timeout等の stale 証拠を一切追加せず、直ちに次の discovery を実行しています。

つまりテストが実際に証明しているのは、

RESTORING + old run open なら RESTORE_BLOCKED にできる

だけです。

一方、454行以降の not_provably_stale テストは「ACKがちょうど競合して先にACTIVEになったケース」しか扱っていません。まだRESTORINGのままだが process は生きているケースがありません。Herdr live handoff がまさにそのケースです。

修正方針

ここは #2752 に先送りすべき問題ではありません。#2752 は明示的に ACTIVE Binding の duplicate resume を扱っています。今回の blocker は RESTORING Bindingを誤ってRESTORE_BLOCKEDへ落とす問題で、#2742 AC2そのものです。

個人趣味開発として複雑なdaemon・lease・distributed coordinatorを増やす必要はありません。ただし、現状の情報だけでは、

RESTORING + ended_at IS NULL

から「dead restore」を識別できません。

したがって実装可能性を再評価して、少なくとも次のどちらかが必要です。

A. #2742のAllowed Paths内で利用できる既存情報から
「このstartupは確実にprocess-lossを伴うcold restart」
と証明できる条件を見つけ、その場合だけguardを呼ぶ

B. それが存在しないなら #2742 Stop Condition:
「既存 mark_restore_blocked_if_pending() のguardだけでは
AC2 staleness判定に不十分」
に該当すると判断する

現在のコードのように primitive の意味を拡張解釈してStop Conditionを回避するのは不可です。

その他の指摘

any_failed を line 412 で

entry["dispatch_status"] != "restored"

にした点は unresolved_target / restore_blocked の false green を塞ぐ目的には有効です。ただ、#2742 は #2570 の語彙として expected_skip_suspended も明記しています。現在は SUSPENDED を discovery から完全に除外するため表面化していませんが、「restored以外は全部failure」という文書・実装では expected_skip_suspended を正常な expected outcome として表現できません。#2570 は cold-restart対象を restored / expected_skip_suspended / restore_blocked / unresolved_target の4区分で追跡する契約です。ここは最低でも success/failure semantics を明文化しておいた方がよいです。

また、query が runtime_locations への inner JOIN なので、ACTIVE/RESTORING Binding が存在しても unreleased location 行自体が無い場合、そのBindingは結果集合から消えます。通常writerがその状態を作らない設計なら直ちにblockerとはしませんが、「candidate lossをsilent successにしない」今回の目的からすると、LEFT JOIN + missing_runtime_location -> unresolved_target の方がfail-closedです。

現 head に対する判定

locator mismatch、duplicate ACTIVE locator、summaryへの unresolved_target 伝播、正常ACTIVE restoreの回帰テストは良い変更です。CIも全て通っています。

ただし AC2(a)/(b) の境界そのものが誤っているため、14/14 test PASS と 537 tests PASS はこのblockerを否定する証拠になりません。むしろ現在のAC2 unit testが誤ったstaleness定義をエンコードしています。

推奨 disposition は REQUEST_CHANGES。最優先 fix_delta は「mark_restore_blocked_if_pending() 成立 = stale proved という前提を撤回し、live handoff中の未ACK RESTORINGを状態変更しない回帰ケースを追加する」です。

PR #2754 自体は mergeable=true ですが、現 head のままのマージは勧めません。

## 結論

PR #2754 は現 head 7c389e9bac74a0096c0a354c4b9d87e3e277d897 に対して REQUEST_CHANGES 相当です。

CI は ci / Check Japanese Content / check-hook-integrity / agent-session-manifest / deploy-pages まで全て success、変更パスも #2742 の Allowed Paths 内、既存レビューthreadもありません。locator mismatch の false green 解消と duplicate ACTIVE claim の処理は妥当です。

ただし AC2 の中心である「RESTORING が本当に stale か」の判定が成立していません。これはテスト不足ではなく、本番状態遷移を誤る production correctness blocker です。

Findings

優先度 Finding 影響
P1 / blocker mark_restore_blocked_if_pending() を「staleを証明するprimitive」と誤解している 正常に進行中の restore を RESTORE_BLOCKED に落とせる
P2 AC2テストが「process が死んだ」という証拠を一切作らず RESTORING を stale と仮定している P1を検出するどころか誤った仕様を固定している
P2 expected_skip_suspended と any_failed の語彙が #2570 契約と十分整合していない 将来その状態をsummaryへ載せると expected skip まで failure になる
P2 / hardening JOIN runtime_locations のため current location 行自体が欠けた ACTIVE/RESTORING は依然 silent drop 同系統の false green が残る

P1: mark_restore_blocked_if_pending() は stale detector ではない

PR の核心はここです。

scripts/task-context/task_context_cold_restart_startup.py:224

WHERE tb.runtime_health IN ('ACTIVE', 'RESTORING')

そして全 RESTORING に対し、同ファイル 287–290行付近で、

_task_id, _activity_id, execution_run_id = ...
guard_applied = dispatcher.mark_restore_blocked_if_pending(
    binding_id, execution_run_id
)

を無条件に呼んでいます。

しかし既存 primitive の実装を見ると、task_context_resume_dispatcher.py:343-378 が検証しているのは実質、

Binding がまだ RESTORING
AND
old execution_run がまだ ended_at IS NULL

だけです。成立するとその場で RESTORE_BLOCKED にします。

この条件は 「staleである証拠」ではありません。むしろ正常な、

ACTIVE
→ prepare_managed_resume()
→ RESTORING
→ launch済み / ACK待ち

の最中も完全に同じ状態です。

既存 primitive のdocstring自体も、これは late launch failure / timeout が ACK と競合したとき「まだ同じ pending restore なら failure を適用してよいか」を確認するための guard と説明しています。pendingness の確認であって liveness/staleness の確認ではありません。

SQLite の BEGIN IMMEDIATE が保証するのも、即座にwrite transactionを取得して競合するwriterとの原子性を確保することです。「この restore process は死んだ」という時間的・外部runtime的事実は何も証明しません。:chatgpt-content-reference{index="0"}

そして Herdr 側では、この区別が実際に必要です。Herdr 0.9.1 の live handoff は pane process を生存させ得ます。さらに [[startup]] hook は通常startupだけでなく、live handoffで新serverがtake overした際にも再実行されます。:chatgpt-content-reference{index="1"}

したがって次が成立します。

restore が正当に進行中
Binding = RESTORING
old run.ended_at = NULL

        ↓ live handoff

pane/process は生存
[[startup]] が再発火

        ↓ PR #2754

mark_restore_blocked_if_pending()
        ↓
RESTORE_BLOCKED

これは #2742 本文に明記されている、

staleと確定できない場合(例: Herdr live handoff等でpane processが生存している可能性を排除できない場合)はDB stateを変更しない

という Outcome と直接矛盾します。

さらに #2742 の anchor review issuecomment-5827586250 も、まさに 「RESTORING を無条件でstale扱いしてはいけない」 と指摘しています。refinement時にその指摘を契約へ取り込んだのに、実装段階で guard succeeded == stale proved と読み替えてしまっています。

テストも同じ誤りを固定しています

tests/task-context/test_cold_restart_startup.py:373 の

test_stale_restoring_binding_converges_to_restore_blocked_idempotently

では、394行付近で、

decision = dispatcher.prepare_managed_resume("stale-s1")

として RESTORING にしたあと、process death、cold restart generation、handoff/non-handoff、lease expiry、timeout等の stale 証拠を一切追加せず、直ちに次の discovery を実行しています。

つまりテストが実際に証明しているのは、

RESTORING + old run open なら RESTORE_BLOCKED にできる

だけです。

一方、454行以降の not_provably_stale テストは「ACKがちょうど競合して先にACTIVEになったケース」しか扱っていません。まだRESTORINGのままだが process は生きているケースがありません。Herdr live handoff がまさにそのケースです。

修正方針

ここは #2752 に先送りすべき問題ではありません。#2752 は明示的に ACTIVE Binding の duplicate resume を扱っています。今回の blocker は RESTORING Bindingを誤ってRESTORE_BLOCKEDへ落とす問題で、#2742 AC2そのものです。

個人趣味開発として複雑なdaemon・lease・distributed coordinatorを増やす必要はありません。ただし、現状の情報だけでは、

RESTORING + ended_at IS NULL

から「dead restore」を識別できません。

したがって実装可能性を再評価して、少なくとも次のどちらかが必要です。

A. #2742のAllowed Paths内で利用できる既存情報から
   「このstartupは確実にprocess-lossを伴うcold restart」
   と証明できる条件を見つけ、その場合だけguardを呼ぶ

B. それが存在しないなら #2742 Stop Condition:
   「既存 mark_restore_blocked_if_pending() のguardだけでは
    AC2 staleness判定に不十分」
   に該当すると判断する

現在のコードのように primitive の意味を拡張解釈してStop Conditionを回避するのは不可です。

その他の指摘

any_failed を line 412 で

entry["dispatch_status"] != "restored"

にした点は unresolved_target / restore_blocked の false green を塞ぐ目的には有効です。ただ、#2742 は #2570 の語彙として expected_skip_suspended も明記しています。現在は SUSPENDED を discovery から完全に除外するため表面化していませんが、「restored以外は全部failure」という文書・実装では expected_skip_suspended を正常な expected outcome として表現できません。#2570 は cold-restart対象を restored / expected_skip_suspended / restore_blocked / unresolved_target の4区分で追跡する契約です。ここは最低でも success/failure semantics を明文化しておいた方がよいです。

また、query が runtime_locations への inner JOIN なので、ACTIVE/RESTORING Binding が存在しても unreleased location 行自体が無い場合、そのBindingは結果集合から消えます。通常writerがその状態を作らない設計なら直ちにblockerとはしませんが、「candidate lossをsilent successにしない」今回の目的からすると、LEFT JOIN + missing_runtime_location -> unresolved_target の方がfail-closedです。

現 head に対する判定

locator mismatch、duplicate ACTIVE locator、summaryへの unresolved_target 伝播、正常ACTIVE restoreの回帰テストは良い変更です。CIも全て通っています。

ただし AC2(a)/(b) の境界そのものが誤っているため、14/14 test PASS と 537 tests PASS はこのblockerを否定する証拠になりません。むしろ現在のAC2 unit testが誤ったstaleness定義をエンコードしています。

推奨 disposition は REQUEST_CHANGES。最優先 fix_delta は「mark_restore_blocked_if_pending() 成立 = stale proved という前提を撤回し、live handoff中の未ACK RESTORINGを状態変更しない回帰ケースを追加する」です。

PR #2754 自体は mergeable=true ですが、現 head のままのマージは勧めません。

@squne121

Copy link
Copy Markdown
Owner Author

推奨は、PR #2754 をそのまま修正ループへ戻すのではなく、最初の1ステップで AC2 の実装可能性を再判定させてから impl-review-loop を継続です。

現 head はレビュー対象と同じ 7c389e9bac74a0096c0a354c4b9d87e3e277d897 のままです。最大の問題はレビュー指摘どおり、mark_restore_blocked_if_pending() が証明するのは pending/race 条件であって staleness ではないことです。Herdr 公式仕様でも [[startup]] は live handoff 後に再実行され、成功した handoff では pane process 自体が生存します。したがって単に「startup が再発火した」「RESTORING で旧 run が open」という条件から process loss を導くことはできません。:chatgpt-content-reference{index="0"}

さらに、現在の dedicated-session scope gate は「対象Herdr sessionか」を絞るものではありますが、「通常cold restartか live handoffか」を区別する証拠にはなっていません。公式に公開されている startup hook 環境にも、少なくとも文書化された handoff/restart reason はありません。:chatgpt-content-reference{index="1"}

なので Claude Code には、まず既存情報だけで安全な stale proof が作れるか調査させ、作れない場合は #2742 の明示的 Stop Condition に該当したものとして、誤ったACを実装で捻じ曲げず contract を安全側へ修復してからループを再開させるのがよいです。expected_skip_suspended の成功意味論と runtime_locations INNER JOIN による silent drop も、同じPR内で低コストに直せるなら一緒に処理させます。

再発防止については重複を検索し、直接対応する既存Issueがなかったため #2755 を起票済みです。
実装: review loops で既存 primitive の guard 成立を未保証の semantic proof へ誤昇格しない
#2755

以下を、すでに auto mode で起動している対話的 Claude Code にそのまま投入してください。

PR #2754 を、以下の OWNER review comment を必須 fix_delta として扱い、.claude/skills/impl-review-loop に従って実装・テスト・レビューを再開してください。

Target PR:
#2754

Authoritative OWNER review / fix_delta:
#2754 (comment)

Linked Issue:
#2742

再発防止 follow-up はすでに起票済みです。重複起票しないでください:
#2755

目的は PR #2754 を human merge の直前、すなわち impl-review-loop の draft_pr_ready / APPROVE 相当まで自律的に収束させることです。
マージそのもの、auto-merge、有効化済みIssueの勝手なcloseは行わないでください。

人間への承認確認は不要です。
通常の implementation / test / review / commit / push / PR更新 / review feedback 修正は自律的に継続してください。

最重要 fix_delta

OWNER review の全 Finding を読み、特に以下を必須 blocker として扱ってください。

  1. mark_restore_blocked_if_pending() の成功を RESTORING の staleness proof と解釈してはいけない。
    この primitive が実際に保証している predicate を implementation / docstring / tests から再確認すること。

  2. 現在の
    RESTORING && old execution_run.ended_at IS NULL
    は process death / cold restart / non-handoff の証拠ではない。
    live handoff 中の正常な restore でも成立し得る。

  3. test_stale_restoring_binding_converges_to_restore_blocked_idempotently は、名前やコメントではなく causal evidence を再評価すること。
    process loss 等の stale 証拠を何も作らず RESTORING にしただけなら、そのテストを AC2 stale proof として扱わない。

  4. RESTORING のまま process/pane が生存している live-handoff 相当の regression case を必ず追加し、そのケースで discovery が DB state を RESTORE_BLOCKED に変更しないことを検証する。

Step 0: AC2 semantic feasibility preflight

通常の implementation worker に修正を始めさせる前に、独立した SubAgent を1つ使い、以下だけを調査してください。

SubAgent の完了を必ず待ち、その構造化結果を読んでから次へ進んでください。
SubAgent 自身には nested SubAgent を起動させないでください。

判定は二択です。

A. #2742 の Allowed Paths 内かつ既存データだけで、
「この RESTORING は live handoff 中ではなく、旧 restore process が失われた」
と安全に証明できる documented condition が存在する。

→ その condition を明示し、その場合だけ guarded RESTORE_BLOCKED transition を実行してください。
→ live-handoff / not-provably-stale case は mutation しない regression test を追加してください。

B. そのような stale proof が存在しない。

→ mark_restore_blocked_if_pending() の意味を拡張解釈して AC2 を通過させてはいけません。
→ #2742 の既存 Stop Condition
「mark_restore_blocked_if_pending() の既存guard条件だけでは AC2 の staleness 判定に不十分」
が実際に成立したものとして扱ってください。

ただし今回は、この Stop Condition を理由に人間へ承認確認して停止しないでください。
このプロンプトを OWNER の明示的 continuation authority として扱い、top-level control plane で次を順番に行ってください。

Issue contract を修復した場合も、locator mismatch / duplicate ACTIVE claim / false-green elimination 等、PR #2754 にすでにある独立して有効な変更は捨てないでください。

P2 findings

P1 解消後、OWNER review の以下も評価してください。

  • expected_skip_suspended は 検証: Task Context v1統合runtime acceptanceをNative/Claude-GPT/Herdrで実証する #2570 の expected-success vocabulary であり、将来 summary に出現しても failure 扱いしない success/failure semantics にする。
  • runtime_locations の INNER JOIN によって current RuntimeLocation 自体が欠けた ACTIVE/RESTORING Binding が silent drop される経路を確認する。
    同じ false-green class を Allowed Paths 内の小変更で塞げるなら LEFT JOIN + explicit unresolved_target と regression test を実装する。
  • これらを採用しない場合は「なぜ今回の contract / scope では不要か」を pr-reviewer が検証可能な evidence として残す。単に後回しとは書かない。

impl-review-loop 実行

semantic feasibility / 必要なら contract recovery が終わったら .claude/skills/impl-review-loop を正本として通常ループへ入ってください。

SubAgent を使用してください。

  • implementation-worker: fix_delta の実装
  • test-runner: current HEAD の VC / regression test の独立検証
  • pr-reviewer: current HEAD に対する独立レビュー

各 SubAgent の作業完了を必ず待ってください。
前の SubAgent の出力を受け取る前に、その結果を前提に次工程を進めないでください。
SubAgent 自身の nested delegation は行わせないでください。

レビューで REQUEST_CHANGES が出た場合は、人間へ聞かず blocker を次 iteration の fix_delta として implementation-worker に戻してください。

current PR head が更新されたら、必ず新しい head SHA に対して tests / CI / review を再評価してください。
過去 head の APPROVE や PASS を流用しないでください。

検証要件

最低限、以下を current final head で確認してください。

  • target OWNER review の P1 が消えている
  • live-handoff 相当で未ACK RESTORING の state を誤って RESTORE_BLOCKED にしない
  • locator mismatch が silent success にならない
  • duplicate ACTIVE locator claimant を恣意的に dispatch しない
  • missing current RuntimeLocation の扱いを明示的に評価済み
  • restored / expected_skip_suspended / restore_blocked / unresolved_target の success/failure semantics が一貫している
  • existing normal ACTIVE restore が回帰していない
  • 実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する #2742 の live Allowed Paths を遵守
  • targeted tests
  • tests/task-context/ relevant suite
  • lint/static checks
  • current-head required CI
  • current-head pr-reviewer verdict

テスト名やコメントではなく、fixture が実際に作っている causal state をレビューしてください。

GitHub follow-up

再発防止Issue #2755 はすでに存在します。重複作成しないでください。

今回の調査で #2755 とは別の、実際の product/runtime gap
「safe な stale RESTORING discriminator が存在しない」
を別Issueへ分離する必要が確定した場合のみ、先に GitHub Issues を検索して dedupe し、narrow issue を起票してください。

その際は:

停止条件

通常の review finding、CI failure、test failure、fixable implementation defect、contract snapshot warning、max-iteration 到達だけを理由に承認待ち停止しないでください。

impl-review-loop の1 run が max_iterations に到達しても、fix_delta が明確かつ安全に継続可能なら current PR を対象に新しい continuation run を開始してください。

停止して人間へ報告するのは次の場合だけです。

  • actual Git conflict を自律解消すると user change を壊す可能性が高い
  • secret / credential の開示が必要
  • destructive operation が必要
  • semantic contract recovery を行っても mutually inconsistent な要求しか残らず、安全な target state を定義できない

完了条件

最終 current head に対して:

  • implementation complete
  • required tests PASS
  • required CI PASS
  • pr-reviewer APPROVE
  • blockers == []
  • mergeability が skill 契約上の merge-ready 条件を満たす

まで進め、IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready 相当で終了してください。

PR はマージしないでください。

最後に concise な run report を出してください。

このプロンプトでは、**「Stop Condition を無視して実装を強行」ではなく、「Stop Condition が実際に成立したら contract を自律修復してから再開」**にしています。今回のレビュー内容では、この経路の方が false green を増やさず、かつ人間承認待ちにもなりにくいです。

squne121 and others added 2 commits September 25, 2026 16:55
PR #2754 に対するOWNERレビュー(issuecomment-5828693174)を受けたIssue
#2742のContract Reconciliationに基づき、mark_restore_blocked_if_pending()
のguard成立をstalenessの証明として扱いRESTORE_BLOCKEDへ自動遷移する設計
から、RESTORINGのBindingは常にunresolved_targetとして報告しDB stateを
変更しない設計に変更する。guard条件はACK待ち未完了の確認に過ぎず、live
handoff中の正常なRESTORINGでも同じ条件が成立するため、guard成立をstale
確定の根拠にしてはならない。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121
squne121 marked this pull request as ready for review September 25, 2026 08:40
@squne121
squne121 merged commit e3ee04c into main Sep 25, 2026
28 checks passed
@squne121
squne121 deleted the worktree-issue-2742-cold-restart-resume-candidate-discovery branch September 25, 2026 09:51
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.

実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する

1 participant