Skip to content

実装: SHA-bound evidence index と command fingerprint budget で再読・重複調査・wait polling による context churn を抑制する #2052

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "同一 issue-refinement-loop 実行内で取得済み Issue/comment snapshot を SHA-bound evidence key で再利用し、不要な再取得・全文再展開を削減する"
change_kind: workflow

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: run_refinement_preflight.py が同一 loop 実行内で繰り返し取得する Issue body / comment snapshot が、同じ内容のまま再取得・再展開され main context と token usage を増大させている問題を、SHA-bound evidence cache で抑制する。
  • Desired Destination: scripts/agent-ops/evidence_index.py が run_refinement_preflight.py の Issue/comment fetch 経路に対して phase-scoped の SHA-bound reuse を提供し、scripts/agent-ops/context_budget_report.py が実際に観測できた fetch_count / emitted_utf8_bytes / snapshot_reuse_count / duplicate_projection_count を記録する。

Current Validated Scope

  • scripts/agent-ops/evidence_index.py の新規追加。evidence_key(repository, resource_kind [issue_body | comment], resource_id [issue_number | comment_id], observed_content_sha256, config_sha256)で、run_refinement_preflight.py が取得した Issue/comment snapshot の parse/projection 結果を 同一 phase 内に限り 再利用する。command 実行結果や任意の generic command は cache 対象にしない。
  • scripts/agent-ops/context_budget_report.py の新規追加。実際に観測できた fetch_count / emitted_utf8_bytes / snapshot_reuse_count / duplicate_projection_count のみを phase 単位で記録する(未観測の token / model-turn 値は生成しない)。
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py の Issue/comment fetch 経路への evidence_index オプトイン統合。既存の raw_issue_snapshot.json / planner_input.json / refinement_preflight_result_v1.json の artifact 構造を再利用し、別 bundle / receipt / ledger 形式を新設しない。
  • 対応する scripts/agent-ops/tests/test_evidence_index.py / test_context_budget_report.py、および run_refinement_preflight.py を実際に経由する統合テスト scripts/agent-ops/tests/test_evidence_index_preflight_integration.py の追加。

Remaining Parent Gaps

  • #1093(AGENTS/CLAUDE/skills/hooks/subagents/rules/scripts の静的テキスト読み込み inventory)と #1117(同スコープの context budget 導入)は、repo 内の静的ドキュメント/skill テキストの読み込み予算を扱う別スコープであり、本 Issue が扱う GitHub 実行時 state(Issue/comment)の evidence cache とは独立。context_budget_report.py の出力形式は #1117 の CONTEXT_BUDGET_DECISION_V1 系形式と揃えることを推奨するが、実装・モジュールは統合しない。
  • #88(adjudicate_vc_result.py / LOOP_STATE.vc_adjudication による current-head VC binding)、#1909(SubAgent 向け bounded context bundle)、#2077(closed / not_planned の cross-process no-progress persistence)は本 Issue のスコープに含めず、既存所有者のまま維持する。

Outcome

scripts/agent-ops/evidence_index.py が、issue-refinement-loop の同一 loop 実行内で run_refinement_preflight.py が取得した Issue/comment snapshot とその parse/projection 結果を SHA-bound evidence_key で phase 内再利用し、同じ大きな evidence の不要な再取得・全文再展開を減らす。phase transition、対象への mutation 後、explicit refresh、freshness-sensitive decision 直前では常に fresh fetch を行い、snapshot は「取得時点の観測」であって現在の GitHub state の保証ではないことを維持する。scripts/agent-ops/context_budget_report.py が、この consumer で実際に観測できた fetch_count / emitted_utf8_bytes / snapshot_reuse_count / duplicate_projection_count を記録し、cache 有効/無効で独立VC・CI/current-head確認・mutation判断が変わらない状態。対応する pytest と run_refinement_preflight.py を実際に経由する統合テストが PASS している状態。

In Scope

  • evidence_key schema(repository, resource_kind, resource_id, observed_content_sha256, config_sha256)と、同一 phase 内の lookup/reuse ロジックの実装
  • phase transition / 対象への mutation 後 / explicit refresh / freshness-sensitive decision 直前での fresh fetch 強制(snapshot を現在状態として扱わない)
  • Issue 本文変更、コメント追加・編集・削除が、定義された refresh boundary 後に反映されることの保証
  • cached artifact が missing / corrupt / stale / incompatible な場合の通常 read path への fallback(fallback した通常読取自体が失敗した場合は成功扱いにしない)
  • run_refinement_preflight.py の Issue/comment fetch 経路への SHA-bound cache のオプトイン統合
  • phase ごとの fetch_count / emitted_utf8_bytes / snapshot_reuse_count / duplicate_projection_count の記録(観測値のみ)

Out of Scope

  • 汎用 command cache、全 command に対する二度目実行禁止(tests / build / lint / mutable worktree を読む command / transient failure 後の retry / GitHub mutation / review approval / CI・current-head 確認 / artifact regeneration を伴う command / 入力集合を完全に束縛できない command は本 Issue の suppression 対象にしない)
  • cross-session / process restart をまたぐ persistent no-progress ledger(#2077 で closed / not_planned 済みであり本 Issue へ復活させない)
  • compaction を阻止する新規 gate、loop 全体を支配する polling framework、wait-only model turn の上限制御
  • #88 が所有する独立VC verdict・current-head binding・LOOP_STATE.vc_adjudication・review eligibility の再実装
  • #1909 が所有する bounded SubAgent context bundle の再実装、または類似の別 bundle / receipt / ledger 形式の新設
  • #1093 / #1117 が扱う AGENTS/CLAUDE/skills/hooks/rules/scripts の静的テキスト読み込み inventory 自体の変更
  • mutation authority・review approval・CI status の cache 化
  • GitHub state に対する無期限 TTL cache の導入
  • 実際の Claude Code session 全体での token consumption 削減・billing 削減の主張(本 Issue の VC が証明するのは実装経路の動作と出力量のみ)

Acceptance Criteria

  • AC1: run_refinement_preflight.py の Issue/comment fetch 経路が、同一 phase 内で同じ evidence_key を2回参照しても、不要な再取得・全文再展開が発生しない
  • AC2: phase transition、対象への mutation 後、explicit refresh、freshness-sensitive decision 直前では fresh fetch が行われ、旧 snapshot を現在の GitHub state として扱わない
  • AC3: Issue 本文変更、コメント追加・編集・削除が、定義された refresh boundary 後に反映される(stale snapshot を使い続けない)
  • AC4: tests / build / lint / mutable worktree を読む command / 一時的失敗後の retry / 入力を完全に束縛できない command は suppression されない
  • AC5: cached artifact が missing / corrupt / stale / incompatible でも通常の読取経路へ fallback できる。fallback した通常読取自体が失敗した場合はその失敗を成功扱いにしない
  • AC6: cache 有効/無効で独立VC・CI/current-head 確認・mutation 判断が変わらず、重複ケースでは fetch_count または emitted_utf8_bytes の少なくとも一方が実測で減る
  • AC7: report は実際に観測した fetch_count / emitted_utf8_bytes / snapshot_reuse_count / duplicate_projection_count のみを出力し、未観測の token / model-turn 値を生成しない
  • AC8: .claude/skills/issue-refinement-loop/SKILL.md の手順変更後も Step 0f preflight の手順が宣言順に実行され、scripts/agent-ops/** に新設する subagent-lifecycle-script が Step 1 codebase-investigator の SubAgentStart/SubagentStop に対して hook-id-correlated causal evidence を伴って観測されることを、evidence cache 有効時にも維持する

Verification Commands

# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index.py::test_duplicate_read_within_phase_is_cached -q # AC1
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index.py::test_fresh_fetch_on_phase_transition_and_mutation -q # AC2
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index.py::test_body_and_comment_change_invalidates_cache_after_refresh_boundary -q # AC3
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index.py::test_unbounded_or_transient_commands_not_suppressed -q # AC4
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index.py::test_missing_or_corrupt_cache_falls_back_to_normal_read -q # AC5
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index_preflight_integration.py::test_cache_toggle_semantic_equivalence_and_fetch_count_reduction -q # AC6
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_context_budget_report.py::test_report_only_observed_metrics_no_fabricated_tokens -q # AC7
# baseline-expect: fail
$ uv run --locked pytest scripts/agent-ops/tests/test_evidence_index_runtime_smoke.py::test_preflight_and_investigator_smoke_preserves_causal_evidence_and_procedure_order -q # AC8

Allowed Paths

  • docs/dev/agent-skill-boundaries.md
  • .claude/skills/issue-refinement-loop/SKILL.md
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • scripts/agent-ops/evidence_index.py
  • scripts/agent-ops/context_budget_report.py
  • scripts/agent-ops/tests/test_evidence_index.py
  • scripts/agent-ops/tests/test_context_budget_report.py
  • scripts/agent-ops/tests/test_evidence_index_preflight_integration.py
  • scripts/agent-ops/tests/test_evidence_index_runtime_smoke.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • AC8 の動作検証 VC が SKIP(exit 77)を返した場合(実行環境不可のためエスカレーション)
  • fallback 経由でのみ「成功」する場合(FAIL として扱い、実行環境を確認)

Required Skills

worktree-agent-runtime-smoke

Required Design References

  • docs/dev/agent-skill-boundaries.md
  • docs/dev/extension-surface-runtime-policy.yaml

Runtime Verification Applicability

  • decision: immediate
  • reason: 本 Issue の Allowed Paths は .claude/skills/issue-refinement-loop/SKILL.md(skill-invocation-procedure-or-contract-change rule, hard enforcement)と scripts/agent-ops/** 配下の新規ファイル(subagent-lifecycle-start-stop-delegation-fallback rule の selector scripts/agent-ops/** に一致)の双方に該当し、docs/dev/extension-surface-runtime-policy.yaml の resolution.final_decision: most_restrictive により default_decision: immediate が確定する。proven_not_runtime_loaded 等の例外は、本 Issue が実際に issue-refinement-loop の Step 0f 手順・Step 1 codebase-investigator delegation から到達可能な変更を行うため適用しない(human OWNER の direct interactive instruction による確定判断)。
    applicable_acs: [AC8]
    execution_environment: worktree-agent-runtime-smoke structured lane(scripts/agent-ops/run_worktree_agent_runtime_smoke.py --runtime claude --mode structured)
    skip_conditions: Claude Code runtime または worktree-agent-runtime-smoke 実行環境(対象 worktree、claude 実行バイナリ)が利用不可の場合は SKIP(exit 77)を宣言し、Stop Conditions を発火させる
    fallback_policy: marker 文字列の一致のみ、または _*_fallback: true 相当のフォールバック経由でのみ「成功」した場合は FAIL として扱う(PASS への読み替え禁止)。causal_evidence_source が hook_id_correlated であることを必須とする
    artifact_requirements: --output-dir 配下の stream-json / hook payload ログおよび --evidence-json 出力を、PR 本文の ## Runtime Verification Evidence セクションへ redact ルール準拠で inline 引用する
  • 対応 AC / VC / 証跡要件: AC8(<!-- runtime-verification: true -->)が scripts/agent-ops/run_worktree_agent_runtime_smoke.py の structured lane を用いた system test を要求する。SKIP(exit 77)/ fallback FAIL の実装を VC スクリプトに含め、証跡は PR 本文の ## Runtime Verification Evidence セクションへ inline 引用する。

Scope Delta(任意)

N/A

Notes for Reviewer

anchor comment(#2052 (comment) )の OWNER REQUEST_CHANGES を反映し、Outcome を「同一 loop 実行内での snapshot 再利用」に縮小し、汎用 command cache・cross-process no-progress ledger・compaction gate・loop 全体 polling framework を Out of Scope へ明示した。実 consumer は run_refinement_preflight.py の Issue/comment fetch 経路に確定し(impl-review-loop Step 2→Step 4 への接続は、既存 #88 の LOOP_STATE.vc_adjudication binding と重複するため今回は追加しない)、Verification Commands は rg/grep の文字列存在確認から実行可能な pytest(unit + 実 consumer 経由の integration test)へ置き換えた。

## Runtime Verification Applicability: immediate は、前回 refinement iteration の canonical_step2_route: step_5_operator_intervention_required(EXTSURF001: docs/dev/extension-surface-runtime-policy.yaml の skill-invocation-procedure-or-contract-change / subagent-lifecycle-start-stop-delegation-fallback 両 rule 一致)を、human OWNER の direct interactive instruction による明示判断として解消したものである。#1858(byte 計測と実 token 計測の分離)、#1093/#1117(静的テキスト読み込み inventory、別スコープ)は本 Issue のスコープ外として維持する。

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Aug 9, 2026
  2. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    結論

    判定は REQUEST_CHANGES です。目的は有用ですが、現行契約のまま実装すると「重複作業を減らす仕組み」より「必要な再読・再試行まで止める仕組み」になりやすいです。

    推奨するのは、#2052 を閉じることではなく、「同一実行内の証拠参照と出力の重複削減」に絞って、本文を更新することです。汎用コマンドキャッシュ、永続的な再試行台帳、compaction を止めるゲートまでは不要です。

    確認した main は 59d132fb57afd779788f84504156f7e04084f0b4 です。以下は、現行Issue契約と、その実装先・関連実装に対するレビューです。

    先に押さえるべき、関連議論と現在の実装

    現本文だけを読むと、新しく作る必要がないものまで作り直しかねません。

    関連資産・議論 | 確認できたこと | #2052への含意 -- | -- | -- PR #2310 のOWNERコメント | #2052へ impl-review-loop のconsumer接続とreview-cycle metricsを追加する改訂案がある。現本文の接続先は依然としてpreflightのオプトイン利用のみ。 | 関連コメントの提案を検討したうえで、今回の接続先を本文へ確定する必要がある。 #88に対応する現行実装 | adjudicate_vc_result.py とStep 4に、current-head照合、LOOP_STATE.vc_adjudication の保持、同じbindingでの再利用がある。 | 独立VCの再実行抑制やレビュー可否を、別のキャッシュで再実装しない。 #1909 | SubAgent向けbounded context bundleを所有し、既存 planner_input/ARTIFACT の再利用を要求している。 | #2052で別のbundle生成・保存方式を増やさない。 #1093/#1117 | 静的inventoryだけでなく、compact output、artifact参照、context metrics、loop入口への接続も扱っている。 | 「完全に独立」ではない。計測・出力契約の重複は整理する。 #2077 | process restartをまたぐno-progress永続化案は、現在 closed / not_planned。 | この要件を#2052へ暗黙に持ち込んで復活させない。 #1858 | 静的byte比較と、実際のfirst-turn input tokens計測を分けている。 | #2052でも「出力byteが減った」と「実際のtoken消費が減った」を区別する。

    Verification Commandsは、少なくとも予定している2ファイルのテストを実行する形へ変えるべきです。

    uv run --locked pytest \
      scripts/agent-ops/tests/test_evidence_index.py \
      scripts/agent-ops/tests/test_context_budget_report.py \
      -q

    これに、選定したconsumerの統合テストを加えます。時間経過はfake clock、GitHub変化はfixture、取得回数はfake transportで検証すればよく、この段階で毎回live GitHubや大規模なClaude Code benchmarkを要求する必要はありません。

    ただし、fixtureで証明できるのは実装した経路の動作と出力量です。実際の開発セッション全体でtoken消費が減ったという主張は、実行ログを観測してからにしてください。

    最終判断

    #2052で実装する価値が高いのは、証拠の参照整理、不要な全文再展開の削減、実際のconsumerでの効果計測です。

    一方、現契約のまま「汎用的な再実行禁止」「自動compaction前の保存保証」「loop全体の待機制御」まで一緒に実装するのは勧めません。必要な再読・再試行を通したまま、同じ大きな情報を何度もmainへ運ばない設計へ更新するのが、最も費用対効果が高いと判断します。

    なお、今回は実リポジトリのpytestやClaude Code実行は行っていません。実行したのは、上記の「現Verification Commandsが機能未実装でも通る」ことを示す独立した反例テストです。GitHub上のIssue・PRは変更していません。

    ## 結論

    判定は REQUEST_CHANGES です。目的は有用ですが、現行契約のまま実装すると「重複作業を減らす仕組み」より「必要な再読・再試行まで止める仕組み」になりやすいです。

    推奨するのは、#2052 を閉じることではなく、「同一実行内の証拠参照と出力の重複削減」に絞って、本文を更新することです。汎用コマンドキャッシュ、永続的な再試行台帳、compaction を止めるゲートまでは不要です。

    確認した main は 59d132fb57afd779788f84504156f7e04084f0b4 です。以下は、現行Issue契約と、その実装先・関連実装に対するレビューです。

    先に押さえるべき、関連議論と現在の実装

    現本文だけを読むと、新しく作る必要がないものまで作り直しかねません。

    関連資産・議論 確認できたこと #2052への含意
    PR #2310 のOWNERコメント #2052へ impl-review-loop のconsumer接続とreview-cycle metricsを追加する改訂案がある。現本文の接続先は依然としてpreflightのオプトイン利用のみ。 関連コメントの提案を検討したうえで、今回の接続先を本文へ確定する必要がある。
    #88に対応する現行実装 adjudicate_vc_result.py とStep 4に、current-head照合、LOOP_STATE.vc_adjudication の保持、同じbindingでの再利用がある。 独立VCの再実行抑制やレビュー可否を、別のキャッシュで再実装しない。
    #1909 SubAgent向けbounded context bundleを所有し、既存 planner_input/ARTIFACT の再利用を要求している。 #2052で別のbundle生成・保存方式を増やさない。
    #1093/#1117 静的inventoryだけでなく、compact output、artifact参照、context metrics、loop入口への接続も扱っている。 「完全に独立」ではない。計測・出力契約の重複は整理する。
    #2077 process restartをまたぐno-progress永続化案は、現在 closed / not_planned。 この要件を#2052へ暗黙に持ち込んで復活させない。
    #1858 静的byte比較と、実際のfirst-turn input tokens計測を分けている。 #2052でも「出力byteが減った」と「実際のtoken消費が減った」を区別する。

    重大な指摘

    1. P1:Verification Commandsが、機能未実装でも全件成功する

    対象:Verification Commands全体、AC1〜AC10。

    現行の10コマンドは、すべて rg または grep による文字列の存在確認です。テスト関数名、fresh_required、artifact_ref、ttl などが書かれていれば通り、実際のキャッシュ・失効・再実行抑制は検証しません。

    これは反例を実行して確認しました。実リポジトリとは別の一時ディレクトリに、機能を持たない次のようなスタブを作成しました。

    # evidence_index.py
    # fresh_required artifact_ref mutation_authority ttl
    def test_duplicate_read_within_phase_is_cached():
        raise NotImplementedError("intentional counterexample")

    他の要求文字列・テスト関数名も同様に配置した結果は次のとおりです。

    実行内容 結果
    Issue記載の検証コマンド10本 10本すべて exit 0
    同じスタブに対するpytest 4件失敗、exit 1

    つまり、現VCは「要求された機能が存在しない実装」を合格にできます。

    修正案: 文字列検索を補助確認へ下げ、合否は実際のpytestへ移してください。特に、helperだけでなく、実際のconsumer経由で「取得回数」「返却byte数」「失効後の再取得」を観測するテストが必要です。

    ここはセキュリティ強化ではなく、このIssueの成果が本当に動くかどうかの最低限の検証です。

    2. P1:「SHAで束縛する」と「最新状態を確認する」が混同されている

    対象:evidence key、AC1・AC3・AC10。

    本文は、同じkeyならphase内で再取得しない一方、Issue本文・コメント本文などの変更で失効することを要求しています。しかし、いつ新しい本文やコメント集合を観測し、変更を知るのかが未定義です。

    ハッシュで分かるのは、観測済みの内容が同じかどうかです。手元の旧ハッシュだけでは、GitHub側でその後に変更されたかは分かりません。

    例えば、次のケースを現契約では区別できません。

    ケース 不足している契約
    同じphase中にOWNERがIssue本文を修正する phase内では旧snapshotを使うのか、途中で再検証するのか
    新しいコメントが追加される 既存コメントのbody hashでは、新しいコメントの存在を検知できない
    コメントが削除される 既存キャッシュだけでは、現在も存在するか判断できない
    PRのbaseが変更される head SHAだけを使ったdiffの再利用では足りない場合がある
    同じ内容の別Issue・別コメントを読む contentの重複排除と、出典・対象リソースの同一性を分ける必要がある

    また、明示されているkey項目には、repository・Issue番号・comment ID・取得対象のqueryといったリソースを特定する情報がありません。bytesの共有自体は問題ありませんが、出典や鮮度の記録まで同一視してはいけません。

    修正案:最初は「phase snapshot」として定義するのが簡単です。

    phase入口で取得したsnapshotは、同じphase内の分析用途に再利用できる。
    phaseの切替、対象へのmutation後、明示的refresh、判断直前のfresh readでは再取得する。
    snapshotは取得時点の観測結果であり、現在のGitHub状態を保証しない。

    必要になれば、GitHubが提供するETag/Last-Modifiedによる条件付きGETも利用できます。ただし、これは再検証リクエストを送り、変更がなければ304を受け取る方式であり、「一切アクセスせずに変更を検知する方式」ではありません。([GitHub ドキュメント]1)

    AC1は「再取得を絶対にしない」ではなく、**「同一snapshotの不要な再取得をしない。鮮度確認は例外として明示する」**に変えるべきです。

    3. P1:汎用的な「同じコマンドを2回実行しない」は、実装ループを壊す

    対象:AC2・AC4、command_fingerprint、fresh_required。

    現行の「identical no-progress commandを2回目に実行しない」には、no-progressの判定条件、対象コマンド、失敗の種類、成果物の扱いがありません。fresh_required だけをbypass可能とする契約も、何を通常実行として残すかが曖昧です。

    このままargvやHEAD中心で実装すると、次のような正常作業を誤って抑制できます。

    未コミットの修正後の再テスト。 同じHEADで同じpytestコマンドでも、作業ツリーのソースは変わっています。単一の file_blob_sha を持つだけでは、コマンドが参照する入力全体を束縛できるとは限りません。

    一時的な失敗からの再試行。 timeoutや一時的な通信障害の後、同じコマンドを再実行することには意味があります。「前回進まなかった」ことは、「次も実行不要」の証拠ではありません。

    成果物を再生成する処理。 入力が同じでも、出力ファイルが消えているならbuild等の再実行が必要です。以前のstdoutや終了コードを返すだけでは成果物は復元されません。

    比較対象として、Bazelのキャッシュはactionの入力、出力名、コマンド、環境変数を扱い、結果metadataとは別に出力ファイルも保持します。汎用コマンドの正しいキャッシュは、argvをハッシュするだけの小さな機能ではありません。([Bazel Documentation]2)

    修正案:このIssueでは、汎用コマンドキャッシュを外してください。

    再利用するのは、入力が明確な「snapshotのparse結果」「同じblobからの抜粋」「同じ入力に対する純粋な整形処理」程度で十分です。未知のコマンド、テスト、build、可変状態の観測は通常実行を既定にします。

    fresh_required は実行許可を得るための特別扱いではなく、キャッシュを使ってはいけない用途の明示に限定するのが適切です。明示的な再読・再試行を、追加の人間承認に結び付ける必要はありません。

    4. P1:実際に重複しているconsumerへ接続する契約が足りない

    対象:Current Validated Scope、Allowed Paths、Outcome。

    現本文にある具体的な接続は、run_refinement_preflight.py からのオプトイン利用だけです。一方、Outcomeにはcommandの再実行、main contextへの展開、wait-only model turn、compactionまで含まれます。preflightのhelperだけでは、それらの発生源を観測・制御できません。

    さらに、既存preflightはすでに、raw Issue/commentsをstdoutへ出さず、raw_issue_snapshot.json、planner_input.json、結果artifactとcompact stdoutを分離しています。単に新しい artifact_ref を導入するだけでは、既存機能の重複になる可能性があります。

    impl-review-loop 側にも、すでにcurrent-headの独立VCを保持・再利用する経路があります。旧in-process cacheがCLI再起動で失われる問題に対し、LOOP_STATE ベースへ置き換えた経緯までStep 4に明記されています。新しいモジュール内のdictだけでは、複数CLI呼び出しをまたぐ同一loop内の再利用にはなりません。

    修正案:接続する一往復を先に確定してください。

    第一候補は、PR #2310のコメントが提案している方向を絞り、Step 2からStep 4へ渡る証拠参照の重複展開とmetricsを対象にすることです。独立VCの合否・再利用判定は既存実装へ残し、#2052は参照と計測だけを担当します。

    その場合は、実際に変更するStep手順・consumer・統合テストをAllowed Pathsへ追加します。逆にpreflightだけに限定するなら、Outcomeもその範囲へ縮め、loop全体のwaitやcompaction改善まで達成したことにしないでください。

    5. P2:APIキャッシュが当たっても、contextが減るとは限らない

    対象:AC5・AC6、context budget report。

    「再取得しない」と「main contextへ再展開しない」は別です。キャッシュした全文を毎回返せば、APIアクセスは減っても、main contextへ追加する文章量は減りません。

    反対に、artifact_ref しか返さず、必要なエラーやdiffの抜粋まで見せなくすると、レビューの質が下がったり、参照先の再探索が増えたりします。現AC5は全文のartifact退避を要求していますが、必要な内容へどう到達するかまでは定義していません。

    Claude Code公式も、大量の処理をSubAgentへ分離し、mainには要約を返す方法を説明しています。また、prompt cachingは反復内容のコスト最適化であり、履歴を小さくする取り組みとは分けて扱っています。(Claude)

    修正案:返却契約を「短い判断材料+参照先」にしてください。

    返すものは、対象・観測時点・重要な結果・必要な抜粋・全文artifact参照です。すでに返した内容の自動的な全文再展開は抑えてよいですが、人間やreviewerが根拠を求めた再読、compaction後に必要になった再読は許可します。「一度返したから二度と見せない」は避けるべきです。

    計測も、初期版では次のように、実際に観測できる値に限定するのがよいです。

    指標 意味
    emitted_utf8_bytes この経路からmainへ返した出力のbyte数
    fetch_count 実際の取得回数
    snapshot_reuse_count 同じsnapshotを再利用した回数
    duplicate_projection_count 同じ内容を再展開しようとした回数

    これを「モデルの現在のcontext全体」「実際の入力token」「課金削減額」と呼ばないことが重要です。未観測のmodel turn数も、便宜的にゼロと記録せず、未取得と区別してください。

    6. P2:wait上限とcompaction保存が、余計な停止条件になる余地がある

    対象:AC7・AC8。

    同じCI statusが何度か続くのは、単に処理中である可能性があります。「同じstatusのpolling上限」だけを契約化すると、正常な待機をno-progress failureと誤認する実装が入り得ます。現本文には、上限到達後の扱いがありません。

    GitHub CLIには gh pr checks --watch --interval があり、待機をCLI側へ寄せる選択肢があります。毎回モデルへ同じpending結果を返すより、待機中の出力をartifactへ逃がし、完了・状態変化・期限到達時だけ要約を返す方が、このIssueの目的に合います。(GitHub CLI)

    上限到達は「未完了の待機を終了した」であり、CIのFAILでもPASSでもないと明記してください。最終的なレビュー判断には、既存のcurrent-head確認を使います。

    compactionについても、公式にはmanual/autoの PreCompact lifecycleがありますが、今回確認したproject settingsにはその登録がなく、Allowed Pathsにも設定・hook追加はありません。helperの保存関数だけで「自動compaction前に必ず保存する」は証明できません。([Claude]5)

    初期版ではAC8を、既存のStep完了時の状態記録へmission/pending checks等を含める程度に縮めることを推奨します。現行loopにもStep完了時の LOOP_STATE 更新があります。自動compaction直前の厳密な保存保証は、今回の成立条件から外してよいです。


    推奨する再設計

    Outcomeは、次の程度まで絞る

    同一loop実行内で、取得済みsnapshotおよびその解析結果を既存artifact参照として再利用し、同じ証拠の不要な全文再展開を減らす。
    対象consumer経由の取得回数と返却byte数を計測する。
    鮮度が必要な読取、明示的refresh、テスト・build・mutation・review判断は抑制しない。
    キャッシュまたはartifact参照が利用できない場合は通常経路へ戻り、最適化機構の不調を理由に作業を止めない。

    実装の責務は、次のように分けるのがよいです。

    既存のGitHub/repo読取経路
        ↓
    取得時点が明確なsnapshot
        ↓
    同じsnapshotのparse・抜粋結果を再利用
        ↓
    既存のcompact出力+artifact参照
        ↓
    既存loop consumer
    
    判断直前のfresh read/VC判定/CI確認
        └─ 既存経路を維持し、キャッシュで代替しない
    

    特に、キャッシュの破損・失効・参照先消失では、キャッシュを捨てて通常読取へ戻すべきです。ただし、通常読取そのものが失敗した場合まで成功扱いにしてはいけません。

    gh api --cache <duration> は既存の選択肢ですが、duration指定のresponse cacheであり、これを追加するだけでSHA-bound evidence管理やcontext削減が完成するわけではありません。既存transportを増やして置き換えるより、取得済みsnapshotの再利用と出力整形を先に改善する方を推奨します。([GitHub CLI]6)

    今回は持ち込まないもの

    新規DB、cross-sessionの汎用台帳、全コマンドへの実行ゲート、全ツールを監視する高頻度hook、cache missによる人間承認、予算超過による一律停止は不要です。

    また、古い関連IssueにあるCodex CLI向け資産・live smoke要求をそのままコピーしないでください。現在の責務境界では、.claude/agents/*.md を claude-native/claude-gpt 共通の実行宣言とし、native Codex CLIの旧projectionは撤去したとされています。今回の配布範囲も、まずrepo-localの補助スクリプトで十分です。

    置き換えるべきAcceptance Criteria

    初期版としては、次の8項目で、効果と非回帰をかなり明確にできます。

    AC案 実際に検証すること
    AC1 対象consumerから同じsnapshotを2回参照しても、不要な再取得・全文再展開が発生しない
    AC2 phase切替・mutation後・明示的refreshでは再取得し、旧snapshotを最新扱いしない
    AC3 Issue本文変更、コメント追加・編集・削除を、定義した再取得境界で反映する
    AC4 入力を完全に束縛できないコマンド、テスト、build、一時的失敗後の再試行を抑制しない
    AC5 artifactが欠落・破損・失効しても、通常の読取経路へ戻れる。必要な根拠の再読も可能
    AC6 cache有効/無効で判断結果と必要な証拠が変わらず、重複ケースでは取得回数または返却byte数が減る
    AC7 cacheの有無で、既存の独立VC gate・CI確認・mutation判断が変わらない
    AC8 reportは観測できた範囲と指標を明示し、未観測のtoken数・model turn数を捏造しない

    Verification Commandsは、少なくとも予定している2ファイルのテストを実行する形へ変えるべきです。

    uv run --locked pytest \
      scripts/agent-ops/tests/test_evidence_index.py \
      scripts/agent-ops/tests/test_context_budget_report.py \
      -q

    これに、選定したconsumerの統合テストを加えます。時間経過はfake clock、GitHub変化はfixture、取得回数はfake transportで検証すればよく、この段階で毎回live GitHubや大規模なClaude Code benchmarkを要求する必要はありません。

    ただし、fixtureで証明できるのは実装した経路の動作と出力量です。実際の開発セッション全体でtoken消費が減ったという主張は、実行ログを観測してからにしてください。

    最終判断

    #2052で実装する価値が高いのは、証拠の参照整理、不要な全文再展開の削減、実際のconsumerでの効果計測です。

    一方、現契約のまま「汎用的な再実行禁止」「自動compaction前の保存保証」「loop全体の待機制御」まで一緒に実装するのは勧めません。必要な再読・再試行を通したまま、同じ大きな情報を何度もmainへ運ばない設計へ更新するのが、最も費用対効果が高いと判断します。

    なお、今回は実リポジトリのpytestやClaude Code実行は行っていません。実行したのは、上記の「現Verification Commandsが機能未実装でも通る」ことを示す独立した反例テストです。GitHub上のIssue・PRは変更していません。

  3. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    指定コメントを anchor にするのが適切です。現時点の Issue #2052 本文は、レビュー前の「汎用 command fingerprint」「wait polling 上限」「compaction 前保存」「rg/grep 中心の VC」をまだ保持しています。 一方、OWNER の指定コメントは、それらを削って 同一 loop 内の snapshot / evidence projection 再利用と重複出力削減に絞ること、実 consumer の統合テストへ移すことを明示しています。

    また現行 issue-refinement-loop 自体が loop_iteration_approval_gate.default_required: false で、needs-fix は iteration 上限までは自動継続する設計です。anchor が direct human context の場合には preflight.run.with_human_context → contract_update.run.with_human_context という canonical mutation lane も既にあります。 したがって、新しい「no approval」機構を作るのではなく、既存 loop を正しく駆動するのが推奨です。

    サブエージェントについては、Step 1 の codebase-investigator を必ず使わせる一方、canonical Step 2 では現在 issue-reviewer SubAgent を直接起動せず root-owned review pipeline を使う契約なので、そこを無理に変えない構成にしています。 codebase-investigator は mutation 不可の SubAgent として定義されています。 Claude の現行公式ガイダンスとも、複雑な agentic task では指示を明示しつつ、独立した調査を subagent に委譲する方針が整合します。([Claude Platform Docs]1)

    以下をそのまま Auto mode の対話的 Claude Code に渡すのを推奨します。

    Issue #2052 を、現在の repository に定義されている canonical issue-refinement-loop で refinement してください。

    Target:

    • repository: squne121/loop-protocol
    • issue: #2052
    • anchor comment:
      https://github.com/squne121/loop-protocol/issues/2052#issuecomment-5549144071
    • max_iterations: 3

    目的は、指定 OWNER comment の REQUEST_CHANGES を Issue 本文へ反映し、Issue #2052 を implementation-ready な live contract にすることです。

    これは Issue refinement のみです。
    実装、実装用 worktree 作成、PR 作成、impl-review-loop 開始までは行わないでください。

    Autonomous execution policy

    この refinement loop の iteration 間で人間承認を要求しないでください。

    repository の issue-refinement-loop が定義する
    loop_iteration_approval_gate.default_required: false
    をそのまま適用し、needs-fix の場合は max_iterations の範囲内で自動的に次 iteration へ進んでください。

    「次へ進めてよいですか」「Issue を更新してよいですか」「レビューを続けますか」等の任意の確認は行わず、自律的に進めてください。

    ただし、canonical planner / reviewer / scope authority が exact に以下を要求した場合は、その repository contract を無視しないでください。

    • human_judgment_required
    • max_iterations 到達時点で unresolved blocker が残る
    • canonical hard-stop / fail-closed condition
    • OWNER の明示的な停止指示

    これら以外を新しい human approval gate として追加しないでください。

    Claude Code の permission mode 自体を変更する必要はありません。
    現在の interactive Auto mode の範囲で作業してください。

    Step 0 — fresh state と canonical entrypoint

    最初に canonical main root / default branch の fresh state を確認してください。

    そのうえで、現在の

    を必要な範囲だけ取得してください。

    過去の記憶やこの prompt の記述より、current repository contract を優先してください。

    anchor comment は OWNER による direct human context として扱ってください。

    production の canonical entrypoint を迂回して
    run_refinement_preflight.py を直接実行しないでください。

    必要なら canonical executor の human-context profile:

    uv run --locked python3 scripts/agent-guards/skill_runtime_exec.py \
      --command-id preflight.run.with_human_context \
      --issue-number 2052 \
      --repo squne121/loop-protocol \
      --anchor-comment-url https://github.com/squne121/loop-protocol/issues/2052#issuecomment-5549144071

    を repository contract に従って使用してください。

    planner が trusted contract patch plan を生成し canonical contract update が許可された場合だけ、main control-plane から:

    uv run --locked python3 scripts/agent-guards/skill_runtime_exec.py \
      --command-id contract_update.run.with_human_context \
      --issue-number 2052 \
      --repo squne121/loop-protocol \
      --anchor-comment-url https://github.com/squne121/loop-protocol/issues/2052#issuecomment-5549144071

    の canonical lane を使用してください。

    手動 GitHub edit で canonical contract-update transaction を迂回しないでください。

    Step 1 — codebase-investigator SubAgent

    codebase-investigator SubAgent を必ず起動してください。

    Issue #2052 の refinement に必要な repository evidence を調査させてください。

    最低限、以下を調べさせます。

    agent/issue-refinement-loop 用の canonical local-advisory route が現在存在するなら、それを使用してください。

    調査は advisory / read-only とし、調査 SubAgent 自身には Issue mutation をさせないでください。

    重要

    codebase-investigator の作業完了を必ず待ってください。

    SubAgent を起動しただけで Step 2 や Issue rewrite に進んではいけません。

    完了結果を main control-plane が受け取り、evidence として取り込んでから次へ進んでください。

    SubAgent がまだ running / pending の間は、その結果を推測して先へ進まないでください。

    nested SubAgent delegation を repository contract が禁止している経路では追加しないでください。

    Step 1b — web-researcher

    planner が critical_external_claims または equivalent な external evidence requirement を返した場合だけ、web-researcher SubAgent を起動してください。

    特に必要なら以下の仕様を current official sources で確認してください。

    • GitHub REST conditional request / ETag semantics
    • GitHub CLI gh api --cache
    • GitHub CLI checks watching / polling behavior
    • Claude Code artifact/context/subagent/compaction lifecycle
    • generic build/test command caching と単純 command fingerprint の違い

    ただし外部技術の一般論を Issue の scope 拡大理由にしないでください。

    web-researcher を起動した場合も、その作業完了を必ず待ってください。

    完了前に review / rewrite へ進まず、結果を planner/reviewer input に join してから続行してください。

    Step 2 — canonical review

    current issue-refinement-loop の canonical review pipeline を使用してください。

    現在の repository contract が Step 2 で root-owned run_root_review_pipeline.py を要求している場合、issue-reviewer SubAgent を独自に追加起動しないでください。

    古い issue-refinement-loop の手順を復活させないでください。

    review result の

    • status
    • verdict
    • next_action

    を canonical routing contract のまま consume してください。

    prose で独自に verdict を上書きしないでください。

    Refinement direction for #2052

    anchor comment を主要な change request として扱ってください。

    現在の Issue #2052 の広すぎる契約を、そのまま実装可能扱いしないでください。

    特に次の方向へ更新してください。

    1. Outcome を狭める

    中心目的を:

    「同一 loop 実行内で、取得済み snapshot とその解析・projection 結果を既存 artifact reference として再利用し、同じ大きな evidence の不要な再取得・全文再展開を減らす」

    へ絞ってください。

    以下を initial implementation の必須成果にしないでください。

    • generic command cache
    • 全コマンドに対する二度目実行禁止
    • cross-session / process-restart 永続 no-progress ledger
    • generic retry suppression
    • compaction を阻止する新規 gate
    • loop 全体を支配する polling framework
    • 新規 DB
    • 新規 persistent state store
    • 新しい bounded-context bundle format

    2. freshness と snapshot reuse を分離する

    「SHA-bound だから GitHub の現在状態が分かる」という契約にしないでください。

    phase snapshot として明示してください。

    同一 phase の analysis では既取得 snapshot を再利用可能。

    以下では fresh read / refresh が必要です。

    • phase transition
    • 対象への mutation 後
    • explicit refresh
    • freshness-sensitive decision の直前
    • repository の既存 contract が current-head/current-state read を要求する箇所

    snapshot は「取得時点の観測」であり、現在の remote state の保証ではないことを明記してください。

    resource provenance と content identity を混同しないよう、

    • repository
    • resource kind
    • issue number
    • comment ID / query identity 等
    • observed content hash / blob SHA
    • observation boundary

    を必要な範囲で区別してください。

    新しい schema を作る必要があるかは、既存 schema / artifact contract を調査してから判断してください。
    不要なら作らないでください。

    3. generic command suppression を外す

    以下は cache / duplicate suppression の対象にしないでください。

    • tests
    • build
    • lint
    • mutable worktree を読む command
    • transient failure 後の retry
    • external mutable state の observation
    • GitHub mutation
    • review approval
    • CI/current-head verification
    • artifact regeneration を伴う command
    • 入力集合を完全に束縛できない command

    fresh_required を「実行するために特別な権限が必要」という意味にしないでください。

    必要な再読・再試行は人間承認なしで通常実行可能なままにしてください。

    4. 実 consumer を確定する

    preflight helper を追加するだけで loop 全体の context churn を改善したことにしないでください。

    PR #2310 の OWNER comment と current repository implementation を調査し、

    第一候補として
    impl-review-loop の Step 2 → Step 4 に渡る evidence reference / duplicate projection / review-cycle metrics
    が #2052 の最小で有効な consumer か検証してください。

    適切なら:

    • concrete consumer
    • exact integration point
    • required Allowed Paths
    • integration test

    を Issue contract に追加してください。

    ただし既存の

    • independent VC verdict
    • current-head binding
    • LOOP_STATE.vc_adjudication
    • review eligibility

    自体は #2052 で再実装しないでください。

    調査結果として preflight だけに限定する方が妥当なら、consumer を無理に増やすのではなく Outcome / AC を preflight の実効果範囲まで縮小してください。

    5. existing artifact / bundle を再利用する

    既存の

    を優先してください。

    同じ責務を持つ別 bundle / receipt / ledger / persistent cache hierarchy を増やさないでください。

    6. optimization failure は workflow blocker にしない

    cache / snapshot reuse / artifact projection は optimization です。

    artifact が:

    • missing
    • corrupt
    • stale
    • incompatible

    なら、通常の read / computation path へ戻れる契約にしてください。

    optimization mechanism の失敗だけを理由に refinement / implementation workflow を止めないでください。

    ただし fallback した通常 read 自体が失敗した場合は、その失敗を成功扱いしないでください。

    7. context output contract

    「全文を一度返したら二度と読めない」という設計にしないでください。

    main context へ返すものは原則として:

    • evidence の対象
    • observation point / binding
    • decision に必要な短い summary
    • 必要最小限の excerpt
    • full artifact reference

    としてください。

    明示的な再読、reviewer が根拠を必要とした再読、compaction 後に必要になった再読は許可してください。

    8. metrics は観測値だけにする

    initial metrics は、実際に consumer で観測できるものへ限定してください。

    候補:

    • emitted_utf8_bytes
    • fetch_count
    • snapshot_reuse_count
    • duplicate_projection_count

    これらを、

    • model total context size
    • actual input tokens
    • billing reduction
    • wait-only model turns

    と同一視しないでください。

    actual token reduction を主張する場合は、別途 actual session evidence が取得された場合だけにしてください。

    未観測値を 0 と捏造せず、unknown / not_observed と区別してください。

    9. wait / compaction scope

    normal CI pending を no-progress failure と誤認する単純 polling limit は initial scope から外すことを優先してください。

    もし wait の出力削減を残すなら、
    「pending の反復全文を main へ何度も展開しない」
    という projection optimization として定義し、

    timeout / observation window 到達を
    PASS または FAIL に変換しないでください。

    compaction 直前を必ず捕捉する保証も、実際の hook wiring が scope に入っていない限り AC にしないでください。

    必要なら既存 Step completion state に mission / pending checks を保持する程度まで縮めてください。

    Acceptance Criteria

    anchor comment の提案を baseline とし、少なくとも次の意味を coverage してください。

    1. 対象 consumer が同じ snapshot を2回参照した場合、不要な再取得または全文再展開が抑制される。
    2. phase transition、mutation 後、explicit refresh 等の defined freshness boundary では fresh read が行われ、旧 snapshot を現在状態として扱わない。
    3. Issue body change、comment add/edit/delete 等が、定義された refresh boundary 後に反映される。
    4. tests/build/transient retry/入力を完全束縛できない command は suppression されない。
    5. cached artifact が missing/corrupt/stale でも normal read path へ fallback でき、必要な evidence の再読も可能。
    6. optimization enabled / disabled で decision semantics と必要な evidence が変わらず、duplicate case では fetch count または emitted bytes が実測で減る。
    7. independent VC、CI/current-head confirmation、mutation/review decision は optimization の有無で変わらない。
    8. report は観測した metric だけを報告し、未観測 token/model-turn 値を生成しない。

    必要なら current implementation に合わせて wording を調整して構いませんが、この意味を弱めないでください。

    Verification Commands

    現在 Issue にある rg / grep の文字列存在確認だけを acceptance の合否判定にしないでください。

    最低限、実際の pytest を literal Verification Commands にしてください。

    候補:

    uv run --locked pytest \
      scripts/agent-ops/tests/test_evidence_index.py \
      scripts/agent-ops/tests/test_context_budget_report.py \
      -q

    加えて、選択した actual consumer を通る integration test を Verification Commands に含めてください。

    integration test では可能なら:

    • fake transport で fetch count
    • fixture で Issue/comment state transition
    • fake clock で時間境界
    • emitted bytes
    • cache corruption/missing fallback
    • fresh-read boundary
    • optimization enabled/disabled の semantic equivalence

    を deterministic に検証してください。

    この refinement phase では、毎回 live GitHub benchmark や大規模 Claude Code token benchmark を必須化しないでください。

    ただし「実際の Claude Code session 全体で token consumption が減った」と Issue に書く場合は、fixture test ではなく actual runtime observation が必要です。

    Rewrite / review loop

    review が needs-fix / request_changes を返した場合:

    1. blocker を exact に取り込む
    2. Issue contract を canonical mutation path で修正
    3. fresh Issue body を再取得
    4. 必要な codebase evidence が stale なら再調査
    5. canonical review を再実行
    6. review の完了を待つ
    7. max_iterations 未満なら人間承認なしで次 iteration へ進む

    という順序を守ってください。

    必要な SubAgent を起動した場合は、各 SubAgent の完了を必ず待ってから次の phase に進んでください。

    「SubAgent を dispatch 済み」で完了扱いにしないでください。

    Completion condition

    以下を満たしたところで refinement loop を終了してください。

    • current live Issue body が anchor comment の blocker を実質的に解消している
    • scope / Outcome / AC / Allowed Paths / Verification Commands が互いに整合している
    • 実 consumer または明示的に縮小された consumer scope が特定されている
    • generic command suppression 等の過剰 scope が除かれている
    • canonical review が implementation-ready / proceed 相当
    • fresh read した Issue body が review された contract と一致する
    • unresolved blocker がない

    完了後は implementation を開始せず、そこで停止してください。

    最後に簡潔に以下だけ報告してください。

    途中経過の任意承認は求めず、この completion condition または canonical hard-stop まで自律的に進めてください。

    この形なら、指定コメントの重要な修正をほぼ literal contract として与えつつ、repository 側の planner/reviewer を SSOT のまま維持できます。また「サブエージェントを使え」を理由に旧 issue-reviewer 経路まで復活させず、必要な codebase-investigator の完了待ちだけを強く固定しています。

  4. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: human_escalation

    Blockers(今回 review が返した内容、Issue 本文の書き換えでは解消しない可能性がある readiness 分類)

    • 必須セクション '## Runtime Verification Applicability' が存在しない
    • extension-surface risk-trigger policy との不整合: 宣言された Allowed Paths が skill-invocation-procedure-or-contract-change / subagent-lifecycle-start-stop-delegation-fallback ルールに抵触し、most-restrictive default_decision が immediate であるにもかかわらず Issue は decision: 'None' としている
    • VC が新規 Allowed Path(scripts/agent-ops/evidence_index.py, scripts/agent-ops/context_budget_report.py, および対応する test ファイル)を対象としているが、baseline に存在しないため # baseline-expect: fail マーカーが必要
    • checker が一部 VC コマンドの exit code を自動分類できない(Unable to automatically classify exit code)

    Note

    構造化差分修復(structural repair, disposition: auto_apply_safe)を試行したが、
    candidate readiness check が EXTSURF001(extension-surface risk-trigger policy 不整合)で
    needs_fix を返したため mutation は適用されなかった(mutation_outcome: not_attempted)。

    その後 canonical Step 2 review(run_root_review_pipeline.py produce)を実行した結果、
    canonical_step2_route: step_5_operator_intervention_required
    (status: ok + verdict: needs-fix + next_action: request_changes +
    failure_class: contract_readiness_human_judgment)が確定した。

    このルーティングは repository canonical contract 上、Issue 本文の Step 4 rewrite では
    解消できない operator/runtime 起因の readiness 状態として Step 5 で停止することを
    要求しており、autonomous refinement loop はこの hard-stop を上書きしない。

    推奨される次のアクション(human judgment)

    • Runtime Verification Applicability decision(immediate / deferred / not_applicable)を、
      extension-surface risk-trigger policy(docs/dev/extension-surface-runtime-policy.yaml)の
      skill-invocation-procedure-or-contract-change / subagent-lifecycle-start-stop-delegation-fallback
      ルールとの整合を含めて明示的に決定する
    • VC の baseline-expect: fail マーカー付与は次 iteration の Step 4 rewrite で機械的に解消可能
      だが、上記 decision が未確定のままでは canonical routing が Step 4 へ進めない

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
    schema_version: 1
    materialized_by: issue-refinement-loop
    follow_up_issues: []
    note_only_observations: []

  5. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: approved

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: null
        generated_at: "2026-09-05T04:26:40Z"
        body_sha256: "sha256:4e425430eb7247a5016dbaa4b92f5504c34022f4c7f9a1658748440f439bbfec"
      metadata:
        title_prefix_ready: true
      label_sync_observation:
        kind: presentation_sync
        result: noop
        detail: "本 refinement loop では label 変更を行っていない"
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: "2026-09-05T04:26:40Z"
      checked_body_sha256: "sha256:4e425430eb7247a5016dbaa4b92f5504c34022f4c7f9a1658748440f439bbfec"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []

    Note: routing_action: run_impl_review_loop は canonical contract 上のルーティング先を示す telemetry であり、本 comment 自体は impl-review-loop の起動 authority ではない。今回は human OWNER の明示指示(「実装、実装用 worktree でのコード変更、PR 作成、impl-review-loop の実行開始は行わないでください」)により、run_root_transition()(Root-Owned Synchronous Entry Transition)は本 turn で実行していない。impl-review-loop の開始は別途 OWNER の明示指示を要する。

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
    schema_version: 1
    materialized_by: issue-refinement-loop
    follow_up_issues: []
    note_only_observations: []

  6. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    現状では、#2052 は refinement 後の実装契約としてかなり具体化されています。特に AC8 は runtime smoke を必須とし、SKIP(exit 77) や fallback-only success を Stop Condition にしています。

    また current impl-review-loop は implementation-worker → test-runner → pr-reviewer を SubAgent として使い、REQUEST_CHANGES なら自動反復し、最終的に draft_pr_ready で「人間がマージ判断」に止まる設計です。 2026-09-05 13:38 JST 時点の main は 95db5e3ec98e0f0b1120687aa00db86179b378e9 ですが、Claude Code 側では必ず fresh state を取り直させるべきです。

    推奨は、「任意承認は全面禁止」「canonical hard-stop は維持」「merge/auto-merge のみ禁止」です。以下を Auto mode の対話的 Claude Code にそのまま渡せます。

    Issue #2052 を、現在の repository に定義されている canonical impl-review-loop で実装・検証・レビューしてください。

    Target:

    • repository: squne121/loop-protocol
    • issue: #2052
    • issue URL: https://github.com/squne121/loop-protocol/issues/2052
    • max_iterations: 3
    • target completion: IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready

    目的は、Issue #2052 の 現在の live contract を実装し、独立検証と PR review の反復を完了して、人間が Merge ボタンを押す直前の状態まで自律的に進めることです。

    このセッションは Claude Code の Auto mode で実行されています。

    Autonomous execution policy

    通常の実装ループ中に人間承認を要求しないでください。

    以下について、個別に

    • 「進めてよいですか」
    • 「ファイルを変更してよいですか」
    • 「commit / push してよいですか」
    • 「PR を作ってよいですか」
    • 「テストを再実行してよいですか」
    • 「REQUEST_CHANGES を修正してよいですか」
    • 「次の iteration に進んでよいですか」
    • 「review を再実行してよいですか」

    などの確認を行わないでください。

    Issue の live contract と repository の canonical workflow の範囲内にある、通常の

    • worktree / branch 作成
    • Allowed Paths 内の編集
    • test / lint / build / Verification Commands 実行
    • commit
    • push
    • PR 作成・更新
    • reviewer feedback の反映
    • current-head 再検証
    • required CI の確認
    • canonical bounded retry
    • BEHIND に対する canonical update-branch
    • REQUEST_CHANGES 後の次 iteration

    は、この指示によって承認済みとして扱い、自律的に進めてください。

    ただし、Issue #2052 自身の Stop Conditions と current repository contract が定義する genuine hard-stop は上書きしないでください。

    任意の safety / governance / harness approval gate を新しく追加しないでください。
    advisory artifact、telemetry、任意 receipt の欠落だけを理由に停止しないでください。

    Absolute merge boundary

    以下は実行しないでください。

    IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready に到達したところで停止してください。

    つまり、

    implementation → verification → PR review → REQUEST_CHANGES 修正 → current-head verification → review → required CI / mergeability 確認

    までは自律実行し、

    実際の merge だけを人間判断として残してください。

    Source-of-truth policy

    過去の会話、過去の snapshot、この prompt に書かれた repository 状態より、current repository と live GitHub state を常に優先してください。

    最初に canonical repository root / default branch の fresh state を確認してください。

    現在の以下を必要な範囲で読んでください。

    必要な場合だけ関連 Issue / PR / repository asset を追加取得してください。

    Issue #2052 は refinement 済みの implementation issue として扱ってください。
    fresh live contract が implementation-ready である限り、通常は issue-refinement-loop に戻らず implementation を開始してください。

    ただし canonical root-owned entry transition が fresh issue-contract-review を要求する場合は、それを省略しないでください。

    Canonical entry

    production の canonical impl-review-loop entrypoint を使用してください。

    Step 1 の implementation-worker を手動で先に起動して canonical root transition を迂回しないでください。

    current repository が定義する Root-Owned Synchronous Entry Transition:

    1. capability preflight
    2. live Issue fetch
    3. current-run issue-contract-review
    4. immediate live refetch
    5. root entry routing
    6. invoke_impl_review_loop の場合のみ Step 1 起動

    を、current implementation が要求する単一 continuous control flow のまま実行してください。

    historical comment、artifact、snapshot、旧 authorization packet だけを Step 1 authorization として使わないでください。

    SubAgent execution rule — MUST WAIT FOR COMPLETION

    canonical impl-review-loop が定義する SubAgent を使用してください。

    最低限、通常経路では以下を root/main thread から起動します。

    1. implementation-worker
    2. test-runner
    3. pr-reviewer

    REQUEST_CHANGES / update-branch / stale-head 等で canonical workflow が再委譲を要求した場合も、その current contract に従ってください。

    SubAgent を fire-and-forget してはいけません。

    各 SubAgent invocation について current repository の Common Completion Protocol を厳守してください。

    具体的には:

    1. spawn_agent の返却から canonical task_name / task identity を保存する。
    2. 必要なら wait_agent を使って待つ。
    3. wait_agent の timeout、途中 update、mailbox activity を「完了」とみなさない。
    4. 対象 task の final result を必ず取得・消費する。
    5. その後 list_agents を確認し、同じ canonical task が terminal completed であることを確認する。
    6. final result と terminal completed の両方が確認できるまで次の Step / iteration / routing に進まない。
    7. errored / interrupted / shutdown / lifecycle not_found を成功扱いしない。
    8. recoverable agent discovery failure について current canonical recovery procedure がある場合はそれを先に実行する。
    9. recovery 不可能な genuine lifecycle failure の場合だけ hard-stop とする。

    特に test-runner の完了を必ず待ってください。

    test-runner の final read-only report と、同 task の terminal completed の両方を確認する前に pr-reviewer を起動してはいけません。

    同様に pr-reviewer の完了を必ず待ってください。

    pr-reviewer の final canonical verdict と terminal completed の両方を確認してから Step 5 の routing を行ってください。

    implementation-worker に対しても同じ completion protocol を適用してください。

    SubAgent 自身にさらに任意の SubAgent orchestration を追加させないでください。
    Issue #2052 が必要とする runtime smoke 内部の canonical runtime behavior は別として、main orchestration に新規 nested delegation 構造を作らないでください。

    Step 1 — Implementation

    implementation-worker SubAgent に current implement-issue skill を実行させてください。

    worker には placeholder ではなく materialize 済みの実値として最低限以下を渡してください。

    • Issue #2052
    • full Issue URL
    • current live Allowed Paths
    • current contract
    • iteration
    • serialized fix_delta(iteration > 0 の場合)
    • current repository / branch facts
    • 必要な bounded evidence references

    Issue #2052 の Allowed Paths を literal implementation boundary として扱ってください。

    現 live Issue で定義された Allowed Paths 外の変更が必要なら、勝手に scope expansion しないで Issue の Stop Conditions に従ってください。

    実装中は「テストを通すためだけ」の contract weakening、VC 削除、SKIP 化、assertion 弱体化を行わないでください。

    Issue #2052 implementation intent

    current live Issue の contract が最優先ですが、実装時には特に以下を維持してください。

    • cache 対象は run_refinement_preflight.py の Issue/comment snapshot の parse/projection
    • phase-scoped SHA-bound evidence reuse
    • generic command cache を作らない
    • tests / build / lint / mutable worktree reads / transient retry / GitHub mutation / review / CI/current-head check を suppression しない
    • phase transition / mutation / explicit refresh / freshness-sensitive decision では fresh fetch
    • snapshot を current GitHub state の保証として扱わない
    • missing / corrupt / stale / incompatible cache は通常 read path へ fallback
    • fallback した通常 read 自体の失敗を success にしない
    • measured metrics だけを report し、未観測 token / model-turn 値を捏造しない
    • #88 の current-head VC binding を再実装しない
    • #1909 の bounded context bundle を再実装しない
    • 新規 bundle / receipt / ledger architecture を増やさない
    • cross-process persistent no-progress ledger を復活させない
    • compaction gate / global polling framework を導入しない

    Required runtime verification

    Issue #2052 の Runtime Verification Applicability: immediate を必須として扱ってください。

    Required Skill worktree-agent-runtime-smoke を省略しないでください。

    AC8 は unit test の文字列一致だけでは PASS にしないでください。

    current Issue が要求する structured lane を実際に通し、

    • declared preflight procedure order
    • codebase-investigator SubAgentStart / SubagentStop
    • hook-id-correlated causal evidence
    • required evidence JSON / logs
    • fallback absence

    を current contract に従って検証してください。

    AC8 が SKIP / exit 77 になった場合は Issue #2052 の Stop Condition として扱ってください。

    marker-only evidence や _*_fallback: true 相当の fallback 経由だけで成功した場合も PASS に昇格させないでください。

    必要な runtime evidence は current Issue の artifact_requirements に従って PR 本文の ## Runtime Verification Evidence に反映してください。

    Step 2 — Independent Verification

    Step 1 完了後、test-runner SubAgent を起動してください。

    実装 worker 自身の「テスト済み」という申告を Step 2 の代わりにしないでください。

    fresh live Issue #2052 から

    • Acceptance Criteria 全文
    • Verification Commands 全文
    • current Issue body SHA
    • current PR number
    • current PR head SHA

    を materialize して test-runner に渡してください。

    Issue #2052 の Verification Commands は literal contract として扱ってください。
    コマンドを都合よく置換・省略・短縮しないでください。

    test-runner の final result を受け取り、terminal completed を確認するまで待ってください。

    その後 root/main thread が current repository の canonical adjudicate_vc_result.py 経路を使用して、

    • current head binding
    • Issue body binding
    • literal command hashes
    • per-AC result
    • fallback / SKIP / stop-condition facts
    • Allowed Paths

    を独立 adjudicate してください。

    VC_ADJUDICATION_RESULT_V1.blocking == false が current-head で成立した場合だけ Step 4 に進んでください。

    stale / invalid の場合は canonical routing に従って Step 2 を再実行し、人間承認を求めないでください。

    Step 4 — PR Review

    current-head verification gate が通った場合のみ pr-reviewer SubAgent を起動してください。

    pr-reviewer の起動直前に current-head gate を再評価してください。

    以下のどれかが stale / malformed / blocking なら reviewer を起動せず Step 2 へ戻してください。

    • PR head SHA
    • current Issue body SHA
    • literal Verification Command hashes
    • persisted VC adjudication

    同じ valid binding の VC は canonical LOOP_STATE.vc_adjudication から再利用し、無意味に test-runner を再起動しないでください。

    pr-reviewer には materialize 済みの

    • actual PR number
    • actual current reviewed head SHA
    • live Issue contract
    • current diff
    • verification evidence

    を渡してください。

    pr-reviewer の final canonical LOOP_VERDICT と terminal completed の両方を確認するまで待ってください。

    Step 5 — Autonomous judgment and iteration

    current canonical route_loop_verdict_v2() の routing を使用してください。

    APPROVE

    verdict: APPROVE だけで終了しないでください。

    current repository が要求する

    • reviewed head が current
    • blockers が空
    • current verification nonblocking
    • required CI / current-head conditions
    • live mergeability が accepted state

    を満たすまで canonical flow を継続してください。

    最終的に canonical route が approved になり、

    IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready

    を emit したら成功終了です。

    そこで停止し、merge は行わないでください。

    REQUEST_CHANGES

    人間に確認せず、blockers を fix_delta として次の Step 1 iteration に渡してください。

    その後、

    implementation-worker
    → completion wait
    → test-runner
    → completion wait
    → current-head adjudication
    → pr-reviewer
    → completion wait
    → judgment

    を再実行してください。

    レビュー後に head が変わった場合、旧 test/review evidence は stale として current head に再bindしてください。

    BEHIND

    current canonical route が route_to_update_branch の場合、canonical worker delegation で update branch を実行し、その worker の完了を待った後、新 head に対して Verification と PR Review を再実行してください。

    stale review head

    route_stale_head_rereview の場合、人間承認を求めず current head で review を再実行してください。

    ordinary fail_closed / transient states

    repository が retry / reevaluation を許可している UNKNOWN、一時的 CI state、agent discovery 等は current bounded recovery policy に従って処理してください。

    単なる advisory warning を human escalation に変換しないでください。

    Human escalation / hard-stop

    以下の場合のみ、この autonomous run を停止して人間へ報告してください。

    1. Issue 実装: SHA-bound evidence index と command fingerprint budget で再読・重複調査・wait polling による context churn を抑制する #2052 の live Stop Conditions が実際に発火した。
    2. current impl-review-loop の genuine hard-stop が発火した。
    3. live Issue/PR に OWNER/HUMAN の明示的な停止指示が追加された。
    4. actual Git conflict / canonical conflict hard-stop が recovery 不可能。
    5. max_iterations に到達しても draft_pr_ready にならない。
    6. AC8 が required environment unavailable により SKIP / exit 77。
    7. runtime verification が fallback-only でしか成立しない。
    8. Allowed Paths 外の変更なしでは contract を満たせない。
    9. contract 自体の変更・新規 Issue への scope split が必要。
    10. canonical SubAgent lifecycle failure が bounded recovery 後も解消しない。

    SubAgent が単に human_review_required: true と自己申告しただけなら、それ単独で停止せず、current impl-review-loop の routing authority に従ってください。

    CI and PR completion

    PR 作成後は current head の required checks を確認してください。

    自身の変更に起因する failure なら修正ループへ戻してください。

    明らかな transient failure で repository の canonical policy が bounded rerun を許可している場合は、人間確認なしでその recovery を実施してください。

    CI のためだけに新規 polling framework や cache frameworkを実装しないでください。

    PR 本文には current repository template と Issue contract が要求する情報を正確に反映してください。特に Issue #2052 が要求する runtime verification evidence を欠落させないでください。

    Completion condition

    以下をすべて満たすまで作業を終了しないでください。

    • Issue 実装: SHA-bound evidence index と command fingerprint budget で再読・重複調査・wait polling による context churn を抑制する #2052 の current live contract が実装されている
    • Allowed Paths compliance が成立している
    • Issue に記載された Verification Commands が current head で実行済み
    • AC1–AC8 が canonical adjudication 上 nonblocking
    • AC8 runtime verification が実際に PASS している
    • test-runner final result + terminal completed を確認済み
    • pr-reviewer final result + terminal completed を確認済み
    • pr-reviewer verdict が current head に対する APPROVE
    • blockers が空
    • required CI が current PR head で PASS
    • live mergeability が canonical approved route の条件を満たす
    • unresolved review thread / canonical blocker が残っていない
    • IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready

    この状態に到達したら merge せず停止してください。

    Final report

    最後は簡潔に以下を報告してください。

    draft_pr_ready の場合は、その後に追加変更・merge・post-merge cleanup を行わず終了してください。

    このプロンプトで特に効くのは、「wait_agent 自体を完了証拠にしない」「final result + list_agents: completed の両方を要求する」「任意承認と canonical hard-stop を分離する」の3点です。Anthropic の現行ガイダンスも、長い agentic task ではツール利用や subagent delegation の条件を明示する方向を推奨しています。([docs.anthropic.com]1)

  7. squne121 commented on Sep 5, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-09-05T05:44:51Z)

    • PR: feat: SHA-bound phase-scoped evidence cache for issue-refinement-loop preflight (#2052) #2502
    • Worktree: .claude/worktrees/issue-2052-sha-bound-evidence-index-command-fingerp
    • Branch: worktree-issue-2052-sha-bound-evidence-index-command-fingerp
    • Verification: pnpm typecheck/lint/test/build 全 PASS、AC1-AC8 の Verification Commands 全 PASS(AC8 は実 Claude Code プロセスで hook-id-correlated causal evidence を実機取得)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  8. added a commit that references this issue on Sep 5, 2026
  9. self-assigned this
    on Sep 5, 2026
  10. added a commit that references this issue on Sep 5, 2026
    9784e37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent/implementerenhancementphase/implementationtriage-required

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions