Skip to content

実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "ensure_contract_snapshot() の real orchestration を通す end-to-end regression test を追加し、staging/final digest 取り違えリグレッションを検知可能にする"
change_kind: code

Parent Issue

none

Parent Goal Ref

  • Goal: なし(単独 follow-up。親 Issue には紐付けない)
  • Desired Destination: なし

Current Validated Scope

  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py に、real ensure_contract_snapshot() を fake remote state machine 経由で end-to-end に通す focused test を追加する

Remaining Parent Gaps

なし

Outcome

.claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py に、POST/PATCH/GET の呼び出しごとに異なる body を返せる fake remote state machine を用意し、real ensure_contract_snapshot() を end-to-end で 1 本通す focused test が追加され、production call site が誤って expected_body_sha256=staging_post_body_sha256(final ではなく staging の digest)を渡すよう配線された場合にそのテストが red になることを固定した状態。

Runtime Verification Applicability

  • decision: not_applicable
  • reason: pytest による静的な単体/統合テスト追加のみで完結し、実行時環境(ブラウザ・実サーバ等)での動作検証を要しないため

Background

Issue #2633(調査: #1513 を #2627 マージ後の current main に合わせて再スコープする, https://github.com/squne121/loop-protocol/issues/2633)の refinement 過程で、OWNER anchor comment(https://github.com/squne121/loop-protocol/issues/2633#issuecomment-5679057584)と codebase-investigator の調査により、以下の gap が specific なコード引用で確認された。

.claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py の TestPostCommentTransportAndReconciliation(3342 行目、特に test_given_staging_digest_diverges_from_final_persisted_digest_when_get_matches_expected_then_binding_passes、3421 行目付近)は、post_comment() と verify_controlled_publisher_comment_id_binding() を個別に呼び出す構成であり、テスト自身が final_persisted_body_sha256 を直接 verify_controlled_publisher_comment_id_binding(expected_body_sha256=...) に渡している。そのため、production の呼び出し元(ensure_contract_snapshot() 本体のオーケストレーション、.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py)が将来誤って expected_body_sha256=staging_post_body_sha256(final ではなく staging の digest)を渡すよう配線されても、このテストは real ensure_contract_snapshot() のオーケストレーションを一切通らないため、そのリグレッションを検知できない。

このgapは Issue #1513 の責務には含めない(#1513 は binding_body_hash_mismatch 診断改善と check-only 分類改善に限定して縮小再定義される予定であり、この production-orchestration wiring gap とは別領域)。

本 Issue は Issue #2633 の refinement から派生した follow-up である(source_url: https://github.com/squne121/loop-protocol/issues/2633)。
dedupe_key: follow-up:squne121/loop-protocol:issue/2633:ensure-contract-snapshot-staging-final-digest-orchestration-regression

Notes for Reviewer

