Skip to content

実装: preflight scope rollup に proceed_with_coordination を追加し uncertain 衝突の過剰停止を廃止する #607

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "preflight scope rollup の uncertain 衝突に proceed_with_coordination を導入し、キーワードベースの即時停止ルールを廃止する"
change_kind: mixed

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: N/A(単独改善)
  • Desired Destination: N/A

Current Validated Scope

  • .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py に ACTION_PROCEED_WITH_COORDINATION 定数追加、CONFLICT_UNCERTAIN を escalation_required=False, coordination_required=True に変更、_suggested_action で uncertain → proceed_with_coordination に変更
  • .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py のテスト更新(uncertain パスの期待値変更)と fixture 4 件追加
  • .claude/skills/impl-review-loop/steps/preparation.md のキーワードベース停止ルール削除と proceed_with_coordination → LOOP_STATE.scope_rollup_decision.related_coordination[] 保存ルール追記

Remaining Parent Gaps

なし

Background

impl-review-loop の scope rollup preflight(preparation.md Step 2.5)に、以下の過剰停止が存在する。

問題 1: キーワードベース即時停止

preparation.md の orchestrator ルールが「security / auth / permission / sandbox 関連の候補(suggested_action: human_review_required): 即時停止」と明記しており、たとえ plan_issue_scope_rollup.py の判定で escalation_required: False が返っても、キーワードに反応して停止する経路が残っている。

問題 2: uncertain 衝突の過剰エスカレーション

_suggested_action は conflict_type == uncertain(同一ファイル・anchor なし)のとき human_review_required を返す。しかし「anchor がない=disjoint 性を証明できない」は「実際に衝突している」ではなく、調整しながら進めるべきケースである。genuine structural conflict(same_anchor_conflicting_op、escalation_required: True)とは別に扱う必要がある。

