Skip to content

実装: issue-refinement-loop の SubAgent-owned contract migration を行う #394

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#391"
goal_ref: "issue-refinement-loop が保持している SubAgent 固有の判断契約を各 SubAgent 側へ移し、orchestrator を routing 責務に限定する"
change_kind: workflow

Depends On

Background

  • issue-refinement-loop は orchestrator であり、codebase-investigator / web-researcher / issue-author / issue-reviewer の詳細判断契約を保持し続けると、SKILL.md が再肥大化する。
  • Phase 3 では、各 SubAgent が所有すべき input/output contract を SubAgent 側または専用 reference に移し、orchestrator は planner JSON と SubAgent result を routing するだけにする。

Outcome

  • SubAgent 固有の contract が各 SubAgent 側へ移り、issue-refinement-loop は SubAgent の内部判定 prose を保持しない。

In Scope

Out of Scope

Acceptance Criteria

Verification Commands

$ rg -n "(SubAgent-owned)" .claude/skills/issue-refinement-loop/references/  # AC1
$ rg -n "WEB_RESEARCH_RESULT_V1.*SubAgent-owned|retry_count|fallback_used" .claude/agents/web-researcher.md  # AC2
$ rg -n "CODEBASE_INVESTIGATION_RESULT_V1|Fact-check Contract.*SubAgent-owned" .claude/agents/codebase-investigator.md  # AC3
$ rg -n "ISSUE_AUTHOR_RESULT_V1|reflection_notes" .claude/agents/issue-author.md  # AC4
$ rg -n "REVIEW_ISSUE_RESULT_V1.*SubAgent-owned|blocking_findings" .claude/agents/issue-reviewer.md  # AC5
$ pnpm typecheck && pnpm lint && pnpm test && pnpm build && uv run pytest .claude/skills/review-issue/tests/ -v && python3 scripts/validate_agent_skill_frontmatter.py  # AC6

Allowed Paths

  • .claude/skills/issue-refinement-loop/SKILL.md
  • .claude/skills/issue-refinement-loop/references/
  • .claude/agents/codebase-investigator.md
  • .claude/agents/web-researcher.md
  • .claude/agents/issue-author.md
  • .claude/agents/issue-reviewer.md

Stop Conditions

Runtime Verification Applicability

decision: not_applicable
reason: prompt / contract migration。静的検証と既定 gate で確認する。

Delivery Rule

  • 1 Issue = 1 PR
  • Draft PR 既定
  • Phase 1, 2 merge 後に着手

Activity

  1. squne121 commented on May 26, 2026

    @squne121
    OwnerAuthor

    対象を squne121/loop-protocol の #394 として見ました。結論から言うと、Issue の方向性は正しいが、このまま実装すると「orchestrator から SubAgent に prose を移しただけ」で、責務分離・検証可能性・GeminiCLI依存の時限リスクが残るため、実装前に Issue 本文を補強した方がよいです。

    結論

    判定: REQUEST_CHANGES 相当。

    #394 は「issue-refinement-loop が持つ SubAgent 固有契約を各 SubAgent 側へ移し、orchestrator を routing 責務へ限定する」実装 Issue です。In Scope には codebase-investigator、web-researcher、issue-author、issue-reviewer の契約移管、重複削除、cross-link 追加が含まれています。 これは親 #391 の「thin entrypoint / script-first / SubAgent-owned contract」方針と整合しています。

    ただし現状の #394 は、何を「移管完了」とみなすかが grep ベースで弱いです。Issue 本文の VC は rg -n "SubAgent-owned|input/output contract|does not redefine" のような存在確認に寄っており、実際に orchestrator が SubAgent 内部判断を再定義していないこと、SubAgent が機械可読 result contract を返すこと、downstream がその contract を検証して fail-close することまでは保証できません。

    関連 Issue / PR から見た位置づけ

    #393 / PR #413 は、issue-refinement-loop/SKILL.md を thin entrypoint にし、anchor handling、scope guard、AC/VC reflection、web research routing、termination policy などを reference に分割した PR です。 ただし #393 側では、SubAgent prompt の責務移動、web-researcher / gemini-cli-headless-delegation の retry/fallback/attempt log 設計変更、.claude/agents/*.md 変更を明示的に Out of Scope にしており、#394 を残課題として切り出しています。

    #248 / PR #406 は REPO_EVIDENCE_REF_V1 を gemini-cli-headless-delegation に追加し、file evidence の commit_sha 固定、excerpt_sha256、mutable URL 禁止、verification metadata を schema 化する方向です。 PR #406 も gemini-cli-headless-delegation 側に schema を追加し、codebase-investigator には cross-link / fail-close rule を追加する設計です。 したがって #394 で codebase-investigator 側に evidence 詳細仕様を再定義すると、#248 と二重管理になります。

    #391 は、Claude Code 公式 docs の「skill body は呼び出し後 context に残る」「複雑な skill は supporting files に分割」「SKILL.md は 500 行未満推奨」「description + when_to_use は 1,536 文字で truncation」などを根拠に、固定 token cost と確率的判断を削る親 Issue です。 これは公式 docs とも一致し、Claude Code docs は supporting files に詳細 reference を逃がすこと、SKILL.md を 500 行未満に保つこと、skill content が session context に残り recurring token cost になることを明記しています。([Claude Code]1) ([Claude Code]1) ([Claude Code]1)

    敵対的レビュー

    BLOCKER-1: 「SubAgent-owned」の完了条件が prose 配置換えに留まる

    #394 のゴールは正しいですが、現在の AC だと「orchestrator の長文を削り、SubAgent 文書へリンクを置いた」だけで通ります。これは責務分離ではなく、責務の所在を曖昧にしたまま文章を移動した状態です。

    必要なのは、各 SubAgent について少なくとも以下の 3 層を分けることです。

    1. Input contract: orchestrator から渡される最小入力。
    2. Execution contract: SubAgent が内部で判断してよい範囲。
    3. Result contract: orchestrator が消費できる machine-readable result。

    Claude Code の subagent は独立 context / custom system prompt / tool access / independent permissions で動くため、main conversation の状態を暗黙に読める前提にできません。([Claude Code]2) また、SubAgent は高出力作業の隔離には有効ですが、返却 summary が曖昧だと main thread 側で再解釈が必要になります。([Claude Code]2)

    修正案: #394 の Outcome を「SubAgent 文書へ移す」ではなく、次に変更してください。

    Outcome:
    - issue-refinement-loop は SubAgent 内部判断 prose を保持しない。
    - 各 SubAgent は INPUT_V1 / RESULT_V1 を明示し、orchestrator は RESULT_V1 の routing fields だけを consume する。
    - SubAgent 内部判断の再定義は禁止され、orchestrator 側には link-only + schema validation のみを残す。

    BLOCKER-2: web-researcher と gemini-cli-headless-delegation の責務境界が未確定

    #394 は web-researcher に retry / fallback / attempt log / critical claim contract を持たせる前提ですが、実際には Gemini CLI headless 経路の失敗分類は wrapper / provider layer 側で握るべきです。Gemini CLI headless mode は -p/--prompt で非TTY実行され、--output-format json は response、stats、error を返し、stream-json は tool_use / tool_result / error / result event を返します。exit code も 0, 1, 42, 53 が定義されています。([Gemini CLI]3)

    つまり auth_error、quota、turn limit、input error、tool failure は、web-researcher の自然言語判断ではなく、headless wrapper の normalized provider result として扱う方が決定論的です。

    さらに 2026-05-27 時点で、Gemini CLI docs は「Unpaid tier and Google One users: Gemini CLI will be replaced by Antigravity CLI on June 18th」と表示しています。([Gemini CLI]3) したがって #394 で Gemini CLI 固有の retry/fallback contract を web-researcher.md に焼き込むと、2026-06-18 以降に契約が陳腐化する可能性があります。

    修正案: web-researcher は「research result contract」を持つ。Gemini CLI / Antigravity CLI / web.run などの provider retry は gemini-cli-headless-delegation または provider wrapper に閉じる。

    WEB_RESEARCH_RESULT_V1:
      status: success | failed | partial
      critical_claims:
        - claim
          source_ref
          verification_status: verified | unverified | contradicted
      provider_attempts:
        - provider: gemini_cli | antigravity_cli | web
          status: success | failed
          failure_class: auth_error | quota | input_error | tool_error | timeout | unknown
          exit_code: int | null
          output_format: json | stream-json | text | null
      fallback_used: boolean
      needs_human_escalation: boolean

    BLOCKER-3: #248 の evidence contract と重複する危険が高い

    #394 の codebase-investigator scope には evidence accuracy / repo fact claim / line anchor contract へのリンク整理が入っています。 ただし #248 はすでに REPO_EVIDENCE_REF_V1 を gemini-cli-headless-delegation の output contract として定義する方向で、mutable blob/main URL の禁止、commit SHA 固定、excerpt hash 検証、delegation fail-close を扱っています。

    したがって #394 で codebase-investigator.md に同じ schema を再掲すると、将来の schema drift が起きます。codebase-investigator は「REPO_EVIDENCE_REF_V1 を要求し、inconclusive を verified に昇格しない」だけを持つべきです。

    修正案: #394 の In Scope を次のように狭める。

    - codebase-investigator:
      - REPO_EVIDENCE_REF_V1 を再定義しない
      - gemini-cli-headless-delegation の REPO_EVIDENCE_REF_V1 への canonical link のみ保持
      - result 受信時の fail-close / inconclusive handling を明示

    MEDIUM-1: AC/VC が grep 依存で、負例を捕まえられない

    現状 VC は rg でキーワード存在を見るだけです。これだと次の悪い実装も通ります。

    issue-refinement-loop:
    - web-researcher は retry/fallback を自分で判断すること。
    - auth_error の場合は orchestrator が 1 回 retry すること。

    これは「SubAgent-owned」と書いていても、orchestrator 側が判断契約を保持しているため失敗です。

    追加すべき VC:

    # orchestrator 側に SubAgent 内部判断 prose が残っていないこと
    uv run python3 .claude/skills/issue-refinement-loop/tests/test_no_subagent_contract_duplication.py
    
    # 各 SubAgent result schema の fixture が妥当であること
    uv run python3 .claude/skills/issue-refinement-loop/tests/test_subagent_result_contracts.py
    
    # REPO_EVIDENCE_REF_V1 を issue-refinement-loop / codebase-investigator が再定義していないこと
    rg -n "commit_sha:|excerpt_sha256:|REPO_EVIDENCE_REF_V1 schema" \
      .claude/skills/issue-refinement-loop/ .claude/agents/codebase-investigator.md \
      && exit 1 || true

    MEDIUM-2: Gemini CLI security / sandbox 前提が Scope にない

    Gemini CLI は file operations / shell commands / web fetching / Google Search grounding を built-in tools として持ち、非対話実行も可能です。([GitHub]4) さらに sandboxing docs は、sandbox が shell/file modification のような危険操作を host から隔離し、-s/--sandbox、GEMINI_SANDBOX、settings.json で有効化できると説明しています。([Gemini CLI]5)

    #394 が web-researcher / gemini-cli-headless-delegation の retry/fallback を扱うなら、provider invocation の安全境界も最低限の contract に含めるべきです。特に external research worker が shell/file tool を持つ場合、attempt log に sandbox mode / allowed directories / secret redaction status が残らないと、後続レビューが安全性を検証できません。

    追加フィールド案:

    provider_attempts:
      - provider: gemini_cli
        sandbox_mode: docker | podman | sandbox-exec | runsc | lxc | none | unknown
        working_directory: string
        allowed_paths: string[]
        secret_redaction: applied | not_applicable | unknown

    LOW-1: issue-author / issue-reviewer の契約が抽象的

    #394 は issue-author に AC/VC reflection / issue body mutation result contract、issue-reviewer に final verdict / needs_second_pass / non_blocking_improvements consume contract を持たせるとしています。 ただし、このままだと「何を返せば orchestrator が routing できるか」が不明です。

    最低限の result schema:

    ISSUE_AUTHOR_RESULT_V1:
      status: body_updated | no_change | failed
      mutated_sections: []
      ac_vc_reflection:
        ac_complete: boolean
        vc_executable: boolean
        missing_items: []
      next_action: review | human_escalation | stop
    
    ISSUE_REVIEWER_RESULT_V1:
      verdict: approve | request_changes | needs_second_pass
      blocking_findings: []
      non_blocking_improvements: []
      required_body_changes: []
      next_action: author_revise | close | human_escalation

    Issue 本文への具体的な追記案

    ## Additional Acceptance Criteria
    
    - [ ] `issue-refinement-loop` は SubAgent 内部判断 prose を保持せず、SubAgent result の routing fields のみを consume する
    - [ ] 各 SubAgent は `*_RESULT_V1` を定義し、orchestrator はその schema に依存する
    - [ ] `web-researcher` は provider retry/fallback の詳細を再定義せず、provider wrapper の normalized attempt log を consume する
    - [ ] `codebase-investigator` は `REPO_EVIDENCE_REF_V1` を再定義せず、canonical contract への link-only と fail-close rule のみ保持する
    - [ ] Gemini CLI / Antigravity CLI の provider 差分を吸収できる `provider_attempts[]` schema を持つ
    - [ ] grep だけでなく、負例 fixture を含む pytest で「orchestrator 側の契約重複禁止」を検証する
    
    ## Additional Verification Commands
    
    ```bash
    uv run pytest .claude/skills/issue-refinement-loop/tests/test_no_subagent_contract_duplication.py -v
    uv run pytest .claude/skills/issue-refinement-loop/tests/test_subagent_result_contracts.py -v
    uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_provider_attempt_log.py -v
    bash scripts/sync-agent-skills.sh --check
    
    ## 最終判断
    
    #394 は **close せず実装すべき** ですが、実装単位としてはまだ粗いです。特に `web-researcher` と `gemini-cli-headless-delegation` の境界を曖昧にしたまま進めると、前回の人間指摘どおり「オーケストレーターが作業コンテクストを持ち続ける」構造が再発します。
    
    推奨は、#394 を次の方針に修正してから実装です。
    
    **方針:**  
    `issue-refinement-loop` から SubAgent 内部判断を削る。ただし削った判断を別 prose に移すのではなく、SubAgent / provider wrapper ごとの machine-readable result contract と deterministic validator に落とす。Gemini CLI 固有の retry/fallback は `web-researcher` ではなく provider wrapper 側へ寄せる。
    ::contentReference[oaicite:20]{index=20}
    
  2. squne121 commented on May 26, 2026

    @squne121
    OwnerAuthor

    結論

    #394 は方向性として妥当です。issue-refinement-loop を orchestration に寄せ、SubAgent 固有の判断契約を codebase-investigator / web-researcher / issue-author / issue-reviewer 側へ移す、という設計は #391 の親方針と整合します。#391 は「script-first / thin entrypoint / SubAgent-owned contract」によって固定トークンと確率的判断を減らす parent であり、#394 はその Phase 3 に相当します。

    ただし、現状の #394 は “移す” ことの成功条件が弱い です。敵対的に見ると、単なる文言移設・リンク整理で AC を満たせてしまい、SubAgent が実際にその契約を安定して produce/consume できるか、orchestrator が再び判断責務を抱え込まないか、既存 Issue との吸収・重複判断ができるかが未保証です。


    高リスク指摘

    1. AC が rg ベースで、契約の実効性を検証していない

    #394 の AC は、SubAgent-owned、retry、fallback、evidence accuracy、mutation result、verdict などの文字列検出に偏っています。
    これでは、次のような実装でも通ります。

    web-researcher は retry / fallback / attempt log を扱う。
    

    しかし、本当に必要なのは prose の存在ではなく、以下のような 機械可読 I/O contract です。

    WEB_RESEARCH_RESULT_V1:
      status: success | failed | skipped
      critical_external_claims:
        - claim: string
          citation_urls: string[]
          verification_route: web | official_docs | fallback_direct
          confidence: high | medium | low
      attempts:
        - attempt_no: integer
          route: gemini_cli | direct_web | manual
          status: success | failed
          failure_class: auth_error | network_error | insufficient_citation | other
      retry_exhausted: boolean
      fallback_used: boolean
    

    修正案: AC1〜AC5 を “文字列があること” から “schema marker と fixture があること” に変えるべきです。

    追加 AC 案:

    - [ ] 各 SubAgent は `*_RESULT_V1` または既存 result schema を明示し、required fields / enum / failure modes を定義している。
    - [ ] `issue-refinement-loop` は SubAgent result の allowed fields のみを consume し、SubAgent 内部判断条件を prose で再定義していない。
    - [ ] fixture により、success / skipped / retry_failed / fallback_used / insufficient_evidence の各 result を orchestrator が routing できる。
    

    2. Claude Code の subagent 仕様上、「SubAgent 側へ移せば読まれる」とは限らない

    Claude Code の subagent は fresh isolated context で起動し、親会話の履歴や既に呼び出された skill を見ません。親から渡される delegation prompt、agent prompt、CLAUDE.md/memory、preloaded skills 等が初期コンテキストになります。(Claude Code)
    つまり、契約を .claude/skills/issue-refinement-loop/references/ に置くだけでは、SubAgent が必ず読む保証がありません。

    また、subagent の skills field は full skill content を startup context に注入しますが、これは token cost を増やします。Claude Code docs は、subagent の skills は “full content” を注入すると説明しています。(Claude Code)
    #394 の目的は固定 token cost 削減なので、SubAgent 側に preload しすぎると #391 の目的と逆行します。

    修正案: “契約の配置先” を明確に分けるべきです。

    契約種別 | 推奨配置 | 理由 -- | -- | -- SubAgent が必ず従う最小 I/O schema | .claude/agents/.md 本体 | fresh context でも読まれる 長い例・edge case・歴史的背景 | references/*.md | progressive disclosure orchestrator が読む routing interface | issue-refinement-loop/references/subagent-io-contracts.md | consume-only 検証ロジック | script / pytest fixture | prose 依存を排除

    3. #203 / #247 の統合判断が弱い

    #394 は web-researcher の retry / fallback / attempt log 契約を整理し、#203 / #247 の統合判断材料化を In Scope にしています。
    関連 Issue を見ると、#203 は transient auth_error に対する 1 retry を issue-refinement-loop 側に追加する内容で、#247 は web-researcher / gemini-cli-headless-delegation / issue-refinement-loop 間の WEB_RESEARCH_RESULT_V1 と retry/fallback 責務整合が目的です。

    ここでの危険は、#394 が “#203 / #247 を参照した” だけで終わり、実際には責務分界が曖昧なまま残ることです。

    判断基準を明文化すべきです。

    #203 is superseded if:
    - auth_error retry policy is owned by web-researcher or gemini-cli-headless-delegation, not issue-refinement-loop.
    - result schema exposes `failure_class`, `retry_count`, `retry_exhausted`.
    - orchestrator behavior is limited to routing on final result status.
    

    #247 is absorbed if:

    • WEB_RESEARCH_RESULT_V1 or equivalent schema exists.
    • direct fallback criteria are defined.
    • attempt log is required.
    • critical external claims require citations or explicit insufficiency status.

    この条件がないと、OPEN Issue の close sweep から外しているにもかかわらず、統合済みかどうかの判定ができません。


    4. #248 との重複判断も schema level で行う必要がある

    #394 は codebase-investigator の evidence accuracy contract を整理し、#248 との重複判断ができることを AC3 にしています。
    #248 は gemini-cli-headless-delegation の file evidence を REPO_EVIDENCE_REF_V1 として commit 固定・excerpt hash 付きで返す内容です。

    ここは単なる “line anchor contract” では足りません。repo fact claim の検証には最低限、以下が必要です。

    REPO_EVIDENCE_REF_V1:
    file_path: string
    commit_sha: string
    line_start: integer
    line_end: integer
    excerpt_sha256: string
    claim_supported: string

    #394 側の codebase-investigator contract がこれと別形式を作ると、後で統合不能になります。

    修正案: #394 は新 schema を作らず、#248 の REPO_EVIDENCE_REF_V1 を canonical evidence type として参照する。必要なら CODEBASE_INVESTIGATION_RESULT_V1.evidence_refs[] に REPO_EVIDENCE_REF_V1 を含める形に限定するべきです。


    5. #393 との境界が曖昧

    #393 は issue-refinement-loop/SKILL.md を thin entrypoint にして references に分割する Issue です。
    #394 はさらに SubAgent-owned contract migration を行いますが、両者の境界はかなり近いです。

    #393 の Remaining Parent Gaps には、#394 が “web-researcher の retry/fallback/attempt log 等の .claude/agents/.md 側責務整理” として残っています。
    したがって #394 は、単なる issue-refinement-loop/references/ 追記では不十分です。主対象は .claude/agents/
    .md 側であるべきです。

    修正案: In Scope を次のように締めるべきです。

    Primary change targets:
    
  3. .claude/agents/web-researcher.md
  4. .claude/agents/codebase-investigator.md
  5. .claude/agents/issue-author.md
  6. .claude/agents/issue-reviewer.md
  7. Secondary change targets:

    • .claude/skills/issue-refinement-loop/SKILL.md
    • .claude/skills/issue-refinement-loop/references/*.md

    Forbidden:

    • issue-refinement-loop 側に SubAgent 内部判定条件を新規追加すること

    外部仕様に基づく設計上の注意

    Claude Code skills docs は、skill body は呼び出し後 context に残り、行数が継続的 token cost になるため、複雑な skill では supporting files を使い、SKILL.md を 500 行未満に保つことを推奨しています。(Claude Code)
    #391 がこの点を根拠にしているのは妥当です。

    一方で、subagent docs は subagent が fresh context で動作し、親会話や既に呼び出された skill を見ないと説明しています。(Claude Code)
    したがって、#394 の実装方針は “orchestrator から消す” だけではなく “SubAgent 起動時に確実に到達する場所へ最小契約を置く” 必要があります。


    #394 の改訂案

    追加すべき Acceptance Criteria

    - [ ] AC7: 各 SubAgent の result contract が *_RESULT_V1 marker 付きで定義され、required fields / enum / failure modes が明示されている。
    
  8. AC8: issue-refinement-loop は SubAgent result の top-level fields のみで routing し、retry/fallback/evidence/authoring/review の内部判定条件を再定義していない。
  9. AC9: web-researcher contract は failure_class, retry_count, attempt_log, fallback_used, critical_external_claims[].citations を含む。
  10. AC10: codebase-investigator contract は #248 の REPO_EVIDENCE_REF_V1 を canonical evidence ref として参照し、独自 evidence schema を作らない。
  11. AC11: issue-author contract は input issue draft / output mutation result / unchanged reason / validation blockers を区別する。
  12. AC12: issue-reviewer contract は final_verdict, needs_second_pass, blocking_findings, non_blocking_improvements を machine-readable に返す。
  13. AC13: fixture または static test により、orchestrator references から forbidden fragments(retry algorithm, fallback criteria, line-anchor validation details 等)が除去されていることを検証する。
  14. [ ] AC14: #203 / #247 / #248 について absorbed / superseded / still-needed の判定コメント案が作成されている。
  15. 追加すべき Verification Commands

    # SubAgent contract markers
    rg -n "WEB_RESEARCH_RESULT_V1|CODEBASE_INVESTIGATION_RESULT_V1|ISSUE_AUTHOR_RESULT_V1|ISSUE_REVIEW_RESULT_V1" .claude/agents/

    Orchestrator must not redefine internal decisions

    ! rg -n "auth_error.*retry|fallback.*criteria|excerpt_sha256|line anchor.*must|critical claim.*citation.*retry"
    .claude/skills/issue-refinement-loop/SKILL.md
    .claude/skills/issue-refinement-loop/references/

    Canonical repo evidence schema reuse

    rg -n "REPO_EVIDENCE_REF_V1" .claude/agents/codebase-investigator.md .claude/agents/gemini-cli-headless-delegation.md

    Web researcher required fields

    rg -n "failure_class|retry_count|attempt_log|fallback_used|critical_external_claims" .claude/agents/web-researcher.md

    Reviewer result fields

    rg -n "final_verdict|needs_second_pass|blocking_findings|non_blocking_improvements" .claude/agents/issue-reviewer.md


    実装方針

    1. まず schema marker を置く。
      prose を整理する前に、各 SubAgent の output contract を短い YAML block で固定する。

    2. orchestrator 側は consume-only にする。
      issue-refinement-loop には「どの result field を見て routing するか」だけ残す。

    3. 歴史的背景・長い例は references に逃がす。
      ただし SubAgent が必ず従う required field は .claude/agents/.md 本体に置く。

    4. 改善: issue-refinement-loop の web-researcher Step 1b に transient auth failure への 1-retry 機構を追加する #203 / 実装: web-researcher / gemini-cli-headless-delegation に grounding failure retry と direct fallback 判定を集約する #247 / 実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 の close 判断条件を明文化する。
      実装: issue-refinement-loop の SubAgent-owned contract migration を行う #394 完了後に close sweep しないとしても、判断材料はこの Issue の成果物に含めるべきです。

    5. テキスト検索ではなく forbidden-fragment test を追加する。
      “移した契約がある” より “orchestrator 側に戻っていない” ことの方が重要です。


    敵対的レビューとしての最終判定

    現状の #394 は、このまま実装すると “ドキュメントの再配置” で終わるリスクが高いです。
    親 Issue #391 の目的は、単なる軽量化ではなく、script-first / thin entrypoint / SubAgent-owned contract によって固定 token cost と確率的判断を減らすことです。

    したがって #394 は、以下を満たすように改訂してから着手するのが安全です。

    この改訂なしに merge すると、#391 の Phase 3 完了を主張しにくく、後続で “SubAgent-owned と言いながら orchestrator が判断している” という再肥大化が再発します。

    ## 結論

    #394 は方向性として妥当です。issue-refinement-loop を orchestration に寄せ、SubAgent 固有の判断契約を codebase-investigator / web-researcher / issue-author / issue-reviewer 側へ移す、という設計は #391 の親方針と整合します。#391 は「script-first / thin entrypoint / SubAgent-owned contract」によって固定トークンと確率的判断を減らす parent であり、#394 はその Phase 3 に相当します。

    ただし、現状の #394 は “移す” ことの成功条件が弱い です。敵対的に見ると、単なる文言移設・リンク整理で AC を満たせてしまい、SubAgent が実際にその契約を安定して produce/consume できるか、orchestrator が再び判断責務を抱え込まないか、既存 Issue との吸収・重複判断ができるかが未保証です。


    高リスク指摘

    1. AC が rg ベースで、契約の実効性を検証していない

    #394 の AC は、SubAgent-owned、retry、fallback、evidence accuracy、mutation result、verdict などの文字列検出に偏っています。
    これでは、次のような実装でも通ります。

    web-researcher は retry / fallback / attempt log を扱う。

    しかし、本当に必要なのは prose の存在ではなく、以下のような 機械可読 I/O contract です。

    WEB_RESEARCH_RESULT_V1:
      status: success | failed | skipped
      critical_external_claims:
        - claim: string
          citation_urls: string[]
          verification_route: web | official_docs | fallback_direct
          confidence: high | medium | low
      attempts:
        - attempt_no: integer
          route: gemini_cli | direct_web | manual
          status: success | failed
          failure_class: auth_error | network_error | insufficient_citation | other
      retry_exhausted: boolean
      fallback_used: boolean

    修正案: AC1〜AC5 を “文字列があること” から “schema marker と fixture があること” に変えるべきです。

    追加 AC 案:

    - [ ] 各 SubAgent は `*_RESULT_V1` または既存 result schema を明示し、required fields / enum / failure modes を定義している。
    - [ ] `issue-refinement-loop` は SubAgent result の allowed fields のみを consume し、SubAgent 内部判断条件を prose で再定義していない。
    - [ ] fixture により、success / skipped / retry_failed / fallback_used / insufficient_evidence の各 result を orchestrator が routing できる。

    2. Claude Code の subagent 仕様上、「SubAgent 側へ移せば読まれる」とは限らない

    Claude Code の subagent は fresh isolated context で起動し、親会話の履歴や既に呼び出された skill を見ません。親から渡される delegation prompt、agent prompt、CLAUDE.md/memory、preloaded skills 等が初期コンテキストになります。(Claude Code)
    つまり、契約を .claude/skills/issue-refinement-loop/references/ に置くだけでは、SubAgent が必ず読む保証がありません。

    また、subagent の skills field は full skill content を startup context に注入しますが、これは token cost を増やします。Claude Code docs は、subagent の skills は “full content” を注入すると説明しています。(Claude Code)
    #394 の目的は固定 token cost 削減なので、SubAgent 側に preload しすぎると #391 の目的と逆行します。

    修正案: “契約の配置先” を明確に分けるべきです。

    契約種別 推奨配置 理由
    SubAgent が必ず従う最小 I/O schema .claude/agents/<agent>.md 本体 fresh context でも読まれる
    長い例・edge case・歴史的背景 references/*.md progressive disclosure
    orchestrator が読む routing interface issue-refinement-loop/references/subagent-io-contracts.md consume-only
    検証ロジック script / pytest fixture prose 依存を排除

    3. #203 / #247 の統合判断が弱い

    #394 は web-researcher の retry / fallback / attempt log 契約を整理し、#203 / #247 の統合判断材料化を In Scope にしています。
    関連 Issue を見ると、#203 は transient auth_error に対する 1 retry を issue-refinement-loop 側に追加する内容で、#247 は web-researcher / gemini-cli-headless-delegation / issue-refinement-loop 間の WEB_RESEARCH_RESULT_V1 と retry/fallback 責務整合が目的です。

    ここでの危険は、#394 が “#203 / #247 を参照した” だけで終わり、実際には責務分界が曖昧なまま残ることです。

    判断基準を明文化すべきです。

    #203 is superseded if:
    - auth_error retry policy is owned by web-researcher or gemini-cli-headless-delegation, not issue-refinement-loop.
    - result schema exposes `failure_class`, `retry_count`, `retry_exhausted`.
    - orchestrator behavior is limited to routing on final result status.
    
    #247 is absorbed if:
    - WEB_RESEARCH_RESULT_V1 or equivalent schema exists.
    - direct fallback criteria are defined.
    - attempt log is required.
    - critical external claims require citations or explicit insufficiency status.

    この条件がないと、OPEN Issue の close sweep から外しているにもかかわらず、統合済みかどうかの判定ができません。


    4. #248 との重複判断も schema level で行う必要がある

    #394 は codebase-investigator の evidence accuracy contract を整理し、#248 との重複判断ができることを AC3 にしています。
    #248 は gemini-cli-headless-delegation の file evidence を REPO_EVIDENCE_REF_V1 として commit 固定・excerpt hash 付きで返す内容です。

    ここは単なる “line anchor contract” では足りません。repo fact claim の検証には最低限、以下が必要です。

    REPO_EVIDENCE_REF_V1:
      file_path: string
      commit_sha: string
      line_start: integer
      line_end: integer
      excerpt_sha256: string
      claim_supported: string

    #394 側の codebase-investigator contract がこれと別形式を作ると、後で統合不能になります。

    修正案: #394 は新 schema を作らず、#248 の REPO_EVIDENCE_REF_V1 を canonical evidence type として参照する。必要なら CODEBASE_INVESTIGATION_RESULT_V1.evidence_refs[] に REPO_EVIDENCE_REF_V1 を含める形に限定するべきです。


    5. #393 との境界が曖昧

    #393 は issue-refinement-loop/SKILL.md を thin entrypoint にして references に分割する Issue です。
    #394 はさらに SubAgent-owned contract migration を行いますが、両者の境界はかなり近いです。

    #393 の Remaining Parent Gaps には、#394 が “web-researcher の retry/fallback/attempt log 等の .claude/agents/*.md 側責務整理” として残っています。
    したがって #394 は、単なる issue-refinement-loop/references/ 追記では不十分です。主対象は .claude/agents/*.md 側であるべきです。

    修正案: In Scope を次のように締めるべきです。

    Primary change targets:
    - .claude/agents/web-researcher.md
    - .claude/agents/codebase-investigator.md
    - .claude/agents/issue-author.md
    - .claude/agents/issue-reviewer.md
    
    Secondary change targets:
    - .claude/skills/issue-refinement-loop/SKILL.md
    - .claude/skills/issue-refinement-loop/references/*.md
    
    Forbidden:
    - issue-refinement-loop 側に SubAgent 内部判定条件を新規追加すること

    外部仕様に基づく設計上の注意

    Claude Code skills docs は、skill body は呼び出し後 context に残り、行数が継続的 token cost になるため、複雑な skill では supporting files を使い、SKILL.md を 500 行未満に保つことを推奨しています。([Claude Code]2)
    #391 がこの点を根拠にしているのは妥当です。

    一方で、subagent docs は subagent が fresh context で動作し、親会話や既に呼び出された skill を見ないと説明しています。(Claude Code)
    したがって、#394 の実装方針は “orchestrator から消す” だけではなく “SubAgent 起動時に確実に到達する場所へ最小契約を置く” 必要があります。


    #394 の改訂案

    追加すべき Acceptance Criteria

    - [ ] AC7: 各 SubAgent の result contract が `*_RESULT_V1` marker 付きで定義され、required fields / enum / failure modes が明示されている。
    - [ ] AC8: `issue-refinement-loop` は SubAgent result の top-level fields のみで routing し、retry/fallback/evidence/authoring/review の内部判定条件を再定義していない。
    - [ ] AC9: `web-researcher` contract は `failure_class`, `retry_count`, `attempt_log`, `fallback_used`, `critical_external_claims[].citations` を含む。
    - [ ] AC10: `codebase-investigator` contract は #248 の `REPO_EVIDENCE_REF_V1` を canonical evidence ref として参照し、独自 evidence schema を作らない。
    - [ ] AC11: `issue-author` contract は input issue draft / output mutation result / unchanged reason / validation blockers を区別する。
    - [ ] AC12: `issue-reviewer` contract は `final_verdict`, `needs_second_pass`, `blocking_findings`, `non_blocking_improvements` を machine-readable に返す。
    - [ ] AC13: fixture または static test により、orchestrator references から forbidden fragments(retry algorithm, fallback criteria, line-anchor validation details 等)が除去されていることを検証する。
    - [ ] AC14: #203 / #247 / #248 について absorbed / superseded / still-needed の判定コメント案が作成されている。

    追加すべき Verification Commands

    # SubAgent contract markers
    rg -n "WEB_RESEARCH_RESULT_V1|CODEBASE_INVESTIGATION_RESULT_V1|ISSUE_AUTHOR_RESULT_V1|ISSUE_REVIEW_RESULT_V1" .claude/agents/
    
    # Orchestrator must not redefine internal decisions
    ! rg -n "auth_error.*retry|fallback.*criteria|excerpt_sha256|line anchor.*must|critical claim.*citation.*retry" \
      .claude/skills/issue-refinement-loop/SKILL.md \
      .claude/skills/issue-refinement-loop/references/
    
    # Canonical repo evidence schema reuse
    rg -n "REPO_EVIDENCE_REF_V1" .claude/agents/codebase-investigator.md .claude/agents/gemini-cli-headless-delegation.md
    
    # Web researcher required fields
    rg -n "failure_class|retry_count|attempt_log|fallback_used|critical_external_claims" .claude/agents/web-researcher.md
    
    # Reviewer result fields
    rg -n "final_verdict|needs_second_pass|blocking_findings|non_blocking_improvements" .claude/agents/issue-reviewer.md

    実装方針

    1. まず schema marker を置く。
      prose を整理する前に、各 SubAgent の output contract を短い YAML block で固定する。

    2. orchestrator 側は consume-only にする。
      issue-refinement-loop には「どの result field を見て routing するか」だけ残す。

    3. 歴史的背景・長い例は references に逃がす。
      ただし SubAgent が必ず従う required field は .claude/agents/*.md 本体に置く。

    4. 改善: issue-refinement-loop の web-researcher Step 1b に transient auth failure への 1-retry 機構を追加する #203 / 実装: web-researcher / gemini-cli-headless-delegation に grounding failure retry と direct fallback 判定を集約する #247 / 実装: gemini-cli-headless-delegation に REPO_EVIDENCE_REF_V1 を追加し file evidence の commit_sha 固定・excerpt_sha256 検証を SSOT 化する #248 の close 判断条件を明文化する。
      実装: issue-refinement-loop の SubAgent-owned contract migration を行う #394 完了後に close sweep しないとしても、判断材料はこの Issue の成果物に含めるべきです。

    5. テキスト検索ではなく forbidden-fragment test を追加する。
      “移した契約がある” より “orchestrator 側に戻っていない” ことの方が重要です。


    敵対的レビューとしての最終判定

    現状の #394 は、このまま実装すると “ドキュメントの再配置” で終わるリスクが高いです。
    親 Issue #391 の目的は、単なる軽量化ではなく、script-first / thin entrypoint / SubAgent-owned contract によって固定 token cost と確率的判断を減らすことです。

    したがって #394 は、以下を満たすように改訂してから着手するのが安全です。

    この改訂なしに merge すると、#391 の Phase 3 完了を主張しにくく、後続で “SubAgent-owned と言いながら orchestrator が判断している” という再肥大化が再発します。

  16. squne121 commented on May 26, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot 2026-05-26T17:49:10Z

    • Outcome: SubAgent 固有の contract が各 SubAgent 側へ移り、issue-refinement-loop は SubAgent の内部判定 prose を保持しない。
    • Acceptance Criteria: AC1-AC6
    • Verification Commands:
      • rg -n "(SubAgent-owned)" .claude/skills/issue-refinement-loop/references/
      • rg -n "WEB_RESEARCH_RESULT_V1.*SubAgent-owned|retry_count|fallback_used" .claude/agents/web-researcher.md
      • rg -n "CODEBASE_INVESTIGATION_RESULT_V1|Fact-check Contract.*SubAgent-owned" .claude/agents/codebase-investigator.md
      • rg -n "ISSUE_AUTHOR_RESULT_V1|reflection_notes" .claude/agents/issue-author.md
      • rg -n "REVIEW_ISSUE_RESULT_V1.*SubAgent-owned|blocking_findings" .claude/agents/issue-reviewer.md
      • pnpm typecheck
    • Allowed Paths:
      • .claude/skills/issue-refinement-loop/SKILL.md
      • .claude/skills/issue-refinement-loop/references/
      • .claude/agents/codebase-investigator.md
      • .claude/agents/web-researcher.md
      • .claude/agents/issue-author.md
      • .claude/agents/issue-reviewer.md
    • Worktree: .claude/worktrees/issue-394-subagent-owned-contract-migration
    • Branch: worktree-issue-394-subagent-owned-contract-migration
    • VC preflight: baseline fail = 5, 想定外 pass = 0, 実行不可 = 0
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-26T17:49:10Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/394
      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: 1
          vc_skipped: 0
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
        worktree_branch_collision: clear
      next_action: implement_issue
  17. squne121 commented on May 26, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-05-26T17:55:22Z)

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      follow_up_issues: []
      note_only_observations: []
    
    ISSUE_SCOPE_ROLLUP_DECISION_V2:
      schema_version: 2
      recorded_at: "2026-05-26T17:55:22Z"
      rollup_plan_ref:
        body_sha256: "d8c9e00633bf7839e5ba97a7cb35093baa7e9d72a2c428d1da98f1dc67fa8b79"
        generated_at: "2026-05-26T17:55:22Z"
      decision: skipped
      executed_actions: []
      skipped_reason: "No high-confidence open candidates found (excluding self)."
      candidates_reviewed:
        - kind: "issue"
          number: 395
          confidence: "medium"
          suggested_action: "create_parent_rollup_issue"
          final_decision: "deferred"
          rejection_reason: null
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/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions