Skip to content

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

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#2154"
goal_ref: "Claude Code を共通 development harness とし worktree-agent-runtime-smoke の SubAgent 実行 evidence を model 生成文字列でなく hook ID ベースの相関証拠で証明する"
change_kind: mixed

Parent Issue

#2154

Parent Goal Ref

  • Goal: Claude Code を共通 development harness とし、Anthropic subscription と ChatGPT Pro Codex subscription を独立 runtime として並列運用できる状態へ移行し、Codex CLI 実行系を段階的に廃止する。
  • Desired Destination: worktree-agent-runtime-smoke 共有 harness が、native Claude / claude-gpt launcher いずれの経路でも SubAgent 実行の因果性を model 出力に依存しない構造的証拠(hook ID 相関)で証明できる状態。

Current Validated Scope

  • 本 Issue の write-capable scope は scripts/agent-ops/run_worktree_agent_runtime_smoke.py / scripts/agent-ops/tests/ / docs/dev/runtime-verification-policy.md / .claude/skills/worktree-agent-runtime-smoke/SKILL.md / .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md に限定する。
  • SubagentStart / SubagentStop の agent_id 相関、および PreToolUse / PostToolUse の tool invocation ID 相関を用いた causal evidence 判定ロジックを追加し、marker 文字列の出力のみに基づく PASS 判定を置き換える。
  • docs/dev/runtime-verification-policy.md へ、SubAgent 実行の causal evidence 要件(hook ID 相関を要求し marker 文字列単独では不十分とする規約)を追記する。
  • scripts/claude-gpt/ 側(launch.sh 本体・narrow observability channel)の実装は Issue 実装: claude-gpt launcher を bootstrap し native canary で runtime を検証する #2158 / PR feat: claude-gpt launcher を bootstrap し native canary で runtime を検証する #2162 の scope であり、本 Issue では変更しない。

Remaining Parent Gaps

Outcome

scripts/agent-ops/run_worktree_agent_runtime_smoke.py に、SubagentStart/SubagentStop の同一 agent_id 相関・Agent tool call の invocation ID 相関・child transcript の存在と内容の相関・terminal completion を組み合わせた causal evidence 判定関数が追加され、marker 文字列(例: 完了を示す固定文字列)の出力のみでは PASS と判定されないことを示す hermetic regression test が PASS し、structured lane(因果性を hard gate とする)と interactive lane(因果性ではなく operability/multi-turn/session isolation を証明対象とする)の責務分離が契約・実装・docs に一貫して反映され、docs/dev/runtime-verification-policy.md に同要件が明文化されたコミットが作成された状態。

In Scope

  • scripts/agent-ops/run_worktree_agent_runtime_smoke.py に、extract_claude_hook_lifecycle_events が返す SubagentStart/SubagentStop イベント列から同一 agent_id を持つ Start/Stop ペアの有無を判定する関数 subagent_causal_evidence_verdict() を追加する。
  • PreToolUse/PostToolUse hook payload に含まれる tool invocation を相関する ID(Claude Code hook payload の tool_use_id 相当のフィールド)と Agent tool call のマッチングを行い、判定結果のフィールド tool_invocation_id_correlated(bool)として subagent_causal_evidence_verdict() の戻り値に含める。
  • subagent_causal_evidence_verdict() の戻り値に causal_evidence_source フィールド(enum: hook_id_correlated / marker_only_insufficient / no_evidence)を含める。hook_id_correlated を返すのは、以下をすべて満たした場合に限る(いずれか一つでも欠落・不一致の場合は hook_id_correlated へ昇格しない fail-closed 判定とする)。
    1. 同一 agent_id の SubagentStart と terminal な SubagentStop(stop_reason 相当のフィールドが取得できる場合はエラー・タイムアウト等の non-terminal 値でないこと)が同一実行(同一 stdout ストリーム・取得可能なら同一 session_id)内に観測されること。
    2. SubagentStop payload の agent_transcript_path 相当のフィールドが取得でき、tool_invocation_id_correlated == True(対応する Agent tool call の invocation ID 相関が成立していること)であること。
    3. --expect-marker 等で期待成果物・marker 文字列の照合を要求する呼び出しにおいては、その期待値が 相関済み child の transcript / last_assistant_message 相当のフィールド由来であることを追加確認し、parent 自身の最終応答文字列のみに一致した場合は hook_id_correlated としない。
  • lane separation: structured lane(run_structured_claude 経由、--include-hook-events の stream-json チャンネルが構造的に利用可能)は、呼び出し側が --expect-marker 等で SubAgent 実行結果の照合を要求する場合、causal_evidence_source == "hook_id_correlated" を PASS の必要条件として要求する(既定強制。追加フラグ不要)。interactive lane(run_interactive_herdr_isolated 経由、herdr pane のテキストレンダリングには --include-hook-events の hook payload が構造的に現れない)は、Skill/SubAgent の因果性証明を hook evidence に依存させず、既存の operability / multi-turn / session isolation の証拠(Issue 実装: worktree-agent-runtime-smoke に claude-gpt launcher 選択入力を追加し Lane A/B 実機検証する #2174 で追加された Herdr session baseline 比較等)を PASS 条件として維持する。interactive lane で causal hook evidence の追加確認を要求したい呼び出し元向けに、--require-subagent-causal-evidence 相当の opt-in フラグを提供してよい。marker 文字列判定は両 lane で補助情報として残してよいが単独で PASS 判定に用いない。
  • SubagentStart のみが観測され対応する SubagentStop が観測されない場合(既存の CHILD_TERMINAL_STATUS_ASYNC_NO_STOP 相当のケース)、hook イベントが一切観測されず marker 文字列のみが出力された場合、SubagentStart/SubagentStop の agent_id が不一致の場合、tool_invocation_id_correlated == False の場合、agent_transcript_path が欠落または実在しない/内容が相関しない場合、無関係な SubAgent が正常終了した後に parent model 自身が completion marker を出力した場合、のそれぞれで causal_evidence_source が hook_id_correlated 以外(no_evidence または marker_only_insufficient)になることを検証する hermetic regression test(合成 stdout fixture ベース、live 実行不要)を追加する。
  • docs/dev/runtime-verification-policy.md の「10. worktree-agent-runtime-smoke」セクション付近に、SubAgent 実行の causal evidence は hook ID 相関(Start/Stop agent_id 一致・tool invocation ID 相関・child transcript 由来の成果物確認・terminal completion)を要求し marker 文字列単独では不十分とする規約、および structured/interactive lane の責務分離を追記する。
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md および references/claude-code.md に、subagent_causal_evidence_verdict() の利用方法・causal_evidence_source の意味・lane ごとの既定挙動を追記する。

Out of Scope

Acceptance Criteria

  • AC1: scripts/agent-ops/run_worktree_agent_runtime_smoke.py に関数 subagent_causal_evidence_verdict() が定義されている。
  • AC2: subagent_causal_evidence_verdict() の戻り値に causal_evidence_source フィールドが含まれる。
  • AC3: subagent_causal_evidence_verdict() の戻り値に tool_invocation_id_correlated フィールドが含まれ、tool_invocation_id_correlated == False の場合は causal_evidence_source が hook_id_correlated にならない(判定結果に実効性がある)。
  • AC4: SubagentStart のみ観測(SubagentStop 欠落)の合成 stdout fixture を入力した場合に causal_evidence_source が hook_id_correlated 以外(no_evidence または既存の CHILD_TERMINAL_STATUS_ASYNC_NO_STOP 相当の否定的な値)を返すことを検証する hermetic regression test が追加されている。
  • AC5: hook イベントが一切観測されず marker 文字列のみが出力された合成 stdout fixture を入力した場合に causal_evidence_source が marker_only_insufficient を返すことを検証する hermetic regression test が追加されている。
  • AC6: 追加した causal evidence regression test が pytest で PASS する。
  • AC7: docs/dev/runtime-verification-policy.md に、SubAgent 実行の causal evidence は hook ID 相関を要求し marker 文字列出力のみでは不十分とする規約が追記されている。
  • AC8: .claude/skills/worktree-agent-runtime-smoke/SKILL.md に subagent_causal_evidence_verdict() の利用方法が追記されている。
  • AC9: structured lane(run_structured_claude 経由)は --expect-marker 指定時、causal_evidence_source == hook_id_correlated を追加フラグなしで PASS の必要条件として要求する(既定強制)ことを検証する hermetic regression test が追加されている。
  • AC10: interactive lane(run_interactive_herdr_isolated 経由)は、既存の operability / multi-turn / session isolation の証拠を PASS 条件として維持し、causal hook evidence を既定で要求しない(--require-subagent-causal-evidence 相当の opt-in 時のみ要求する)ことがコード・テストで確認できる。
  • AC11: SubagentStart/SubagentStop の agent_id が一致するが agent_transcript_path が欠落・空・実在しない、または期待される marker/成果物がその transcript / last_assistant_message 相当のフィールド由来であると確認できない合成 fixture を入力した場合に、causal_evidence_source が hook_id_correlated にならないことを検証する hermetic regression test が追加されている。
  • AC12: 無関係な SubAgent(別の agent_id、期待成果物と無関係な transcript)が正常に Start/Stop し、期待 marker 文字列が parent model 自身の最終応答テキストにのみ出現するケースを合成 stdout fixture で再現し、PASS/hook_id_correlated にならないことを検証する negative control regression test が追加されている。
  • AC13: .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md に subagent_causal_evidence_verdict() / causal_evidence_source / lane ごとの既定挙動に関する causal-evidence documentation が追記されている。

Verification Commands

# AC1
# baseline-expect: fail
$ rg -n "def subagent_causal_evidence_verdict" scripts/agent-ops/run_worktree_agent_runtime_smoke.py
# AC2
# baseline-expect: fail
$ rg -n "causal_evidence_source" scripts/agent-ops/run_worktree_agent_runtime_smoke.py
# AC3
# baseline-expect: fail
$ rg -n "tool_invocation_id_correlated" scripts/agent-ops/run_worktree_agent_runtime_smoke.py
# AC4
# baseline-expect: fail
$ rg -n "def test.*subagent_start_without_stop" scripts/agent-ops/tests
# AC5
# baseline-expect: fail
$ rg -n "marker_only_insufficient" scripts/agent-ops/tests
# AC6
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py -v
# AC7
# baseline-expect: fail
$ rg -n "hook ID 相関" docs/dev/runtime-verification-policy.md
# AC8
# baseline-expect: fail
$ rg -n "subagent_causal_evidence_verdict" .claude/skills/worktree-agent-runtime-smoke/SKILL.md
# AC9
# baseline-expect: fail
$ rg -n -e "def test.*expect_marker.*default" -e "def test.*structured.*default.*causal" -e "def test.*default.*require.*causal" scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py
# AC10
# baseline-expect: fail
$ rg -n -e "def test.*interactive.*causal.*opt.?in" -e "def test.*herdr.*causal_evidence" scripts/agent-ops/tests
# AC11
# baseline-expect: fail
$ rg -n -e "def test.*transcript.*not_correlated" -e "def test.*transcript.*content" scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py
# AC12
# baseline-expect: fail
$ rg -n -e "def test.*unrelated_subagent" -e "def test.*parent.*marker" scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke_causal_evidence.py
# AC13
# baseline-expect: fail
$ rg -n "causal_evidence_source" .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md

Allowed Paths

  • scripts/agent-ops/run_worktree_agent_runtime_smoke.py
  • scripts/agent-ops/tests/(新規テストファイル test_run_worktree_agent_runtime_smoke_causal_evidence.py を含む既存テストの更新を許容)
  • docs/dev/runtime-verification-policy.md
  • .claude/skills/worktree-agent-runtime-smoke/SKILL.md
  • .claude/skills/worktree-agent-runtime-smoke/references/claude-code.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • scripts/claude-gpt/launch.sh 自体の修正が必要と判明した場合(Issue 実装: claude-gpt launcher を bootstrap し native canary で runtime を検証する #2158 / PR feat: claude-gpt launcher を bootstrap し native canary で runtime を検証する #2162 側の scope へ差し戻す)
  • live claude-gpt launcher 実行による evidence 再取得が必須と判明した場合(対象 Issue 側の運用へ差し戻し、本 Issue は判定ロジック追加のみに留める)
  • interactive lane に対して structured lane 相当の hook payload 観測チャネルを新設する必要があると判明した場合(herdr 側の構造的制約変更が必要になり別 Issue の scope になるため)

Required Skills

なし

Required Design References

Runtime Verification Applicability

  • decision: not_applicable
  • reason: subagent_causal_evidence_verdict() は既存の extract_claude_hook_agent_identity / extract_claude_hook_lifecycle_events と同様、既にキャプチャされた stdout テキスト(JSON イベント列)を入力とする純粋関数として実装可能であり、合成 stdout fixture を用いた hermetic pytest で全 AC を決定論的に検証できる。live claude-gpt launcher 実行や実際の Herdr session を新規に起動する必要はない。
applicable_acs: なし
execution_environment: N/A(hermetic pytest のみで検証完結)
skip_conditions: N/A
fallback_policy: N/A
artifact_requirements: N/A

Notes for Reviewer

Scope Delta(該当時のみ記載)

N/A(本 Issue 自体の in-place reframe。実装時の命名規約調整は引き続き Scope Delta として PR 側に記録する)

Delivery Rule

1 Issue = 1 PR で repository implementation を完結させる。dedicated worktree で作業し、Draft PR をデフォルトとする。

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Aug 15, 2026
  2. squne121 commented on Aug 16, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了

  3. added a commit that references this issue on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions