Skip to content

調査: worktree_scope_guard の issue番号命名要求が汎用 isolation worktree agent の preflight.run 実行を妨げる問題の対応方針を決定する #1464

Closed
1 of 1 issue completed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: "none"
goal_ref: "canonical_main_root/default_branch invariant と isolation worktree agent の cwd との衝突という正しい root cause に基づき、preflight.run 認可を isolation worktree agent から成立させる対応方針を real hook chain runtime evidence で決定し、必要なら implementation Issue を起票する"
change_kind: research-only

Parent Issue

none(単独改善)

Related Issues

Outcome

.claude/hooks/worktree_scope_guard.py の issue worktree 判定パターン(_ISSUE_RE 等)不一致を根本原因と誤認していた事象について、正しい root cause(scripts/agent-guards/skill_runtime_command_policy.py が preflight.run に要求する required_cwd: canonical_main_root / required_branch: default_branch invariant と、Agent tool の isolation: "worktree" で生成される汎用 worktree の cwd との衝突。ROOT_NO_WORKTREE_ALLOWED_COMMAND_IDS は linked issue worktree の存在のみを免除し、root cwd / default branch の要求は免除しない)を本Issueに確定的に記録し、対応方針候補 (a)〜(d) を real hook chain runtime evidence で比較し、採用方針を1つに決定し、implementation Issue が起票可能な状態になる。

Research Result

以下は本Issueの調査結論を機械可読な形でまとめたものである。詳細な根拠は Background / In Scope / AC2 の runtime matrix を参照する。

research_result:
  root_cause: canonical_main_root_invariant_conflicts_with_isolated_agent_cwd
  secondary_cause: generic_isolation_worktree_has_no_issue_identity_binding
  non_root_cause: issue_worktree_regex_mismatch_alone
  adopted_option: d_parent_owned_preflight
  agent_name_based_authorization: prohibited
  direct_wrapper_use: prohibited
  issue_1465_relationship: related_but_not_duplicate
  issue_1472_relationship: architecture_precedent
  pr_1473_relationship: implementation_precedent
  runtime_evidence:
    artifact_root: ".claude/artifacts/issue-refinement-loop/1464/runtime_matrix/ (ephemeral, issue-1464専用worktree内・untracked)"
    matrix_status: pass
  implementation_issue_number: 1478

In Scope

  • 正しい root cause(skill_runtime_command_policy.py の required_cwd / required_branch invariant と isolation worktree agent の cwd との衝突)の、line anchor 付きでの確定的記録
  • 対応方針候補の比較検討:
    • (a) guard 側に agent-* 系の汎用 isolation worktree 命名パターンを追加する
    • (b) orchestrator が isolation worktree agent へ issue-refinement-loop を委譲する際に事前に issue-<N>-* 命名の worktree を作らせるよう手順を変更する
    • (c) 現状維持(run_refinement_preflight.py を registry 外で直接呼ぶ回避策を継続する)
    • (d) parent-owned preflight: 親 orchestrator が canonical main root / default branch で exact executor(skill_runtime_exec.py 経由の preflight.run)を実行し、NEXT_ACTION と bounded な planner result のみを isolation agent に渡す。isolation agent は skill_runtime_exec.py も direct wrapper も実行しない
  • 各方針が既存の認可境界(exact command class、trusted repo binding、canonical root/default branch 検査、registry entry invariant 検査、artifact subtree containment、direct wrapper block)を壊さないかの評価
  • 次の runtime matrix を real hook chain(実際の PreToolUse hook, stdin JSON, 実 git worktree)で実行し、各ケースの cwd・project root・branch・exit code・reason code を machine-readable artifact として保存する:
    • main root・default branch・exact executor → allow
    • issue worktree・exact executor → deny
    • generic isolation worktree・exact executor → deny
    • main root・direct wrapper → deny
    • non-default branch・exact executor → deny
  • 採用方針の選定
  • 採用方針が (a)(b)(d) のいずれかで実装を要する場合、それを実装する implementation Issue の起票(変更対象を issue-refinement-loop の orchestration/documentation に限定し、guard regex 拡張は scope に含めない)
  • 調査: isolation worktree 環境で issue-reviewer 等 SubAgent の artifact が呼び出し元から解決できない問題の対応方針を決定する #1465(CLOSED)/実装: issue-reviewer SubAgent 内に Step 2a arbitration を co-locate し親の raw artifact 直接読み契約を廃止する #1472/実装: issue-reviewer SubAgent 内で reviewer_claim_replay.py を co-locate 実行する #1473 の内容を取り込んだ上で、本Issueを継続・他Issueへの supersede・duplicate のいずれにするかの記録

Out of Scope

  • .claude/hooks/worktree_scope_guard.py 本体の実装変更
  • .claude/skills/issue-refinement-loop/SKILL.md 以外のスキル手順変更
  • Agent tool(isolation worktree 起動基盤)自体の変更
  • preflight.run 以外の command registry entry の挙動変更
  • guard に agent-* 命名パターンを追加することを認可根拠とする実装(候補 (a) は issue binding が成立しないため単独では不採用)

Acceptance Criteria

  • AC1: scripts/agent-guards/skill_runtime_command_policy.py の preflight.run 認可条件(required_cwd / required_branch / ROOT_NO_WORKTREE_ALLOWED_COMMAND_IDS 等)と .claude/hooks/worktree_scope_guard.py の issue worktree 判定 regex(_ISSUE_RE 等)が、line anchor 付きで本Issue本文に記載され、実在確認済みである
  • AC2: runtime matrix(main root・default branch・exact executor=allow / issue worktree・exact executor=deny / generic isolation worktree・exact executor=deny / main root・direct wrapper=deny / non-default branch・exact executor=deny)が real hook chain で実行され、各ケースの cwd・project root・branch・exit code・reason code が machine-readable artifact として保存され、本Issueから参照されている
runtime_matrix:
  schema: RUNTIME_MATRIX_ISSUE_1464_V1
  hook_chain:
    - .claude/hooks/local_main_branch_guard.sh
    - .claude/hooks/worktree_scope_guard.sh
  matrix_status: pass
  cases:
    - case_id: 1_main_root_default_branch_exact_executor
      expected_result: allow
      actual_result: allow
      status: pass
      exit_code: 0
      branch: main
    - case_id: 2_issue_worktree_exact_executor
      expected_result: deny
      actual_result: deny
      status: pass
      exit_code: 2
      branch: worktree-issue-1464-child
      blocking_hook: worktree_scope_guard.sh
      reason: "mutation outside active issue worktree (expected_worktree: <skill-runtime-denied>)"
    - case_id: 3_generic_isolation_worktree_exact_executor
      expected_result: deny
      actual_result: deny
      status: pass
      exit_code: 2
      branch: worktree-agent-a0000000000000000
      blocking_hook: worktree_scope_guard.sh
    - case_id: 4_main_root_direct_wrapper
      expected_result: deny
      actual_result: deny
      status: pass
      exit_code: 2
      branch: main
      blocking_hook: local_main_branch_guard.sh
      reason_code: unparseable_branch_mutation
    - case_id: 5_main_root_non_default_branch_exact_executor
      expected_result: deny
      actual_result: deny
      status: pass
      exit_code: 2
      branch: topic/no-worktree-negative

この matrix は、実在の .claude/hooks/local_main_branch_guard.sh と .claude/hooks/worktree_scope_guard.sh を、既存の契約テスト scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py と同じ手法(実 git repo を一時ディレクトリに構築し、stdin JSON で実 hook shell wrapper を subprocess 起動)で、issue-1464 専用の一時 worktree(worktree-issue-1464-preflight-runtime-matrix)内から実行して得た。重要な発見は、preflight.run の認可判定が worktree_scope_guard.sh 単体ではなく、local_main_branch_guard.sh → worktree_scope_guard.sh という2段の hook chain 全体で行われていることである。direct wrapper(run_refinement_preflight.py の main root からの直接呼び出し)の拒否は local_main_branch_guard.sh 側(reason_code: unparseable_branch_mutation)が担っている。

Verification Commands

# AC1
$ rg -n "required_cwd" scripts/agent-guards/skill_runtime_command_policy.py
$ rg -n "required_branch" scripts/agent-guards/skill_runtime_command_policy.py
$ rg -n "ROOT_NO_WORKTREE_ALLOWED_COMMAND_IDS" scripts/agent-guards/skill_runtime_command_policy.py
$ rg -n "_ISSUE_RE = re.compile" .claude/hooks/worktree_scope_guard.py

# AC2
$ gh issue view ISSUE_NUMBER --repo squne121/loop-protocol --json body --jq ".body"

# AC3
$ gh issue view ISSUE_NUMBER --repo squne121/loop-protocol --json body --jq ".body"

# AC4
$ gh issue view ISSUE_NUMBER --repo squne121/loop-protocol --json body --jq ".body"

# AC5
$ rg -n "def test_direct_preflight_block" scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py

# AC6
$ gh issue view ISSUE_NUMBER --repo squne121/loop-protocol --json body --jq ".body"

# AC7
$ gh issue view ISSUE_NUMBER --repo squne121/loop-protocol --json body --jq ".body"

Allowed Paths

  • 読み取り専用。リポジトリ追跡ファイルへの変更なし。
  • runtime evidence 収集のための .claude/artifacts/issue-refinement-loop/1464/ 配下の untracked artifact 生成のみ許可する。

Stop Conditions

  • Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
  • Allowed Paths 外への書き込みを試みた場合は即停止
  • 権限不足(permission denied)により操作が完了できない場合は即停止
  • 成果物の書き込みに失敗した場合(I/O エラー等)は即停止

Runtime Verification Applicability

  • decision: not_applicable
  • 本Issueは research-only(issue_kind: research)であり、実装コードのデプロイを伴わない。AC2 の runtime matrix 収集自体は本Issueの調査行為そのものであり、docs/dev/runtime-verification-policy.md が扱う「実装後の runtime 検証要否」の対象ではない。

Handoff Contract

Background

Issue #1458 に対して issue-refinement-loop を isolation worktree agent 内で実行した際、issue-refinement-loop Step 0f の規約どおり uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number 1458 --repo squne121/loop-protocol を実行しようとしたところ、worktree_scope_guard hook がこのコマンドの実行をブロックした。

当初、原因は .claude/hooks/worktree_scope_guard.py の issue worktree 判定 regex(_ISSUE_RE 等、^(?:worktree-)?issue-(\d+)-)が、Agent tool の isolation: "worktree" で生成される汎用 worktree(例: ブランチ worktree-agent-a4771f29e143cb291)に一致しないためだと考えられていた。

しかし、OWNER によるレビュー(anchor comment、2026-07-11)により、この原因分析は誤りであることが判明した。scripts/agent-guards/skill_runtime_command_policy.py の認可条件は、preflight.run に対して required_cwd: canonical_main_root / required_branch: default_branch を要求しており、ROOT_NO_WORKTREE_ALLOWED_COMMAND_IDS は linked issue worktree の存在のみを免除する。root cwd / default branch の要求そのものは免除されないため、候補 (a) のように agent-* を _ISSUE_RE へ追加しても、isolation worktree の cwd からは cwd_not_canonical_main_root で拒否される。

この実行境界は意図的な設計であり、#1154 で preflight.run 専用の privileged exact executor が導入され、#1228 / PR #1231 で「linked worktree がなくても main root/default branch から実行可能」という現行仕様が固まった経緯がある。また #1465(isolation worktree 環境での SubAgent artifact 可視性問題)は本Issueを関連Issueとして明示していたが、#1465 の採択方針 (e)(producer/consumer co-location、#1472/#1473 で実装済み)は Step 2a の別の authorization layer を解決するものであり、本Issueの preflight.run root/branch invariant の問題を直接解決しない。

以上を踏まえ、本Issueの root cause 記述・対応方針候補・Acceptance Criteria を全面的に改訂した。AC1〜AC7 の実施結果として、runtime matrix(AC2)を real hook chain で実行し 5/5 ケース期待通りの結果を得たうえで、採用方針を (d) parent-owned preflight に決定し、implementation Issue #1478 を起票した。