実例(#569 / #597 の過剰停止):
Intake Gate を pass した有効な go snapshot 付き Issue に対して、関連 Issue に permissionMode という語が含まれるだけで security_match_evidence=["permission"] と same Allowed Paths が重なり human_escalation で停止した。意味論的に独立した 2 Issue への機械的過剰停止であった。

Outcome

この Issue の実装完了後、以下の状態になる。

plan_issue_scope_rollup.py に ACTION_PROCEED_WITH_COORDINATION 定数が追加され、CONFLICT_UNCERTAIN の状態モデルが escalation_required=False, coordination_required=True となり、_suggested_action() で conflict_type: uncertain → proceed_with_coordination が返る(human_review_required ではない)。preparation.md のキーワードベース即時停止ルールが削除され、既存・新規テストがすべて PASS している。

In Scope

1. plan_issue_scope_rollup.py

  • ACTION_PROCEED_WITH_COORDINATION = "proceed_with_coordination" 定数追加
  • CONFLICT_UNCERTAIN の状態モデルを escalation_required=False, coordination_required=True に変更する(状態モデルの意味分離。suggested_action と escalation_required が矛盾しないようにする)
  • _suggested_action で conflict_type == CONFLICT_UNCERTAIN → proceed_with_coordination を返す(human_review_required でない)。escalation_required: True は same_anchor_conflicting_op など genuine structural conflict のみ human_review_required にする

2. test_plan_issue_scope_rollup.py

  • test_scope_rollup_escalates_uncertain_or_boundary_affecting_changes の uncertain パスの期待値を proceed_with_coordination に更新(human_review_required でない)
  • 以下の fixture テスト追加:
    • test_same_allowed_paths_no_anchor_should_proceed_with_coordination — 同一ファイル・anchor なし → proceed_with_coordination
    • test_permission_keyword_only_should_not_escalate — permissionMode 語含む body・同一 Allowed Paths・anchor なし → proceed_with_coordination(human_review_required でない)
    • test_same_anchor_conflicting_op_should_escalate — escalation_required: True(genuine conflict)→ human_review_required
    • test_prefix_overlap_uncertain_should_not_escalate — conflict_type: prefix_overlap_uncertain → human_review_required でない

3. preparation.md(.claude/skills/impl-review-loop/steps/preparation.md)

  • キーワードベース停止ルール削除: security / auth / permission / sandbox 関連の候補(suggested_action: human_review_required): 即時停止 の一行を削除
  • proceed_with_coordination handling 追記: 候補の suggested_action が proceed_with_coordination の場合は LOOP_STATE.scope_rollup_decision.related_coordination[] に関連 Issue 番号を構造化保存して次ステップへ継続するルールを追加。PR body への ## Related coordination 反映は PR 作成・更新フェーズの責務とし、preparation フェーズでは担わない。

Out of Scope

Acceptance Criteria

  • AC1: plan_issue_scope_rollup.py に ACTION_PROCEED_WITH_COORDINATION 定数が追加されている
  • AC2: _suggested_action で conflict_type == uncertain → proceed_with_coordination を返す(human_review_required でない)。かつ CONFLICT_UNCERTAIN の escalation_required=False, coordination_required=True である
  • AC3: conflict_type == same_anchor_conflicting_op(escalation_required: True)の場合は引き続き human_review_required を返す
  • AC4: preparation.md にキーワードベース停止ルール(security / auth / permission / sandbox 関連の候補 → 即時停止)の記述が存在しない
  • AC5: preparation.md に proceed_with_coordination → LOOP_STATE.scope_rollup_decision.related_coordination[] への構造化保存 + 継続のルールが記述されている(PR body への直接反映は含まない)
  • AC6: test_plan_issue_scope_rollup.py の新規 fixture テスト 4 件を含む全テストが PASS する

Verification Commands

# AC1
$ rg -c "ACTION_PROCEED_WITH_COORDINATION" .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
# AC2 (baseline: rg exits 1 — function not yet created; after impl: rg exits 0)
$ rg -c "test_permission_keyword_only_should_not_escalate" .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py
# AC3 (baseline: rg exits 1 — function not yet created; after impl: rg exits 0)
$ rg -c "test_same_anchor_conflicting_op_should_escalate" .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py
# AC4 (パターンが存在しないことを確認: 見つかれば exit 1 = baseline fail、削除後は exit 1 of rg → ! で exit 0)
$ ! rg -qc "sandbox.*即時停止" .claude/skills/impl-review-loop/steps/preparation.md
# AC5
$ rg -c "proceed_with_coordination" .claude/skills/impl-review-loop/steps/preparation.md
# AC6
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py -v
$ pnpm typecheck
$ pnpm test
$ pnpm build

Scope Boundary Note

本 Issue は scope rollup 判定ロジックと proceed_with_coordination handling の修正に限定する。
plan_issue_scope_rollup.py の実行主体を main conversation から Haiku SubAgent / runner agent に委譲し、結果を GitHub comment / machine-readable marker 経由で共有する設計変更は本 Issue の対象外とし、別 Issue で扱う。

Allowed Paths

  • .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
  • .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py
  • .claude/skills/impl-review-loop/steps/preparation.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

なし

Scope Delta(任意)

N/A

Runtime Verification Applicability

本 Issue の変更対象はワークフロー文書・スクリプトのみです。ゲームの実行時動作には影響しません。

decision: not_applicable
reason: "Workflow documentation and script changes only. No runtime game behavior changed."

Activity

  1. added
    enhancement
    phase/implementation
    on Jun 2, 2026
  2. squne121 commented on Jun 3, 2026

    @squne121
    OwnerAuthor

    人間からのコメントです。
    オーケストラレーションを責務とするメイン会話で「plan_issue_scope_rollup.py」を行うべきなの?レビューループ作業計画を目的としてると思うのだけど、事前準備もサブエージェントに委譲できない?
    test_plan_issue_scope_rollup.py もメイン会話の責務か疑問。
    スクリプトによる決定論的な処理はHaikuサブエージェントに委譲して結果だけGithub経由で共有すればいいのでは?
    このIssueのスコープ外とは思う。

  3. squne121 commented on Jun 3, 2026

    @squne121
    OwnerAuthor

    #607 (comment)

    結論: 人間コメントは正しいが、#607 の本体修正には混ぜない方がよいです。

    #607 は現在、plan_issue_scope_rollup.py の uncertain 判定を human_review_required から proceed_with_coordination に変え、対応するテストと impl-review-loop/steps/preparation.md の扱いを更新する Issue です。Allowed Paths もその3ファイルに限定されています。([GitHub]1)
    現在の preparation.md には Step 2.5 として plan_issue_scope_rollup.py を実行し、出力を LOOP_STATE.scope_rollup_plan に保存する設計が明記されています。つまり、#607 は「既存の preflight が返す判定が過剰停止になる」問題を直す Issue です。([GitHub]2)

    敵対的に見ると、コメントの論点は2つに分けるべきです。

    1つ目は 判定ロジックの正しさ。これは #607 のスコープ内です。現行 script は exact same files かつ anchor 不在を CONFLICT_UNCERTAIN とし、escalation_required = True にしています。さらに _suggested_action は escalation_required または conflict_type == uncertain を human_review_required に倒します。これが #607 の主対象です。([GitHub][3])
    この挙動を直さずに Haiku SubAgent へ委譲しても、間違った決定論的ロジックを別の実行主体が実行するだけです。したがって plan_issue_scope_rollup.py と test_plan_issue_scope_rollup.py は #607 に残すべきです。

    2つ目は preparation の実行主体を main conversation から SubAgent に逃がす設計。これは妥当ですが、#607 からは外すべきです。Claude Code の公式 docs でも、SubAgent は別 context で作業し、要約だけを main conversation に返す用途、tool 制限、Haiku など低コスト model routing に適しています。([Claude Code][4]) また tools allowlist、model: haiku、permissionMode が frontmatter で制御可能です。([Claude Code][4])
    つまり、「scope rollup preflight を Haiku SubAgent が実行し、main は result marker / GitHub comment / LOOP_STATE だけ採用する」は設計として筋が良い。ただしこれは orchestration architecture の別 Issue です。

    特に #607 の Stop Conditions には nested SubAgent delegation が必要になった場合 が含まれています。([GitHub]1) なので、#607 実装中に「SubAgent 化もやろう」とすると、Issue 自身の停止条件に引っかかります。

    #607 への判断

    #607 は継続。ただし本文に一文追加して責務境界を明確化するのがよいです。

    追加案:

    ## Scope Boundary Note
    
    本 Issue は scope rollup 判定ロジックと `proceed_with_coordination` handling の修正に限定する。
    `plan_issue_scope_rollup.py` の実行主体を main conversation から Haiku SubAgent / runner agent に委譲し、結果を GitHub comment / machine-readable marker 経由で共有する設計変更は本 Issue の対象外とする。
    当該設計は別 Issue で扱う。

    別 Issue 化するならタイトル案

    設計: impl-review-loop preparation の決定論的 preflight を Haiku SubAgent runner に委譲する

    本文案:

    ## Background
    
    `impl-review-loop` の main conversation は orchestration / routing / final adoption を責務とするべきであり、`plan_issue_scope_rollup.py` のような決定論的 preflight 実行や大量の `gh issue list` / `gh pr list` 出力処理を main context に載せ続けるのは context 汚染・token 消費・責務肥大化につながる。
    
    Claude Code SubAgent は独立 context、tool 制限、`model: haiku`、`permissionMode` を持てるため、read-only / mutation-free な preflight runner と相性がよい。
    
    ## Goal
    
    `impl-review-loop` preparation のうち、決定論的で mutation-free な preflight を Haiku SubAgent に委譲し、main conversation は GitHub comment または machine-readable marker を再取得・検証して `LOOP_STATE` に採用するだけにする。
    
    ## In Scope
    
    - `.claude/agents/scope-rollup-runner.md` の新規作成
      - `model: haiku`
      - `tools: Read, Grep, Glob, Bash`
      - Write/Edit/PR作成/Issue編集は禁止
      - `plan_issue_scope_rollup.py` 実行と summary marker 出力に限定
    - `impl-review-loop/steps/preparation.md` の Step 2.5 を runner 委譲型に変更
    - runner 出力の machine-readable marker 仕様追加
      - `ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1`
      - `schema_version`
      - `current_issue`
      - `generated_at`
      - `script`
      - `input_refs`
      - `result_sha256`
      - `suggested_actions_summary`
      - `raw_plan_location`
    - main conversation は marker を再取得し、schema / issue number / generated_at / sha256 を検証してから `LOOP_STATE.scope_rollup_plan` に採用する
    
    ## Out of Scope
    
    - `plan_issue_scope_rollup.py` の判定ロジック変更
    - `proceed_with_coordination` の導入
    - security-risk gate の設計
    - Issue 本文編集、label変更、PR作成
    - nested SubAgent delegation
    
    ## Acceptance Criteria
    
    - AC1: scope rollup preflight の raw command output が main conversation に大量流入しない
    - AC2: Haiku SubAgent が `plan_issue_scope_rollup.py` を実行し、結果 marker を生成する
    - AC3: main conversation は marker を検証し、妥当な場合のみ `LOOP_STATE.scope_rollup_plan` / `scope_rollup_decision` に採用する
    - AC4: runner agent は mutation 系操作を禁止している
    - AC5: `plan_issue_scope_rollup.py` の既存テストは引き続き script 側で担保される

    GitHubコメントとして返すなら

    指摘は妥当です。ただし #607 では混ぜない方がよいです。
    
    #607 の主問題は「`plan_issue_scope_rollup.py` が `conflict_type: uncertain` を `human_review_required` に倒し、`permissionMode` のような語彙や同一 Allowed Paths に反応して過剰停止する」ことです。これは実行主体を Haiku SubAgent に移しても直りません。まず script の deterministic output と test fixture を修正する必要があります。
    
    一方で、`impl-review-loop` main conversation が preparation で `gh issue list` / `gh pr list` / `plan_issue_scope_rollup.py` の実行・大量出力処理を直接抱えるべきか、という責務境界の指摘は別論点として正しいです。main は orchestration / final adoption / LOOP_STATE 更新だけを持ち、mutation-free な preflight runner は Haiku SubAgent に委譲し、結果だけ machine-readable marker / GitHub comment 経由で検証・採用する設計がよいです。
    
    ただしその変更は runner agent 追加、preparation Step 2.5 の委譲化、result marker 仕様、権限制限、検証手順を含むため #607 のスコープ外です。#607 には Scope Boundary Note を追加し、SubAgent runner 化は別 Issue として切り出すのがよいです。

    最終判断: #607 は判定ロジック修正として残す。SubAgent 委譲化は follow-up Issue。test は #607 に残す。

    # 既存衝突確認
    git worktree list | grep "$WORKTREE" && echo "[WARN] worktree 既存" || echo "[OK] worktree 未作成"
    git branch --list "$BRANCH" && echo "[WARN] branch 既存" || echo "[OK] branch 未作成"
    ```

    既存衝突あり → 過去のイテレーションの残骸の可能性。人間判断を仰ぐ。

    ## 4. Product Spec Gate 評価完了後の LOOP_STATE 初期化

    Product Spec Check 評価(1-d)を完了後、iteration = 0 で以下の状態で開始:

    ```yaml
    LOOP_STATE:
    issue_number:
    contract_snapshot_url:
    contract_snapshot_source: provided | detected_existing | materialized_by_issue_contract_review
    iteration: 0
    max_iterations: 3
    worktree: .claude/worktrees/issue-<番号>-
    branch: worktree-issue-<番号>-
    last_step: null
    last_loop_verdict: null
    blockers_history: []
    external_research_skip_basis: null
    termination_reason: null
    intake_gate:
    status: pass | intake_gate_failed
    subreason: null | metadata_not_ready | missing_contract_go | stale_contract_review | body_snapshot_mismatch | request_changes_after_go
    evaluated_at: ""
    product_spec_preflight:
    source: contract_snapshot.checks.product_spec_check
    applicability: applicable | not_applicable | missing
    decision: pass | fail | human_judgment | missing
    blocked_rule_ids: []
    contract_snapshot_url: ""
    body_sha256: ""
    routing_action: continue | stop_human | refresh_contract_snapshot
    ```

    routing_action が stop_human または refresh_contract_snapshot の場合は、ループを開始せず人間判断へ escalate する。

    ## 5. 外部仕様調査スキップ判断(任意)

    internal-only 変更(src/state / src/systems 内の純粋ロジック変更等)なら external_research_skip_basis に理由を記録してスキップ。
    外部仕様が絡む場合は gemini-cli-headless-delegation を先行起動して情報を集める。

    ## 出力

    LOOP_STATE 初期値を会話履歴に明示記録し、Step 1(Implementation)へ進む。
    "
    [3]: https://raw.githubusercontent.com/squne121/loop-protocol/main/.claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py "raw.githubusercontent.com"
    [4]: https://code.claude.com/docs/en/sub-agents "Create custom subagents - Claude Code Docs"

    結論: 人間コメントは正しいが、#607 の本体修正には混ぜない方がよいです。

    #607 は現在、plan_issue_scope_rollup.py の uncertain 判定を human_review_required から proceed_with_coordination に変え、対応するテストと impl-review-loop/steps/preparation.md の扱いを更新する Issue です。Allowed Paths もその3ファイルに限定されています。([GitHub]1)
    現在の preparation.md には Step 2.5 として plan_issue_scope_rollup.py を実行し、出力を LOOP_STATE.scope_rollup_plan に保存する設計が明記されています。つまり、#607 は「既存の preflight が返す判定が過剰停止になる」問題を直す Issue です。([GitHub]2)

    敵対的に見ると、コメントの論点は2つに分けるべきです。

    1つ目は 判定ロジックの正しさ。これは #607 のスコープ内です。現行 script は exact same files かつ anchor 不在を CONFLICT_UNCERTAIN とし、escalation_required = True にしています。さらに _suggested_action は escalation_required または conflict_type == uncertain を human_review_required に倒します。これが #607 の主対象です。([GitHub][3])
    この挙動を直さずに Haiku SubAgent へ委譲しても、間違った決定論的ロジックを別の実行主体が実行するだけです。したがって plan_issue_scope_rollup.py と test_plan_issue_scope_rollup.py は #607 に残すべきです。

    2つ目は preparation の実行主体を main conversation から SubAgent に逃がす設計。これは妥当ですが、#607 からは外すべきです。Claude Code の公式 docs でも、SubAgent は別 context で作業し、要約だけを main conversation に返す用途、tool 制限、Haiku など低コスト model routing に適しています。([Claude Code][4]) また tools allowlist、model: haiku、permissionMode が frontmatter で制御可能です。([Claude Code][4])
    つまり、「scope rollup preflight を Haiku SubAgent が実行し、main は result marker / GitHub comment / LOOP_STATE だけ採用する」は設計として筋が良い。ただしこれは orchestration architecture の別 Issue です。

    特に #607 の Stop Conditions には nested SubAgent delegation が必要になった場合 が含まれています。([GitHub]1) なので、#607 実装中に「SubAgent 化もやろう」とすると、Issue 自身の停止条件に引っかかります。

    #607 への判断

    #607 は継続。ただし本文に一文追加して責務境界を明確化するのがよいです。

    追加案:

    ## Scope Boundary Note
    
    本 Issue は scope rollup 判定ロジックと `proceed_with_coordination` handling の修正に限定する。
    `plan_issue_scope_rollup.py` の実行主体を main conversation から Haiku SubAgent / runner agent に委譲し、結果を GitHub comment / machine-readable marker 経由で共有する設計変更は本 Issue の対象外とする。
    当該設計は別 Issue で扱う。

    別 Issue 化するならタイトル案

    設計: impl-review-loop preparation の決定論的 preflight を Haiku SubAgent runner に委譲する

    本文案:

    ## Background
    
    `impl-review-loop` の main conversation は orchestration / routing / final adoption を責務とするべきであり、`plan_issue_scope_rollup.py` のような決定論的 preflight 実行や大量の `gh issue list` / `gh pr list` 出力処理を main context に載せ続けるのは context 汚染・token 消費・責務肥大化につながる。
    
    Claude Code SubAgent は独立 context、tool 制限、`model: haiku`、`permissionMode` を持てるため、read-only / mutation-free な preflight runner と相性がよい。
    
    ## Goal
    
    `impl-review-loop` preparation のうち、決定論的で mutation-free な preflight を Haiku SubAgent に委譲し、main conversation は GitHub comment または machine-readable marker を再取得・検証して `LOOP_STATE` に採用するだけにする。
    
    ## In Scope
    
    - `.claude/agents/scope-rollup-runner.md` の新規作成
      - `model: haiku`
      - `tools: Read, Grep, Glob, Bash`
      - Write/Edit/PR作成/Issue編集は禁止
      - `plan_issue_scope_rollup.py` 実行と summary marker 出力に限定
    - `impl-review-loop/steps/preparation.md` の Step 2.5 を runner 委譲型に変更
    - runner 出力の machine-readable marker 仕様追加
      - `ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1`
      - `schema_version`
      - `current_issue`
      - `generated_at`
      - `script`
      - `input_refs`
      - `result_sha256`
      - `suggested_actions_summary`
      - `raw_plan_location`
    - main conversation は marker を再取得し、schema / issue number / generated_at / sha256 を検証してから `LOOP_STATE.scope_rollup_plan` に採用する
    
    ## Out of Scope
    
    - `plan_issue_scope_rollup.py` の判定ロジック変更
    - `proceed_with_coordination` の導入
    - security-risk gate の設計
    - Issue 本文編集、label変更、PR作成
    - nested SubAgent delegation
    
    ## Acceptance Criteria
    
    - AC1: scope rollup preflight の raw command output が main conversation に大量流入しない
    - AC2: Haiku SubAgent が `plan_issue_scope_rollup.py` を実行し、結果 marker を生成する
    - AC3: main conversation は marker を検証し、妥当な場合のみ `LOOP_STATE.scope_rollup_plan` / `scope_rollup_decision` に採用する
    - AC4: runner agent は mutation 系操作を禁止している
    - AC5: `plan_issue_scope_rollup.py` の既存テストは引き続き script 側で担保される

    GitHubコメントとして返すなら

    指摘は妥当です。ただし #607 では混ぜない方がよいです。
    
    #607 の主問題は「`plan_issue_scope_rollup.py` が `conflict_type: uncertain` を `human_review_required` に倒し、`permissionMode` のような語彙や同一 Allowed Paths に反応して過剰停止する」ことです。これは実行主体を Haiku SubAgent に移しても直りません。まず script の deterministic output と test fixture を修正する必要があります。
    
    一方で、`impl-review-loop` main conversation が preparation で `gh issue list` / `gh pr list` / `plan_issue_scope_rollup.py` の実行・大量出力処理を直接抱えるべきか、という責務境界の指摘は別論点として正しいです。main は orchestration / final adoption / LOOP_STATE 更新だけを持ち、mutation-free な preflight runner は Haiku SubAgent に委譲し、結果だけ machine-readable marker / GitHub comment 経由で検証・採用する設計がよいです。
    
    ただしその変更は runner agent 追加、preparation Step 2.5 の委譲化、result marker 仕様、権限制限、検証手順を含むため #607 のスコープ外です。#607 には Scope Boundary Note を追加し、SubAgent runner 化は別 Issue として切り出すのがよいです。

    最終判断: #607 は判定ロジック修正として残す。SubAgent 委譲化は follow-up Issue。test は #607 に残す。

    # 既存衝突確認
    git worktree list | grep "$WORKTREE" && echo "[WARN] worktree 既存" || echo "[OK] worktree 未作成"
    git branch --list "$BRANCH" && echo "[WARN] branch 既存" || echo "[OK] branch 未作成"
    ```

    既存衝突あり → 過去のイテレーションの残骸の可能性。人間判断を仰ぐ。

    ## 4. Product Spec Gate 評価完了後の LOOP_STATE 初期化

    Product Spec Check 評価(1-d)を完了後、iteration = 0 で以下の状態で開始:

    ```yaml
    LOOP_STATE:
    issue_number:
    contract_snapshot_url:
    contract_snapshot_source: provided | detected_existing | materialized_by_issue_contract_review
    iteration: 0
    max_iterations: 3
    worktree: .claude/worktrees/issue-<番号>-
    branch: worktree-issue-<番号>-
    last_step: null
    last_loop_verdict: null
    blockers_history: []
    external_research_skip_basis: null
    termination_reason: null
    intake_gate:
    status: pass | intake_gate_failed
    subreason: null | metadata_not_ready | missing_contract_go | stale_contract_review | body_snapshot_mismatch | request_changes_after_go
    evaluated_at: ""
    product_spec_preflight:
    source: contract_snapshot.checks.product_spec_check
    applicability: applicable | not_applicable | missing
    decision: pass | fail | human_judgment | missing
    blocked_rule_ids: []
    contract_snapshot_url: ""
    body_sha256: ""
    routing_action: continue | stop_human | refresh_contract_snapshot
    ```

    routing_action が stop_human または refresh_contract_snapshot の場合は、ループを開始せず人間判断へ escalate する。

    ## 5. 外部仕様調査スキップ判断(任意)

    internal-only 変更(src/state / src/systems 内の純粋ロジック変更等)なら external_research_skip_basis に理由を記録してスキップ。
    外部仕様が絡む場合は gemini-cli-headless-delegation を先行起動して情報を集める。

    ## 出力

    LOOP_STATE 初期値を会話履歴に明示記録し、Step 1(Implementation)へ進む。
    "
    [3]: https://raw.githubusercontent.com/squne121/loop-protocol/main/.claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py "raw.githubusercontent.com"
    [4]: https://code.claude.com/docs/en/sub-agents "Create custom subagents - Claude Code Docs"

  4. squne121 commented on Jun 3, 2026

    @squne121
    OwnerAuthor

    敵対的レビュー結果

    判定: Request changes。方向性、つまり「uncertain を即 human stop にせず proceed_with_coordination として継続する」「security/auth/permission/sandbox の語彙だけで止めない」は妥当です。ただし、#607 は現状の契約・実装・検証設計が噛み合っておらず、このままでは approve しない方がよいです。

    なお、GitHub HTML/API 経由で指定コメント本文そのものは取得できませんでした。ここでは、指定コメントの論点を「メイン会話が plan_issue_scope_rollup.py とそのテストを直接担うべきか。決定論的処理は Haiku SubAgent に委譲し、結果だけ GitHub 経由で共有すべきではないか」として扱います。

    主要な確認事実

    #607 のスコープは、ACTION_PROCEED_WITH_COORDINATION の追加、_suggested_action() の uncertain ルーティング変更、fixtures/tests 更新、preparation.md のキーワード即時停止削除と proceed_with_coordination の扱い追加です。背景として、#569/#597 のように同一 Allowed Paths でも本来は調整で進められるケースが uncertain -> human_review_required になって過剰停止していた、という問題設定になっています。([GitHub]1)

    一方で、現時点で取得できる main の plan_issue_scope_rollup.py には ACTION_PROCEED_WITH_COORDINATION が存在せず、uncertain は escalation_required=True とされ、_suggested_action() でも escalation_required または conflict_type == uncertain なら human_review_required を返す実装のままです。([GitHub]2) preparation.md も security/auth/permission/sandbox 候補を suggested_action: human_review_required として即時停止する記述が残っています。([GitHub]3) テストも「同一ファイル・anchor なしは uncertain で human_review_required」という旧期待値のままです。([GitHub][4])

    Blocker

    1. Issue の Outcome とリポジトリ実態が矛盾している

    #607 の本文は「PR merged/tests pass」「uncertain is no longer human_review_required」という完了状態を主張していますが、main の実装・準備手順・テストはその状態にありません。これは単なる実装漏れではなく、Issue 契約の信頼性を壊しています。レビュー対象が「仕様案」なのか「完了済み実装」なのか不明です。([GitHub]1)

    修正要求: #607 本文から虚偽の Outcome を削除するか、対応 PR/branch を明示し、main との差分を提示してください。現状のまま「完了」として扱うのは不可です。

    2. suggested_action だけ変えても下流が止まる可能性が残る

    現在のコードは uncertain 自体に escalation_required=True を付けています。単に _suggested_action() で uncertain を優先して proceed_with_coordination にしても、下流が escalation_required を直接見ている場合は停止します。suggested_action と escalation_required が矛盾した状態になるため、将来の回帰も起きやすいです。([GitHub]2)

    修正要求: uncertain は human escalation ではなく coordination requirement として表現すべきです。少なくとも以下のように意味を分離してください。

    scope_context:
      conflict_type: uncertain
      escalation_required: false
      coordination_required: true
      disjointness_proof: absent
    suggested_action: proceed_with_coordination

    本当に止めるべきものは same_anchor_conflicting_operation などの決定的衝突だけに限定するべきです。

    3. preparation.md の責務設計が曖昧

    #607 は proceed_with_coordination の場合に LOOP_STATE と PR body の Related coordination に記録するとしていますが、preparation フェーズは PR 作成前である可能性があります。PR body への反映責務が preparation なのか、implementation-worker なのか、cleanup-pr なのかが未定義です。([GitHub]1)

    修正要求: preparation は LOOP_STATE.scope_rollup_decision.related_coordination[] へ構造化保存するだけにし、PR 作成・更新フェーズが ## Related coordination をレンダリングする、と明記してください。そうしないと AC が検証不能です。

    4. #569/#597/#558 との境界が甘い

    #569 は blocked reason の分類と worker self-fix flow を扱っており、preparation.md/SKILL.md の同一領域に触れます。#597 は Haiku SubAgent が issue-contract-review を実行し、GitHub comment を再取得して検証する設計を含んでいます。#558 は scope rollup を security gate に戻すな、専用 security-risk gate を設計せよ、という非ゴールを明示しています。([GitHub][5])

    #607 はこれらを「Out of scope」として逃がしていますが、実際には preparation.md の停止条件とサブエージェント前処理に直撃しています。特に keyword stop 削除は #558 の方向性とは合っていますが、専用 security gate が未整備なら防御層の削除にもなります。ここは「削除して終わり」ではなく、「scope rollup では止めないが、security-risk gate に委譲する」までを書かないと危険です。

    5. 指定コメントの懸念は正しい

    メイン会話は orchestration を担うべきで、plan_issue_scope_rollup.py の実行や pytest の詳細確認まで抱える設計はコンテキスト汚染を起こします。Claude Code の subagents は、独立した context window・独自プロンプト・独自 tools/permissions を持ち、メイン会話の context を保護しつつ専門タスクを処理する用途に向いています。さらに model として Haiku を指定でき、permissionMode も設定できます。([Claude Code][6])

    ただし、subagent は fresh context で開始し、会話履歴や既読ファイルを自動継承しません。また subagent はさらに subagent を spawn できません。したがって「Haiku に丸投げ」ではなく、メインが入力・期待 schema・検証手順を明示し、GitHub comment を再取得して schema/hash/current issue を検証する必要があります。([Claude Code][6])

    推奨する実装形

    #607 は単なる _suggested_action() の分岐変更ではなく、次のように整理した方がよいです。

    ACTION_PROCEED_WITH_COORDINATION = "proceed_with_coordination"
    
    def _suggested_action(scope_context):
        if not scope_context:
            return ACTION_CREATE_IMPLEMENTATION_ISSUE
    
        conflict_type = scope_context["conflict_type"]
    
        if conflict_type == CONFLICT_SAME_ANCHOR_CONFLICTING_OP:
            return ACTION_HUMAN_REVIEW_REQUIRED
    
        if scope_context.get("escalation_required"):
            return ACTION_HUMAN_REVIEW_REQUIRED
    
        if scope_context.get("coordination_required"):
            return ACTION_PROCEED_WITH_COORDINATION
    
        return ACTION_CREATE_IMPLEMENTATION_ISSUE

    CONFLICT_UNCERTAIN は escalation_required=False, coordination_required=True に変更すべきです。escalation_required=True のまま suggested_action=proceed_with_coordination にする実装は、状態表現として破綻しています。

    Haiku SubAgent 化するなら、役割は次に限定してください。

    name: scope-rollup-preflight-runner
    model: haiku
    permissionMode: dontAsk
    responsibility:
      - run plan_issue_scope_rollup.py
      - run focused tests
      - emit ISSUE_SCOPE_ROLLUP_RESULT_V1 as GitHub comment
    forbidden:
      - edit issue body
      - create PR
      - push branch
      - modify source files

    dontAsk は未許可 tool を自動 deny するモードであり、deny-first の権限モデルは Claude Code 側で強制されます。したがって agent frontmatter だけでなく、gh issue view/comment、対象 python script、対象 pytest だけを許可し、gh issue edit、gh pr create、git push、Edit/Write を拒否する権限設定まで Issue の配布物に含めるべきです。([Claude Code][7])

    追加すべきテスト

    最低限、以下が必要です。

    1. 同一 Allowed Paths・anchor なし・security/permission 語彙ありでも suggested_action=proceed_with_coordination
    2. そのケースで escalation_required=False, coordination_required=True
    3. 同一 anchor かつ conflicting operation は human_review_required
    4. prefix overlap は disjoint/proceed/human のどれに分類するかを fixture で固定
    5. preparation.md から keyword immediate stop 文言が消えていること
    6. proceed_with_coordination が LOOP_STATE に保存されること
    7. PR body の Related coordination が別フェーズで生成されること
    8. Haiku SubAgent comment の schema validation と再取得検証
    9. 実装: impl-review-loop の contract blocked 時エスカレーションを blocked reason 3 分類と worker 自律修正手順に置換する #569/実装: impl-review-loop で missing_contract_go 時に Haiku SubAgent が issue-contract-review を自動実行する #597 の blocked/missing_contract_go flow を壊していないこと
    10. 設計: scope rollup から security escalation を分離した専用 security-risk gate skill を検討する #558 の security gate 非ゴールに反して scope rollup に security judgement を戻していないこと

    GitHub に投げるレビューコメント案

    Request changes.
    
    #607 の方向性(uncertain を human stop にせず coordination として継続、keyword-only security/auth/permission/sandbox stop の削除)は妥当です。ただし現状の契約では approve できません。
    
    Blockers:
    
    1. Issue body は「PR merged/tests pass」「uncertain is no longer human_review_required」と主張していますが、main の `plan_issue_scope_rollup.py` には `ACTION_PROCEED_WITH_COORDINATION` がなく、`uncertain` は `escalation_required=True` かつ `_suggested_action()` で `human_review_required` のままです。`preparation.md` と tests も旧挙動のままです。Outcome を削除するか、対象 PR/branch を明示してください。
    
    2. `_suggested_action()` だけで `uncertain -> proceed_with_coordination` にしても、`escalation_required=True` が残るなら下流が停止します。`uncertain` は `escalation_required=False, coordination_required=True` として意味を分離してください。
    
    3. preparation フェーズで PR body の `Related coordination` を更新する設計は責務が曖昧です。preparation は `LOOP_STATE.scope_rollup_decision` に構造化保存し、PR 作成/更新フェーズが body にレンダリングする、と明記してください。
    
    4. #569/#597/#558 と同じ `preparation.md` 領域に触れており、単独改善ではありません。特に #597 の Haiku SubAgent preflight/comment 再取得検証の設計と統合してください。
    
    5. 指定コメントに同意します。メイン会話が `plan_issue_scope_rollup.py` や `test_plan_issue_scope_rollup.py` の詳細実行を抱えるべきではありません。決定論的な preflight は Haiku SubAgent に委譲し、メインは GitHub comment の machine-readable result を再取得・schema/hash/current issue 検証して LOOP_STATE に取り込む設計にしてください。
    
    6. keyword stop 削除は #558 の「scope rollup は security gate ではない」という方向性と合っていますが、security-risk gate への委譲または非回帰説明が必要です。単に防御層を削除するだけに見える状態は不可です。

    このレビューの核心は、uncertain を「人間判断」ではなく「調整しながら進める」に変えるなら、状態モデル・準備手順・SubAgent 責務・検証経路を一貫して変える必要があるという点です。現状の #607 はその一貫性が不足しています。

    # 既存衝突確認
    git worktree list | grep "$WORKTREE" && echo "[WARN] worktree 既存" || echo "[OK] worktree 未作成"
    git branch --list "$BRANCH" && echo "[WARN] branch 既存" || echo "[OK] branch 未作成"
    ```

    既存衝突あり → 過去のイテレーションの残骸の可能性。人間判断を仰ぐ。

    ## 4. Product Spec Gate 評価完了後の LOOP_STATE 初期化

    Product Spec Check 評価(1-d)を完了後、iteration = 0 で以下の状態で開始:

    ```yaml
    LOOP_STATE:
    issue_number:
    contract_snapshot_url:
    contract_snapshot_source: provided | detected_existing | materialized_by_issue_contract_review
    iteration: 0
    max_iterations: 3
    worktree: .claude/worktrees/issue-<番号>-
    branch: worktree-issue-<番号>-
    last_step: null
    last_loop_verdict: null
    blockers_history: []
    external_research_skip_basis: null
    termination_reason: null
    intake_gate:
    status: pass | intake_gate_failed
    subreason: null | metadata_not_ready | missing_contract_go | stale_contract_review | body_snapshot_mismatch | request_changes_after_go
    evaluated_at: ""
    product_spec_preflight:
    source: contract_snapshot.checks.product_spec_check
    applicability: applicable | not_applicable | missing
    decision: pass | fail | human_judgment | missing
    blocked_rule_ids: []
    contract_snapshot_url: ""
    body_sha256: ""
    routing_action: continue | stop_human | refresh_contract_snapshot
    ```

    routing_action が stop_human または refresh_contract_snapshot の場合は、ループを開始せず人間判断へ escalate する。

    ## 5. 外部仕様調査スキップ判断(任意)

    internal-only 変更(src/state / src/systems 内の純粋ロジック変更等)なら external_research_skip_basis に理由を記録してスキップ。
    外部仕様が絡む場合は gemini-cli-headless-delegation を先行起動して情報を集める。

    ## 出力

    LOOP_STATE 初期値を会話履歴に明示記録し、Step 1(Implementation)へ進む。
    "
    [4]: https://github.com/squne121/loop-protocol/raw/refs/heads/main/.claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py "raw.githubusercontent.com"
    [5]: #569 "実装: impl-review-loop の contract blocked 時エスカレーションを blocked reason 3 分類と worker 自律修正手順に置換する · Issue #569 · squne121/loop-protocol · GitHub"
    [6]: https://code.claude.com/docs/en/sub-agents "Create custom subagents - Claude Code Docs"
    [7]: https://code.claude.com/docs/en/permissions "Configure permissions - Claude Code Docs"

  5. squne121 commented on Jun 3, 2026

    @squne121
    OwnerAuthor

    Contract Review: BLOCKED (2026-06-03T00:50:27Z)

    不足項目

    • vc_preflight: blocked
    • AC2 の VC uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py -k "test_permission_keyword_only_should_not_escalate" -v が pytest exit 5(0 tests collected)で baseline fail ではなく VC 設計不備になっています。
    • AC3 の VC uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py -k "test_same_anchor_conflicting_op_should_escalate" -v が pytest exit 5(0 tests collected)で baseline fail ではなく VC 設計不備になっています。

    参考

    • blocker/dependency check: pass
    • product spec preflight: applicability=not_applicable, decision=pass
    • pnpm typecheck, pnpm test, pnpm build, およびテストファイル全体実行は baseline で pass しています。

    推奨アクション

    • issue-refinement-loop で AC2/AC3 の Verification Commands を「baseline で決定論的に fail し、実装後に pass へ変化する」形へ修正することを推奨します。
    • 具体的には、存在しない新規テスト名への -k ではなく、追加予定のシンボル・fixture・assertion を対象にした baseline-fail VC へ置き換えるか、該当 VC を pr_review_only / runtime_only に再分類する必要があります。
  6. squne121 commented on Jun 3, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-03T05:02:00Z)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-03T05:02:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/607
      body_sha256: "sha256:46f62a827f850cec6d6afeac1ac084b646b0a1f27f0daf695cd1df7cb7923243"
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 5
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 4
          vc_skipped: 0
          status: pass
          classifications:
            - ac: AC1
              command: "rg -c \"ACTION_PROCEED_WITH_COORDINATION\" .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py"
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC2
              command: "rg -c \"test_permission_keyword_only_should_not_escalate\" .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py"
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC3
              command: "rg -c \"test_same_anchor_conflicting_op_should_escalate\" .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py"
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC4
              command: "! rg -qc \"sandbox.*即時停止\" .claude/skills/impl-review-loop/steps/preparation.md"
              exit_code: null
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC5
              command: "rg -c \"proceed_with_coordination\" .claude/skills/impl-review-loop/steps/preparation.md"
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC6
              command: "uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py -v"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: regression
              command: "pnpm typecheck"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: regression
              command: "pnpm test"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
            - ac: regression
              command: "pnpm build"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "AC2/AC3/AC4 の VC コメントに parenthetical テキストがあるため preflight が AC_UNKNOWN と表示したが decision: go。機能的影響なし。"

    • Outcome: plan_issue_scope_rollup.py の uncertain 衝突を proceed_with_coordination に変更し、preparation.md のキーワードベース即時停止ルールを削除する
    • Acceptance Criteria: AC1–AC6(上記 YAML classifications 参照)
    • Allowed Paths:
      • .claude/skills/issue-refinement-loop/scripts/plan_issue_scope_rollup.py
      • .claude/skills/issue-refinement-loop/tests/test_plan_issue_scope_rollup.py
      • .claude/skills/impl-review-loop/steps/preparation.md
    • Worktree: .claude/worktrees/issue-607-preflight-scope-rollup-proceed-with-coor
    • Branch: worktree-issue-607-preflight-scope-rollup-proceed-with-coor
    • VC preflight: baseline fail = 5, regression_gate pass = 4, 想定外 pass = 0, 実行不可 = 0
  7. squne121 commented on Jun 3, 2026

    @squne121
    OwnerAuthor

    implement-issue 実装完了 (2026-06-03T14:15:00Z)

    実装が完了しました。以下の状態です。

  8. added 2 commits that reference this issue on Jun 3, 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

    enhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions