Skip to content

feat: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定を追加する - #2220

Merged
squne121 merged 12 commits into
mainfrom
worktree-issue-2183-worktree-agent-runtime-smoke-hook-id-sub
Aug 17, 2026
Merged

squne121 merged 12 commits into
mainfrom
worktree-issue-2183-worktree-agent-runtime-smoke-hook-id-sub

Conversation

@squne121

@squne121 squne121 commented Aug 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Issue #2183 を実装する。worktree-agent-runtime-smoke 共有 harness の SubAgent 実行 evidence が marker 文字列出力のみ(synthetic fixture でも trivially 満たせる)に依存していた構造的欠陥(Issue #2174 OWNER REQUEST_CHANGES、PR #2214 OWNER レビュー)を解消するため、scripts/agent-ops/run_worktree_agent_runtime_smoke.py に hook ID ベースの SubAgent causal evidence 判定関数 subagent_causal_evidence_verdict() を追加した。

  • subagent_causal_evidence_verdict(stdout, expected_markers=None): SubagentStart/SubagentStop の同一 agent_id 相関 + agent_transcript_path の回収を causal_evidence_source == "hook_id_correlated" の必要条件とする。lone SubagentStart(SubagentStop 欠落)は no_evidence、hook イベントが一切なく marker 文字列のみの場合は marker_only_insufficient に fail-closed する。
  • tool_invocation_id_correlated(bool): 相関済み agent_id を Agent tool_use の id と対応する tool_result の tool_use_id で追加検証する(既存 extract_claude_canonical_read_receipt の tool_use_id 相関パターンを Agent tool 呼び出しに適用)。
  • extract_claude_hook_lifecycle_events() の戻り値に agent_transcript_path フィールドを追加した(既存フィールドの削除・型変更なし、後方互換)。
  • structured lane(run_structured_claude 経由の呼び出し箇所)・interactive lane(run_interactive_herdr_isolated 経由の呼び出し箇所)双方の PASS 判定に causal evidence gate を組み込んだ。structured lane は --expect-marker 指定時、causal_evidence_source == hook_id_correlated を追加フラグなしで既定強制する(PR feat: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定を追加する #2220 レビュー fix-delta。herdr pane が hook payload を構造的にエコーしない interactive lane との責務分離、および --expect-marker を指定しない structured lane 実行に対しては、新設 CLI フラグ --require-subagent-causal-evidence(既定 OFF)で opt-in させる)。判定結果はフラグの有無・lane に関わらず常に schema_summary["subagent_causal_evidence"] へ記録され、marker のみの PASS だったのか hook ID 相関で PASS したのかを事後に判別できる。

2026-08-16 fix_delta: AC3 強化・AC11・AC12・AC13 の追加対応

4体の read-only SubAgent 調査(contract/SSOT analyst・causal-evidence adversarial reviewer・runtime/CI verifier・documentation reviewer)が指摘した specification gap を解消するため、Issue #2183 本文を in-place reframe した上で以下を追加実装した:

  • AC3 強化: tool_invocation_id_correlated を causal_evidence_source の promotion 条件へ実際に組み込んだ。従来はフィールドとして計算・記録されるだけで判定に無関係だったが、tool_invocation_id_correlated == False の場合は単独で hook_id_correlated への昇格を阻止する。
  • AC11 新設: agent_transcript_path の実在性・読み取り可能性・非空性を検証する _read_claude_agent_transcript_content() を追加し、新フィールド agent_transcript_verified(bool)として結果に含めた。加えて --expect-marker 等で成果物照合を要求する呼び出しでは、期待マーカーが相関済み child 自身の transcript ファイル内容、または SubagentStop の新規 last_assistant_message フィールド由来であることを追加確認する marker_provenance_verified(bool)を導入した。いずれか一つでも欠落・不一致なら hook_id_correlated へ昇格しない。
  • AC12 新設: 無関係な SubAgent(別の agent_id)が Start/Stop・transcript・tool 相関まで正常に完了する一方、期待マーカーが parent 自身の最終応答テキストにのみ出現する negative control シナリオを hermetic regression test で再現し、causal_evidence_source が hook_id_correlated に昇格しないことを検証した。
  • AC13 新設: .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md に subagent_causal_evidence_verdict() の利用方法・causal_evidence_source の意味・lane ごとの既定挙動を追記した。

既存の 3 テストフィクスチャ(_subagent_hook_lines() を使う FAKE_CLAUDE_SUCCESS_BODY_WITH_SUBAGENT_EVIDENCE 系)は、AC3/AC11 の強化に伴い Agent tool_use/tool_result envelope の発行と実ファイルとしての transcript 書き込みを追加するよう更新した(tool_invocation_id_correlated・agent_transcript_verified を満たさないと hook_id_correlated へ昇格しなくなったため)。

opt-in / 既定強制の設計(Scope Delta 相当、Notes for Reviewer 許容範囲)

Issue #2183 の In Scope は「PASS 判定ロジックが causal_evidence_source == hook_id_correlated を必要条件として要求するよう変更する」と記述しているが、これを常に全呼び出しに強制する形で実装すると、interactive lane の herdr pane はそもそも --include-hook-events の stream-json hook payload を転記しないため、この lane に無条件強制を課すと恒常的に FAIL する構造的制約に直面する(Issue #2183 の 2026-08-16 in-place reframe で明文化)。

そのため最終的な設計は次のとおり:

  • structured lane: --expect-marker を指定する呼び出しでは causal_evidence_source == hook_id_correlated を 既定強制(追加フラグ不要)。--expect-marker を指定しない structured lane 実行には --require-subagent-causal-evidence(既定 OFF)で opt-in させる。
  • interactive lane: herdr pane の構造的制約により、causal_evidence_source は今のところ no_evidence/marker_only_insufficient になる想定であるため、本要件は引き続き opt-in(--require-subagent-causal-evidence を明示した場合のみ exit を昇格)のままとし、既存の operability / multi-turn / session isolation の証拠を PASS 条件として維持する。

いずれの場合も判定結果は常に schema_summary["subagent_causal_evidence"] へ記録される。

Checks

  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py -v → 20 件成功
  • uv run --locked pytest scripts/agent-ops/tests/ -q → 558 件成功(既存回帰なし。fixture 更新 3 件を含む)
  • uv run --locked ruff check scripts/agent-ops/run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py → All checks passed

Issue #2183 AC1〜AC13 の Verification Commands は全て実行し、AC1/AC2/AC3/AC4/AC5/AC7/AC8/AC9/AC10/AC11/AC12/AC13 の全 VC が期待どおり文字列を検出し、AC6(pytest -v)も PASS を確認した。

Runtime Verification Applicability: not_applicable(Issue #2183 本文どおり。subagent_causal_evidence_verdict() は既にキャプチャされた stdout テキストを入力とする純粋関数であり、live claude-gpt launcher 実行や実際の Herdr session の新規起動は不要)。

Schema Change Applicability

  • decision: not_schema_change
  • reason: 既存 JSON schema ファイルの追加・変更は行っていない。extract_claude_hook_lifecycle_events() の戻り値 dict へ agent_transcript_path/last_assistant_message キーを追加し、subagent_causal_evidence_verdict() の戻り値 dict へ agent_transcript_verified/marker_provenance_verified キーを追加したが、いずれも既存キーの削除・型変更を伴わない additive な in-process 戻り値拡張であり、.claude/skills/**/schemas/*.json 等の formal schema 契約の変更ではない。

Schema Consumer Inventory

N/A(Schema Change Applicability: not_schema_change のため対象外)。

Safety Claim Matrix

# SAFETY_CLAIMS_V1
safety_claims:
  - claim: "subagent_causal_evidence_verdict() は hook イベントが一切ない/不完全な場合に hook_id_correlated へ昇格しない(fail-closed)"
    implemented: "yes"
    evidence:
      - "test_given_subagent_start_without_stop_when_verdict_computed_then_not_hook_id_correlated / test_given_subagent_start_with_mismatched_stop_agent_id_when_verdict_computed_then_no_evidence / test_given_correlated_start_stop_no_transcript_path_when_verdict_computed_then_not_correlated が SubagentStart 単独・agent_id 不一致・transcript_path 欠落のいずれも hook_id_correlated に昇格しないことを検証"
    not_controlled: []
    follow_up: []
  - claim: "marker 文字列のみの観測は hook_id_correlated に昇格しない"
    implemented: "yes"
    evidence:
      - "test_given_marker_only_no_hook_events_when_verdict_computed_then_marker_only_insufficient が marker_only_insufficient を返すことを検証"
    not_controlled: []
    follow_up: []
  - claim: "tool_invocation_id_correlated == False は単独で hook_id_correlated への昇格を阻止する(AC3 強化)"
    implemented: "yes"
    evidence:
      - "test_given_hook_correlated_but_no_agent_tool_result_when_verdict_computed_then_not_hook_id_correlated が、実在する transcript ファイルを与えた上でも tool_invocation_id_correlated が False であれば hook_id_correlated に昇格しないことを検証"
    not_controlled: []
    follow_up: []
  - claim: "agent_transcript_path は実在性・読み取り可能性・非空性が確認できない限り hook_id_correlated への根拠にならない(AC11)"
    implemented: "yes"
    evidence:
      - "test_given_agent_transcript_path_file_does_not_exist_when_verdict_computed_then_not_hook_id_correlated / test_given_agent_transcript_path_file_is_empty_when_verdict_computed_then_not_hook_id_correlated / test_given_whitespace_only_transcript_file_when_verdict_computed_then_not_verified が、パス文字列のみでは agent_transcript_verified が True にならないことを検証"
    not_controlled: []
    follow_up: []
  - claim: "期待マーカーの provenance が相関済み child の transcript / last_assistant_message 由来であることを確認できない場合は hook_id_correlated へ昇格しない(AC11/AC12)"
    implemented: "yes"
    evidence:
      - "test_given_expected_marker_absent_from_real_transcript_when_verdict_computed_then_not_hook_id_correlated(実在する transcript だがマーカー内容が無関係)"
      - "test_given_unrelated_subagent_completes_and_parent_emits_marker_when_verdict_computed_then_not_hook_id_correlated(無関係な SubAgent が正常完了しつつ parent 自身の最終応答にのみマーカーが出現する negative control)"
    not_controlled: []
    follow_up: []
  - claim: "structured lane は --expect-marker 指定時、causal evidence 要件を追加フラグなしで既定強制する(AC9)"
    implemented: "yes"
    evidence:
      - "test_given_marker_only_fake_claude_when_default_require_causal_evidence_gate_applies_then_structured_lane_fails / test_given_marker_only_fake_claude_when_no_expect_marker_then_default_causal_gate_does_not_apply"
    not_controlled: []
    follow_up: []
  - claim: "interactive lane は causal evidence 要件を既定で要求せず、--require-subagent-causal-evidence 指定時のみ要求する(AC10)"
    implemented: "yes"
    evidence:
      - "test_given_interactive_lane_marker_only_when_require_subagent_causal_evidence_opt_in_then_fails / test_given_herdr_interactive_lane_pane_marker_only_when_causal_evidence_not_required_then_exit0"
    not_controlled:
      - "interactive lane の herdr pane は --include-hook-events の stream-json hook payload を転記しないため、--require-subagent-causal-evidence を interactive lane で有効化した場合 causal_evidence_source は現状 no_evidence/marker_only_insufficient に留まる構造的制約がある(SKILL.md / references/claude-code.md に明記)"
    follow_up:
      - "interactive lane 向け hook 出力チャネル整備(herdr 側の構造的制約変更、別 Issue の scope)"

既知の制約(Known Limitations)

  • interactive lane の herdr pane は hook payload を構造的にエコーしないため、この lane で --require-subagent-causal-evidence を有効化しても causal_evidence_source が hook_id_correlated になることは現状想定されない。herdr 側の観測チャネル整備は別 Issue の scope。
  • agent_transcript_verified はローカルファイルシステム上の実在性・非空性のみを検証し、transcript の内容が本物の Claude Code セッション出力であることまでは検証しない(marker_provenance_verified はあくまで期待マーカー文字列の provenance を切り分けるものであり、transcript 内容自体の真正性証明ではない)。

Notes

…dence 判定を追加する (#2183)

marker 文字列の出力のみに基づく PASS 判定は synthetic fixture でも trivially
満たせてしまい、PR #2214 OWNER レビューで AC4 の causal receipt 検証がその
構造的欠陥を突かれた。subagent_causal_evidence_verdict() を追加し、同一
agent_id を持つ SubagentStart/SubagentStop ペア + agent_transcript_path の
回収を PASS の必要条件(causal_evidence_source == hook_id_correlated)とし、
Agent tool_use/tool_result の tool_use_id 相関を tool_invocation_id_correlated
として独立に記録する。--require-subagent-causal-evidence(既定 OFF、opt-in)
で structured/interactive 両 lane の PASS 判定へ組み込み、既存呼び出し元の
exit_code は変更しない。docs/dev/runtime-verification-policy.md と
worktree-agent-runtime-smoke/SKILL.md に規約・利用方法を追記した。

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-2220/

The preview will be removed when this PR is closed.

squne121 and others added 2 commits August 16, 2026 20:12
Japanese Check の見出し単位判定(ratio=0.044 < threshold 0.1)を満たすため、
英語専門用語を保持したまま日本語語句を併記する。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…制する (#2183)

PR #2220 レビュー fix-delta。structured lane では hook stream-json チャンネルが
常に利用可能であるため、--expect-marker 指定時は causal_evidence_source ==
hook_id_correlated を追加フラグなしで既定要求するよう変更した。
--require-subagent-causal-evidence は marker 未指定の structured 実行、および
hook payload を構造的に転記できない interactive lane 向けの opt-in のまま残す。
既定強制の影響を受ける既存 3 テストは相関済み SubagentStart/SubagentStop
フィクスチャを追加して更新し、runtime-verification-policy.md /
worktree-agent-runtime-smoke/SKILL.md の記述を実装と一致させた。

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

Copy link
Copy Markdown
Owner Author

fix_delta 対応(head 695c97e5)

レビュー指摘 2 件を解消しました。

1. --require-subagent-causal-evidence の既定強制化(structured lane)

  • structured lane(run_structured_claude 経由)は SubagentStart/SubagentStop の stream-json チャンネルが常に利用可能なため、呼び出し側が --expect-marker を指定する場合、causal_evidence_source == hook_id_correlated を 追加フラグなしで既定要求するよう変更しました(scripts/agent-ops/run_worktree_agent_runtime_smoke.py の causal_evidence_required = args.require_subagent_causal_evidence or bool(args.expect_marker))。
  • --require-subagent-causal-evidence フラグは、--expect-marker を指定しない structured 実行にこの要件を課したい場合、および interactive lane(herdr pane のテキストレンダリングには hook payload が構造的に現れないため genuinely opt-in のまま維持)向けの opt-in として残しています。interactive lane 側のロジックは変更していません。
  • この既定強制化の影響を受けた既存 3 テスト(test_given_fake_claude_success_when_structured_lane_runs_then_exit0_and_summary_has_event_count / test_given_required_unavailable_runtime_field_when_fake_claude_succeeds_then_exit77 / test_given_script_checked_out_inside_linked_worktree_when_invoked_without_repo_root_then_not_rejected_as_root)は、相関済み SubagentStart/SubagentStop(+ agent_transcript_path)を emit する fake claude フィクスチャ(_subagent_hook_lines() ヘルパー / FAKE_CLAUDE_SUCCESS_BODY_WITH_SUBAGENT_EVIDENCE)に更新し、テスト本体は削除せず PASS のまま維持しました。

2. ポリシー文書の opt-in 範囲の明示

  • docs/dev/runtime-verification-policy.md の該当節に、structured lane(--expect-marker 指定時)は既定強制・それ以外(marker 未指定の structured 実行・interactive lane 全般)は opt-in という適用範囲を追記しました。
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md も同様に、lane ごとの既定挙動の違いを明記するよう更新しました。

検証結果

  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py -v → 12 件成功(AC6 該当コマンド)
  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py -q → 76 件成功
  • uv run --locked pytest scripts/agent-ops/tests/ -q → 547 件成功(fix-delta 適用前のベースラインと同数、既存回帰なし)
  • uv run --locked ruff check scripts/agent-ops/run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py → All checks passed
  • AC1〜AC8 の Verification Commands をすべて再実行し、全て pass を確認しました。

head SHA: 695c97e5a48943cf1fcfb28e988ff489e5e15c01

@squne121

Copy link
Copy Markdown
Owner Author

結論として、PR #2220 はまだ merge-ready 扱いにせず、impl-review-loop でもう1周以上回すのが妥当です。現在は Draft / open / mergeable、head は 45267ea5... で、current-head の ci もまだ in_progress です。

推奨アクションは次の順です。

  1. 最優先 P0 は causal evidence の強化です。 現実装では hook_id_correlated への昇格条件が「同一 agent_id の Start/Stop + agent_transcript_path」までで、tool_invocation_id_correlated は別フィールドに留まります。さらにテストが明示的に「tool_invocation_id_correlated == false でも causal_evidence_source == hook_id_correlated」を期待しており、これは元の OWNER 要求「Start/Stop、Agent tool call、child transcript、terminal completion を相関する」より弱いです。 OWNER の起点コメントも、この組合せを correlating evidence として要求しています。
    加えて、expected_markers がその child 由来かも証明した方がよいです。「無関係な SubAgent を1体走らせ、parent が marker を出す」false PASS が残り得ます。Claude Code の現行公式仕様では SubagentStop に agent_transcript_path だけでなく last_assistant_message もあり、PreToolUse / PostToolUse には同じ tool call を相関する tool_use_id があります。これらを使えば、より直接的に閉じられます。 ([Claude]1)

  2. Issue 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 の SSOT を先に整合させるべきです。 現在の Issue 本文は structured / interactive 双方の PASS に hook_id_correlated を必要条件としています。 一方、この Issue を生んだ OWNER コメントは「interactive lane は継続利用可能性・multi-turn、SubAgent 因果性は structured hook evidence」と明確にレーン分離を推奨しています。 PR の fix-delta も structured --expect-marker は既定強制、interactive は opt-in へ寄せています。 したがって、interactive に存在しない hook payload を無理に捏造するより、OWNER anchor を根拠に 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 を in-place refinement して lane separation を SSOT 化してから impl-review-loop が一番きれいです。

  3. 監査用文書も同期が必要です。 PR 本文にはまだ「structured / interactive とも --require-subagent-causal-evidence の opt-in」という旧設計が残っており、最新 fix-delta と矛盾しています。 また 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 の In Scope は references/claude-code.md にも causal-evidence 利用方法を追記するとしていますが、current head の同ファイルにはまだその節がありません。 PR body の Summary / design decision / Safety Claim Matrix と合わせて直すべきです。

  4. その後、impl-review-loop を承認問い合わせなしで完走させます。fixable な REQUEST_CHANGES は自動修正→検証→再レビューへ戻し、stale head や BEHIND も skill のルーティングに従います。APPROVE 単独では終了せず、current-head が CLEAN/HAS_HOOKS、blocker なしまで確認する契約です。一方、merge は人間判断として明示的に残されています。 したがって今回の権限範囲は Ready for Review / merge-ready まで。merge と auto-merge は禁止でよいです。

その前提で、Claude Code には以下を渡すのを推奨します。

対象 repository は squne121/loop-protocol。対象は Issue #2183 / PR #2220。

PR #2220 を、現在の live GitHub state・Issue contract・関連 OWNER context・current repository assets を正本として再評価し、必要な修正を実施してください。

最終目標は、impl-review-loop により実装 → 検証 → PR review → fix_delta のループを人間の逐次承認なしで反復し、PR #2220 を merge 直前の状態まで持っていくことです。

PR の merge 自体は禁止します。auto-merge も有効化しないでください。
Ready for Review 化、current-head CI、最終レビュー、mergeability 確認までは必要に応じて自律実行して構いません。

Authority / context

開始時に GitHub から live state を再取得してください。prompt 内の状態を最新状態だと仮定しないでください。

特に Issue #2183、PR #2220 の本文・コメント・diff・current head、Issue #2174 の OWNER comment 5302215173、PR #2214 の OWNER comment 5307009937、PR #2220 の fix_delta comment 5307233796 を必ず読んでください。

Issue #2174 comment 5302215173 と PR #2214 comment 5307009937 は、この作業の設計意図を決める direct human/OWNER context として扱ってください。

impl-review-loop を起動する際、skill が human_context_comment_urls を受け取れるなら、これら OWNER comment を human context として明示的に渡してください。投稿者アカウント等から origin を推測せず、明示入力として扱ってください。

最初の SubAgent 調査

実装を変更する前に、main/control-plane から少なくとも4体の read-only specialist SubAgent を並列起動してください。

1体目は contract / SSOT analyst とし、Issue #2183、Issue #2174 OWNER context、PR #2220 の現在実装の意味的差分を調査してください。

2体目は causal-evidence adversarial reviewer とし、synthetic false PASS、unrelated SubAgent、parent-generated marker、agent/tool ID mismatch、cross-session evidence、missing transcript、incomplete completion を使って現在実装を破れるか調査してください。

3体目は runtime/test/CI verifier とし、current head の tests、required CI、既存 worktree-agent-runtime-smoke architecture、structured / interactive lane の実際の観測チャネルを調査してください。

4体目は documentation/review-consistency reviewer とし、PR body、Safety Claim Matrix、SKILL.md、references/claude-code.md、runtime-verification-policy と実コードの drift を調査してください。

各 SubAgent に nested SubAgent delegation はさせないでください。

4体すべての完了を待ってから、統合判断と mutation を開始してください。
一部だけ返った状態で実装を開始しないでください。

必要であれば公式 Claude Code documentation を外部ネットワーク経由で調査して構いません。技術仕様は可能な限り公式一次資料を使用してください。GitHub の read/write、CI readback、必要な公式仕様参照のための外部ネットワーク利用を許可します。

P0: Issue #2183 contract と OWNER intent の整合

Issue #2183 の live body は現在、structured lane と interactive lane の双方について causal evidence を PASS 必須条件とする契約になっている可能性があります。

一方、起点となった Issue #2174 OWNER comment 5302215173 は、interactive lane を「人間操作として継続利用可能・警告なし・multi-turn」の確認に使い、Skill/SubAgent の因果性は structured hook evidence で証明する、という lane separation を明示しています。

まずこの差を authoritative context として判定してください。

OWNER context から一意に lane separation が導け、追加の人間 policy choice が不要である場合は、人間承認を要求せず、repository の issue-refinement-loop 等の正規経路を使用して Issue #2183 を reframe/refine in place し、live Issue SSOT を OWNER intent と同期してください。

その場合、structured lane では causal evidence を hard gate、interactive lane では operability/multi-turn/session isolation を証明し causal hook evidence 自体は要求しない、という責務分離を契約・AC・Verification Commands・docs に一貫して表現してください。

一方、OWNER context だけでは新しい policy choice が必要になる場合だけ human escalation としてください。単なる本文不足、明白な contract drift、fixable な AC/VC 不整合を理由に人間へ問い合わせないでください。

P0: causal evidence を本当に causal にする

現在実装を「Start/Stop の agent_id が同じだった」だけで APPROVE しないでください。

structured lane で SubAgent causal evidence を PASS に使う場合は、少なくとも同一実行/session に属すること、同一 agent_id の SubagentStart / terminal SubagentStop が存在すること、対応する Agent tool invocation の ID correlation が成立すること、child transcript evidence が存在すること、そして completion が terminal であることを fail-closed に相関してください。

現在 tool_invocation_id_correlated == false でも causal_evidence_source == hook_id_correlated へ昇格できるなら、その意味論を再検討してください。OWNER context が要求した「Agent tool call を含む correlating evidence」を満たすなら、tool invocation correlation を PASS 条件へ含めてください。

Claude Code の現行 hook interface で PreToolUse / PostToolUse の tool_use_id が取得可能なら、その公式 channel を優先的に検討してください。既存 stream-json の tool_use / tool_result 相関を利用する場合は、それが公式 hook correlation と意味的に等価かを一次資料と実 fixture で証明してください。名前が似ているだけで同等扱いしないでください。

また、--expect-marker を SubAgent 実行証拠として使うケースでは、単に「何らかの SubAgent lifecycle が存在し、stdout のどこかに marker が存在する」だけでは不十分です。

「無関係な SubAgent A が正常終了した後、parent model 自身が completion marker を出力する」ケースを negative control として追加し、それが PASS しないことを確認してください。

利用可能なら SubagentStop.last_assistant_message または相関済み child transcript を用いて、期待 marker/result が その correlated child 由来であることまで証明してください。

取得不能な evidence を推測で補わないでください。

Regression / negative controls

少なくとも、marker only、Start only、Start/Stop agent ID mismatch、transcript 欠落、Agent tool invocation correlation 欠落、tool invocation ID mismatch、unrelated child + parent marker、必要なら session mismatch の各ケースで fail-closed になる regression を追加してください。

positive fixture は実際の Claude Code hook/stream shape と意味的に一致させてください。test を green にするためだけの自己都合 synthetic schema を新設しないでください。

既存テストが壊れた場合、「既存テストを壊さないため security/causal gate を opt-in に戻す」という解決を優先しないでください。契約上必要な gate なら fixture/harness を現実の runtime contract に合わせて修正してください。

Documentation / PR auditability

Issue #2183 が要求している .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md の causal-evidence documentation も確認してください。In Scope に含まれているのに未更新なら追加してください。

SKILL.md、runtime-verification-policy、reference、実コードで structured / interactive lane の責務を一致させてください。

PR #2220 本文も current implementation に同期してください。旧設計の「structured / interactive 双方とも opt-in」の説明や、現在成立しない backward-compatibility claim を残さないでください。

Summary、design decision、Checks、Runtime Verification Applicability、Safety Claim Matrix、known limitations を current head の事実に合わせて更新してください。

PR コメントだけが新設計を説明し、PR body が旧設計のまま、という状態を最終成果にしないでください。

impl-review-loop

contract reconciliation と初期調査後、Issue #2183 を対象に repository の正規 impl-review-loop を実行してください。

/impl-review-loop 2183 相当の処理を、skill の現行仕様に従って実行してください。

implementation → verification → pr-review → judgment を反復し、REQUEST_CHANGES が返った場合は blocker を fix_delta として implementation に戻してください。

各 iteration の通常の fixable blocker について人間承認を求めないでください。

reviewed head が stale なら current head で再レビューしてください。branch が BEHIND なら skill の正規 update-branch route に従い、その後 verification と review を再実行してください。

SubAgent / worker / reviewer を起動した場合は、必ずその作業完了を待ってから次の routing decision をしてください。

APPROVE という文字列だけで終了しないでください。current head、live mergeability、blockers、required CI を control-plane から独立 readback してください。

Verification

Issue #2183 の全 Verification Commands を current head で再実行してください。

causal-evidence unit testsだけでなく、変更による既存 regression を含む scripts/agent-ops/tests/ の関連/full suite と Ruff を実行してください。

GitHub Actions は current head SHA に束縛して required CI の完了を待ってください。古い head の green check を再利用しないでください。

CI failure があればログを調査して修正し、push 後の新しい head で再度 CI / review を評価してください。

main の取り込み等で head が変化した場合、最終 review evidence も必ず新しい head に対して再取得してください。

Autonomy boundary

今回、人間の逐次承認は不要です。

通常の implementation fix、test fixture 修正、docs 同期、PR body 更新、branch update、CI rerun、review rerun は自律実行してください。

ただし live Issue の Stop Conditions、Allowed Paths hard boundary、実 Git conflict、route_human_escalation、新しい人間 policy choice が本当に必要なケースは無視しないでください。

「作業が面倒」「テストが多い」「既存 fixture の更新が必要」「レビューで追加修正が出た」は human escalation 理由にしないでください。

新規 follow-up Issue が必要だと判明し、それ自体が Issue #2183 の Stop Condition に該当する場合は、無理に scope を拡張せず termination reason と必要な decision を明示してください。

Merge boundary

PR #2220 を merge しないでください。

gh pr merge、GitHub merge API、auto-merge enable は禁止です。

impl-review-loop が APPROVE となり、current-head required CI が green、reviewed head が current head と一致、blocker が空、live mergeability が merge-ready となったところで停止してください。

repository workflow 上必要かつ安全なら Ready for Review への遷移までは行って構いません。その後も current head の最終 review / CI を確認してください。

最終報告

最後に、開始時 head SHA、終了時 head SHA、Issue #2183 を refinement したか、PR #2220 の変更概要、使用した SubAgent と全員の完了状態、impl-review-loop iteration 数、各 iteration の review verdict、実行した verification と結果、current-head CI、最終 mergeability、残存 blocker、Ready for Review 状態を報告してください。

最後に明示的に merge performed: no と記録してください。

merge-ready に到達できなかった場合も、曖昧に「ほぼ完了」とせず、正確な termination route / blocker / human decision が必要な理由を報告してください。

@squne121 squne121 self-assigned this Aug 16, 2026
…追記する

Issue #2183 の 2026-08-16 in-place reframe(AC3 強化・AC11・AC12・AC13 新設)に
追従する fix_delta。

- subagent_causal_evidence_verdict() の hook_id_correlated 昇格条件へ
  tool_invocation_id_correlated を実効的に組み込んだ(AC3 強化)
- agent_transcript_path の実在性/読み取り可能性/非空性を検証する
  agent_transcript_verified、期待マーカーの provenance を child 自身の
  transcript/last_assistant_message に限定する marker_provenance_verified
  を追加した(AC11)
- 無関係な SubAgent が正常完了しつつ parent 自身の最終応答にのみ marker が
  出現する negative control regression test を追加した(AC12)
- references/claude-code.md に causal-evidence documentation を追記した(AC13)
- AC9/AC10 の structured/interactive lane 既定挙動を検証する統合テストを
  追加し、AC3/AC11 強化に伴い既存フィクスチャ(Agent tool_use/tool_result
  envelope・実ファイル transcript)を更新した

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

Copy link
Copy Markdown
Owner Author

fix_delta: Issue #2183 の 2026-08-16 in-place reframe(AC3強化/AC11/AC12/AC13)に追従

Issue #2183 が body_sha256: sha256:0970d0a2ffc692ddf5681f9ee09fac619b624e1fa949429449b973d6f254cf8a へ改訂(AC3 強化・AC11/AC12/AC13 新設)されたことを受け、既存 worktree/PR を継続して以下を対応した。

新しい head SHA

28d577950401f9e8250874b9ee2a8376245bce82

変更ファイル

  • scripts/agent-ops/run_worktree_agent_runtime_smoke.py
    • subagent_causal_evidence_verdict() の hook_id_correlated 昇格条件へ tool_invocation_id_correlated を実効的に組み込んだ(AC3 強化)
    • _read_claude_agent_transcript_content() を新設し、agent_transcript_path の実在性・読み取り可能性・非空性を検証する agent_transcript_verified フィールドを追加した(AC11)
    • extract_claude_hook_lifecycle_events() に last_assistant_message フィールドの回収を追加した
    • 期待マーカーの provenance が相関済み child 自身の transcript 内容 or last_assistant_message 由来であることを検証する marker_provenance_verified フィールドを追加し、hook_id_correlated 昇格条件へ組み込んだ(AC11)
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py
    • AC3 強化と矛盾していた既存テスト(test_given_hook_correlated_but_no_agent_tool_result_when_verdict_computed_then_no_correlation)を、新しい gate に合わせて not_hook_id_correlated を期待するテストへ改訂(gate を弱める方向ではなく、強化に追従)
    • AC11 用の transcript 実在性/内容/last_assistant_message provenance テスト、AC12 用の negative control(無関係 SubAgent が正常完了しつつ parent 自身の最終応答にのみ marker が出現するケース)を新規追加。20テストに拡張(旧12→新20)
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py
    • _subagent_hook_lines() フィクスチャに Agent tool_use/tool_result envelope の発行と、実ファイルとしての transcript 書き込み(marker 内容込み)を追加(AC3/AC11 強化に伴う既存 fixture 更新。3テストが影響、いずれも Allowed Paths 内のテストファイル更新)
    • AC9(structured lane 既定強制)の統合テストを2件追加
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py
    • AC10(interactive lane opt-in)の統合テストを2件追加
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md
    • causal_evidence_source の昇格条件説明を AC3/AC11 強化に合わせて更新
  • .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md
    • subagent_causal_evidence_verdict() の利用方法・causal_evidence_source の意味・lane ごとの既定挙動を新規追記(AC13)

Verification

  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py -v → 20 件成功
  • uv run --locked pytest scripts/agent-ops/tests/ -q → 559 件成功(既存回帰なし)
  • uv run --locked ruff check scripts/agent-ops/run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py → All checks passed
  • Issue 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 の AC1〜AC13 の Verification Commands を全実行し、AC1/AC2/AC3/AC4/AC5/AC7/AC8/AC9/AC10/AC11/AC12/AC13 が期待どおり文字列を検出、AC6(pytest)が PASS することを確認した。

PR body も同期済み(Summary/Checks/Safety Claim Matrix/Known Limitations を fix_delta 内容と一致させた)。マージ・auto-merge は行っていません。

PR Body/changed-Markdown Japanese Check が、AC13 で追加した見出し
(英語識別子中心で日本語比率がしきい値未満)を検知したための修正。

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

Copy link
Copy Markdown
Owner Author

fix_delta 続報: CI Japanese Check 修正・deploy-pr infra flake 解消確認

前コメントの push(head 28d577950401f9e8250874b9ee2a8376245bce82)後、CI で以下 2 点を検出・対処した。

1. PR Body / changed-Markdown Japanese Check FAIL

  • 新規追加した PR body の ## Known Limitations 見出しが heading_policy SSOT に存在しない非 canonical 見出しで、日本語比率 0 のため fail。## 既知の制約(Known Limitations) に修正して PR body を再同期した。
  • .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md に AC13 で追加した見出し(## SubAgent 実行の hook-ID-correlated causal evidence(...))も同様に日本語比率不足(ratio=0.075)で fail。日本語表現を増やした見出しに修正し、commit c2f875a1f3f40066f16efd2a3ba59734a95d3052 として push した。

2. component-vrt-report FAIL の原因

astral-sh/setup-uv の fetch failed(uv インストーラのネットワーク取得失敗)に起因する transient infra flake で、本 PR の変更(scripts/agent-ops/ / .claude/skills/**/*.md のみ、frontend/component 側は無変更)とは無関係と判断した。新しい head への push で自動的に再実行され、component-vrt-report は PASS した(コード修正は不要)。

現在の状態

  • head: c2f875a1f3f40066f16efd2a3ba59734a95d3052
  • 全 CI チェック PASS、mergeStateStatus: CLEAN、mergeable: MERGEABLE

マージ・auto-merge は行っていません。

@squne121

Copy link
Copy Markdown
Owner Author

impl-review-loop: LOOP_VERDICT (iteration 1)

verdict: APPROVE
reviewed_head_sha: "c2f875a1f3f40066f16efd2a3ba59734a95d3052"
blockers: []
warnings:
  - "PR body記載のIssue body_sha256(0970d0a2...)が現在のgh issue view取得値と不一致(advisory cache相当、live本文で直接照合済みのためverdictには非影響)"
  • Issue 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 の live 本文(AC1〜AC13、2026-08-16 in-place reframe 済み)を current head に対して独立検証済み。AC3強化(tool_invocation_id_correlated gating)・AC11(transcript 実在性・内容相関)・AC12(無関係 SubAgent + parent marker negative control)・AC13(references/claude-code.md documentation)全て実コードで確認。
  • control-plane 独立 readback: current head c2f875a1f3f40066f16efd2a3ba59734a95d3052、mergeStateStatus: CLEAN、mergeable: MERGEABLE、required CI 全 pass(current head SHA 束縛)。
  • Allowed Paths 遵守確認済み(7ファイル全て範囲内)。
  • route_loop_verdict_v2(): approved(verdict: APPROVE かつ live mergeability CLEAN かつ blockers == [])。impl-review-loop 終了。

次: Ready for Review への遷移。PR のマージ・auto-merge は行いません(人間判断に残します)。

@squne121
squne121 marked this pull request as ready for review August 16, 2026 15:35
@squne121

Copy link
Copy Markdown
Owner Author

動作検証済み?実際にClaudeCode、Claude-GPTどちらも証跡を確認できた?セッションログからも比較検証できた?

@squne121

Copy link
Copy Markdown
Owner Author

結論

REQUEST_CHANGESです。PR #2220 は open・未マージ・mergeable: true、current head は c2f875a1f3f40066f16efd2a3ba59734a95d3052 ですが、少なくとも P0 の merge blocker が3件あります。

指定コメントへの回答は、現時点では次になります。

未検証です。
current head の判定器について、Claude Code native と Claude-GPT の双方を実起動した証跡、同条件での比較結果、session log/child transcript/hook stream の突合結果は、PR上の監査可能な証跡として確認できません。

PR本文自身が Runtime Verification Applicability: not_applicable とし、検証を synthetic stream-json fixture による hermetic test に限定しています。指定コメントはまさに、その分類が妥当かを問い直しています。

過去の PR #2176 には Claude-GPT・proxy v0.1.34・Herdr v0.8.0 を使った live evidence がありますが、別head・旧判定器に対する証跡です。PR #2220 の current evaluator や、native Claude Codeとの比較証明にはなりません。


Findings

P0-1: Claude専用の causal gate が Codex structured lane に誤適用され、正常なCodex実行が必ずFAILする

structured lane の実装は、Claude以外では causal_evidence = None にする一方、causal_evidence_required は runtime を限定せず、--expect-marker があれば常に有効化しています。

実質的には次の状態です。

if args.runtime == "claude":
    causal_evidence = subagent_causal_evidence_verdict(...)
else:
    causal_evidence = None

causal_evidence_required = (
    args.require_subagent_causal_evidence
    or bool(args.expect_marker)
)

if causal_evidence_required and causal_evidence is None:
    exit_code = EXIT_FAIL

したがって、

--runtime codex
--mode structured
--expect-marker SOME_MARKER

でCodexが正常終了し、markerも出力した場合でも、最後に causal_evidence is None を理由として exit 1 に反転します。

これは理論上の未使用経路ではありません。既存の tests/test_codex_issue_creator_editor_runtime_smoke.py は、Codex positive route に対して実際に --expect-marker を付け、正常時は return code 0 を要求しています。

CIで見逃される理由も明確です。この live test は linked-worktree runtime surface がなければ SKIP するため、通常の detached CI が green でも、実環境のCodex経路は壊れたままになり得ます。

必須修正

if args.require_subagent_causal_evidence and (
    args.runtime != "claude" or args.mode != "structured"
):
    parser.error(
        "--require-subagent-causal-evidence requires "
        "--runtime claude --mode structured"
    )

causal_evidence_required = (
    args.runtime == "claude"
    and args.mode == "structured"
    and bool(args.expect_marker)
) or args.require_subagent_causal_evidence

最低限、次の回帰テストが必要です。

fake codex success + expected marker present
→ exit 0
→ subagent_causal_evidence == null
→ causal gate not applied

さらに linked worktree 上で既存の test_codex_creator_editor_runtime_evidence を実行する必要があります。


P0-2: 複数markerのうち1個だけがchild由来でも hook_id_correlated に昇格する

現在の marker_provenance_verified は、期待markerに対して any(...) を使用しています。

any(marker in transcript_content for marker in expected_markers)

一方、上流の通常marker gateは、全markerがcombined stdout/stderrに存在することを確認します。結果として、次のfalse PASSが成立します。

expected_markers = [M1, M2]

child last_assistant_message: M1
parent final response:         M2

combined output: M1, M2 が存在
child provenance: M1 が存在

現在の結果:
marker_provenance_verified = true
causal_evidence_source = hook_id_correlated

これは「期待成果物が相関済みchild自身から生成された」というACの意味を満たしていません。

さらに transcript をJSONLとして解析せず、ファイル全体へ部分文字列検索しています。そのため、markerがchildの最終回答ではなく、childに渡されたuser prompt、tool input、hook contextにしか存在しない場合でもchild由来と判定できます。

Claude Code公式仕様では、SubagentStop.last_assistant_message がchildの最終応答であり、transcriptを解析せず取得できる正式な出力チャネルです。またtranscriptは非同期書き込みで、hook発火時に最新メッセージが未反映の場合があるため、最終応答には last_assistant_message を使うよう明記されています。(Claude)

必須修正

markerごとにchild output provenanceを証明してください。

marker_sources = {
    marker: (
        marker in last_assistant_message
        or marker in parsed_child_assistant_messages
    )
    for marker in expected_markers
}

marker_provenance_verified = all(marker_sources.values())

加えて、次のテストが必要です。

  • M1はchild、M2はparentのみ → FAIL
  • markerはchildのuser promptのみ → FAIL
  • markerはchild tool inputのみ → FAIL
  • markerはchild assistant final messageのみ → PASS
  • repeatable markerすべてがchild assistant outputに存在 → PASS
  • parentとchildが同じmarkerを出しても、child provenanceを独立確認 → PASS

実行ごとに高エントロピーnonceを生成し、固定markerのfixture replayやstale transcriptを排除すべきです。


P0-3: session_id・時系列・agent typeを捨てているため、別sessionや逆順イベントを誤結合できる

extract_claude_hook_lifecycle_events() は、inner hook payloadに存在する session_id を保存していません。prompt_id、outer/inner hook_event_name、stop_hook_active も捨てています。

その後の判定は次の方式です。

  1. 全 SubagentStart.agent_id を集合化
  2. 全イベントを先頭から調べる
  3. 集合内のIDを持つ最初の SubagentStop を採用
  4. StartがStopより前か、同一sessionか、同一promptか、agent typeが一致するかを確認しない

したがって、次の入力でも昇格可能です。

event 1: SubagentStop
         session=B, agent_id=X

event 2: SubagentStart
         session=A, agent_id=X

event 3: Agent tool_result
         session=C, agentId=X

現行関数に残る情報だけを見ると、同じ agent_id=X として相関します。これは「same execution/session の因果鎖」ではなく、集合の共通要素です。

Issue #2183 の契約は、同一実行、同一agent ID、利用可能なら同一session ID、tool invocation、child transcriptを相関することを要求しています。Issue #2174 のOWNER要求も、Start/Stop、Agent tool call、child transcript、terminal completionの組合せを要求しています。

Claude Code公式hookには共通フィールドとして session_id があり、Claude Code v2.1.196以降はprompt単位の prompt_id もあります。PreToolUse/PostToolUse には同一tool callを結ぶ tool_use_id があり、PostToolUse はtoolが正常完了した後に発火します。(Claude)

必須修正

イベントを最低でも次の構造へ正規化してください。

HookEvidenceEvent(
    stream_index,
    source_channel,
    hook_event_name,
    session_id,
    prompt_id,
    agent_id,
    agent_type,
    tool_use_id,
    agent_transcript_path,
    last_assistant_message,
    stop_hook_active,
)

promotion条件は次です。

同一 session_id
同一 prompt_id(対応versionでは必須)
同一 agent_id
同一 agent_type
Start が Stop より前
対応する Agent tool call が同一session/prompt内
successful terminal tool result が存在
候補chainが一意
全期待markerがそのchildのassistant output由来

tool_use_result.agentId は現在の観測形式としては利用できますが、公式仕様は tool_response の具体的schemaがtoolごとに異なるとしています。したがって、フィールド名が現在見えていることだけで永続契約扱いせず、Claude Code versionを固定した実fixtureとcontract testが必要です。(Claude)


P1-1: child transcriptの「実在確認」が証跡の同一性・freshnessを証明していない

現在の _read_claude_agent_transcript_content() は次だけを確認します。

os.path.isfile(path)
open(path)
non-empty

これでは以下を排除できません。

  • symlink経由の任意ファイル
  • 別sessionのstale transcript
  • main transcriptと無関係な場所のファイル
  • agent IDと無関係なtranscript
  • 非常に大きいファイルの無制限read
  • transcript内のuser/tool入力にしかmarkerがないケース
  • hook発火後に差し替えられたファイル

公式仕様ではchild transcriptはmain transcript配下のネストされた subagents/ フォルダに置かれます。また、最終child textには last_assistant_message を使えます。([Claude]1)

修正要件

realpath containment、symlink拒否、regular-file確認、最大サイズ、run開始・終了時刻とのmtime整合、SHA-256、JSONL parse、assistant message限定抽出を実装してください。last_assistant_message をprimary provenance、transcriptをidentity・監査digestの補助証拠とするのが妥当です。


P1-2: stdout と output の矛盾、複数childの曖昧性をfail-closedにしていない

hook extractorは同一イベントの stdout と output を順に読み、後から読んだ値で先の値を上書きします。両者の agent_id、agent_type、transcript pathが矛盾してもエラーになりません。

また、複数childが存在する場合は、Start集合に含まれるIDを持つ「最初のStop」を採用します。どのAgent tool invocationが今回期待した作業なのか、一意性を証明していません。

次をfail-closedにすべきです。

outer / stdout / output の同一フィールド不一致
outer / inner hook_event_name 不一致
同一 agent_id の複数Start
同一 agent_id の複数terminal Stop
複数candidate chainが全条件を満たす
Start/Stop間のagent type不一致
tool resultのstatus未完了・error・interrupted

P1-3: 「Runtime Verification not_applicable」は外部wire-format parserとして不適切

対象関数のbooleanロジック自体はhermetic test可能ですが、このPRが依存しているのは以下の外部契約です。

  • Claude Code --include-hook-events のstream-json envelope
  • hook payloadのouter/inner配置
  • Agent tool resultの実際のschema
  • child transcriptの実パスと書き込みタイミング
  • native Claude CodeとClaude-GPT launcherのsettings差分
  • proxy経由時に実際にAgent dispatchが発生するか
  • Herdr interactive laneで観測可能な範囲

公式CLIではhook lifecycle eventをstream-jsonへ含めるには --include-hook-events と --output-format stream-json が必要です。([Claude]2)

またHerdrの現行ドキュメントでは、Claude Code integrationはsession identityを提供する一方、状態判定はscreen manifestをauthorityとしています。したがってHerdr snapshot/pane logはoperabilityやsession isolationの証明には使えますが、SubAgent causal evidenceの代替にはなりません。([Herdr]3)

分類は少なくとも次に変更すべきです。

unit_logic:
  applicability: hermetic

external_wire_compatibility:
  applicability: immediate
  required_runtimes:
    - native Claude Code
    - Claude-GPT

指定コメントを解消するためのlive verification matrix

merge前にcurrent headのまま、stacked worktreeで次を実行すべきです。mainへの先行mergeは不要です。

Native Claude Code

  1. randomized nonceをchildにのみ出力させるpositive run
  2. parentだけがnonceを出すnegative control
  3. 複数SubAgentを起動し、対象child以外が正常完了するnegative control
  4. sanitized stream-json、child transcript digest、summary receiptを保存

Claude-GPT

nativeと同じprompt、同じagent definition、同じnegative controlを scripts/claude-gpt/launch.sh 経由で実行します。launcherは現在 CLAUDE_GPT_RUNTIME_SMOKE_HOOKS=subagent-start-stop でStart/Stop hookを設定する実装なので、Agent PreToolUse/PostToolUse を正式なtool correlation sourceに採用する場合はlauncher側設定も同期が必要です。

証跡には、Claude Code version、launcher SHA、proxy version、proxy binary SHA-256を残すべきです。claude-code-proxy v0.1.34のreleaseにはasset checksumが公開されているため、単なるversion文字列より強いbindingが可能です。

比較receipt

raw promptやraw transcriptをPRへ添付せず、次のallowlist receiptを両runtimeで比較すべきです。

tested_head_sha:
runtime:
runtime_version:
launcher_sha256:
proxy_version:
proxy_binary_sha256:
session_id_sha256:
prompt_id_sha256:
agent_id_sha256:
agent_type:
agent_tool_use_id_sha256:
start_stream_index:
stop_stream_index:
terminal_result_stream_index:
child_transcript_sha256:
child_transcript_bytes:
last_assistant_message_sha256:
expected_markers:
  - marker_sha256:
    source: last_assistant_message
    observed: true
causal_evidence_source:
verdict:

Herdrについては、実行前後の全session/workspace/pane topology一致、isolated sessionの削除、multi-turn operabilityを別receiptにしてください。causal proofと混ぜるべきではありません。


必須の追加テスト

少なくとも以下を追加しない限り、判定器をfail-closedとは評価できません。

  1. Codex success + marker → exit 0
  2. Start/Stopが別session → FAIL
  3. StopがStartより前 → FAIL
  4. Start/Stopが別prompt → FAIL
  5. agent type不一致 → FAIL
  6. tool use/resultが別sessionまたは別prompt → FAIL
  7. tool resultがerror/未完了 → FAIL
  8. M1はchild、M2はparent → FAIL
  9. markerがchild user promptだけに存在 → FAIL
  10. markerがchild assistant finalだけに存在 → PASS
  11. transcript symlink/session外path/stale file/oversized file → FAIL
  12. stdout と output が矛盾 → FAIL
  13. 複数candidate childで一意に選べない → FAIL
  14. native Claude Codeから取得したsanitized fixture → PASS
  15. Claude-GPTから取得したsanitized fixture → PASS

現在のcausal-evidence testは、単一固定 SESSION_ID、synthetic fixture、正順序の単一childを中心としており、live Claude Code/Codex processを一切起動しないことを明示しています。現在問題になっている境界条件を十分には覆っていません。

最終disposition

PR #2220 は現在のまま承認しないでください。

優先順位は次です。

  1. Codex structured laneの回帰を修正
  2. marker provenanceを any からmarkerごとの all 証明へ変更
  3. session/prompt/時系列/agent type/terminal resultを含む一意なcausal chainへ変更
  4. transcript path・freshness・digestを強化
  5. current-headでnative Claude Code/Claude-GPTのpaired live verificationを実施
  6. session log比較をallowlist receiptとして添付
  7. そのheadに対して再度 adversarial review

CI greenや既存の impl-review-loop APPROVE は、上記の実Codex経路とcross-session/multi-marker反例を通していないため、merge readinessの根拠にはなりません。

squne121 and others added 3 commits August 17, 2026 07:00
Issue #2183 causal evidence 判定を以下の観点で強化する。

- P0-1: causal_evidence_required を args.runtime == "claude" にスコープし、
  Codex structured lane への誤適用(marker/exit0 でも causal_evidence が
  None を理由に FAIL する)を修正。--require-subagent-causal-evidence は
  --runtime claude --mode structured 以外の組み合わせを argparse level で
  拒否する。
- P0-2: marker_provenance_verified を「いずれか1つ」から「期待マーカー全て」
  の child-scoped (last_assistant_message + transcript JSONL の assistant
  record のみ)検証へ強化。
- P0-3: extract_claude_hook_lifecycle_events に stream_index/session_id/
  prompt_id/agent_type/stop_hook_active を追加し、Start<Stop の順序・
  session/prompt/type 一致・terminal かつ成功した tool result・候補の
  一意性を correlation 条件に追加。
- P1-1: _read_claude_agent_transcript_content に symlink 拒否・
  allowed_roots containment・サイズ上限・mtime 整合チェック・sha256
  digest 記録を追加。
- P1-2: stdout/output 矛盾検知(contradictory イベント)と複数候補 chain の
  曖昧性を fail-closed にする。

回帰テストを 43 -> 拡張、既存 test_run_worktree_agent_runtime_smoke.py /
test_run_worktree_agent_runtime_smoke_herdr_isolation.py の一部を新挙動へ
更新。docs (SKILL.md / references/claude-code.md) を同期。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…nt-runtime-smoke-hook-id-sub' into worktree-issue-2183-worktree-agent-runtime-smoke-hook-id-sub
@squne121

Copy link
Copy Markdown
Owner Author

fix_delta: OWNER REQUEST_CHANGES P0-1〜P1-2 対応

#2220 (comment) の指摘 6 件すべてに対応しました。新 head: 1866c646fb758f8a1bc9b7eda404580ccb12df79(worktree/branch は既存のものを継続使用、新規 worktree・新規 PR は作成していません)。

P0-1: Codex structured lane への causal gate 誤適用

causal_evidence_required を args.require_subagent_causal_evidence or (args.runtime == "claude" and bool(args.expect_marker)) に変更し、Codex 実行が誤って causal-evidence gate に巻き込まれないようにしました。あわせて --require-subagent-causal-evidence を --runtime claude --mode structured 以外と組み合わせた場合は main() が起動前に parser.error(exit 2)で拒否するようにしました。

  • 追加テスト: test_given_fake_codex_success_with_expected_marker_when_structured_lane_runs_then_exit0_and_causal_evidence_null(test_run_worktree_agent_runtime_smoke.py)
  • 既存テストの更新: test_given_interactive_lane_marker_only_when_require_subagent_causal_evidence_opt_in_then_fails を test_given_interactive_lane_with_require_subagent_causal_evidence_when_parsed_then_rejected へ改訂(test_run_worktree_agent_runtime_smoke_herdr_isolation.py)。注記: この変更により interactive lane はもはや --require-subagent-causal-evidence の opt-in 対象ではなくなりました(Issue 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 AC10 原文の opt-in 要求とは異なる破壊的変更です。P0-1 指示を文字通り実装した結果であり、OWNER の意図確認をお願いします)。

P0-2: marker provenance を any から marker ごとの all 証明へ

_marker_provenance_verified() を新設し、期待マーカー全てが child-scoped なテキスト(SubagentStop.last_assistant_message を主、transcript ファイルの JSONL パース後 type: "assistant" record のみを対象とした抽出を副)から見つかることを要求するよう変更しました。transcript の JSONL パース(_extract_assistant_message_texts_from_transcript)は assistant record のみを対象にし、user prompt / tool input record は除外します(非 JSONL の旧フィクスチャ互換のため、全行が JSON として解釈できない場合は raw content の部分一致にフォールバック)。

  • 追加テスト: test_given_marker_two_only_in_parent_final_message_when_verdict_computed_then_not_correlated、test_given_marker_only_in_child_user_prompt_record_when_verdict_computed_then_not_hook_id_correlated、test_given_marker_only_in_child_tool_input_record_when_verdict_computed_then_not_hook_id_correlated、test_given_marker_only_in_child_assistant_final_message_when_verdict_computed_then_hook_id_correlated、test_given_multiple_expected_markers_all_in_child_assistant_output_when_verdict_computed_then_hook_id_correlated、test_given_parent_and_child_emit_same_marker_when_verdict_computed_then_child_provenance_independently_confirmed

P0-3: session_id・prompt_id・時系列・agent_type の相関組み込み

extract_claude_hook_lifecycle_events() を拡張し、各イベントへ stream_index/session_id(embedded 優先・outer フォールバック)/prompt_id/stop_hook_active/contradictory を追加しました。subagent_causal_evidence_verdict() の相関ロジックを全面書き換えし、(1) 同一 agent_id の Start/Stop がそれぞれちょうど1件のみ、(2) Start の stream_index が Stop より前、(3) 両者が値を持つ場合の session_id/prompt_id/agent_type が一致、(4) Agent tool_use/tool_result が同一 session/prompt スコープで相関しかつ terminal 成功、(5) 全条件を満たす候補 chain がちょうど1つ、を要求するようにしました。_claude_agent_tool_invocation_correlated() は terminal_tool_result_success(status == "completed" かつ非 error)を追加で返します。

  • 追加テスト: test_given_start_and_stop_in_different_sessions_...、test_given_stop_stream_index_before_start_...、test_given_start_and_stop_in_different_prompts_...、test_given_start_and_stop_agent_type_mismatch_...、test_given_agent_tool_call_in_different_session_...、test_given_agent_tool_call_in_different_prompt_...、test_given_agent_tool_result_status_error_...、test_given_agent_tool_result_status_async_not_terminal_...(いずれも test_run_worktree_agent_runtime_smoke_causal_evidence.py)

P1-1: child transcript の実在確認強化

_read_claude_agent_transcript_content() を拡張し、symlink 拒否・許可 root(transcript_allowed_roots)containment・サイズ上限(既定 25MiB)・(run_start_time/run_end_time 指定時の)mtime 整合チェック・SHA-256 digest 記録を追加しました(戻り値を {"content", "sha256", "rejected_reason"} の dict に変更、この関数はモジュール内部専用のため呼び出し元は本 PR 内で完結)。

  • 追加テスト: test_given_transcript_path_is_symlink_...、test_given_read_transcript_content_symlink_path_when_read_then_rejected_is_symlink、test_given_transcript_path_outside_allowed_roots_...、test_given_read_transcript_content_within_allowed_roots_...、test_given_transcript_mtime_outside_run_window_...、test_given_read_transcript_content_oversized_when_read_then_rejected_oversized

P1-2: stdout/output 矛盾・複数候補の曖昧性を fail-closed に

extract_claude_hook_lifecycle_events() が同一イベントの stdout/output 両チャンネルで agent_id/agent_type/agent_transcript_path が矛盾する場合、そのイベントを contradictory: True としてマークし、いかなる派生フィールドも相関に使わないようにしました。相関ロジックは、同一 agent_id に複数 Start/複数 terminal Stop がある場合、および複数の異なる agent_id 候補 chain が独立に全条件を満たす場合(causal_evidence_ambiguous_candidate_count に候補数を記録)を、いずれも hook_id_correlated へ昇格させません。

  • 追加テスト: test_given_stdout_output_contradiction_on_hook_event_when_extracted_then_marked_contradictory、test_given_stdout_output_contradiction_when_verdict_computed_then_not_hook_id_correlated、test_given_multiple_fully_qualifying_candidate_chains_when_verdict_computed_then_ambiguous_not_hook_id_correlated

docs 同期

.claude/skills/worktree-agent-runtime-smoke/SKILL.md と references/claude-code.md の causal-evidence documentation を上記強化内容・lane 別既定挙動(P0-1 反映)に合わせて更新しました。

変更ファイル

  • scripts/agent-ops/run_worktree_agent_runtime_smoke.py
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md
  • .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md

検証結果

claude-gpt launcher の live 実行検証、および native Claude Code の live 検証は本 fix_delta のスコープに含めていません(hermetic synthetic fixture ベースのテストに留めています)。PR のマージ・auto-merge は行っていません。

…rse reject しないようにする

前回の fix_delta(P0-1: Codex structured lane への causal gate 誤適用の修正)で
`args.mode != "structured"` 条件を含めてしまい、claude runtime の interactive
mode でも --require-subagent-causal-evidence が argparse error になっていた。
Issue #2183 AC10(interactive lane は opt-in 時のみ causal evidence を要求する)
と矛盾するため、条件を `args.runtime != "claude"` のみに narrow する。

claude + interactive + --require-subagent-causal-evidence は既存の
causal_evidence 計算ロジック(run_interactive_herdr_isolated 経由)で
正しくゲートされる(marker_only_insufficient で FAIL するのが意図通り)ため、
argparse 時点での reject 対象から外す。

- 誤って reject する既存テストを削除せず、AC10 の正しい contract
  (claude+interactive+opt-inでFAILする回帰)に是正
- 非 claude runtime の reject テストを維持(codex+structured で確認)
@squne121

Copy link
Copy Markdown
Owner Author

fix_delta: --require-subagent-causal-evidence interactive lane 誤 reject の是正(P0-1 の過剰適用を修正)

新 head SHA: 28c16484b43030a29521758ea50420b6d2174bbd

背景

直前の fix_delta(Codex structured lane への causal gate 誤適用を防ぐ P0-1 修正)で argparse バリデーションを

if args.require_subagent_causal_evidence and (
    args.runtime != "claude" or args.mode != "structured"
):

と実装しましたが、args.mode != "structured" の条件により claude runtime の interactive mode でも --require-subagent-causal-evidence が argparse error になってしまい、Issue #2183 AC10(interactive lane は --require-subagent-causal-evidence 相当の opt-in 時のみ causal hook evidence を要求する)と直接矛盾していました。

修正内容

  • scripts/agent-ops/run_worktree_agent_runtime_smoke.py: バリデーション条件を args.runtime != "claude" のみに narrow(args.mode != "structured" を削除)。claude + interactive + --require-subagent-causal-evidence は argparse を通過し、既存の causal_evidence 計算ロジック(run_interactive_herdr_isolated 経由)で正しくゲートされます(herdr pane は hook payload を echo しないため通常 marker_only_insufficient になり opt-in で FAIL するのが意図通り)。
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py:
    • 誤って「claude+interactive で argparse reject される」ことを検証していたテストを削除せず、AC10 の正しい contract に是正: test_given_claude_interactive_lane_with_require_subagent_causal_evidence_when_marker_only_then_fails(claude+interactive+opt-in で marker_only_insufficient により exit 1 になることを検証)。
    • 非 claude runtime の reject を独立に検証するテストを追加: test_given_non_claude_runtime_with_require_subagent_causal_evidence_when_parsed_then_rejected(codex + structured で argparse exit 2 を確認、P0-1 の本来の修正意図を維持)。

structured lane の causal_evidence_required = args.require_subagent_causal_evidence or (args.runtime == "claude" and bool(args.expect_marker)) ロジック・コメントは変更なし(既に runtime == "claude" にスコープ済みで正しい)。codex + structured + --expect-marker の既存回帰テスト(test_given_fake_codex_success_with_expected_marker_when_structured_lane_runs_then_exit0_and_causal_evidence_null)は引き続き pass しています。

Verification 結果

$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py -v
123 passed in 63.29s
$ uv run --locked pytest scripts/agent-ops/tests/ -q
626 passed in 174.46s
$ uv run --locked ruff check scripts/agent-ops/run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py
All checks passed!

Issue #2183 AC9/AC10 VC(rg パターン):

  • AC9: test_given_marker_only_fake_claude_when_default_require_causal_evidence_gate_applies_then_structured_lane_fails / test_given_marker_only_fake_claude_when_no_expect_marker_then_default_causal_gate_does_not_apply がマッチ(既存、影響なし)
  • AC10: test_given_herdr_interactive_lane_pane_marker_only_when_causal_evidence_not_required_then_exit0 がマッチ(既存、影響なし)。今回追加の test_given_claude_interactive_lane_with_require_subagent_causal_evidence_when_marker_only_then_fails が AC10 の opt-in 要求側の実挙動を検証します。

Allowed Paths は変更していません。既存テストの削除もありません。マージ・auto-merge は未実施です。

…ranscript 実在性チェックを条件付き gate にする

live 検証(run_id 2e93d701786c, tested_head 28c1648)で、structured lane の
--no-session-persistence モードでは agent-<id>.meta.json スタブのみが書かれ
完全な .jsonl transcript が書き出されないケースが判明した。この場合
last_assistant_message 経由で marker provenance が確認できているにも関わらず
agent_transcript_verified の欠落だけで causal_evidence_source が no_evidence
に落ち --require-subagent-causal-evidence が誤って FAIL していた。

OWNER の P0-2 コメント方針(last_assistant_message を primary provenance、
transcript を補助 audit evidence とする)に沿い、
_marker_provenance_verified() を (verified, transcript_fallback_used) を
返すよう拡張し、last_assistant_message 単独で全期待 marker を満たせた場合
のみ agent_transcript_verified を causal_evidence_source 判定から除外する。
last_assistant_message が欠落している、または一部の marker しか満たせない
場合は従来どおり transcript ファイルへフォールバックし
agent_transcript_verified を hard gate のまま維持する(AC11 transcript
欠落/空/symlink ケース、AC12 negative control は退行なし)。

live 検証で発見した実バグの regression fixture、および fallback 経路が
維持されることを確認する追加テスト4件を追加した。
@squne121

Copy link
Copy Markdown
Owner Author

fix_delta: live 検証で発見した実バグの是正(P1-1 transcript hard gate を last_assistant_message primary provenance に対して条件付き化)

発見された実バグ(live 検証)

run_worktree_agent_runtime_smoke.py を native Claude Code(--runtime claude --mode structured)に対して実際に起動し、genuine SubAgent(Agent tool call)を実行させたところ(run_id 2e93d701786c, tested_head 28c16484)、以下がすべて genuine に観測できたにもかかわらず、

  • subagent_start_observed: True / subagent_stop_observed: True(agent_id 一致)
  • tool_invocation_id_correlated: True
  • marker_provenance_verified: True(last_assistant_message 由来で正しく確認できた)

agent_transcript_verified: False のために causal_evidence_source: 'no_evidence' となり、--require-subagent-causal-evidence 付きで誤って FAIL していました。

原因は、structured lane が --no-session-persistence を使うため、agent_transcript_path が指す .jsonl transcript ファイルが実際には書き出されず(代わりに agent-<id>.meta.json スタブのみが存在)、P1-1 のファイル実在性チェックが常に False になっていたことです。negative control(SubAgent を起動せず parent が marker だけを出力するケース)は正しく marker_only_insufficient になることも live 検証で確認しました。

修正内容

OWNER の P0-2 コメント「last_assistant_message を primary provenance、transcript を identity・監査 digest の補助証拠とする」方針に沿い、_marker_provenance_verified() を (verified, transcript_fallback_used) を返すよう拡張しました。

  • last_assistant_message 単独で 全期待 marker を満たせた場合のみ transcript_fallback_used = False とし、agent_transcript_verified の成否を causal_evidence_source の判定から除外する(audit metadata としてのみ記録)。
  • last_assistant_message が欠落している、または一部の marker しか満たせない場合は従来どおり transcript ファイルへフォールバックし、agent_transcript_verified を hard gate のまま維持する。

既存 negative control / transcript フォールパスの非弱体化確認

  • AC11(transcript 欠落・空・symlink・oversized 等): すべて last_assistant_message 未設定のフィクスチャであり、フォールバック経路が引き続き必須として動作することを既存テストで再確認しました(変更なしで PASS)。
  • AC12(無関係な SubAgent + parent marker のみ): last_assistant_message 経由のケースでも同様の negative control が成立することを確認する新規テスト test_given_unrelated_subagent_message_has_marker_transcript_missing_then_not_correlated を追加しました。
  • 新規に4件のテストを追加:
    • test_given_last_assistant_message_satisfies_markers_transcript_missing_then_hook_id_correlated(live バグの regression fixture: last_assistant_message あり・agent_transcript_verified=False・synthetic path はあるがファイル実在しない → hook_id_correlated)
    • test_given_no_last_assistant_message_and_transcript_missing_then_not_hook_id_correlated(last_assistant_message 不在時は引き続き transcript 必須のままであることの確認)
    • test_given_last_assistant_message_partial_markers_and_transcript_missing_then_not_correlated(last_assistant_message が一部 marker しか満たさない場合は fast path を使わずフォールバックすることの確認)
    • test_given_unrelated_subagent_message_has_marker_transcript_missing_then_not_correlated(AC12 negative control の last_assistant_message 経路版)

Verification 結果

  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py -v: 47 passed
  • uv run --locked pytest scripts/agent-ops/tests/ -q(full suite): 630 passed(181.40s)
  • uv run --locked ruff check scripts/agent-ops/run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_herdr_isolation.py: All checks passed!
  • Issue 実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する #2183 AC1〜AC13 の Verification Commands: 全 AC で該当文字列・テスト関数が確認できました(AC1/AC2/AC3/AC4/AC5/AC7/AC8/AC9/AC10/AC11/AC12/AC13 すべて一致、AC6 は上記 pytest 実行で確認済み)。

live smoke 再実行(修正後コードに対して、control-plane と同じコマンド)

uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py \
  --runtime claude --mode structured \
  --worktree <worktree絶対パス> \
  --prompt-file tmp/runtime-smoke/claude-structured-positive.md \
  --output-dir artifacts/runtime-smoke/claude-structured-positive-verify-fixdelta \
  --timeout-seconds 180 \
  --expect-marker RUNTIME_SMOKE_CAUSAL_MARKER_9f21a \
  --require-subagent-causal-evidence

結果: exit_code: 0(PASS)。summary.md の subagent_causal_evidence フィールド:

{'agent_id': 'ac5ebc5956db0b7cc', 'subagent_start_observed': True, 'subagent_stop_observed': True,
 'agent_transcript_path': '.../subagents/agent-ac5ebc5956db0b7cc.jsonl',
 'agent_transcript_verified': False, 'tool_invocation_id_correlated': True,
 'marker_provenance_verified': True, 'marker_provenance_transcript_fallback_used': False,
 'causal_evidence_source': 'hook_id_correlated', 'causal_evidence_ambiguous_candidate_count': None}

agent_transcript_verified: False(structured --no-session-persistence lane の構造的制約により transcript ファイルは依然として存在しない)にもかかわらず causal_evidence_source: 'hook_id_correlated' に正しく昇格し、--require-subagent-causal-evidence が PASS することを live で確認しました。

新 head

9d0cb49435794fc6722edd90555f2f95b25443ea

マージ・auto-merge は行っていません。人間のレビュー待ちです。

@squne121

Copy link
Copy Markdown
Owner Author

Native Claude Code live verification(御質問への回答)

動作検証済み?実際にClaudeCode、Claude-GPTどちらも証跡を確認できた?セッションログからも比較検証できた?

Native Claude Code: はい、control-plane が直接 live 検証しました。Claude-GPT: いいえ、Issue #2183 の既存 Stop Condition に該当するため今回は未実施です(詳細は後述)。

Native Claude Code positive/negative live receipt

.claude/worktrees/issue-2183-worktree-agent-runtime-smoke-hook-id-sub 内で run_worktree_agent_runtime_smoke.py --runtime claude --mode structured を fresh subprocess として実際に2回起動しました(--claude-bin 未指定、既定の native 経路)。

tested_head_sha: 9d0cb49435794fc6722edd90555f2f95b25443ea
runtime: claude (native, --claude-adapter native)
runtime_version: "2.1.233 (Claude Code)"

positive_run:
  prompt: "Task/Agent tool で genuine SubAgent を1体起動させ、SubAgent自身にmarkerを出力させる"
  child_agent_id: a57c944cfb7b2fc47
  subagent_start_observed: true
  subagent_stop_observed: true
  agent_transcript_path: ".../subagents/agent-a57c944cfb7b2fc47.jsonl"
  agent_transcript_verified: false   # --no-session-persistence 下では transcript ファイルが永続化されないことを実機確認(下記参照)
  tool_invocation_id_correlated: true
  marker_provenance_verified: true   # last_assistant_message 由来で確認
  marker_provenance_transcript_fallback_used: false
  causal_evidence_source: hook_id_correlated
  exit_code: 0

negative_control_run:
  prompt: "SubAgentを起動せずparent自身がmarkerだけを出力する"
  causal_evidence_source: marker_only_insufficient
  exit_code: 1(--require-subagent-causal-evidence指定時、意図通りFAIL)

live 検証で実際に見つかったバグとその修正(この fix_delta で対応済み)

positive run の初回実行で、subagent_start_observed/stop_observed/tool_invocation_id_correlated/marker_provenance_verified が全て true にもかかわらず、P1-1 で追加した transcript ファイル実在性チェック(agent_transcript_verified)が false になり、causal_evidence_source が no_evidence に落ちる実バグを発見しました。原因は、structured lane が固定 argv で使用する --no-session-persistence の下では、hook payload が指す child .jsonl transcript が実際には書き出されず、agent-<id>.meta.json(agentType/description/toolUseId/spawnDepth のみ)だけが残ることでした。

これは御指摘の P0-2 コメントにある「last_assistant_message をprimary provenance、transcriptをidentity・監査digestの補助証拠とする」という設計をまさに裏付ける実例だったため、agent_transcript_verified を hard gate から「marker provenance が transcript file へフォールバックした場合のみの gate」に変更しました(last_assistant_message で marker provenance を確認できた場合は transcript ファイル実在性を問わない)。修正後の再実行で causal_evidence_source: hook_id_correlated / exit_code: 0 を確認しました(上記 receipt)。

Claude-GPT launcher の live 検証について

御指摘の P1-3・live verification matrix が要求する Claude-GPT launcher 経由の paired live verification は、Issue #2183 の既存 Stop Condition「live claude-gpt launcher 実行による evidence 再取得が必須と判明した場合(対象 Issue 側の運用へ差し戻し、本 Issue は判定ロジック追加のみに留める)」に該当します。本 Issue の Out of Scope にも同旨の記載があります。

したがって本 PR の scope では実施せず、人間判断を仰ぎます。選択肢は概ね次のいずれかと考えます:

  1. Claude-GPT launcher での paired live verification(判定ロジック自体は本 PR で完成しているため、既存の --claude-bin/--claude-adapter claude-gpt 経路を使った実行のみ)を別 follow-up Issue として起票する。
  2. 今回に限り Stop Condition を明示的に override し、本 PR の scope 内で実施する。

御指示があれば従って進めます。


P0-1〜P1-2 修正まとめ

指摘 対応 head
P0-1: Codex structured lane への causal gate 誤適用 causal_evidence_required を runtime == claude 限定に修正。当初 mode == structured も条件に含めてしまい AC10 の interactive opt-in を壊す回帰を作ったため、追加修正で runtime != claude のみに是正 1866c646 → 28c16484
P0-2: marker provenance の any→all、last_assistant_message primary化 実装済み。上記 live 検証で実バグ(transcript hard gate)を発見し追加是正 1866c646 → 9d0cb494
P0-3: session/prompt/時系列/agent_type 相関 実装済み(session_id/prompt_id/stream_index 順序/agent_type 一致を promotion 条件に追加) 1866c646
P1-1: transcript 実在性・symlink・サイズ検証 実装済み。ただし live 検証結果を踏まえ hard gate 適用範囲を是正(上記) 1866c646 → 9d0cb494
P1-2: stdout/output 矛盾・複数candidate曖昧性の fail-closed化 実装済み 1866c646

Verification: pytest full suite 629 passed / 1 skipped、causal_evidence テスト 47 passed、ruff clean、Issue #2183 AC1〜AC13 全 VC PASS、CI 21/21 green、mergeStateStatus: CLEAN。

現 head: 9d0cb49435794fc6722edd90555f2f95b25443ea

@squne121

Copy link
Copy Markdown
Owner Author

impl-review-loop: LOOP_VERDICT (iteration 2, OWNER REQUEST_CHANGES 対応後)

verdict: APPROVE
reviewed_head_sha: "9d0cb49435794fc6722edd90555f2f95b25443ea"
blockers: []
warnings:
  - "PR本文 Checks セクションのテスト件数が古い(実測: causal_evidenceテスト47件、scripts/agent-ops/tests全体629 passed/1 skipped。advisory staleness、劣化ではない)"
  - "Claude-GPT launcher経由のlive検証は未実施(Issue #2183のStop Conditions/Out of Scopeに明記。follow-up Issue化するかは人間判断待ち)"

OWNER REQUEST_CHANGES(P0-1〜P1-2)に対する fix_delta 3周・native Claude Code での live evidence 独立検証(positive/negative control とも control-plane が独立再現)を経て、control-plane 独立 readback:

  • current head 9d0cb49435794fc6722edd90555f2f95b25443ea、mergeStateStatus: CLEAN、mergeable: MERGEABLE
  • required CI 全 pass(current head SHA 束縛)
  • Allowed Paths 遵守確認済み

route_loop_verdict_v2(): approved。impl-review-loop 終了。PR のマージ・auto-merge は行いません。

Claude-GPT launcher の live 検証(P1-3 の一部)は Issue #2183 の既存 Stop Condition に該当するため本ループの scope 外としました。follow-up Issue 化するか、本 Issue の scope 内で追加対応するかは人間判断をお願いします。

@squne121
squne121 merged commit 80b4f39 into main Aug 17, 2026
26 checks passed
@squne121
squne121 deleted the worktree-issue-2183-worktree-agent-runtime-smoke-hook-id-sub branch August 17, 2026 10:13
squne121 added a commit that referenced this pull request Aug 17, 2026
…ltiturn-lifecycle

Issue #2219本文・PR #2222 Notesで既に予告されていたhunk衝突(main()の
interactive-lane branch内、#2183のsubagent causal-evidence判定挿入と
#2219のhook-event multi-turn/lifecycle判定挿入が同一anchor付近)を解消する。

run_worktree_agent_runtime_smoke.py: #2219のhook-sink判定ブロック(既存の
`if args.runtime == "claude" and (require_min_subagents/require_min_turns/
scan_forbidden_markers)`ブロック内、インデント20)はそのまま維持し、その
直後(インデント16に戻った位置)に#2220のsubagent_causal_evidence_verdict
呼び出しブロックを追加する形で両方を保持する。両者は補完関係であり重複しない
(Issue #2219本文のOWNER調整メモ通り)。

SKILL.md: 「## claude-gpt Launcher 向け Multi-Turn / ... Evidence(Issue #2219)」
節と「## SubAgent 実行の因果関係証跡(Issue #2183)」節を両方保持する。

回帰確認: pytest -k worktree_agent_runtime_smoke 233 passed(#2220由来の
causal_evidence テストを含む)。ruff / Japanese content check 全 pass。
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.

実装: worktree-agent-runtime-smoke に hook ID ベースの SubAgent causal evidence 判定と runtime verification policy 更新を導入する

1 participant