Required Skills

  • なし(読み取り専用の調査タスクであるため)

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    phase/research
    on Jul 11, 2026
  2. squne121 commented on Jul 11, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES — Issue #1464 は、現状の原因分析・選択肢・Acceptance Criteria のままでは調査を開始すべきではありません。

    事象自体はあり得ますが、Issue が根本原因としている「Issue worktree の命名 regex 不一致」は主因ではありません。既存実装では preflight.run を許可する前提が canonical main root + default branch に固定されており、汎用 isolation worktree の名前を regex に追加しても実行可能にはなりません。

    Issue #1464 には現時点でコメントがなく、以下は Issue 本文、関連 Issue/PR、現行 main の実装と公式仕様を突き合わせたレビューです。

    Blocker 1: 根本原因が誤っている

    Issue は次の regex が worktree-agent-* に一致しないことを原因としています。

    _ISSUE_RE = re.compile(r"^(?:worktree-)?issue-(\d+)-")
    _ISSUE_BASENAME_RE = re.compile(r"^issue-(\d+)-")
    _ISSUE_BRANCH_RE = re.compile(r"^(?:worktree-)?issue-(\d+)-")
    

    これらは実在します。

    しかし、skill_runtime_exec.py の認可はそれ以前に以下を要求します。

    cwd == project_root
    current branch == default branch
    repo slug == trusted repository
    

    preflight.run は linked issue worktree の存在だけが免除されており、root cwd と default branch の要求は免除されていません。

    したがって、候補 (a) のように agent-* を _ISSUE_RE へ追加しても、isolation worktree の cwd からは cwd_not_canonical_main_root で拒否されます。

    Issue の原因記述は、少なくとも次へ修正すべきです。

    root_cause:
      primary: canonical_main_root invariant conflicts with isolated-agent cwd
      secondary: generic worktree has no issue-number identity binding
      non_root_cause: issue worktree regex mismatch alone
    

    Blocker 2: 既存の意図的な設計を無視している

    この実行境界は偶然ではありません。

    という経緯があります。

    現行 policy も明示的に次を定義しています。

    preflight.run:
      required_cwd: canonical_main_root
      required_branch: default_branch
      allowed_write_roots:
        - .claude/artifacts/issue-refinement-loop/{active_issue}/
      network_effect: github_read_only
    

    さらに、preflight.run だけが root-no-worktree allowlist に登録されています。

    Issue #1464 の三択は、この既存設計に沿う最有力案を欠いています。

    親の canonical main-root control plane が preflight を実行し、その結果だけを isolated agent に渡す。

    これは候補 (d) として追加すべきです。

    Blocker 3: 候補 (a) は issue binding を破壊する

    agent-* という名前からは Issue 番号を導出できません。

    現行の issue worktree 解決は、branch と path basename の双方を同じ Issue 番号へ束縛し、一意な worktree だけを採用します。

    一方、汎用 Agent worktree を許可すると、次の対応関係が存在しません。

    agent ID → issue number
    worktree path → issue number
    branch → --issue-number
    

    単純な allowlist 拡張では、Agent worktree から任意の --issue-number を指定できる設計になり得ます。安全に成立させるには、親が発行した capability、session nonce、Issue 番号、repo、worktree realpath、期限などを束縛した別の認可プロトコルが必要です。

    また、Claude Code の公式仕様は isolation worktree の利用を説明していますが、worktree-agent-<id> という固定ブランチ命名を公開契約として保証していません。WorktreeCreate の識別子も user-specified または auto-generated slug とされています。セキュリティ判定を未保証の名前形式へ依存させるべきではありません。 (Claude Platform Docs)

    候補 (a) は棄却が妥当です。

    Blocker 4: 候補 (b) は Agent tool の動作と整合しない

    「orchestrator が先に issue-<N>-* worktree を作れば、isolation agent がそれを使う」という契約は示されていません。

    公式仕様上、isolation: worktree は SubAgent 用の一時 worktree を作成します。既存 worktree を自動検出して再利用する仕様ではありません。 (Claude Platform Docs)

    既定の worktree 作成を差し替える正式な拡張点は WorktreeCreate hook ですが、この hook は既定動作全体を置き換え、絶対パスを返す必要があります。これは単なる orchestrator 手順変更ではなく、Agent 基盤、cleanup、競合、所有権を含むシステム変更です。 (Claude Platform Docs)

    したがって候補 (b) は、現在の以下の Out of Scope と矛盾します。

    • Agent tool 自体の変更なし

    • worktree_scope_guard.py の実装変更なし

    • issue-refinement-loop/SKILL.md 以外の手順変更なし

    候補 (b) も現行 scope 内では実現不能です。

    Blocker 5: 候補 (c) は回避策ではなく、意図的に禁止された bypass

    Issue は run_refinement_preflight.py の直接呼び出し継続を候補にしています。

    しかし #1228/PR #1231 は、まさに次を安全境界として固定しています。

    • exact skill_runtime_exec.py は main root から許可

    • direct run_refinement_preflight.py は拒否

    • non-default branch/detached HEAD は拒否

    • artifact root 外への書き込みは fail-closed

    現行テストにも direct invocation の block が明示されています。

    直接実行すると、少なくとも以下を迂回します。

    • exact argv parser

    • trusted repo binding

    • canonical root/default branch 検査

    • registry entry invariant 検査

    • artifact subtree containment

    • 実行前後の unauthorized write 検査

    候補 (c) は選択肢から削除すべきです。

    Major findings

    1. SKILL.md と privileged executor の二層構造が曖昧

    現行 issue-refinement-loop/SKILL.md は「registry entry を canonical とする」と書きつつ、コード例では直接 run_refinement_preflight.py を呼んでいます。

    一方、registry の preflight.run は privileged executor が内部で起動する child argv です。metadata は canonical_main_root と default_branch を要求しています。

    次の二層を明文化する必要があります。

    operator/orchestrator-facing command:
      scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run ...
    

    executor-internal child argv:
    run_refinement_preflight.py --issue-number ... --repo ...

    SubAgent が後者を直接使用してはならないことも明記すべきです。

    2. ランタイム証跡がない

    本件は runtime-dependent ですが、AC1・AC2 は regex と Issue 本文の存在確認に留まっています。

    最低限必要なのは次です。

    Claude Code version
    Agent tool invocation and isolation setting
    hook input cwd
    CLAUDE_PROJECT_DIR
    pwd
    git rev-parse --show-toplevel
    git branch --show-current
    exact command
    guard exit code
    guard reason code / stderr

    「Issue #1458 の実行ログ」という Handoff も、具体的なコメント URL、artifact path、run ID、commit SHA がなく追跡不能です。取得した #1458 のコメントからも、本件の正規 runtime evidence を一意に特定できませんでした。

    3. #1465 の結果を先に取り込む必要がある

    #1465 は #1464 を関連 Issue として明示し、共通原因の可能性と、#1465 完了後に #1464 の重複判定を行うことを要求しています。

    その後、#1472/#1473 では isolation 境界をまたぐ raw artifact 読み取りをやめ、producer と consumer を同じ SubAgent 内へ co-locate する変更が実装されています。

    これは preflight.run を直接解決する変更ではありませんが、リポジトリの最新方針として次を示しています。

    generic worktree を issue worktree として緩く認可するのではなく、処理を適切な実行境界へ配置し、境界をまたぐデータを compact にする。

    #1464 もこの方針と整合させるべきです。

    採用すべき方針

    推奨: 候補 (d) — parent-owned preflight

    adopted_option: d_parent_owned_preflight

    手順は次です。

    1. 親 orchestrator が canonical main root/default branch にいる状態で、exact executor を使って preflight.run を実行する。

    2. artifact は既存どおり .claude/artifacts/issue-refinement-loop/<issue>/ に生成する。

    3. NEXT_ACTION、必要な digest、bounded な planner result だけを isolation agent へ渡す。

    4. isolation agent は skill_runtime_exec.py も direct wrapper も実行しない。

    5. preflight の再実行が必要なら、子が親へ要求を返し、親が実行する。

    最も単純なのは、isolation agent を起動する前に Step 0f を完了する構成です。

    この方式は既存の以下を維持できます。

    • canonical root/default branch

    • trusted repository binding

    • exact command class

    • artifact-only write

    • generic Agent worktree と Issue identity の非混同

    • direct wrapper block

    Acceptance Criteria 改訂案

    research_result:
    root_cause: canonical_main_root_invariant_conflicts_with_isolated_agent_cwd
    non_root_cause: issue_worktree_regex_mismatch_alone
    adopted_option: d_parent_owned_preflight
    implementation_issue_number: null
    related_issue_dependencies:
    issue_1465: incorporated
    issue_1472: architecture_precedent
    issue_1473: implementation_precedent

    必要な AC は以下です。

    1. skill_runtime_command_policy.py、skill_runtime_exec.py、worktree_scope_guard.py の実在する認可条件を line anchor 付きで記録する。

    2. 次の runtime matrix を real hook chain で実行する。

    Context Expected
    main root・default branch・exact executor allow
    issue worktree・exact executor deny
    generic isolation worktree・exact executor deny
    main root・direct wrapper deny
    non-default branch・exact executor deny
    1. 各ケースについて cwd、project root、branch、exit code、reason code を machine-readable artifact として保存する。

    2. 候補 (a)〜(d) を issue binding、repo binding、artifact containment、cleanup、公式仕様への依存度で比較する。

    3. agent-* 命名を認可根拠にしないことを決定事項として明記する。

    4. direct wrapper の継続利用を禁止し、既存 negative test が維持されることを確認する。

    5. 調査: isolation worktree 環境で issue-reviewer 等 SubAgent の artifact が呼び出し元から解決できない問題の対応方針を決定する #1465/実装: issue-reviewer SubAgent 内に Step 2a arbitration を co-locate し親の raw artifact 直接読み契約を廃止する #1472/実装: issue-reviewer SubAgent 内で reviewer_claim_replay.py を co-locate 実行する #1473 を取り込んだ上で、調査: worktree_scope_guard の issue番号命名要求が汎用 isolation worktree agent の preflight.run 実行を妨げる問題の対応方針を決定する #1464 を継続、superseded、duplicate のいずれにするか記録する。

    6. 実装 Issue が必要なら、変更対象を issue-refinement-loop の orchestration/documentation に限定し、guard regex 拡張を scope に含めない。

    最終評価

    Issue #1464 の問題意識は妥当ですが、現在は、

    • regex を主因と誤認

    • 実現しない worktree 再利用案

    • セキュリティ境界を迂回する直接実行案

    • 既存の main-root control-plane 設計の欠落

    という状態です。

    guard に agent-* を追加する実装 Issue は起票すべきではありません。
    まず Issue 本文を「isolation worktree を issue worktree として認可する」問題から、「preflight の実行責務を parent control plane に固定する」問題へ全面改訂するのが妥当です。

    # 判定

    REQUEST_CHANGES — Issue #1464 は、現状の原因分析・選択肢・Acceptance Criteria のままでは調査を開始すべきではありません。

    事象自体はあり得ますが、Issue が根本原因としている「Issue worktree の命名 regex 不一致」は主因ではありません。既存実装では preflight.run を許可する前提が canonical main root + default branch に固定されており、汎用 isolation worktree の名前を regex に追加しても実行可能にはなりません。

    Issue #1464 には現時点でコメントがなく、以下は Issue 本文、関連 Issue/PR、現行 main の実装と公式仕様を突き合わせたレビューです。

    Blocker 1: 根本原因が誤っている

    Issue は次の regex が worktree-agent-* に一致しないことを原因としています。

    _ISSUE_RE = re.compile(r"^(?:worktree-)?issue-(\d+)-")
    _ISSUE_BASENAME_RE = re.compile(r"^issue-(\d+)-")
    _ISSUE_BRANCH_RE = re.compile(r"^(?:worktree-)?issue-(\d+)-")

    これらは実在します。

    しかし、skill_runtime_exec.py の認可はそれ以前に以下を要求します。

    cwd == project_root
    current branch == default branch
    repo slug == trusted repository
    

    preflight.run は linked issue worktree の存在だけが免除されており、root cwd と default branch の要求は免除されていません。

    したがって、候補 (a) のように agent-* を _ISSUE_RE へ追加しても、isolation worktree の cwd からは cwd_not_canonical_main_root で拒否されます。

    Issue の原因記述は、少なくとも次へ修正すべきです。

    root_cause:
      primary: canonical_main_root invariant conflicts with isolated-agent cwd
      secondary: generic worktree has no issue-number identity binding
      non_root_cause: issue worktree regex mismatch alone

    Blocker 2: 既存の意図的な設計を無視している

    この実行境界は偶然ではありません。

    という経緯があります。

    現行 policy も明示的に次を定義しています。

    preflight.run:
      required_cwd: canonical_main_root
      required_branch: default_branch
      allowed_write_roots:
        - .claude/artifacts/issue-refinement-loop/{active_issue}/
      network_effect: github_read_only

    さらに、preflight.run だけが root-no-worktree allowlist に登録されています。

    Issue #1464 の三択は、この既存設計に沿う最有力案を欠いています。

    親の canonical main-root control plane が preflight を実行し、その結果だけを isolated agent に渡す。

    これは候補 (d) として追加すべきです。

    Blocker 3: 候補 (a) は issue binding を破壊する

    agent-* という名前からは Issue 番号を導出できません。

    現行の issue worktree 解決は、branch と path basename の双方を同じ Issue 番号へ束縛し、一意な worktree だけを採用します。

    一方、汎用 Agent worktree を許可すると、次の対応関係が存在しません。

    agent ID → issue number
    worktree path → issue number
    branch → --issue-number
    

    単純な allowlist 拡張では、Agent worktree から任意の --issue-number を指定できる設計になり得ます。安全に成立させるには、親が発行した capability、session nonce、Issue 番号、repo、worktree realpath、期限などを束縛した別の認可プロトコルが必要です。

    また、Claude Code の公式仕様は isolation worktree の利用を説明していますが、worktree-agent-<id> という固定ブランチ命名を公開契約として保証していません。WorktreeCreate の識別子も user-specified または auto-generated slug とされています。セキュリティ判定を未保証の名前形式へ依存させるべきではありません。 ([Claude Platform Docs]1)

    候補 (a) は棄却が妥当です。

    Blocker 4: 候補 (b) は Agent tool の動作と整合しない

    「orchestrator が先に issue-<N>-* worktree を作れば、isolation agent がそれを使う」という契約は示されていません。

    公式仕様上、isolation: worktree は SubAgent 用の一時 worktree を作成します。既存 worktree を自動検出して再利用する仕様ではありません。 ([Claude Platform Docs]2)

    既定の worktree 作成を差し替える正式な拡張点は WorktreeCreate hook ですが、この hook は既定動作全体を置き換え、絶対パスを返す必要があります。これは単なる orchestrator 手順変更ではなく、Agent 基盤、cleanup、競合、所有権を含むシステム変更です。 ([Claude Platform Docs]1)

    したがって候補 (b) は、現在の以下の Out of Scope と矛盾します。

    • Agent tool 自体の変更なし
    • worktree_scope_guard.py の実装変更なし
    • issue-refinement-loop/SKILL.md 以外の手順変更なし

    候補 (b) も現行 scope 内では実現不能です。

    Blocker 5: 候補 (c) は回避策ではなく、意図的に禁止された bypass

    Issue は run_refinement_preflight.py の直接呼び出し継続を候補にしています。

    しかし #1228/PR #1231 は、まさに次を安全境界として固定しています。

    • exact skill_runtime_exec.py は main root から許可
    • direct run_refinement_preflight.py は拒否
    • non-default branch/detached HEAD は拒否
    • artifact root 外への書き込みは fail-closed

    現行テストにも direct invocation の block が明示されています。

    直接実行すると、少なくとも以下を迂回します。

    • exact argv parser
    • trusted repo binding
    • canonical root/default branch 検査
    • registry entry invariant 検査
    • artifact subtree containment
    • 実行前後の unauthorized write 検査

    候補 (c) は選択肢から削除すべきです。

    Major findings

    1. SKILL.md と privileged executor の二層構造が曖昧

    現行 issue-refinement-loop/SKILL.md は「registry entry を canonical とする」と書きつつ、コード例では直接 run_refinement_preflight.py を呼んでいます。

    一方、registry の preflight.run は privileged executor が内部で起動する child argv です。metadata は canonical_main_root と default_branch を要求しています。

    次の二層を明文化する必要があります。

    operator/orchestrator-facing command:
      scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run ...
    
    executor-internal child argv:
      run_refinement_preflight.py --issue-number ... --repo ...
    

    SubAgent が後者を直接使用してはならないことも明記すべきです。

    2. ランタイム証跡がない

    本件は runtime-dependent ですが、AC1・AC2 は regex と Issue 本文の存在確認に留まっています。

    最低限必要なのは次です。

    Claude Code version
    Agent tool invocation and isolation setting
    hook input cwd
    CLAUDE_PROJECT_DIR
    pwd
    git rev-parse --show-toplevel
    git branch --show-current
    exact command
    guard exit code
    guard reason code / stderr
    

    「Issue #1458 の実行ログ」という Handoff も、具体的なコメント URL、artifact path、run ID、commit SHA がなく追跡不能です。取得した #1458 のコメントからも、本件の正規 runtime evidence を一意に特定できませんでした。

    3. #1465 の結果を先に取り込む必要がある

    #1465 は #1464 を関連 Issue として明示し、共通原因の可能性と、#1465 完了後に #1464 の重複判定を行うことを要求しています。

    その後、#1472/#1473 では isolation 境界をまたぐ raw artifact 読み取りをやめ、producer と consumer を同じ SubAgent 内へ co-locate する変更が実装されています。

    これは preflight.run を直接解決する変更ではありませんが、リポジトリの最新方針として次を示しています。

    generic worktree を issue worktree として緩く認可するのではなく、処理を適切な実行境界へ配置し、境界をまたぐデータを compact にする。

    #1464 もこの方針と整合させるべきです。

    採用すべき方針

    推奨: 候補 (d) — parent-owned preflight

    adopted_option: d_parent_owned_preflight

    手順は次です。

    1. 親 orchestrator が canonical main root/default branch にいる状態で、exact executor を使って preflight.run を実行する。
    2. artifact は既存どおり .claude/artifacts/issue-refinement-loop/<issue>/ に生成する。
    3. NEXT_ACTION、必要な digest、bounded な planner result だけを isolation agent へ渡す。
    4. isolation agent は skill_runtime_exec.py も direct wrapper も実行しない。
    5. preflight の再実行が必要なら、子が親へ要求を返し、親が実行する。

    最も単純なのは、isolation agent を起動する前に Step 0f を完了する構成です。

    この方式は既存の以下を維持できます。

    • canonical root/default branch
    • trusted repository binding
    • exact command class
    • artifact-only write
    • generic Agent worktree と Issue identity の非混同
    • direct wrapper block

    Acceptance Criteria 改訂案

    research_result:
      root_cause: canonical_main_root_invariant_conflicts_with_isolated_agent_cwd
      non_root_cause: issue_worktree_regex_mismatch_alone
      adopted_option: d_parent_owned_preflight
      implementation_issue_number: null
      related_issue_dependencies:
        issue_1465: incorporated
        issue_1472: architecture_precedent
        issue_1473: implementation_precedent

    必要な AC は以下です。

    1. skill_runtime_command_policy.py、skill_runtime_exec.py、worktree_scope_guard.py の実在する認可条件を line anchor 付きで記録する。
    2. 次の runtime matrix を real hook chain で実行する。
    Context Expected
    main root・default branch・exact executor allow
    issue worktree・exact executor deny
    generic isolation worktree・exact executor deny
    main root・direct wrapper deny
    non-default branch・exact executor deny
    1. 各ケースについて cwd、project root、branch、exit code、reason code を machine-readable artifact として保存する。
    2. 候補 (a)〜(d) を issue binding、repo binding、artifact containment、cleanup、公式仕様への依存度で比較する。
    3. agent-* 命名を認可根拠にしないことを決定事項として明記する。
    4. direct wrapper の継続利用を禁止し、既存 negative test が維持されることを確認する。
    5. 調査: isolation worktree 環境で issue-reviewer 等 SubAgent の artifact が呼び出し元から解決できない問題の対応方針を決定する #1465/実装: issue-reviewer SubAgent 内に Step 2a arbitration を co-locate し親の raw artifact 直接読み契約を廃止する #1472/実装: issue-reviewer SubAgent 内で reviewer_claim_replay.py を co-locate 実行する #1473 を取り込んだ上で、調査: worktree_scope_guard の issue番号命名要求が汎用 isolation worktree agent の preflight.run 実行を妨げる問題の対応方針を決定する #1464 を継続、superseded、duplicate のいずれにするか記録する。
    6. 実装 Issue が必要なら、変更対象を issue-refinement-loop の orchestration/documentation に限定し、guard regex 拡張を scope に含めない。

    最終評価

    Issue #1464 の問題意識は妥当ですが、現在は、

    • regex を主因と誤認
    • 実現しない worktree 再利用案
    • セキュリティ境界を迂回する直接実行案
    • 既存の main-root control-plane 設計の欠落

    という状態です。

    guard に agent-* を追加する実装 Issue は起票すべきではありません。
    まず Issue 本文を「isolation worktree を issue worktree として認可する」問題から、「preflight の実行責務を parent control plane に固定する」問題へ全面改訂するのが妥当です。

  3. squne121 commented on Jul 11, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 12, 2026

    @squne121
    OwnerAuthor

    ISSUE_1464_RUNTIME_MATRIX_SUMMARY_V1

    本Issueの調査を完了した。

    詳細は本Issue本文の Research Result / AC1〜AC7 / runtime_matrix machine-readable block を参照。

  5. squne121 commented on Jul 12, 2026

    @squne121
    OwnerAuthor

    Implementation Issue #1478 が PR #1481(squash merge)でマージされ、CLOSED になりました。

    PR #1481 の内容: issue-refinement-loop SKILL.md の Step 0f に「parent-owned preflight」運用を明文化し、契約テスト test_step_0f_parent_owned_preflight.py を追加しました。pr-review-judge が2 iteration で最終 APPROVE(merge_ready: true)となりました。

    本Issue(#1464)の research 成果(root cause の確定、real hook chain による runtime matrix evidence、採用方針 (d) parent-owned preflight の決定)が実装に正しく反映されています。

    以上により、本Issue(#1464)を completed としてクローズします。

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

    phase/research

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions