Skip to content

実装: Herdr live handoff 後の startup hook 再発火で ACTIVE Binding を重複resumeしない - #2764

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-2752-live-handoff-duplicate-resume
Sep 25, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-2752-live-handoff-duplicate-resume

Conversation

@squne121

@squne121 squne121 commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Herdr live handoff 後の [[startup]] hook 再発火で、生存中の ACTIVE Task Context Binding へ duplicate resume/launch を送らないようにする(Issue #2742 が Out of Scope として切り出した「ACTIVE + live handoff」経路の follow-up、Issue #2752)。

scripts/task-context/task_context_cold_restart_startup.py の discover_resume_candidates() に、locator が live_pane_ids に存在する ACTIVE Binding 向けの tri-state pane-process liveness classification(PROVEN_ALIVE / PROVEN_ABSENT / UNKNOWN)を追加した。

fix_delta(OWNER review、issuecomment-5832937110)反映後の現在の判定:

  • PROVEN_ALIVE: 対象の Task Context Binding/session への causal identity evidence が確立できる場合に限る。herdr pane process-info は pane の現在の foreground job を返すだけで、それが「この Binding/session が最後に起動した runtime process」であることを保証しない。現状の Herdr 0.9.1 primitive だけではこの evidence を確立できないため、この経路は実質的に到達しない(将来 identity-bound evidence を追加する場合は別 Issue の scope)。tri-state 語彙と live_runtime_preserved result bucket 自体は変更せず維持する。
  • PROVEN_ABSENT(pane process-info が成功し、有効な shell_pid を anchor として bare-shell-only を明確に示す): 既存の candidates 経路のまま、dispatch 直前の second probe(下記)を経て exactly-once resume 対象。
  • UNKNOWN(呼び出し失敗・空・unparseable・platform 非対応・identity ambiguous・shell_pid 欠落/無効・shell 以外の foreground process/group id は観測されたが causal identity evidence を伴わない): unresolved_target(reason: liveness_unresolved)として fail-closed に扱い、any_failed = true。

discovery SQL は INNER JOIN から LEFT JOIN へ変更し、runtime_locations の current row が欠けた ACTIVE/RESTORING Binding を missing_current_runtime_location として明示的に unresolved_target へ追加した(従来の silent drop を解消)。

dispatch 直前の second probe(P2-a、TOCTOU 低減): run_startup_orchestrator() は discovery で PROVEN_ABSENT と分類された各候補について、prepare_managed_resume()(ACTIVE→RESTORING の最初の DB mutation)を呼ぶ直前に同一 pane へもう一度 _classify_pane_process_liveness() を実行する。再確認しても PROVEN_ABSENT のままの場合のみ dispatch へ進む。discovery〜dispatch の window で live handoff が発生していた場合は dispatch_status: "second_probe_no_longer_absent" として明示的に報告し、prepare_managed_resume() を一切呼ばない(DB mutation なし、silent drop なし)。SQLite/Herdr を跨ぐ lease/lock で完全 atomic 化することはせず(新規 daemon/lease/lock file 禁止)、この second probe と実際の dispatch の間に残る小さな race は documented residual risk として明記している。

liveness probe は prepare_managed_resume() の write_transaction(BEGIN IMMEDIATE)の外側、discovery phase(DB read-only 取得後・dispatch 前)で実行しており、既存の atomic ACTIVE→RESTORING 遷移には一切触れていない(task_context_resume_dispatcher.py は import/call のみ、本 fix_delta commit でも変更なし)。

実装時の fact-check: herdr pane process-info の呼び出し形(--pane <ID> フラグ、位置引数ではない)とレスポンス形状(result 直下ではなく result.process_info に1段ネスト、foreground_process_group_id フィールド名、foreground_processes は空の場合 Herdr 自身の skip_serializing_if により省略される)は、実装環境で実際に稼働中の Herdr 0.9.1 サーバへ read-only で発行して直接 fact-check した(docs/dev/task-context.md 追記箇所に実レスポンス例を引用)。

AC対応

  • AC1(Contract Correction 2026-09-25: Native live handoff → causal identity evidence がある場合のみ live_runtime_preserved、それ以外は unresolved_target/liveness_unresolved。現状の実装では後者が通常ケース): test_given_active_native_binding_with_non_shell_foreground_process_when_discovering_then_liveness_unresolved — PASS
  • AC2(Contract Correction 2026-09-25: Claude-GPT も AC1 と同じ基準): test_given_active_claude_gpt_binding_with_non_shell_foreground_process_when_discovering_then_liveness_unresolved(test_resume_dispatcher_state_machine.py) — PASS
  • AC3(cold restart 2ケース: locator not live → 既存 unresolved_target 維持/bare-shell-only → 既存 candidates 経路、second probe 経由): test_locator_mismatch_binding_reported_as_unresolved_target_and_any_failed_true + test_given_active_native_binding_with_live_pane_when_discovering_then_candidate_found + test_given_proven_absent_candidate_when_second_probe_confirms_absent_then_dispatched_once 等 — PASS
  • AC4(UNKNOWN → liveness_unresolved, any_failed=true。shell_pid 欠落/無効を含む): test_given_active_binding_with_failed_process_info_call_when_discovering_then_liveness_unresolved + _classify_pane_process_liveness 単体テスト群(test_classify_pane_process_liveness_missing_shell_pid_with_foreground_processes_is_unknown 等) — PASS
  • AC5(missing_current_runtime_location): test_active_binding_with_no_current_runtime_location_reported_as_missing_current_runtime_location / test_restoring_binding_with_no_current_runtime_location_also_reported_as_missing — PASS
  • AC6(既存 test suite 回帰なし): tests/task-context/ 全体 570 passed / 4 skipped(AC7 canary)/ 1 deselected(既存 claude_live marker) — PASS
  • AC7(Contract Correction 2026-09-25、観測範囲の是正: narrow Herdr canary、4 causal boundary。実行可能な環境でも各 canary が実際に観測する範囲を超えた表現をしない): 下記 Runtime Verification Applicability 参照 — SKIP(証跡あり、fabricated PASS にしない)。cold restart 2ケースはテスト docstring を discovery boundary(len(discovery["candidates"]) == 1)のみの観測に是正し、live handoff 2ケースは manual/runtime-unverified であることを明記した
  • AC8(heuristic identity 不使用。name/cwd は判定に使わず pid の同一性のみで判定する。ただし non-shell process の存在自体も causal identity evidence にはならないため PROVEN_ALIVE には使わない): test_classify_pane_process_liveness_ac8_* 系 — PASS
  • AC9(deterministic pytest での AC1-AC6, AC8 再現): 上記の通り test_cold_restart_startup.py / test_resume_dispatcher_state_machine.py に追加・更新 — PASS
  • P2-a(dispatch 直前 second probe、TOCTOU 低減): test_given_proven_absent_candidate_when_second_probe_finds_non_shell_process_then_not_dispatched / test_given_proven_absent_candidate_when_second_probe_confirms_absent_then_dispatched_once — PASS

Checks

uv run --locked pytest tests/task-context/test_cold_restart_startup.py -v
uv run --locked pytest tests/task-context/test_resume_dispatcher_state_machine.py -v
uv run --locked pytest tests/task-context/test_live_handoff_duplicate_resume_canary.py -v -k native_live_handoff
uv run --locked pytest tests/task-context/test_live_handoff_duplicate_resume_canary.py -v -k claude_gpt_live_handoff
uv run --locked pytest tests/task-context/test_live_handoff_duplicate_resume_canary.py -v -k native_cold_restart
uv run --locked pytest tests/task-context/test_live_handoff_duplicate_resume_canary.py -v -k claude_gpt_cold_restart

test_cold_restart_startup.py 37/37 PASS、test_resume_dispatcher_state_machine.py 10/10 PASS。canary 4テストはいずれも SKIP(下記 Runtime Verification Applicability 参照)。tests/task-context/ 全体 570 passed / 4 skipped / 1 deselected。ruff check / ruff format --check は本 PR で新規追加・変更した内容について 0 issues(既存1件の pre-existing E501 は未touch)。pnpm typecheck / pnpm lint / pnpm test(1939 tests)/ pnpm build / gemini model-routing pytest(24 tests)もすべて PASS。

Allowed Paths 遵守: scripts/task-context/task_context_cold_restart_startup.py / scripts/task-context/task_context_resume_dispatcher.py(変更なし、import/call のみ)/ tests/task-context/test_cold_restart_startup.py / tests/task-context/test_resume_dispatcher_state_machine.py / tests/task-context/test_live_handoff_duplicate_resume_canary.py / docs/dev/task-context.md の範囲内。

Runtime Verification Applicability

tests/task-context/test_live_handoff_duplicate_resume_canary.py の 4 テストは、実装時点でいずれも SKIP(exit 相当 77、fabricated PASS にしない、docs/dev/runtime-verification-policy.md SKIP 規約準拠)。理由:

  1. cold restart 2ケース: 実装 agent 自身のプロセスが、この機で実際に稼働中の "default" 名前付き Herdr session(他の複数の並行稼働中 agent pane を含む、実機で HERDR_SOCKET_PATH/herdr pane list により fact-check 済み)の 1 pane として動作していることを canary 自身の capability チェックで検出した。cold restart の検証には disposable session の server プロセスへの kill -9 を要するため、"default" session と同一ホスト・同一ユーザーアカウント・共有 global plugin-link state を持つ nested context からこれを実行すると "default" session への巻き添え被害リスクを負う。本モジュールの "Session scoping" 設計方針と PR 実装: Herdr cold restartでTask BindingとNative/Claude-GPT runtime flavorを自動復元する (#2569) #2731 Real Herdr canary の前例(人間/デフォルト Herdr session への影響を禁ずる hard invariant)に従い、安全側に倒して SKIP する。SKIP されない環境で実行された場合でも、この canary がアサートするのは discovery boundary(discovery["candidates"] がちょうど 1 件)のみであり、実際の dispatch/ACK/runtime profile 永続化までは検証しない(fix_delta P2-b、過大な表現を是正)。
  2. live handoff 2ケース: インストール済み Herdr 0.9.1 の CLI surface を実機 fact-check(herdr --help)した結果、live handoff のローカル trigger は herdr update --handoff(ネットワーク経由でバイナリ自体を更新)と herdr --remote <target> --handoff(SSH remote 必須)の2つのみであることが判明した。いずれも disposable かつ side-effect-free に自動テストから安全に起動できないため、無条件 SKIP する(manual/runtime-unverified)。

各 SKIP の理由・capability 検査結果は artifacts/runtime-verification-AC7-<boundary>-<timestamp>.log(gitignored)へ記録済み。herdr バイナリ + 認証済み native claude login が利用可能かつ canary プロセス自身が Herdr 管理下 pane の外(プレーンな非 Herdr shell)で実行される環境では、cold restart の2ケースは実 disposable session の bootstrap/kill-9/cold-restart/[[startup]] hook 発火観測/cleanup を実際に行う(PR #2731 の実証済みレシピを再利用)。live handoff の2ケースは、その環境であっても Herdr CLI surface 自体の制約により引き続き SKIP する。

AC1-AC6, AC8, AC9 は deterministic pytest で別途検証済みのため、AC7 の SKIP は全体 status を FAIL にしない一方、証跡なしの暗黙 PASS 扱いにもしていない(fallback_success_is_pass: false)。

Schema Change Applicability

  • decision: not_schema_change
  • reason: SQLite スキーマ(tab_bindings / runtime_locations / execution_runs)自体は変更していない。discover_resume_candidates() の戻り値 dict に live_runtime_preserved キーを追加したが、このモジュール内部の呼び出し元(同ファイルの run_startup_orchestrator()、同 PR で追従済み)以外に consumer は存在しない。本 fix_delta commit でも同様。

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 は Allowed Paths に含まれるが、本 PR(本 fix_delta commit を含む)では import/call のみで state machine・guard 条件は一切変更していない(Stop Conditions 遵守)。
  • docs/dev/task-context.md に tri-state liveness classification の新設セクションと、fix_delta で修正した causal identity evidence の定義、dispatch 直前の second probe(TOCTOU 低減、完全 atomic 化はしない設計判断)、AC7 narrow canary の観測範囲の是正を追記した。
  • fix_delta(OWNER review、issuecomment-5832937110)で解消した blocker:
    • P1: _classify_pane_process_liveness() が、causal identity evidence なしに「shell 以外の foreground process が1件でもある」「foreground_process_group_id が shell_pid と単に異なる」だけで PROVEN_ALIVE を返していた誤り、および shell_pid 欠落/無効時に誤って PROVEN_ALIVE/PROVEN_ABSENT へ倒れうる分岐を修正し、いずれも UNKNOWN にした。
    • P2-a: run_startup_orchestrator() の dispatch 直前に同一 pane への second probe を追加し、discovery〜dispatch 間の TOCTOU window で live handoff が発生していた場合に prepare_managed_resume() を呼ばず・DB mutation を発生させず・second_probe_no_longer_absent として明示的に報告するようにした。
    • P2-b: AC7 canary のテスト docstring・SKIP 理由・PR 本文の記述を実際の観測範囲(cold restart 2ケースは discovery boundary のみ、live handoff 2ケースは manual/runtime-unverified)に正確に合わせた。
    • P3: 本 PR body 末尾の IMPLEMENTATION_SCOPE_COVERAGE_V1 を最終 head(本 fix_delta commit)の SHA で再生成した。
  • pane process-info が本 Issue が想定する predicate(bare shell 以外の foreground process の有無で liveness を判定可能)を満たすかどうかは、実 Herdr 環境への read-only 呼び出しで直接 fact-check し、想定通り満たすことを確認した(Stop Condition 非該当)。ただし OWNER review により、その predicate だけでは causal identity evidence として不十分であることが判明したため、上記 P1 の通り判定を修正した。
  • Related issue: Closes 実装: Herdr live handoff 後の startup hook 再発火で ACTIVE Binding を重複resumeしない #2752
  • 実装は Claude Code(claude-sonnet-5)による自動化エージェントが行いました。🤖 Generated with Claude Code
IMPLEMENTATION_SCOPE_COVERAGE_V1:
  schema_version: "IMPLEMENTATION_SCOPE_COVERAGE_V1"
  issue_number: 2752
  issue_body_sha256: "sha256:424471f6677ba9f4f436ce2923511faf769d58bd7a5ce48bf8235529490a23c9"
  normalized_scope_manifest_sha256: "sha256:d579d3e23572fe9c734c1e263e988e2bba2b2b6a33dc9a269757bda34ed32d13"
  pr_head_sha: "83f62227cf206ee06396095a39bc5747bb52643b"
  scope_manifest: {"acceptance_criteria": ["#2742 の REASON_LOCATOR_NOT_LIVE / REASON_DUPLICATE_LOCATOR_CLAIM / RESTORING 未mutation semantics を回帰させない(既存 test suite が引き続き PASS する)。", "AC1(Contract Correction 2026-09-25): live handoff 相当の状態(同一 locator の pane が herdr pane list に存在し、pane process-info が parseable な foreground process を返す)で、ACTIVE Native Binding を startup hook が再発見しても resume/launch command を 0 件しか発行しない。observable な結果は、対象 Binding/session への causal identity evidence が確立できる場合のみ live_runtime_preserved、それ以外(現状の最小実装で想定される通常ケース)は unresolved_target(reason: liveness_unresolved、UNKNOWN 分類)である。いずれの場合も Binding は ACTIVE のまま identity(binding_id / session_id)を保持し、DB mutation は 0 件である。「shell とは別 PID の foreground process が存在するだけ」を根拠に live_runtime_preserved を返してはならない。", "AC2(Contract Correction 2026-09-25): 同条件で ACTIVE Claude-GPT Binding にも duplicate launch を発行しない。observable な結果は AC1 と同じ基準(live_runtime_preserved は causal identity evidence がある場合のみ、それ以外は unresolved_target / liveness_unresolved)に従う。", "AC7(Contract Correction 2026-09-25、観測範囲の是正):  narrow Herdr canary で以下4つの causal boundary を観測し、証跡を残す。常設の重い harness にはしない。実行可能な環境でも、各 canary が実際に観測している範囲を超えた表現(例:「exactly-one resume / runtime identity保持まで実証した」)を PR 本文・test 名で主張しない。", "ACTIVE/RESTORING Binding に対応する runtime_locations の current row が存在しない場合、discovery から silent に消えず、unresolved_target(reason: missing_current_runtime_location)として明示的に報告され、dispatch 0 件・DB mutation 0 件・any_failed = true になる。", "cold-restart / live-handoff の区別に cwd / pane 順序 / terminal title / process name 単独等の heuristic identity を使用しない(pane process-info の parseable な foreground process データ、または locator の live/absent のみを判定根拠にする)。", "deterministic unit/integration test(tests/task-context/test_cold_restart_startup.py, tests/task-context/test_resume_dispatcher_state_machine.py)で AC1-AC6, AC8 を再現する。", "pane process-info が失敗・空・unparseable・platform 非対応を返す ambiguous case は UNKNOWN に分類され、duplicate launch を行わず、unresolved_target(reason: liveness_unresolved)として any_failed = true で observable にする。false green を作らない。 加えて(Contract Correction 2026-09-25)、以下も UNKNOWN に分類し dispatch を行わない: (a) shell_pid が欠落または正の整数でない場合(foreground_process_group_id の有無を問わず)、(b) foreground_processes が省略され foreground_process_group_id のみが存在し、かつそれが shell_pid と一致しない場合、(c) non-shell foreground process は存在するが対象 Binding/session への causal identity evidence を伴わない場合(PROVEN_ALIVE の定義修正により、現状の最小実装ではこれが通常の帰結となる)。", "以下の2つの cold restart 関連ケースをそれぞれ正しく処理する。"], "allowed_paths": ["docs/dev/task-context.md", "scripts/task-context/task_context_cold_restart_startup.py", "scripts/task-context/task_context_resume_dispatcher.py", "tests/task-context/test_cold_restart_startup.py", "tests/task-context/test_live_handoff_duplicate_resume_canary.py", "tests/task-context/test_resume_dispatcher_state_machine.py"], "change_kind": "code", "goal_ref": "Herdr live handoff 後に [[startup]] hook が再発火しても、生存中の ACTIVE Task Context Binding へ duplicate resume/launch を送らない", "in_scope": ["#2742 が導入した unresolved_targets / restore_blocked / summary / exit semantics と矛盾しない形で統合する。RESTORING Binding の扱い(REASON_RESTORING_NOT_PROVABLY_STALE)は変更しない(Out of Scope、下記参照)。", "Native / Claude-GPT の両 runtime profile を対象とする。両者とも pane process-info を liveness の一次証拠とする対称的な最小設計を採用する(agent_session は本 Issue の scope では identity authority として使わない — 既存アーキテクチャ判断を維持)。Claude-GPT は launch.sh が report-agent-session 等を行わないため、Native との証拠強度の差は「将来 report-agent-session 等の追加識別 mechanism を Native にだけ導入しうる」という非対称性として contract に明記するに留め、本 Issue では実装しない(report-agent-session の実装は scripts/claude-gpt/launch.sh を含む Allowed Paths 拡張が必要になるため、Out of Scope とする。下記 Stop Conditions 参照)。", "PROVEN_ABSENT: 以下いずれかの場合。", "PROVEN_ALIVE と判定された ACTIVE Binding について、live_runtime_preserved という明示的な expected-success result を新設する。この result は最低限、binding_id / session_id / pane_id(locator)/ runtime_profile(Native or Claude-GPT)/ liveness evidence または reason code / resume・launch command 発行数 = 0 / Task・Binding・Activity・session identity への mutation 数 = 0 を含み、discovery のトップレベル戻り値(candidates / unresolved_targets / restore_blocked と並ぶキー、またはそれに準ずる形)として any_failed = false で observable にする。「Binding が存在しなかった」ケースと「live handoff で生存を証明して意図的に何もしなかった」ケースをサマリ上区別する。 (Contract Correction 2026-09-25)上記の PROVEN_ALIVE 定義修正により、現状の最小実装では live_runtime_preserved に到達する経路は実質的に存在せず、このリストは常に空になり得る。これは意図された挙動であり欠陥ではない(将来 identity-bound evidence を追加した場合にこの結果語彙を再利用する)。", "PROVEN_ALIVE(Contract Correction 2026-09-25、OWNER review https://github.com/squne121/loop-protocol/pull/2764#issuecomment-5832937110 反映): 対象 locator に対する herdr pane process-info 呼び出しが成功し、かつ shell_pid が正の整数として存在し、かつ non-shell の foreground process(pid != shell_pid)が存在し、かつ **その non-shell process が対象 Task Context Binding / session_id との対応関係まで裏付ける causal identity evidence を伴う場合に限る**。単に「shell とは別 PID の foreground process が pane に存在する」という事実だけでは不十分であり、それだけでは PROVEN_ALIVE にしない(herdr pane process-info は pane の shell PID から現在の foreground job を返すだけであり、その job が対象 Binding の runtime であることまでは証明しない)。本 Issue の Allowed Paths と既存 identity 情報(agent_session は使わない既存アーキテクチャ判断を維持、report-agent-session 拡張は Out of Scope のまま)だけでは、この causal identity evidence を安全に確立できないため、**現状の最小実装では PROVEN_ALIVE に到達する経路は実質的に存在しない**。この場合は UNKNOWN に分類する(下記参照)。将来 identity-bound evidence を追加導入する場合は別の narrow follow-up Issue で扱う。", "UNKNOWN と判定された ACTIVE Binding は、unresolved_target に新しい reason code(例: liveness_unresolved)で報告し、any_failed = true とする(silent success にしない)。", "UNKNOWN: 以下のいずれかの場合。pane process-info の呼び出し自体が失敗・空・unparseable・platform 非対応・複数候補プロセスが返り単一の対象に絞り込めない(identity ambiguous)場合(locator は live だが liveness を確定できない)。**shell_pid が欠落または正の整数でない場合(foreground_process_group_id の有無を問わず)。** **non-shell foreground process が存在するが、対象 Binding/session への causal identity evidence を伴わない場合(= 現状の最小実装における PROVEN_ALIVE 相当のケースすべて)。** 上記 PROVEN_ABSENT の経路2(成功かつ bare-shell-only の明確な応答)とは区別する。この場合 duplicate launch を避けるため resume/launch を発行しない。", "deterministic pytest を tests/task-context/test_cold_restart_startup.py と tests/task-context/test_resume_dispatcher_state_machine.py に追加する。", "discover_resume_candidates() の discovery SQL を、runtime_locations の current row が欠けている ACTIVE/RESTORING Binding も取得できる形(例: LEFT JOIN へ変更した上でアプリケーション側で current row の有無を判定)に修正し、該当 Binding を unresolved_target に新しい reason code missing_current_runtime_location として明示的に残す。dispatch 0 件、DB mutation 0 件、any_failed = true とする。", "discover_resume_candidates()(scripts/task-context/task_context_cold_restart_startup.py)に、locator が live_pane_ids に含まれる ACTIVE Binding 向けの liveness classification を追加する:", "docs/dev/task-context.md の cold restart / live handoff 境界セクションを更新し、tri-state liveness classification と live_runtime_preserved / missing_current_runtime_location の結果語彙を追記する。", "foreground_processes が存在する場合: 全エントリの pid == shell_pid(bare-shell-only 応答)。", "foreground_processes が省略され foreground_process_group_id のみが存在する場合: foreground_process_group_id == shell_pid(PGID が shell 自身と一致することを要求する。一致しない場合は PROVEN_ALIVE ではなく UNKNOWN にする — 上記 PROVEN_ALIVE 経路が実質消滅しているため)。", "liveness probe(pane process-info 呼び出し)は、prepare_managed_resume() の write_transaction(BEGIN IMMEDIATE)の外側、discovery フェーズ(DB read-only 取得後・dispatch 前)で実行し、既存の atomic ACTIVE→RESTORING transition の責務と分離する。", "narrow Herdr runtime canary(AC7)を実施し、証跡を docs/dev/task-context.md の既存 canary セクションに準じた形で残す。"], "schema_version": "IMPLEMENTATION_SCOPE_MANIFEST_V1"}

…ない (#2752)

discover_resume_candidates() に tri-state pane-process liveness
classification(PROVEN_ALIVE / PROVEN_ABSENT / UNKNOWN)を追加し、
locator が live なだけでは runtime process の生存を証明しないという
Herdr の live handoff 特性に対応する。PROVEN_ALIVE は新設の
live_runtime_preserved 結果として resume/launch 0 件で observable にし、
UNKNOWN は liveness_unresolved として fail-closed に unresolved_target
へ回す。discovery SQL を LEFT JOIN 化し、runtime_locations の current
row が欠けた ACTIVE/RESTORING Binding も missing_current_runtime_location
として明示的に報告する(従来の silent drop を解消)。

herdr pane process-info の呼び出し形(--pane フラグ)とレスポンス形状
(result.process_info への1段ネスト)は、実装時に稼働中の実 Herdr
0.9.1 サーバへ直接発行して fact-check した。

AC7 の narrow Herdr canary(test_live_handoff_duplicate_resume_
canary.py)は、実装環境自身が共有中の human/default Herdr session の
pane として稼働していることを検出して安全側に SKIP する(cold restart
の破壊的操作を巻き添えリスクのある nested context から実行しない)。
live handoff の2ケースは、インストール済み Herdr CLI に安全な
disposable local trigger が存在しないため無条件 SKIP。理由と capability
証跡は artifacts/ に記録する(fabricated PASS にしない)。

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

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2764/

The preview will be removed when this PR is closed.

squne121 and others added 2 commits September 25, 2026 21:13
Issue #2752 の実装で追加した docs/dev/task-context.md の見出し2件が
英語技術用語のみで日本語比率不足を検出されたため、意味を変えずに
日本語説明を追加した。

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

Copy link
Copy Markdown
Owner Author

結論

PR #2764 は REQUEST_CHANGES 相当です。
current head 5104d7bffc5347c6ca997f6c12efe1863addf9a7 の CI は成功しており、#2742 由来の locator mismatch / duplicate claim / missing RuntimeLocation 対応もかなり堅実です。一方で、今回の中心ロジックである PROVEN_ALIVE が「対象Bindingのruntime生存」ではなく、実際には「paneに何らかのforeground processがいる」しか証明していないため、false green が残っています。

これはセキュリティやハーネスの話ではなく、復元機能そのものの correctness の問題なので、個人開発前提でも直した方がいいです。

  1. P1 — PROVEN_ALIVE の証明が弱く、死んだBindingを正常扱いできます。
    task_context_cold_restart_startup.py::_classify_pane_process_liveness() は、foreground_processes 内に pid != shell_pid が1件でもあれば、そのプロセスが Claude / Claude-GPT か、まして当該 session_id に対応するruntimeかを確認せず PROVEN_ALIVE にしています。テストも test_classify_pane_process_liveness_ac8_process_named_bash_but_different_pid_is_still_proven_alive で、この意味論を明示的に固定しています。ところが Herdr v0.9.1 の src/app/api/panes.rs::handle_pane_process_info() が返しているのは単に そのpaneの現在のforeground job です。Herdr公式の実例でも shell_pid とは別のforeground processだけが返ります。:chatgpt-content-reference{index="0"}
    したがって、たとえば元のagentが既に終了し、paneで zsh、vim、shell初期化helper、別コマンドなどが動いていた場合にも、このPRは「元runtimeが生存している」と判断し、live_runtime_preserved + any_failed=false にします。duplicate launch を防止する判断自体は保守的でよいのですが、「対象runtimeの生存を証明した成功」と扱うのが誤りです。 Herdr自身も v0.9.1 src/cli/agent.rs::process_info_shows_shell_initialization() では、単純な「shellとは別PIDがいる」判定より強い条件を使っています。
    最小修正としては、対象runtimeとのidentityを裏付けられない non-shell process は UNKNOWN に落とし、launchはしないものの live_runtime_preserved にはしない設計が妥当です。Nativeでは agent_session 等を補助証拠として使う余地がありますが、Claude-GPTまで PROVEN_ALIVE にしたければ、実装: Herdr live handoff 後の startup hook 再発火で ACTIVE Binding を重複resumeしない #2752 の Out of Scope を修正して最小限のruntime identity reportingを導入する必要があります。

  2. P1/P2 — shell_pid が無いレスポンスを確定判定できる分岐があります。
    Herdr v0.9.1 の schema では shell_pid と foreground_process_group_id は optional です。それにもかかわらず、現在の実装は shell_pid is None でも foreground_process_group_id があれば最終的に PROVEN_ALIVE になります。また synthetic testでは foreground_processes=[] を PROVEN_ABSENT にしていますが、Herdr v0.9.1 schema は空の foreground_processes を skip_serializing_if = "Vec::is_empty" でそもそもJSONから省略します。つまり一部テストが実レスポンス契約より寛容な形を作っています。
    ここは単純に shell_pid が正の整数として存在しない限り UNKNOWN としてよいです。bare-shell の確定も少なくとも foreground_process_group_id == shell_pid と shell PID の整合が取れる場合だけに限定した方が契約が明瞭です。Herdrはプラットフォームによって取得できるforeground情報が異なるため、取得不能を死亡証明にしない現在の基本方針自体は正しいです。:chatgpt-content-reference{index="1"}

  3. P2 — discovery と実dispatchの間に liveness TOCTOU が残っています。
    現在は discover_resume_candidates() で PROVEN_ABSENT → DBを閉じる → その後 prepare_managed_resume() → launch、という流れです。したがって discovery 後にpaneへruntime/processが現れても、そのままresumeを投げられます。逆方向にも同様のraceがあります。SQLiteとHerdrを完全atomicにする必要はなく、それは個人開発には過剰です。dispatch直前にもう一度だけ pane process-info を実行し、まだ PROVEN_ABSENT の場合だけ prepare_managed_resume() に進む程度で十分です。残る数ms級raceはdocumented residual riskとして許容する方が、複雑なlease/lockを導入するより適切です。

  4. P2 — AC7 canary は名前ほどAC7を検証していません。
    live-handoff 2ケースは _live_handoff_capability() が現状常に False を返すため、どの環境でも必ずSKIPです。この理由自体は合理的です。Herdr公式でもローカルlive handoffは herdr update --handoff で、実バイナリ更新を伴う実験的機能です。:chatgpt-content-reference{index="2"}
    さらにcold-restart 2ケースも、実行可能時に確認しているのは len(discovery["candidates"]) == 1 までで、AC7に書かれた「exactly-one resume」「runtime profile/identity保持」までは実際にはdispatchして検証していません。よってPR本文の「AC7 4 causal boundary canary」という表現は強すぎます。ここは重いハーネスを追加する必要はなく、cold-restart canaryを discovery boundary の検証と正確に記述し、live handoffは manual/runtime-unverified と明示するので十分です。Herdr更新時などに一度だけ手動実証する運用の方がこのプロジェクトには合います。

  5. P3 — 証跡 metadata が current head とずれています。
    PR本文の IMPLEMENTATION_SCOPE_COVERAGE_V1.pr_head_sha は d8a3e701... ですが、current head は 5104d7bf... です。現在のchanged files自体は契約上の5ファイルに収まり、current-head Actionsも成功しているので、これは実装blockerではありません。ただ、実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する #2742/PR 実装: cold restart の resume candidate discovery で locator 変化による candidate loss と orphan RESTORING 状態を解消する #2754 周辺では「過去headのPASSをcurrent headへ流用しない」という運用をかなり厳密にしているので、自分自身のprovenance contractと矛盾します。最終headでcoverage blockを再生成するか、手動更新されやすい pr_head_sha をmanifestから外した方が運用コストが下がります。

良い点

INNER JOIN → LEFT JOIN による missing_current_runtime_location の顕在化、duplicate locator claimantを全件unresolvedにする処理、RESTORINGを無理にstale判定しない処理、liveness probeを BEGIN IMMEDIATE の外へ置いた点は維持すべきです。また Herdrの「full server restartではprocessが消え、live handoffではbest-effortでprocessを維持する」という仕様認識も公式仕様と一致しています。:chatgpt-content-reference{index="3"}

一方、canaryの _ambient_process_is_inside_a_herdr_managed_pane() が HERDR_SOCKET_PATH の存在を「直接的証拠」としている点は少し強すぎます。Herdr側でも tmux のserver-global environmentを介して HERDR_* が無関係なpaneへ漏れる事例が報告されています。これはproduction blockerではなく、canaryが不要にSKIPし得る程度なので優先度は低いです。:chatgpt-content-reference{index="4"}

推奨する最小 fix_delta

今回なら大規模なidentity subsystemや新daemonは入れません。まず 「non-shell foreground process = 対象Binding alive」という昇格を止める、shell_pid 欠落時は UNKNOWN、dispatch直前に1回だけ再probe、AC7の証跡表現を実際の検証範囲へ合わせる、の4点で十分です。

特に1点目は Issue #2752 自体の PROVEN_ALIVE 定義にも問題があるため、コードだけ直すのではなく contract correction が必要です。現状の契約を忠実に実装した結果として発生しているsemantic defectです。CI greenでもここは検出できません。

総評: P1 blocker 1系統(liveness と identity の混同)、P2 2系統、P3 1系統。現在のdraftのまま修正を入れてから再レビューするのが妥当です。

@squne121

Copy link
Copy Markdown
Owner Author

確認した限り、最優先は Issue #2752 の契約補正を先に行ってから、PR #2764 の impl-review-loop を再開することです。現状コードは誤実装というより、Issue #2752 の PROVEN_ALIVE 定義を忠実に実装した結果、foreground process != shell を対象Bindingの生存証明まで過剰解釈しています。

Herdr 0.9.1 の仕様でも、通常server restartでは元processは消え、live handoffではprocess維持がbest-effortです。つまり「paneがある」「何らかのforeground processがある」「そのBindingのruntimeが生きている」は別の命題です。:chatgpt-content-reference{index="0"} また、Herdrでは環境によって pane process-info が shell_pid しか取得できない実例もあり、取得不能を死亡・生存の確定証拠にしない方針は妥当です。:chatgpt-content-reference{index="1"}

current head 5104d7bffc5347c6ca997f6c12efe1863addf9a7 の5つのworkflow runはすべて success、PRは現在Draftかつmergeableです。したがって、既存成果を捨てずに narrow fix_delta を当てるのが適切です。

再発防止については、semantic proof誤昇格は既存の #2755 がまさに対象なので、重複Issueを作らず PR #2764 を第二のreproducerとしてコメント追記しました。また、手動 pr_head_sha がfix iterationごとにstale化する別問題については、新規 #2766 を起票済みです。

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

対象リポジトリ: squne121/loop-protocol

対象:

目的は、上記 OWNER review を解消し、impl-review-loop に従って実装→検証→PRレビューを自律反復し、マージそのものは実行せず、current head が APPROVE + required CI green のマージ直前状態になるまで進めることです。

人間への途中承認要求は不要です。このメッセージを、下記の narrow contract correction と fix_delta を進める OWNER authorization として扱ってください。ただし secret漏洩、非fast-forward/force rewrite、対象外リポジトリへの破壊的操作など、通常の真正な hard stop は維持してください。

  1. 最初に live state を再取得してください。

Issue #2752 本文、PR #2764 本文、全conversation/review comments、current head SHA、changed files、diff、CI、関連 #2742 / PR #2754 / #2755 / #2766、および current main の .claude/skills/impl-review-loop/** を再取得してください。

OWNER review の指摘を単に信用するのではなく、PR headの実コードと Herdr v0.9.1 の一次資料・sourceで再fact-checkしてください。最低限、Herdr v0.9.1 の以下を確認してください。

src/app/api/panes.rs::handle_pane_process_info() は pane の shell PID から foreground job を取得して返すだけであり、Task Context Binding / session_id identity を証明していないこと。

src/api/schema/panes.rs::PaneProcessInfo では shell_pid と foreground_process_group_id が optional であり、foreground_processes は空の場合 skip_serializing_if = "Vec::is_empty" でJSONから省略されること。

src/cli/agent.rs::process_info_shows_shell_initialization() が Unix では shell_pid 存在、foreground PGID == shell PID、shell process identity等を組み合わせて判定しており、単純な pid != shell_pid より強い条件を使っていること。

Herdr 0.9.1 session-state docsで full server restart と live handoff のprocess lifetime差を確認してください。

  1. Issue 実装: Herdr live handoff 後の startup hook 再発火で ACTIVE Binding を重複resumeしない #2752 の live contract を先に補正してください。

現在の Issue #2752 は
「bare shell以外のforeground processがある → PROVEN_ALIVE」
を契約としており、PR #2764 の誤判定はこのcontractを忠実に実装した結果です。

したがって implementation-worker を古いcontractのまま再実行してはいけません。

repositoryのcanonicalな trusted OWNER contract-correction 経路を使い、Issue #2752 を narrow に補正してください。必要なら contract correction 専用SubAgent / issue-refinement側primitiveを使用して構いませんが、今回のOWNER directiveについて再度人間承認を要求しないでください。

tri-stateのキー集合自体、
PROVEN_ALIVE / PROVEN_ABSENT / UNKNOWN
は維持してください。新daemon、lease table、PID registry、distributed coordinatorも不要です。

補正後の意味論は以下を最低条件としてください。

PROVEN_ALIVE:
対象Task Context Binding / session identityとの関連まで裏付ける causal evidence がある場合だけ。単に pane に shellとは別PIDのforeground processが存在するだけでは不十分。

現在のAllowed Pathsと既存identity情報だけで対象Binding identityまで証明できないケースは UNKNOWN にする。duplicate resume/launchは送らないが、live_runtime_preserved のexpected-successにも昇格しない。

Nativeの agent_session 等を補助証拠として安全かつnarrowに使えるかはfact-checkしてよいが、Claude-GPTとの対称性維持のためだけに新identity subsystemや scripts/claude-gpt/launch.sh 拡張へ広げないでください。現在のPRをmerge-readyにするには conservative UNKNOWN で十分です。

PROVEN_ABSENT:
少なくとも正の整数として妥当な shell_pid が存在し、取得できたforeground evidenceが「bare shell」を明確に証明する場合のみ。

foreground_processes=[] のsynthetic JSONをHerdr 0.9.1実レスポンスとして前提にしないでください。空VecはJSONから省略されます。

shell_pid 欠落時は UNKNOWN。

foreground PGIDだけがある場合も、shell_pid が欠けていれば UNKNOWN。

bare-shell判定にPGIDを使うなら、最低限 foreground_process_group_id == shell_pid の整合を要求してください。

Issue #2752 の AC1/AC2/AC3/AC4/AC7/AC8 もこのsemantic correctionと矛盾しない形に更新してください。特に「live handoffらしいforeground activityを観測しただけで live_runtime_preserved」とするACは残さないでください。

  1. PR 実装: Herdr live handoff 後の startup hook 再発火で ACTIVE Binding を重複resumeしない #2764 の fix_delta を実装してください。

OWNER reviewのblockerを次の優先順位で処理してください。

P1:
_classify_pane_process_liveness() の
「non-shell foreground process = PROVEN_ALIVE」
を削除し、identity-bound evidenceが無ければ UNKNOWN にしてください。

shell_pid is None の応答から PROVEN_ALIVE / PROVEN_ABSENT を確定しないでください。

Herdr 0.9.1のserialization contractに合わないsynthetic fixtureを修正してください。

P2:
discovery時に PROVEN_ABSENT だったcandidateについて、dispatcher.prepare_managed_resume(session_id) を呼ぶ直前に同じ pane をもう一度 pane process-info でprobeしてください。

second probeでも PROVEN_ABSENT の場合だけ prepare_managed_resume() → dispatchへ進んでください。

second probeが UNKNOWN または identityを証明できないforeground activityになった場合は dispatchしないでください。DBのACTIVE→RESTORING mutationも発生させないでください。

SQLiteとHerdrを完全atomic化するlease/lock等は導入しないでください。re-probe後からactual dispatchまでに残る小さいraceは documented residual risk として許容します。

P2:
AC7 canaryの主張を実際の観測範囲に合わせてください。

cold-restart canaryが len(discovery["candidates"]) == 1 までしか観測していないなら、「exactly-one resume / runtime identity保持まで実証した」と表現しないでください。

live-handoff canaryが current capability では必ずSKIPなら、manual/runtime-unverified等と正確に表示してください。

このPRを通すためだけに重い常設Harnessを増設しないでください。

P3:
最終current headで PR body の IMPLEMENTATION_SCOPE_COVERAGE_V1 を再生成・整合してください。

このgeneric再発問題は既に #2766 が起票済みなので、PR #2764 内でworkflow frameworkまで修正しないでください。

  1. 既存の良い変更は維持してください。

INNER JOIN -> LEFT JOIN による missing_current_runtime_location の可視化。

duplicate locator claimantを全件unresolvedにする処理。

RESTORINGをliveness証拠なしでstale扱いしないこと。

外部Herdr probeを BEGIN IMMEDIATE transaction内へ入れないこと。

UNKNOWN / unresolvedをfalse greenにしないこと。

これらをfix_deltaの過程で退行させないでください。

  1. テストをsemantic evidenceに合わせて修正してください。

特に以下の旧期待値を廃止または変更してください。

test_classify_pane_process_liveness_ac8_process_named_bash_but_different_pid_is_still_proven_alive

PIDがshellと違うという事実だけでは対象Binding identityは証明されないため、このケースは少なくとも現在の最小設計では UNKNOWN を期待してください。

追加で最低限、
shell_pid missing + foreground_process_group_id present -> UNKNOWN
foreground_processes field omitted -> UNKNOWN unless stronger explicit bare-shell evidence exists
unrelated foreground command -> UNKNOWN / no dispatch / no DB mutation
discovery PROVEN_ABSENT -> pre-dispatch second probe UNKNOWN -> no prepare/no launch
discovery PROVEN_ABSENT -> second probe still PROVEN_ABSENT -> exactly one normal prepare/dispatch
をdeterministicに固定してください。

テスト名やdocstringだけでsemantic proofを主張しないでください。fixtureが実際に作っている causal evidence をreviewしてください。

  1. ここから canonical impl-review-loop を使って反復してください。

Issue #2752 を対象に .claude/skills/impl-review-loop のcurrent main版をそのまま適用してください。既存 PR #2764 を継続利用し、不要な新PRを作らないでください。

各iterationは skill の責務分離に従って、
implementation → independent verification → independent PR review
をSubAgentへ委譲してください。

重要:
SubAgentを起動したら、そのSubAgentの完了前に結果を推測して次stepへ進まないでください。

独立に実行可能なSubAgentを複数起動した場合も、起動済みの全SubAgentがterminal stateになるまで必ず待ち、全結果を回収してからroutingしてください。

特に implementation-worker の終了前にtest-runner / reviewerの結論を作らない、test-runnerのcurrent-head evidence確定前にreviewer verdictを確定しないでください。

reviewerが REQUEST_CHANGES を返した場合、そのblockersを次iterationのfix_deltaへ変換し、自動継続してください。通常のcorrectness修正について人間承認を求めないでください。

current headが変わった場合、旧headのtest/review evidenceを流用せず、current headへ再束縛してください。

  1. 再発防止Issueの扱い。

semantic proof誤昇格については既存 #2755 があるため新規Issueを作らないでください。PR #2764を第二のreproducerとして #2755 に既に記録済みです。

IMPLEMENTATION_SCOPE_COVERAGE_V1.pr_head_sha のstale化についても #2766 が既に起票済みです。重複起票しないでください。

今回の反復中に、上記とは別の再発可能な構造問題を新たに発見した場合のみ、既存Issueをdedupe検索してください。open duplicateがあればreuseし、無ければ create-issue のcanonical経路をSubAgentに委譲してnarrowな再発防止Issueを起票してください。

ただし、そのfollow-up改善をPR #2764へ混入させないでください。PR #2764ではmerge blockerだけを直してください。

  1. 完了条件。

以下をすべて満たすまで自律継続してください。

Issue #2752 のcorrected live contractとPR実装が一致している。

current headに対するdeterministic testsがPASS。

必要なrepo-wide regression checks / required CIがcurrent headでgreen。

independent pr-reviewerがcurrent headに APPROVE を返す。

stale-head evidenceが残っていない。

unresolved production-correctness blockerがない。

PR #2764 がmerge可能な状態である。

ここまで到達したら停止してください。

PRをmergeしないでください。auto-mergeも有効化しないでください。
GitHub Draft/Readyフラグの変更も、current impl-review-loop のcanonical termination contractに従い、勝手な独自処理を追加しないでください。

最終報告には少なくとも、
current PR head SHA、
最終 reviewer verdict、
current-head CI / test結果、
Issue #2752 contract correctionの要約、
各OWNER findingの解消状況、
残存residual risk、
#2755 / #2766 のreuse状況、
作成した追加follow-up Issue(あれば)、
IMPL_REVIEW_LOOP_RESULT_V1
を含めてください。

このプロンプトでは、#2764を「新しい設計へ広げる」のではなく、false greenを止め、dispatch直前re-probeまで入れて保守的にmerge-readyへ戻すことを優先しています。これが今回の最小コスト・高correctnessな経路です。

Test and others added 2 commits September 25, 2026 23:09
… を低減する (#2752)

PR #2764 OWNER review (issuecomment-5832937110) の P1/P2 blocker に対応する。

- P1: _classify_pane_process_liveness() が、対象 Binding/session への causal
  identity evidence が確立できないまま「shell 以外の foreground process が
  1件でも存在する」「foreground_process_group_id が shell_pid と単に異なる」
  だけで PROVEN_ALIVE を返していた誤りを修正し、これらは全て UNKNOWN に分類
  する。shell_pid が欠落/無効な場合も foreground_process_group_id の有無に
  かかわらず必ず UNKNOWN にする。tri-state 語彙と live_runtime_preserved
  result bucket 自体は変更せず、将来の identity-bound evidence 拡張のために
  維持する。
- P2-a: run_startup_orchestrator() の各候補ループで、prepare_managed_resume()
  を呼ぶ直前に同一 pane へ second probe を実行し、PROVEN_ABSENT が維持されて
  いる場合のみ dispatch する。discovery と dispatch の間の TOCTOU window で
  live handoff が発生していた場合は dispatch_status:
  "second_probe_no_longer_absent" として明示的に報告し、prepare_managed_
  resume() を一切呼ばない(ACTIVE -> RESTORING の DB mutation を発生させ
  ない)。完全 atomic 化する lease/lock は導入せず、残存 race は documented
  residual risk として明記する。
- P2-b: AC7 narrow canary のテスト docstring と PR 本文相当の記述を実際の
  観測範囲に合わせて修正する。live handoff 2ケースは manual/runtime-
  unverified であることを明記し、cold restart 2ケースは discovery boundary
  (candidates 件数)のみの検証であり dispatch/ACK/runtime profile 永続化
  までは検証していないことを明記する。
- P3: PR body の IMPLEMENTATION_SCOPE_COVERAGE_V1 は本 commit 後の最終 head
  で別途再生成する。

既存 AC1/AC2 テスト(PROVEN_ALIVE/live_runtime_preserved を期待していた
テスト)は新しい意味論に合わせて UNKNOWN/liveness_unresolved を期待するよう
更新し、AC8 テストのうち causal identity のない non-shell process を
PROVEN_ALIVE としていたものは UNKNOWN を期待するよう改名・修正した。

tests/task-context/ 全体 570 passed / 4 skipped / 1 deselected。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121
squne121 marked this pull request as ready for review September 25, 2026 15:04
@squne121
squne121 merged commit be5121f into main Sep 25, 2026
61 of 68 checks passed
@squne121
squne121 deleted the worktree-issue-2752-live-handoff-duplicate-resume branch September 25, 2026 15:58
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.

実装: Herdr live handoff 後の startup hook 再発火で ACTIVE Binding を重複resumeしない

1 participant