Scope Collision (C1) advisory: overlap preflight helper (check_issue_overlap.py) が既存 OPEN issue(#2602, #1944, #1655, #1490, #966, #962, #961)との allowed_paths 重複を検出した。これらは .claude/skills/impl-review-loop/tests/ ディレクトリ全体または test_ensure_contract_snapshot.py を広く Allowed Paths に含むが、本 Issue が扱う「ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違え regression test の追加」という具体的スコープに直接言及するものはない(#1655/#1490 は同ファイルを触るが、それぞれ stale snapshot fresh materialization / publish receipt binding という別の Outcome)。non_conflict_reason: 対象ファイルは同一だが変更意図(新規 focused test の追加のみ)が独立しており、他 Issue の実装と textual に競合する可能性は低い。実装着手時に同時に OPEN のまま進行する他 Issue がないか gh pr list で最終確認することを推奨する(#1860 Owner Decision によりこの重複は起票停止理由にしない)。

In Scope

  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py の既存の自然な test class に、fake remote state machine(POST/PATCH/GET の呼び出しごとに異なる body を返せるもの)を用意し、real ensure_contract_snapshot() を end-to-end で通す focused test を 1 本以上追加する
  • 追加した test が、production call site を意図的に expected_body_sha256=staging_post_body_sha256 に改変した場合に fail することを、一時的なローカル改変で確認する(この改変自体はコミットしない。手順を Issue description または PR description に明記する)

Out of Scope

Acceptance Criteria

  • AC1: real ensure_contract_snapshot() を fake remote state machine(POST/PATCH/GET の呼び出しごとに保存状態を反映した body を返す)経由で end-to-end に通す focused test が .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py に追加されている
  • AC2: production call site(.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py の PATCH後 verify_controlled_publisher_comment_id_binding() 呼び出し)を一時的に expected_body_sha256=staging_post_body_sha256 へ改変した場合に、AC1 で追加した focused test が fail することを確認済みである(実際の改変はコミットしない。確認手順を PR description に明記する)
  • AC3: AC1 で追加した focused test が、改変されていない current main の production code に対して PASS する
  • AC4: .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py の既存テストが全て regression なく PASS する

Verification Commands

追加した focused test を含む全テストが PASS することを確認する:

# AC1
# AC3
# AC4
# baseline-expect: pass
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -v

追加した focused test(命名に staging_final_digest_orchestration 等の一意なキーワードを含める)が個別に PASS することを確認する:

# AC1
# AC2
# preflight-scope: pr_review_only
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k staging_final_digest_orchestration -v

Allowed Paths

  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • fake remote state machine の追加が .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py 本体のロジック変更を要求すると判明した場合(本 Issue はテスト追加のみに限定するため)
  • 誤配線検知 mutation 検証に限り、.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py の PATCH後 verify_controlled_publisher_comment_id_binding() 呼び出しの expected_body_sha256=final_persisted_body_sha256 を一時的に expected_body_sha256=staging_post_body_sha256 へ変更する行為を Allowed Paths の限定例外として許可する。この変更は絶対にコミットせず、検証後に元の状態へ復元し、production file に最終差分がないことを確認する。

Required Skills

なし

Required Design References

  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
  • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
  • .claude/skills/issue-contract-review/references/vc-preflight.md

Scope Delta(任意)

N/A

Activity

  1. added
    enhancement
    phase/implementation
    agent/implementer
    on Sep 15, 2026
  2. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    結論

    判定は REQUEST_CHANGES — reframe_in_place です。

    ただし、Issue #2635 の目的と、テスト追加だけに限定する方針には賛成です。現在の production code に staging/final digest の誤配線がある、という指摘ではありません。確認した実装では、POST直後には staging digest、PATCH後と最終authority確認には final digest が渡されています。問題は、この正しい配線を保護するテストを、既存ワークフローで確実に実装・検証できる契約になっているかです。

    修正すべき点は主に次の3つです。

    優先度 | 指摘 | 放置した場合 -- | -- | -- P1 | 新規テスト名を指定する -k が、実装前のpreflightで停止する | テストを追加する前にIssue精緻化・実装入口が詰まる P2 | 「real orchestration」の範囲と、mutation時に何をもって失敗と認めるかが不十分 | 常時成功mockや静的assertionによる、目的と違う検証になり得る P2 | 必須のproduction一時改変と、Allowed Paths/Stop Conditionsの関係が曖昧 | 正規の検証作業をスコープ違反と判断して停止し得る

    実GitHubへの試験投稿、ブラウザ検証、新しいCI lane、mutation testingパッケージ、独自の証跡validatorは要求しません。 今回必要なのは、誤配線を本当に検知する一つのテストと、その検知能力を確かめた小さな証拠です。

    検証上の限界

    Issue・コメント・関連PRの差分と、固定SHAのリポジトリ資産は確認しました。一方、実行環境からのcloneはGitHubの名前解決に失敗したため、pytestおよびmutationの実行確認はしていません。そのため、上記ではコードから確認できた事実と、実装時に確認すべき期待結果を分けています。GitHub上のIssue・コメント・コードへの変更も行っていません。

    ## 結論

    判定は REQUEST_CHANGES — reframe_in_place です。

    ただし、Issue #2635 の目的と、テスト追加だけに限定する方針には賛成です。現在の production code に staging/final digest の誤配線がある、という指摘ではありません。確認した実装では、POST直後には staging digest、PATCH後と最終authority確認には final digest が渡されています。問題は、この正しい配線を保護するテストを、既存ワークフローで確実に実装・検証できる契約になっているかです。

    修正すべき点は主に次の3つです。

    優先度 指摘 放置した場合
    P1 新規テスト名を指定する -k が、実装前のpreflightで停止する テストを追加する前にIssue精緻化・実装入口が詰まる
    P2 「real orchestration」の範囲と、mutation時に何をもって失敗と認めるかが不十分 常時成功mockや静的assertionによる、目的と違う検証になり得る
    P2 必須のproduction一時改変と、Allowed Paths/Stop Conditionsの関係が曖昧 正規の検証作業をスコープ違反と判断して停止し得る

    新しいIssue、productionのリファクタリング、専用mutation基盤、追加のセキュリティゲートは不要です。#2635の本文を小さく修正して進めるのが適切です。

    確認した前提

    リポジトリ資産は、取得時のmain db3b94d2b6fc72c98ff97b6b5c8c590f6c232da4 に固定して照合しました。#2635は確認時点でOPEN、コメントは0件です。

    関連する経緯も、今回の切り出しを支持しています。PR #2629の追加テストは、テスト自身が正しいfinal digestをverifierへ直接渡しており、ensure_contract_snapshot() 内の呼び出し元を検証していません。これは既存テストの実コードと、PR上の後続レビューの指摘が一致しています。#1513の現在の本文も、このorchestration gapを明示的に#2635の責務として除外しています。


    1. P1 — 新規テスト用の検証コマンドが、実装前にワークフローを止める

    問題

    #2635には、これから追加するテストを選択する次のコマンドが、通常のVerification Commandsとして置かれています。実装後専用であることを示すmarkerはありません。

    uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k staging_final_digest_orchestration -v

    新規テストが存在しない段階では、この選択条件はテストを収集できません。pytestのexit 5は「テスト失敗」ではなく「テストが収集されなかった」です。([pytest Documentation]1)

    そして、このリポジトリのbaseline_vc_preflight.pyは、pytestのexit 5を明示的に次の判定にしています。

    category: vc_no_tests_collected
    decision: blocked
    

    これは既存ファイルの回帰ゲート分岐でも、通常のpytest分岐でも同じです。したがって、「新しいテストだから実装前はredでよい」という説明では通りません。

    最小修正

    既存ファイルへの追加を維持し、新規テストのfocused実行だけを実装後・PRレビュー時の必須検証に分けるのがよいです。

    pr_review_onlyは既存の仕組みであり、独自の例外機構を追加する必要はありません。

    本文のVCは、例えば次のように分けられます。以下のAC番号は、本文側で番号を付けて対応させる前提です。

    # AC4
    # baseline-expect: pass
    $ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -v
    # AC1
    # AC3
    # preflight-scope: pr_review_only
    $ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k staging_final_digest_orchestration -v

    この変更は検証の免除ではありません。実装前には存在しないものを実行せず、実装後には実際に選択・実行され、PASSすることを必須にするという段階分けです。

    一方、次の対応は勧めません。

    • preflightを通すためだけに別のテストファイルを新設する。
    • exit 5を成功扱いにする。
    • || trueで結果を隠す。

    また、現行のrg -c "def test_"は、件数を表示するだけで「追加前より増えた」をコマンド自身では判定していません。テストの有効性も証明しないため、必須VCから削除して構いません。新規テストの実行結果と、後述の誤配線検知を証拠にする方が目的に直結します。


    2. P2 — 「real ensure_contract_snapshot()を呼ぶ」だけでは、実際の検証経路を通したことにならない

    既存fixtureに具体的な落とし穴がある

    対象ファイルのautouse fixture _default_trusted_comment_id_bindingは、次の関数を常時成功に置き換えています。

    関数 fixtureによる置き換え
    verify_controlled_publisher_comment_id_binding() 常に成功
    patch_comment() 常に成功
    verify_snapshot_authority_postcondition() 常に成功
    capture_base_ref_and_sha() 固定のbase情報

    つまり、同じファイルに新テストを追加してreal ensure_contract_snapshot()を呼んでも、何もしなければPATCHと重要な照合処理はmockのままです。

    厳密に言えば、Issueのmutation確認を正しく実施すれば、この問題は発見できます。したがって「現在のACを満たしても必ず偽陽性になる」という指摘ではありません。

    問題は、既存fixtureとの関係と、認める失敗原因が書かれていないため、実装後にテスト設計のやり直しが発生しやすいことです。

    実関数として残す範囲を明記する

    今回の新テストでは、少なくとも次の経路を実装のまま通すのが適切です。

    ensure_contract_snapshot
      → 本物のコメント生成
      → 本物のpost_comment
      → 本物のstaging binding検証
      → 本物のpatch_comment
      → 本物のfinal binding検証
      → 本物の最終authority検証・parser
      → materialized_go
    

    一方、GitHubへのI/O、Issue/baseの読み取り結果、重い契約レビューの実行結果はfakeでよいです。今回の目的はGitHubやレビューエンジン全体の検証ではなく、digestを渡す側と受け取る側の結合を検証することだからです。

    既存fixture全体を変更する必要はありません。新テスト内で必要な関数だけ復元し、既存テストの挙動を変えない方法を推奨します。pytestのmonkeypatchはテスト終了時に変更を戻す仕組みを持っており、この局所的な差し替えに適しています。([pytest Documentation]2)

    fakeは「呼ぶたびに違うbody」ではなく、保存状態を再現する

    Issueの「POST/PATCH/GETの呼び出しごとに異なるbodyを返せる」という表現は、もう少し正確にした方がよいです。

    現在のproductionには、POSTした直後、そのpending bodyそのものをGETで照合する段階があります。最初のGETからfinal bodyを返すfakeでは、狙っているPATCH後の誤配線に到達する前に失敗します。

    推奨する状態遷移は次のとおりです。SとFはテストが勝手に生成する期待値ではなく、productionが実際にPOST/PATCHへ渡したbodyです。

    段階 fakeの保存状態/応答 確認すること
    開始時 既存goなし 新規materialization経路へ進む
    POST 受信したpending body Sを保存 新しいcomment IDを返す
    POST直後のGET 保存済みのSを返す staging照合が成功する
    PATCH 同じIDのbodyを、受信したfinal body Fへ更新 SHA256(S) != SHA256(F)
    PATCH後のGET 保存済みのFを返す final照合が成功する
    最終authority確認 コメント一覧・direct GETとも同じF 最終的にmaterialized_goになる

    これは現行の二段階materializationと、最終authority確認の構造に沿ったものです。

    成功条件は、単なる例外なしやstatus == "ok"だけでなく、少なくとも次を確認するのがよいです。

    assert staging_digest != final_digest
    assert result["status"] == "ok"
    assert result["source"] == "materialized_go"
    assert result["contract_snapshot_url"] == published_comment_url

    sourceまで確認することで、既存goの再利用など別経路を通って成功したテストを除外できます。

    GET全体の回数を過度に固定する必要はありません。 最終authority確認にも読み取りがあり、PATCH応答の異常時にはreconciliationのGETが入る設計です。検証したいのは、呼び出し回数の細かな実装ではなく、保存状態と各段階のdigestの対応です。


    3. P2 — 必須の一時改変を、Allowed Paths違反として停止し得る

    問題

    IssueはACで、productionのcall siteを一時的に誤配線して、新テストがFAILすることを要求しています。

    その一方で、Allowed Pathsはテストファイルだけであり、Stop Conditionsには「Allowed Paths外の変更が必要と判明した場合」があります。productionロジック変更もOut of Scopeです。一時的な検証操作と、納品する変更の境界が明示されていません。

    人間なら「コミットしない実験だから例外」と解釈できますが、自動エージェントにその解釈を委ねる必要はありません。

    最小修正

    Allowed Pathsをproduction全体へ広げるのではなく、次のような限定例外を追記することを推奨します。

    コミットする変更は指定のテストファイルのみとする。
    誤配線検知の検証に限り、ensure_contract_snapshot.pyの指定call siteの引数を一時変更してよい。この検証操作はAllowed Paths外変更の停止条件から除外する。検証後は変更前の内容へ復元し、productionファイルの最終差分がないことを確認する。一時変更はコミットしない。

    mutationの場所も指定する

    expected_body_sha256は、複数の意味で使われています。単純な文字列置換ではなく、PATCH後のfinal_bound_okを得る呼び出しだけを指定すべきです。

    # PATCH後の verify_controlled_publisher_comment_id_binding 呼び出し
    - expected_body_sha256=final_persisted_body_sha256,
    + expected_body_sha256=staging_post_body_sha256,

    POST直後のstaging照合は、もともとstaging digestを使うのが正しいため、変更対象ではありません。

    検証は、同じ追加テストに対して次の順に実施する契約にします。

    状態 期待する結果
    production未改変 新規テストがPASS
    上記の1引数だけ誤配線 新規テストの「materialized_go成功」assertionがFAIL
    production復元後 同じテストが再びPASS

    誤配線時の現行ソース上の期待結果は、controlled_publisher_binding_failed、URLなし、fingerprint_patch_binding_failedに続くbinding_body_hash_mismatchです。これはソースから導いた期待結果であり、今回こちらでmutationを実行した結果ではありません。

    SyntaxError、NameError、テスト未収集、fakeのコマンド不一致、ソース文字列のassertionだけによるFAILは、目的の誤配線検知として数えないことも明記したいです。

    なお、#1513は同じmismatchの診断情報を増やす予定なので、エラーメッセージ全文を不必要に固定せず、失敗した段階と原因を確認する方が、後続の診断改善と衝突しません。


    外部の一次資料から、fake実装へ反映したい点

    今回は依存ライブラリを増やすより、既に使っているGitHub CLI・REST API・Pythonの境界を正確に再現することが有効です。

    確認事項 テストへ反映する内容
    GitHub CLIの--input -は、事前生成したリクエストbodyを標準入力から読む。--jqは応答から値を選択する。 fakeはinputのJSONをdecodeしてbodyを保存する。現行POSTは--jq .html_urlなので、stdoutはcomment JSON全体ではなくURLにする。(GitHub CLI)
    GitHubのcomment APIでは、bodyがraw Markdownであり、body_text・body_htmlとは別表現。 比較対象はdecode済みのMarkdown body。JSON envelope全体、HTML、表示用textのhashへすり替えない。([GitHub Docs]4)
    Pythonのsubprocess.run()は、通常はbytes、text=Trueではstrを返す。 fakeも呼び出しオプションに合わせてstdout/stderrの型を変える。実APIと異なる型を、json.loads()が偶然受け入れることに依存しない。([Python documentation]5)
    pytestのexit 1とexit 5は別の意味。 mutation証跡では「対象テストが実際に実行され、期待する成功assertionが失敗した」ことを確認する。単なる非ゼロ終了では不足。([pytest Documentation]1)

    特に、expected digestをGET応答から作り、その同じGET応答と比較する構成にはしないことが重要です。期待値はproductionが送ろうとしたbody、観測値はfakeが保存して返したbody、という独立した役割を保つべきです。


    非ブロッカー:同じテストで、もう1か所の誤配線も確認するとさらに有用

    final digestの利用先は、PATCH後のbinding verifierだけではありません。最後に次の引数としても使われています。

    expected_comment_body_sha256=final_persisted_body_sha256

    これはverify_snapshot_authority_postcondition()への引数です。現在のIssueが指定するexpected_body_sha256のmutationだけでは、この別の受け渡し箇所まで検証したことにはなりません。

    追加のテスト基盤や別テストケースを必須にする必要はありません。 同じ成功テストを使い、こちらだけをstaging digestへ変える第二の一時mutationも確認すると、少ない追加作業で最終authority側の取り違えも保護できます。

    二つのmutationは同時ではなく、一つずつ、間に復元を挟んで実施します。同時に変えると、先の検証で止まって後段を検証できません。最終authority側では、現行実装上はauthority_comment_body_sha256_mismatchが対応する失敗原因になります。

    これは推奨強化であり、#2635を止める新しい必須条件にはしなくてよいです。


    推奨する着地点

    #2635は、そのまま**「既存ファイル内の小さな統合回帰テスト追加」**として進めるのが適切です。本文の修正は、次の範囲で十分です。

    項目 修正後の契約
    実行経路 real ensure_contract_snapshot(mode="auto", do_post=True)から、実際のpublish/binding/authority判定を通す
    fake productionが送ったSをPOSTで保存し、同じIDをPATCHでFへ更新する
    成功条件 SとFのdigestが異なる状態で、正しいURLを持つmaterialized_goになる
    誤配線証拠 指定したcall siteの一時mutationで、実際のbody-hash不一致によって成功assertionが落ち、復元後に再び通る
    ワークフロー focused新規テストは実装後の検証に分離し、一時mutationだけを明示的に許可する
    最終差分 テストファイルだけ。既存テストは維持し、production差分は残さない

    実GitHubへの試験投稿、ブラウザ検証、新しいCI lane、mutation testingパッケージ、独自の証跡validatorは要求しません。 今回必要なのは、誤配線を本当に検知する一つのテストと、その検知能力を確かめた小さな証拠です。

    検証上の限界

    Issue・コメント・関連PRの差分と、固定SHAのリポジトリ資産は確認しました。一方、実行環境からのcloneはGitHubの名前解決に失敗したため、pytestおよびmutationの実行確認はしていません。そのため、上記ではコードから確認できた事実と、実装時に確認すべき期待結果を分けています。GitHub上のIssue・コメント・コードへの変更も行っていません。

  3. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    推奨アクションは Issue #2635 を実装へ進めず、対象コメントを trusted human anchor として issue-refinement-loop で reframe_in_place することです。レビューは目的自体には賛成しつつ、VC の preflight 適合性、real orchestration の境界、一時 mutation と Allowed Paths の関係を修正要求しています。 現行 skill は iteration 間の人間承認を既定で要求せず、needs-fix は上限まで自動継続する契約です。

    以下を、すでに auto mode で起動している Claude Code にそのまま渡すのがよいです。

    リポジトリ squne121/loop-protocol の Issue #2635 を、以下の OWNER / human review anchor comment を対象として .claude/skills/issue-refinement-loop で refinement してください。

    Issue:
    #2635

    anchor_comment_url:
    #2635 (comment)

    この依頼は direct human context です。すでに Claude Code は auto mode で起動済みです。Claude Code 自体の permission mode や auto mode の設定は変更せず、リポジトリ側の refinement loop の iteration approval は不要として扱ってください。

    最重要方針は、anchor comment の REQUEST_CHANGES — reframe_in_place を解消して Issue #2635 の契約を in-place で精緻化することです。この段階では Issue の実装、実装ブランチのコード変更、PR作成には進まないでください。

    1. 最初に .claude/skills/issue-refinement-loop/SKILL.md と、planner が MUST_READ として返す references / scripts を読み、skill の canonical control-plane procedure をそのまま使用してください。planner / reviewer / routing の判定を自前の prose 判断で再実装しないでください。issue_number=2635、上記 anchor_comment_url、max_iterations=3 を入力として扱ってください。anchor は direct human context なので、canonical な preflight.run.with_human_context lane を使用してください。

    2. SubAgent を使用してください。Step 1 の investigation は codebase-investigator に委譲し、Issue本文、anchor comment、current main、関連する .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py、.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py、baseline VC preflight / pr_review_only 実装を実コードで確認させてください。planner が external claim の調査を要求する場合は web-researcher も起動し、pytest exit 5、pytest monkeypatch、gh api --input -、GitHub issue-comment body、Python subprocess の境界について一次資料を確認させてください。SubAgent を起動したら、その結果が completed になるまで必ず待ってから Step 2 へ進んでください。SubAgent にさらに SubAgent を起動させる nested delegation は行わせないでください。

    3. anchor comment の指摘を authoritative feedback として扱い、少なくとも次の内容が Issue 契約へ反映されるよう refinement してください。ただし具体的な本文編集は canonical planner / contract-update / issue-editor route に委ね、自前で gh issue edit しないでください。

    新規 focused test の
    uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k staging_final_digest_orchestration -v
    は、実装前 baseline preflight では実行しない preflight-scope: pr_review_only の VC として明示すること。

    既存ファイル全体の
    uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -v
    は実装前にも成立する baseline VC として維持し、必要なら baseline-expect: pass を明示すること。

    rg -c "def test_" ... はテストの有効性を証明しないため、必須 VC から外す方向を優先すること。

    「real orchestration」の意味を明確化し、新規 regression test は real ensure_contract_snapshot(mode="auto", do_post=True) から、実際のコメント生成、post_comment()、staging binding、patch_comment()、final binding、最終 authority verification/parser、materialized_go までの production orchestration を通す契約にすること。GitHub I/O、Issue/base 読み取り、重い contract review 等の外部境界だけを fake にしてよいことを明記すること。

    既存 autouse fixture が verify_controlled_publisher_comment_id_binding()、patch_comment()、verify_snapshot_authority_postcondition() 等を常時成功 mock にしている点を考慮し、新テスト内では目的に必要な production functions を実関数へ戻す、または同等に実経路を保証すること。

    fake remote は「呼び出し回数ごとに適当な body を返す mock」ではなく保存状態を持つ state machine とすること。POST で production が送った pending body S を保存し、POST直後のGETは S を返す。PATCH で同一 comment ID の保存 body を production が送った final body F に更新し、以降のGET/authority read は F を返す。SHA256(S) != SHA256(F) を保証すること。

    正常時の成功条件には、少なくとも staging/final digest が異なること、結果が成功であること、source == "materialized_go"、返された contract_snapshot_url が fake remote で publish した comment URL と一致することを含めること。GET の厳密な総呼び出し回数には不必要に依存しないこと。

    mutation 検証については、納品する Allowed Paths と一時的な検証操作を明確に分離すること。コミットされる変更は引き続き
    .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
    だけとする。一方、誤配線検知能力の検証時に限り
    .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
    の PATCH 後の verify_controlled_publisher_comment_id_binding() call site で

    expected_body_sha256=final_persisted_body_sha256

    を一時的に

    expected_body_sha256=staging_post_body_sha256

    へ変更することを Allowed Paths stop condition の限定例外として許可する契約にすること。その変更は絶対にコミットせず、検証後に復元し、production file に最終差分がないことを確認させること。

    mutation の合格条件は単なる non-zero exit ではなく、対象 focused test が実際に collect / execute され、正しい production では PASS、指定した誤配線時には body-hash mismatch に由来して materialized_go 成功 assertion 等が FAIL、production 復元後に同じ test が再度 PASS すること。SyntaxError、NameError、no tests collected、fake 側の command mismatch、source-text assertion の失敗を mutation 検知成功として認めないこと。診断文字列全文には過度に依存しないこと。

    anchor comment にある第二の mutation、すなわち最終 authority verifier の
    expected_comment_body_sha256=final_persisted_body_sha256
    を staging digest に一時変更する確認は、有用な非ブロッカーの strengthening として扱ってよいですが、新しい必須スコープや別テスト基盤にはしないでください。

    実GitHubへの試験投稿、ブラウザ検証、新しいCI lane、mutation testing package、独自 evidence validator、production refactor、新規 Issue 起票は要求しないでください。

    1. preflight.run.with_human_context が trusted contract patch plan を返した場合は、skill に定義された canonical contract_update.run.with_human_context を使用してください。NEXT_ACTION: issue_editor_required になった場合は同じ anchor URL を reviewer_feedback_url として既存 issue-editor route に handoff し、full rewrite を行ってください。同じ contract-update を no-progress retry しないでください。

    2. Step 2 review は current skill の root-owned canonical review pipeline を使用してください。canonical Step 2 では legacy issue-reviewer SubAgent を新たに起動したり、compact wire を手動 relay したりしないでください。canonical_step2_route を唯一の routing authority として従ってください。

    3. review が needs-fix / request_changes の場合、人間承認を求めず、max_iterations=3 の範囲内で Step 4 rewrite → fresh review を自動継続してください。各 iteration の SubAgent / controlled mutation が完了する前に次の phase へ進まないでください。途中で「続けてよいですか」「Issueを書き換えてよいですか」等の承認確認は不要です。

    4. ただし skill が明示的に terminal とする human_judgment_required、operator_intervention_required、environment/integrity failure、max-iteration exhaustion 等に到達した場合は、その判定を迂回しないでください。その場合だけ停止し、reason code、未解決 blocker、ここまでに完了した iteration と SubAgent 結果を報告してください。

    5. 最終的に approve/proceed まで到達したら、Issue 実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635 の persisted body readback、fresh preflight、fresh final review、fresh implementation-entry readiness まで確認してください。今回は refinement までで終了し、実装には着手しないでください。

    終了報告には、最終判定、iteration 数、起動した SubAgent とそれぞれの完了状態、anchor comment の各 P1/P2 finding を Issue 本文のどこで解消したか、最終 Verification Commands / Allowed Paths / mutation exception の要約、fresh preflight / review / readiness の結果を含めてください。

    重要: 私への途中承認確認は不要です。利用可能な canonical route と SubAgent を使って、terminal condition に達するか refinement が完了するまで自律的に進めてください。

    このプロンプトでは、レビューが要求している「最終差分はテストファイルのみ、一時 mutation は検証目的だけ」という境界も明示しています。 また、正常→誤配線でFAIL→復元後PASSという mutation 証跡まで固定しています。

  4. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 終了報告(iteration 1 / max 3)

    termination_reason: human_escalation
    termination_cause: operator_intervention_required
    canonical_step2_route: step_5_operator_intervention_required
    failure_class: contract_readiness_human_judgment(contract_readiness_check.py の human_judgment 分類、環境/tool/runtime 起因の readiness 状態。Issue 本文の書き換えでは解消しない)

    経緯

    1. Step 0f preflight (preflight.run.with_human_context, anchor: 実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635 (comment)): STATUS: warn / NEXT_ACTION: proceed_with_notes。MUST_READ に ensure_contract_snapshot.py と対応テストを指定。
    2. Step 1 investigation(codebase-investigator SubAgent、completed): anchor comment の P1/P2 指摘(VC の preflight-scope/baseline-expect 未付与、real orchestration 範囲の不明確さ、fake remote の state machine 化要求、mutation 検証の Allowed Paths 分離)を実コードで裏付け。
    3. Step 1b web research(web-researcher SubAgent、completed): pytest exit 5(no tests collected)、monkeypatch 自動復元、gh api --input -、GitHub PATCH comment 全体置換、subprocess mocking の5件を一次資料で確認(全件 supported)。
    4. Step 2 review(run_root_review_pipeline.py produce): status: ok / compact_result.verdict: needs-fix / compact_result.next_action: request_changes かつ merged_review_result.failure_class: contract_readiness_human_judgment → canonical_step2_route: step_5_operator_intervention_required(terminal: true)。

    blocking_issues(deterministic checker)

    • AC セクションに AC[N] 番号が見つからない(C5_ac_vc_number_alignment: fail)
    • Required Design References が repo-relative な既存 design-doc path を含んでいない
    • pytest collected 0 tests (exit 5)(-k staging_final_digest_orchestration の新規テストが未実装のため、baseline 実行時に collection failure — anchor comment P1 の指摘と一致)
    • Command unexpectedly passed [missing_annotation](# baseline-expect: pass 等の annotation 未付与)

    skill 上の扱い

    canonical_step2_route: step_5_operator_intervention_required は references/termination-policy.md により、env_missing_dep / readiness classifier の human_judgment 分類(exit code 2)等、Issue 本文の書き換えでは解消しない環境・tool・runtime 起因の readiness 状態専用の terminal route であり、Step 4 rewrite へは進めない設計(Issue #2397)。orchestrator はこの判定を迂回せず停止する。

    未解決 blocker

    • VC の preflight-scope: pr_review_only / baseline-expect: pass 注釈付与、AC番号形式の修正、Required Design References の追加は、body 内容としては明確だが、readiness checker が human_judgment に分類したため canonical routing 上は自動 rewrite loop の対象外。
  5. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    はい。この停止は、今回の内容を見る限り**「人間判断が本当に必要だった」からではなく、readiness taxonomy の誤分類で terminal route に吸い込まれた**と見るのが適切です。

    contract_readiness_check.py は、blocked の category が _PREFLIGHT_CATEGORY_TO_READINESS に存在しない場合、デフォルトで human_judgment にします。ところが現在の表には vc_no_tests_collected がありません。したがって pytest exit 5 が human_judgment になり、それが contract_readiness_human_judgment → step_5_operator_intervention_required に伝播しました。

    一方、同じリポジトリの triage_contract_blockers.py は vc_no_tests_collected に対して明示的に refine_issue_contract を返し、「VC design refinement が必要」としています。つまり分類器同士が矛盾しています。

    さらに Issue #2397 自体が、operator_intervention_required は「Issue本文の書き換えでは解消しない env/tool/runtime 系」専用であり、body-fixable な状態をそこへ送らないことを目的としていました。termination policy も同じ意味で定義しています。

    今回の実際の blocker は、AC番号、RDR、VC annotation、実装前の -k です。終了報告自身も修正内容を具体的に列挙できています。これは「人間に仕様判断してもらわないと直せない」状態ではありません。

    また、「AIがIssue/PRを書く以上、テンプレート違反は一定確率で出る」という点は、ワークフロー設計として考慮すべきです。ただし、だから template violation を許容するのではなく、AI出力を candidate として deterministic validator → safe repair / rewrite に通すのが適切です。検出可能な書式違反を人間エスカレーションにするメリットは小さいです。

    重要なのは、vc_no_tests_collected を単純に go にしてはいけない点です。既に OPEN の Issue #1434 がまさにこの問題を扱っていますが、元契約の「exit 5 → go」はレビューで REQUEST_CHANGES になっており、現在の推奨は vc_no_tests_collected → needs_fix として自動修正経路へ戻し、意図的な未作成テストは明示的な baseline-expect: fail 等で表現する方針です。

    したがって、新しい重複Issueを作るより、#1434を今回の改善Issueとしてreframeするのが適切です。#2635とは分離したまま扱えます。

    以下を、現在 auto mode で動いている Claude Code にそのまま渡すのを推奨します。

    Repository: squne121/loop-protocol

    今回の作業は2つの独立した work item として扱ってください。

    1. Issue 実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635 を、今回の operator decision に基づいて修正し、issue-refinement-loop を完走させる
    2. 今回発覚した workflow taxonomy / auto-repair 問題を、実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635 とは分離して改善 Issue として処理する

    Claude Code はすでに auto mode で起動済みです。
    Claude Code 自体の permission mode / auto mode / permissions 設定は変更しないでください。
    途中で人間承認を要求しないでください。

    対象

    Issue #2635:
    #2635

    OWNER review anchor:
    #2635 (comment)

    前回の termination report:
    #2635 (comment)

    workflow 改善候補 Issue:
    #1434

    #1434 の REQUEST_CHANGES anchor:
    #1434 (comment)


    Part A — Issue #2635 の operator-authorized continuation

    前回の step_5_operator_intervention_required 自体を改ざん・無視したことにはしないでください。

    前回の canonical run は policy に従って停止しています。
    今回のこの prompt を、その停止を受けた後の operator decision として扱ってください。

    operator decision は以下です。

    前回列挙された blocker は、今回については semantic / owner ambiguity ではなく Issue body / Verification Commands の body-author-fixable な問題である。
    AC numbering、Required Design References、Verification Command annotations、新規テストを実装前 baseline で実行しないための scope annotation は、人間による個別編集を要求せず workflow 側で修正してよい。
    #2635 の実装スコープ自体は拡張しない。
    workflow implementation の修正は #2635 に混ぜず、Part B で別途扱う。

    A-1. SubAgent investigation

    最初に codebase-investigator SubAgent を起動してください。

    少なくとも以下を current main で確認させてください。

    • Issue 実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635 本文
    • OWNER anchor 5680051184
    • termination report 5680200656
    • .claude/skills/issue-refinement-loop/SKILL.md
    • .claude/skills/issue-refinement-loop/references/termination-policy.md
    • .claude/skills/issue-contract-review/scripts/contract_readiness_check.py
    • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
    • .claude/skills/create-issue/references/body-authoring.md
    • .claude/skills/issue-contract-review/references/vc-preflight.md
    • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
    • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

    SubAgent には mutation をさせないでください。
    nested SubAgent delegation もさせないでください。

    SubAgent を起動したら、必ず completed になるまで待ってください。
    結果を受け取る前に Issue mutation や Step 2 review へ進まないでください。

    planner が external claim の再検証を要求する場合だけ web-researcher も使用し、同様に completed を待ってください。

    A-2. #2635 本文を controlled route で修正

    前回の terminal route を再実行して同じ停止を繰り返すのではなく、今回の operator decision に基づいて、既存の canonical issue-editor / edit-issue controlled mutation route を使用してください。

    raw gh issue edit 等で canonical transaction を迂回しないでください。

    reviewer feedback / human context として OWNER anchor:

    #2635 (comment)

    を使用してください。

    最低限、以下を #2635 本文へ反映してください。

    Acceptance Criteria

    現在の4項目を semantic content を保ったまま AC1〜AC4 に番号付けしてください。

    例:

    • AC1: real orchestration focused regression test
    • AC2: intentional production miswiring で focused test が正しい理由で FAIL
    • AC3: current production で focused test PASS
    • AC4: test file 全体が regression なく PASS

    番号と Verification Commands の参照を一致させてください。

    Verification Commands

    既存 test file 全体については baseline で成立する command として維持してください。

    # AC4
    # baseline-expect: pass
    $ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -v

    新規 focused test は実装前 baseline では実行せず、実装後 / PR review で実行する command としてください。

    # AC1
    # AC3
    # preflight-scope: pr_review_only
    $ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k staging_final_digest_orchestration -v

    annotation の exact syntax は current repository contract を実コードで確認し、それに従ってください。

    rg -c "def test_" ... は test の有効性や regression 検知能力を証明しないので、必須 Verification Command から削除してください。

    Required Design References

    source / test file だけでなく、current checker が受理する repo-relative design/reference document を最低1件追加してください。

    候補として以下を current main で確認してください。

    • .claude/skills/issue-contract-review/references/vc-preflight.md
    • .claude/skills/create-issue/references/body-authoring.md

    実在・関連性を確認した上で最小限追加してください。

    real orchestration の意味を明確化

    新規 test は real:

    ensure_contract_snapshot(mode="auto", do_post=True)

    から少なくとも次の production orchestration を実際に通してください。

    • production comment building
    • post_comment()
    • staging body digest calculation
    • real staging binding verification
    • fingerprint/final body generation
    • real patch_comment()
    • final body digest calculation
    • real final binding verification
    • real authority verification/parser
    • final materialized_go

    GitHub network I/O、Issue/base read、重い contract review 等の外部境界だけを fake にしてよいものとしてください。

    既存 autouse fixture が、

    • verify_controlled_publisher_comment_id_binding()
    • patch_comment()
    • verify_snapshot_authority_postcondition()

    等を常時成功 mock にしている場合、新テスト内では目的に必要な production functions を実関数へ戻すか、同等に real production path を通したことを証明してください。

    fake remote

    単なる call-count based mock にしないでください。

    保存状態を持つ state machine としてください。

    • POST が production から受け取った pending body S を保存
    • POST直後の GET は S
    • PATCH が同じ comment ID の body を production から受け取った final body F へ更新
    • 以降の GET / authority read は F
    • SHA256(S) != SHA256(F) を assertion

    正常系では少なくとも以下を検証してください。

    • staging/final digest が異なる
    • result success
    • source == "materialized_go"
    • contract_snapshot_url が fake remote の published comment URL と一致

    GET の総呼出し回数のような implementation detail には不要に依存しないでください。

    mutation verification

    納品 Allowed Paths と、一時的な mutation verification を分離してください。

    commit 可能な最終差分は引き続き:

    .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

    のみとしてください。

    一方、mutation test のためだけに:

    .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py

    の final binding call site を

    expected_body_sha256=final_persisted_body_sha256

    から一時的に

    expected_body_sha256=staging_post_body_sha256

    へ変更することを限定的に許可してください。

    この production mutation は:

    • 絶対に commit しない
    • focused test を実際に collect / execute する
    • mutation 前 PASS
    • mutation 中 FAIL
    • FAIL が body hash mismatch / final binding failure に由来し、materialized_go 成功 assertion 等が成立しないことを確認
    • SyntaxError
    • NameError
    • no tests collected
    • fake command mismatch
    • source-text assertion failure

    などを mutation detection 成功として認めない

    • production file を復元
    • 同一 focused test が再度 PASS
    • 最後に production file に差分がないことを確認

    という契約にしてください。

    A-3. fresh validation

    Issue mutation 完了後、必ず GitHub readback で本文を再取得してください。

    その後 fresh に:

    1. preflight
    2. canonical root-owned Step 2 review
    3. readiness

    を実行してください。

    古い artifact / old review result を再利用しないでください。

    needs-fix / request_changes が body-fixable である限り、max_iterations=3 の範囲で Step 4 rewrite → fresh review を自動継続してください。

    途中承認は不要です。

    #2635 の修正作業中に workflow implementation 自体を変更しないでください。


    Part B — workflow 改善を #2635 から分離して処理

    #2635 が current body-fixable defect の修正を終えた後、今回の停止原因を workflow improvement として別管理してください。

    ただし、新規 Issue を無条件に重複起票しないでください。

    まず existing Issues / PRs を検索し、特に Issue #1434 を確認してください。

    Issue #1434:
    #1434

    OWNER review:
    #1434 (comment)

    current evidence 上、#1434 は今回の taxonomy defect とほぼ同一原因を既に扱っています。

    そのため原則として #1434 を今回の「別改善Issue」として利用し、新規重複Issueは作らないでください。

    #1434 に未解決の conflicting implementation PR 等があり、同 Issue の reframe では安全に扱えないことを実コード・GitHub state で確認した場合のみ、新規 Issue を起票してください。その場合は #1434 との non-duplicate reason を本文に明記してください。

    B-1. SubAgent

    #1434 の処理前に別途 codebase-investigator を起動し、少なくとも:

    を確認させてください。

    completed まで待ってください。

    nested delegation は禁止です。

    B-2. #1434 を refinement

    comment:

    #1434 (comment)

    を direct human context anchor として .claude/skills/issue-refinement-loop を実行してください。

    #1434 の旧契約にある:

    vc_no_tests_collected -> go

    をそのまま実装しないでください。

    採用する基本方針は:

    vc_no_tests_collected -> needs_fix

    です。

    理由:

    • pytest exit 5 だけでは「意図した未実装テスト」と「selector typo / VC 設計ミス」を区別できない
    • go にすると producer の blocked を consumer が握りつぶす
    • 一方 human_judgment は body-fixable な VC defect を operator intervention に誤配送する

    したがって通常の vc_no_tests_collected は body-author-fixable な needs_fix とし、Issue rewrite / deterministic repair へ戻してください。

    意図的な「まだ存在しないテスト」は current repository が定義する明示的な:

    • baseline-expect: fail
    • preflight-scope: pr_review_only

    等の canonical mechanism を使用してください。
    どちらを使うかは use case と current policy に従ってください。

    B-3. 改善Issueに含めるべき設計原則

    今回の #2635 を regression case として利用してください。

    Issue/PR 本文が AI により生成されることを前提として、

    生成結果を正しいものと仮定するのではなく、deterministic validator が検出可能な template / schema / annotation defect は workflow-owned repair とする

    方針を明記してください。

    少なくとも以下を検討してください。

    • vc_no_tests_collected の unknown→human_judgment fallback をなくす
    • body-fixable category は operator intervention route へ送らない
    • AC numbering
    • Verification Command annotations
    • Required Design References
    • template-derived structural defect

    など、checker が十分な修正情報を持っているものは、既存の deterministic / structural repair が安全に導出できる場合は自動修正する

    安全に deterministic repair できないが reviewer feedback から修正内容が明確な場合は、通常 Step 4 issue-editor rewrite へ送る

    step_5_operator_intervention_required は今後も:

    • missing dependency
    • timeout
    • validator/runtime/internal failure
    • body retrieval failure
    • genuinely unknown environment/tool state

    等、Issue body の書き換えで解消できないものだけに限定する

    「AIがテンプレートを破る可能性がある」ことを理由に additional approval gate を増やさないでください。

    今回の目的は workflow friction を減らすことであり、

    • 新しい permission plane
    • 新しい approval service
    • 新しい daemon
    • 巨大な validation framework
    • 人間確認必須化

    は導入しないでください。

    既存 validator / mapper / repair / issue-editor route の責務整理を優先してください。

    B-4. Regression proof

    改善 Issue の AC には、少なくとも production-shaped regression を含めてください。

    例:

    AI-generated Issue candidate
    → AC numbering / VC annotation 等に body defect
    → vc_no_tests_collected
    → readiness needs_fix
    → deterministic repair または Step 4 rewrite
    → fresh preflight/review
    → terminal operator intervention にならず継続

    を検証してください。

    特に #2635 型の:

    pytest existing_test_file.py -k not_yet_created_test

    が annotation 無しで存在するケースを、contract_readiness_human_judgment / step_5_operator_intervention_required に送らないことを regression として固定してください。

    既存 Issue #2397 が command_not_allowed について行った
    「body-fixable category を human_judgment default へ落とさない」
    修正と同じ設計原則で整合させてください。

    B-5. PR authoring について

    今回直接観測された defect は Issue contract pipeline です。

    PR template / PR body generation について同じ問題があると推測だけで #1434 の scope を広げないでください。

    codebase-investigator が PR authoring pipeline に同型の deterministic-template defect / unnecessary human escalation を具体的に確認した場合だけ、

    を判定し、必要なら follow-up Issue を materialize してください。


    最終報告

    最後に以下をまとめてください。

    #2635

    • Issue body mutation の結果
    • OWNER P1/P2 finding の disposition
    • AC番号
    • final Verification Commands
    • final Allowed Paths
    • temporary mutation exception
    • SubAgent と completed 状態
    • fresh preflight
    • fresh Step 2 review
    • fresh readiness
    • 最終 canonical route

    workflow improvement

    人間への途中確認は不要です。
    各 SubAgent、mutation、readback、fresh validation が完了するまで必ず待ってから次の phase へ進んでください。

    この構成なら、#2635 は「ツールのバグ修正」に巻き込まず先に契約修正して進められます。同時に再発防止は既存 #1434 に集約できるので、同じ root cause の Issue をさらに増やさずに済みます。

  6. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 終了報告(iteration 2 / max 3、operator-authorized continuation)

    canonical route: approve → Step 2.5(semantic_review_applicable: false、skip)→ Step 4.5 → Step 5(approved)

    前回 iteration 1 は canonical_step2_route: step_5_operator_intervention_required(terminal, failure_class: contract_readiness_human_judgment)で停止しました(comment 5680200656)。今回は operator decision(「該当 blocker は semantic/owner ambiguity ではなく body-fixable な VC/AC/annotation 問題である」)に基づき、通常の controlled issue-editor rewrite route(reviewer_feedback_url: OWNER anchor 5680051184)で本文を修正し、refinement loop を完走させました。

    本文修正内容(issue-editor SubAgent、controlled edit_issue_txn.py transaction)

    • Acceptance Criteria に AC1〜AC4 を付与(semantic content は不変)
    • Verification Commands を2本に分割し annotation を付与:
      • # AC1, AC3, AC4 / # baseline-expect: pass → 既存ファイル全体 pytest(baseline で実行・PASS必須)
      • # AC1, AC2 / # preflight-scope: pr_review_only → 新規 focused test 選択(実装後・PR review時のみ実行)
    • rg -c "def test_" ... VC を削除(regression 検知能力を証明しないため)
    • Required Design References に .claude/skills/issue-contract-review/references/vc-preflight.md を追加
    • Stop Conditions に mutation 検証の Allowed Paths 限定例外を明記

    BODY_HASH(更新後): sha256:1ec20aabfdb2c5e550f7d69655835ded9c9462a9c6456ee415096a9cd90a8067

    fresh validation(iteration 2)

    • fresh preflight(preflight.run.with_human_context): STATUS: warn / NEXT_ACTION: proceed_with_notes、BLOCKERS: []
    • fresh Step 2 review(run_root_review_pipeline.py produce): canonical_step2_route: step_2_5 → compact_result.verdict: approve / next_action: proceed、REVIEWED_BODY_SHA256 は上記 BODY_HASH と一致(stale 再利用なし)
    • Step 2.5 semantic design review applicability: semantic_review_applicable: false(owner_decision_conflict なし、checker_gap_count 0、severity_tagged_anchor_findings 解消済み)→ skip、直接 Step 4.5 へ
    • fresh readiness(contract_readiness_check.py --mode preflight-static): status: go、errors: []

    既知の副次的発見(本 Issue のスコープ外、workflow follow-up 候補)

    issue-editor 実行時、vc_contract_syntax.py がサポートする comma-grouped AC marker(# AC1, AC3, AC4)と validate_issue_body.py の LP016 checker の間に不整合がある可能性が判明しました(LP016 が grouped marker を suffix ありと誤判定しうる)。今回は stacked bare marker(# AC1 を複数行)で回避したため #2635 の contract には影響していません。別途 follow-up の検討価値があります。

    スコープ境界について

    本ターンでは refinement loop の完走(承認済み終了への到達)までを行い、impl-review-loop への自動 handoff(root_entry_router.py 実行、LOOP_HANDOFF_RESULT_V1 の status: impl_ready marker 投稿を含む)は意図的に実行していません。これは直前ターンで確立された「refinement までで終了し、実装には着手しない」境界を維持するための判断です。実装フェーズへ進める場合は、別途明示的な承認のうえで impl-review-loop(または本 skill の Step 5 標準手順)を起動してください。

  7. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    推奨は、Issue #2635 をそのまま impl-review-loop の実装フェーズへ進めることです。前回の refinement は iteration 2 で approve、fresh readiness も status: go まで到達しています。さらに終了報告では、impl-review-loop への handoff だけが意図的に未実行で、「実装へ進む場合は別途明示的な承認」が必要とされています。今回のあなたの指示をその明示的な実装開始承認として扱えます。

    現行 #2635 は、最終コミット差分を test_ensure_contract_snapshot.py に限定しつつ、AC2 の mutation 検証だけ ensure_contract_snapshot.py を一時変更してよい契約になっています。また focused test は pr_review_only になっているため、実装前の no-tests-collected で止めず、実装後に必須検証する構成です。

    impl-review-loop 自体も、implementation-worker → test-runner → pr-reviewer を SubAgent に委譲し、REQUEST_CHANGES は自動で Step 1 に戻し、BEHIND や stale head も自動処理する設計です。最終 APPROVE では draft_pr_ready を出して終了し、merge は人間判断として残すため、「マージ直前まで承認不要」という今回の目的と一致します。

    以下を、すでに auto mode で動いている Claude Code にそのまま渡すのを推奨します。

    Repository: squne121/loop-protocol

    Issue #2635:
    #2635

    Issue #2635 を .claude/skills/impl-review-loop に従って、実装 → 検証 → PR review → fix loop まで自律的に実行してください。

    今回のこのプロンプトは、前回の issue-refinement-loop 完了後に必要とされていた 実装フェーズ開始の operator authorization です。

    Claude Code はすでに auto mode で起動済みです。Claude Code 自体の permission mode / auto mode / permissions 設定は変更しないでください。

    通常の実装・検証・レビュー反復について、私への途中承認確認は不要です。merge 直前まで自律的に進めてください。ただし PR の merge、auto-merge 有効化、gh pr merge 等は絶対に実行しないでください。

    1. canonical impl-review-loop から開始する

    最初に必ず現在の:

    .claude/skills/impl-review-loop/SKILL.md

    および同 skill が指定する steps/、MUST_READ references、docs/dev/workflow.md を読み、現在の main に存在する canonical procedure を正本として実行してください。

    過去の refinement 完了コメントや contract snapshot を Step 1 authorization として再利用しないでください。

    root/main thread 自身が、現行 skill の Root-Owned Synchronous Entry Transition に従い、同一の継続した invocation 内で capability preflight → live Issue fetch → current-run issue-contract-review → live readback → routing を実行し、fresh route が invoke_impl_review_loop になった場合のみ Step 1 を起動してください。

    issue_number=2635
    max_iterations=3

    として扱ってください。

    Issue 本文が current contract の正本です。前回 refinement completion report は履歴・telemetry として参照して構いませんが、fresh review の代用にはしないでください。

    2. SubAgent の実行と completion 待ちを必須にする

    impl-review-loop が規定する SubAgent delegation を省略しないでください。

    Step 1 は root/main thread から implementation-worker SubAgent に委譲してください。

    起動後は その SubAgent が completed になるまで必ず待ってください。途中結果だけを受け取って Step 2 へ進まないでください。

    Step 2 は root/main thread から test-runner SubAgent に委譲してください。

    起動後は completed になるまで必ず待ってください。検証結果が揃う前に PR review へ進まないでください。

    Step 4 は root/main thread から pr-reviewer SubAgent に委譲し、pr-review-judge の canonical review procedure を実行させてください。

    同様に completed になるまで必ず待ってください。

    REQUEST_CHANGES になった場合は、root/main thread が blocker / fix_delta を保持し、新しい Step 1 の implementation-worker へ渡してください。各 iteration で implementation-worker → test-runner → pr-reviewer のそれぞれについて completed を待ってから次へ進んでください。

    route_to_update_branch が選ばれた場合も update-branch worker の完了を待ち、その後 Step 2 / Step 4 を fresh に再実行してください。

    route_stale_head_rereview なら current PR head に対して pr-reviewer を fresh に再実行し、completed を待ってください。

    SubAgent にさらに SubAgent を起動させる nested delegation は禁止します。SubAgent の起動権限は root/main orchestrator に保持してください。

    SubAgent が単に human_review_required: true を自己申告しただけでは停止しないでください。現行 impl-review-loop の canonical routing に従って warning として扱い、iteration が残っていれば継続してください。

    3. 実装前に live state と競合を確認する

    Issue #2635 の live body、main HEAD、canonical worktree、branch、dirty state を確認してください。

    Issue Notes for Reviewer に従い、現在 OPEN の PR を fresh に確認し、特に以下への変更が同時進行していないか調べてください。

    .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

    .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py

    Issue番号の文字列検索だけで競合なしと判定せず、必要なら OPEN PR の changed files まで確認してください。

    actual Git conflict や同じコード領域を競合する進行中実装が確認された場合だけ、canonical conflict route に従ってください。単なる Allowed Paths の重複 advisory は、それ自体を停止理由にしないでください。

    root checkout では作業せず、canonical issue worktree を使用してください。

    4. #2635 のスコープを厳守する

    納品する実装差分は原則として:

    .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

    だけにしてください。

    production の:

    .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py

    を恒久変更しないでください。

    目的は production logic の修正ではなく、現在正しく実装されている staging/final digest orchestration を保護する regression test の追加です。

    real ensure_contract_snapshot() を通した focused integration regression を実装してください。

    fake remote は単に call sequence ごとに固定レスポンスを返す mock にせず、production が実際に送信した comment body を保持する state machine にしてください。

    POST で staging body S を保存し、POST 後 GET では S を返す。

    PATCH で同じ comment ID の保存 body を final body F に更新し、PATCH 後 GET と最終 authority read では F を返す。

    SHA256(S) != SHA256(F) が実際に成立するケースにしてください。

    既存 autouse fixture が verify_controlled_publisher_comment_id_binding()、patch_comment()、verify_snapshot_authority_postcondition() 等を success stub にしている場合、新規テスト内だけで必要な real implementation を復元し、既存テスト全体の fixture semantics は変更しないでください。

    成功テストは少なくとも real orchestration が materialized_go まで到達したこと、正しい published comment URL が返ること、staging digest と final digest が異なることを確認してください。

    GET 呼び出し回数など、目的と無関係な implementation detail を過剰固定しないでください。

    5. Verification Commands の phase semantics を守る

    実装前 baseline では Issue の baseline-expect: pass の VC を実行してください。

    新規 test 名を -k staging_final_digest_orchestration 等で選ぶ focused VC は preflight-scope: pr_review_only です。

    テストがまだ存在しない実装前 preflight では、この focused VC を blocking command として実行しないでください。

    実装後は focused VC と全体 VC の両方を必ず実行してください。

    既存テストファイル全体:

    uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -v

    新規 focused regression:

    uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k staging_final_digest_orchestration -v

    実際の追加テスト名に合わせて -k expression を調整して構いませんが、Issue の意図が分かる一意な名前を維持してください。

    6. AC2 mutation verification を必ず実施する

    通常 production code の状態で focused test が PASS することをまず確認してください。

    次に AC2 の検証目的に限り:

    .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py

    の PATCH 後の verify_controlled_publisher_comment_id_binding() 呼び出しだけを一時的に:

    expected_body_sha256=final_persisted_body_sha256

    から:

    expected_body_sha256=staging_post_body_sha256

    へ変更してください。

    これは Issue 本文の明示的な Allowed Paths 限定例外です。

    この一時変更は 絶対に commit しないでください。

    一時 mutation 後、focused test を実行し、テストが実際に collect / execute された上で、staging/final body hash の取り違えを検出して FAIL することを確認してください。

    SyntaxError、NameError、no tests collected、fake implementation 自体の破損などによる非ゼロ終了を AC2 の成功証拠として扱わないでください。

    mutation の検知を確認したら、production file を mutation 前の内容へ完全に復元してください。

    復元後:

    git diff -- .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py

    が空であることを確認してください。

    その後 focused test を再実行して PASS を確認し、さらに test file 全体を実行して PASS を確認してください。

    PR description には、この PASS → intentional wrong wiring で FAIL → restore → PASS の mutation verification を簡潔に記録してください。

    Issue の必須 AC を超える第二 mutation や production refactor は、この作業では追加しないでください。

    7. commit / PR / CI まで自律的に進める

    テスト実装と検証が完了したら、canonical repository workflow に従って commit / push / PR 作成まで進めてください。

    PR は Issue #2635 に明確に link してください。

    PR description には最低限、実装概要、AC1〜AC4 の対応、実行した Verification Commands、mutation verification の結果、最終 changed files、production file に mutation 差分が残っていないことを記載してください。

    PR 作成後は CI / required checks を確認し、失敗が #2635 の変更に起因する場合は iteration 内で修正してください。

    PR review は pr-reviewer SubAgent / pr-review-judge を使用し、必ず completion を待ってください。

    reviewer が REQUEST_CHANGES を返したら、人間承認を求めず fix_delta を Step 1 に送り、実装 → 検証 → review を反復してください。

    レビュー後に head が変わった場合、古い APPROVE を再利用せず fresh head をレビューしてください。

    base に遅れて BEHIND になった場合も canonical update-branch route で自動追従し、その新 head に対する Verification と PR review をやり直してください。

    8. 自動停止してよい境界

    通常の warning、advisory artifact 不整合、SubAgent の自己申告だけを理由に私へ承認を求めないでください。

    一方、現行 skill / Issue contract が定める genuine terminal condition は勝手に無効化しないでください。

    actual Git conflict、live Issue/PR 上の明示的 human veto、Issue の Stop Conditions に該当する本物の scope expansion、canonical HUMAN_REVIEW_REQUIRED route、iteration 上限到達などが発生した場合は canonical contract に従って停止し、具体的 evidence を報告してください。

    その場合でも、停止前に実行可能な非破壊的 readback / evidence collection は完了させてください。

    9. merge はしない

    ゴールは「マージ」ではなく マージ直前の review-approved PR です。

    route_loop_verdict_v2() が、current PR head に対して:

    verdict: APPROVE

    blockers: []

    かつ live mergeability が canonical approved state (CLEAN / HAS_HOOKS) を満たし、required verification / CI が完了した状態まで進めてください。

    そこに到達したら IMPL_REVIEW_LOOP_RESULT_V1.status: draft_pr_ready 相当で終了してください。

    PR を merge しないでください。auto-merge も有効にしないでください。

    10. 最終報告

    終了時は、散文だけで済ませず canonical loop result を保持した上で、人間向け要約として以下を明確に報告してください。

    Issue #2635 の最終状態、PR番号とURL、PR head SHA、iteration 数、起動した各 SubAgent と completion status、changed files、focused test / full test / CI の結果、mutation verification の PASS→FAIL→PASS 証拠、pr-reviewer の最終 verdict、live mergeability、未解決 blocker の有無、merge を実行していないこと。

    途中の人間承認は不要です。

    各 SubAgent、test、mutation、CI、fresh PR review の完了を必ず待ちながら、canonical terminal condition に到達するまで現在の auto mode のまま自律的に進めてください。

    このプロンプトのポイントは、前回の refinement 完了を「実装 authorization」として使わず、今回の人間指示を起点に fresh root transition を行わせることと、mutation のための一時 production 変更を「コミット対象」と誤解させないことです。さらに、各 implementation-worker / test-runner / pr-reviewer の completion 待ちを明文化しているため、SubAgent を投げただけで親が先へ進むケースも避けています。

  8. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-09-15T13:31:02Z)

    • PR: test: ensure_contract_snapshot() の staging/final digest 取り違えregression testを追加する #2639
    • Worktree: .claude/worktrees/issue-2635-ensure-contract-snapshot-staging-final-regression
    • Branch: worktree-issue-2635-ensure-contract-snapshot-staging-final-regression
    • Verification: 4/4 PASS(pnpm typecheck/lint/test/build)+ pytest full/-k focused 全 PASS
    • AC2 mutation verification: PASS → FAIL → PASS を手元確認済み(production file 最終 diff ゼロ)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions