Skip to content

調査: baseline_vc_preflight rg exit2 判定と allowed_paths_review_gate fingerprint 必須要件の contract-review ブロック問題の対応方針を決定する #1324

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: "none"
goal_ref: "新規ファイル追加を伴う implementation Issue で issue-contract-review の status:go が構造的に発行できず、pr-review-judge の allowed_paths_gate も indeterminate のまま解消しない問題への対応方針を決定する"
change_kind: research-only

Parent Issue

none

Outcome

baseline_vc_preflight.py の rg exit code 分類と allowed_paths_review_gate.py の fingerprint 必須要件について、原因の再現手順と対応方針候補((a)/(b)/(c))を比較し、採用案を選定して implementation Issue が起票可能な状態にする。

In Scope

  • baseline_vc_preflight.py の rg exit code 分類ロジック(exit_code==1 のみ expected_baseline_fail、exit_code==2 は category:unknown/human_judgment)の該当箇所を特定する
  • allowed_paths_review_gate.py が expected_contract_fingerprint / contract_source_kind / contract_source_id の binding 欠如時に無条件で status: indeterminate を返す該当箇所を特定する
  • Issue 実装: UpgradeSystem で quote / atomic purchase / snapshot save を実装する #1281 / PR feat: add UpgradeSystem atomic purchase core (#1281) #1318 の実例(2回連続で同一原因により contract-review go 未発行・pr-reviewer REQUEST_CHANGES が継続した経緯)を裏付け証跡として整理する
  • 対応方針候補を比較する:
    • (a) baseline_vc_preflight.py で rg exit2 かつ対象ファイルが Issue の Allowed Paths で宣言された新規追加ファイルの場合に expected_baseline_fail として扱う
    • (b) allowed_paths_review_gate.py に fingerprint 不在時のフォールバック経路(Allowed Paths 宣言と実変更ファイルの静的一致で代替判定)を追加する。ただしセキュリティ低下(worker self-report を正本にしない設計原則との整合)を伴うため、フォールバック発動条件と監査ログ要件を含めて検討する
    • (c) 別解(例: 新規ファイル用の VC 記述規約を変更する、test -f 存在確認 AC を先に挟む等)があれば提示する
  • 採用案を選定し、実装 Issue(実装: prefix)を起票する

Out of Scope

Acceptance Criteria

  • AC1: baseline_vc_preflight.py の rg exit code 分類ロジックの該当行が本 Issue 本文または comment に特定・引用されている
  • AC2: allowed_paths_review_gate.py の fingerprint 必須要件の該当行が本 Issue 本文または comment に特定・引用されている
  • AC3: 対応方針候補 (a)/(b)/(c) の比較(トレードオフ・リスク)が本 Issue 本文に記載されている
  • AC4: 採用案を実装する implementation Issue が起票され、本 Issue がその Issue 番号を link している
  • AC5: 本 Issue は close 可能、もしくは追加調査要件が明示されている

Verification Commands

# AC1
# preflight-scope: pr_review_only
$ gh issue view 0 --repo squne121/loop-protocol --json body

# AC2
# preflight-scope: pr_review_only
$ gh issue view 0 --repo squne121/loop-protocol --json body

# AC3
# preflight-scope: pr_review_only
$ gh issue view 0 --repo squne121/loop-protocol --json body

# AC4
# baseline-expect: pass
$ gh issue list --search "baseline_vc_preflight allowed_paths_review_gate" --state open --repo squne121/loop-protocol --json number,title,url

# AC5
# preflight-scope: pr_review_only
$ gh issue view 0 --repo squne121/loop-protocol --json state

Allowed Paths

  • 読み取り専用。リポジトリ変更なし(既定)

Stop Conditions

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

Handoff Contract

Notes for Reviewer

Activity

  1. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    判定: 要修正。#1324 の問題設定は正しいが、採用案を誤ると gate の安全性を落とす

    Issue #1324 は research-only Issue で、目的は「新規ファイル追加を伴う implementation Issue で issue-contract-review の status:go が出ず、pr-review-judge の allowed_paths_gate も indeterminate のまま残る問題」の対応方針選定です。コメントはまだ空なので、現時点のレビュー対象は Issue 本文、#1281、PR #1318、リポジトリ内 script、外部仕様です。

    結論として、採用すべきは「(c) 新規ファイル用 VC 規約の明確化 + (a) の極小特例」です。(b) allowed_paths_review_gate.py の fingerprint 欠落 fallback は rejectすべきです。


    根本原因の切り分け

    問題は2つに分かれます。

    1つ目は baseline_vc_preflight.py 側です。現実装では rg の no-match は exit_code == 1 のときだけ expected_baseline_fail になります。一方、その他の grep/rg 系も原則 exit_code == 1 のみ expected fail で、最後は human_judgment / unknown に落ちます。

    外部仕様上もこれは自然です。ripgrep の man page は、match ありを exit 0、match なしを exit 1、error 発生を exit 2 と定義しています。さらに exit 2 は regex syntax error のような catastrophic error と、file を読めないような soft error の両方を含むとされています。したがって、rg exit 2 を無条件に “new file expected fail” と扱うのは危険です。([Debian Manpages]1)

    2つ目は allowed_paths_review_gate.py 側です。この script は設計原則として worker report を canonical input にせず、review mode では明示的な snapshot binding と expected fingerprint を要求します。 実装上も expected_contract_fingerprint is None の時点で changed files の計算に進まず indeterminate を返します。 CLI でも --expected-contract-fingerprint は required です。

    PR #1318 の履歴はこの2つが連鎖した実例です。PR 本文上は tests/phase-transition-system.test.ts の Scope Delta が説明され、後続 iteration で corrupt state / overflow 系 blocker も修正されています。 しかし review 側では、実変更ファイルが最終的に Allowed Paths 内に収まっていることを手動確認しても、fresh fingerprint 付きの canonical gate が無いため REQUEST_CHANGES が継続しました。


    敵対的レビュー: 各案の評価

    (a) rg exit2 + Allowed Paths 新規ファイル を expected fail 扱いする案

    方向性は一部正しいですが、そのまま実装すると false-green になります。

    特に危険なのは、「exit 2 = 対象ファイル未作成」と短絡することです。ripgrep の exit 2 は regex syntax error や read error も含むため、exit_code == 2 だけを見て expected fail にしてはいけません。([Debian Manpages]1)

    さらに、現行 baseline_vc_preflight.py には _candidate_new_allowed_path_target() という、新規ファイル候補を拾う helper がありますが、これは test -f|-e|-s PATH と rg ... PATH の path を簡易抽出するだけです。rg の option / -e / --glob / -- / 複数 path / option value を安全に扱う parser としては弱いです。 しかも classify_result() の signature には allowed_paths が渡っていないため、現状の結果分類フェーズだけでは Allowed Paths 判定と結合できません。

    採用するなら、条件をかなり絞るべきです。

    • rg invocation が classify_static_command() を通過済みであること
    • path operand を既存の mature な rg path parser と同等の logic で抽出すること
    • missing と判定した path がすべて normalized Allowed Paths 配下であること
    • stderr が「対象 path が存在しない / 読めない」系に限定され、regex/config/option error ではないこと
    • classification は expected_baseline_fail ではなく、できれば new_file_missing_expected のような別 category にすること
    • invalid regex、broad path、Allowed Paths 外 path、複数 path の一部だけ missing、--glob/-e/-- を含む case を test fixture 化すること

    (b) fingerprint 欠落時に allowed_paths_review_gate.py で fallback OK する案

    これは reject です。

    この gate の価値は、「現在の Issue body と changed files がたまたま一致する」ことではなく、「レビュー対象の contract snapshot と PR head が同じ根拠に binding されている」ことです。ContractFingerprint には issue number、contract source kind/id、body hash、Allowed Paths normalized hash、base ref、base sha が含まれます。 ここを fallback で bypass すると、Issue body の後編集、worker self-report、stale snapshot の混入を検出できなくなります。

    許容できるのは、非 canonical の manual_supplementary_audit を diagnostics として出すことまでです。merge readiness の status: ok に昇格させるべきではありません。

    (c) 新規ファイル用 VC 記述規約を変える案

    これが主採用案です。

    test -f / test -d / test -s の exit 1 は現行実装でも file_not_found_expected として扱われます。 したがって、新規追加ファイルを検証する Issue では、まず test -f <new-file> を baseline-expect: fail として置き、content assertion の rg は file 作成後の runtime / regression 側に寄せるのが安全です。

    ただし既存 Issue 群との互換性を考えるなら、(a) の極小特例を併用する価値はあります。つまり、「新規ファイル missing と厳密に証明できる rg exit 2 だけ」を expected fail にする補助策です。


    #1324 に不足している受け入れ条件

    #1324 の AC は調査 Issue としては成立していますが、implementation Issue へ移すには粒度が粗いです。次を追加すべきです。

    1. rg exit 2 の分類条件を明文化すること
      exit 2 全体ではなく、「missing path が Allowed Paths 内の新規予定ファイルであることを stderr + argv parser + baseline cwd で確認できた場合」に限定する。

    2. _candidate_new_allowed_path_target() の扱いを決めること
      現状は有用そうな helper だが、classify_result() に allowed_paths が無く、完全統合されているとは言いにくい。削除・統合・置換のいずれかを implementation Issue の AC に入れるべきです。

    3. fingerprint 必須要件を弱めないこと
      allowed_paths_review_gate.py は現状の fail-closed を維持し、解決策は fallback OK ではなく、issue-contract-review が fresh go / expected fingerprint を再発行できる回復経路にする。

    4. PR files API / rename provenance の今後対応を混ぜないこと
      GitHub の PR files API は pagination され、デフォルト 30 files/page、最大 3000 files という制約があります。([GitHub Docs]2) allowed_paths_review_gate.py 側も rename provenance を重視し、filename-only を不十分として扱う設計です。 これは 調査: baseline_vc_preflight rg exit2 判定と allowed_paths_review_gate fingerprint 必須要件の contract-review ブロック問題の対応方針を決定する #1324 の主問題とは別 Issue に分離した方がよいです。

    5. 配布物・Web 実装との接続は follow-up に限定すること
      Vite の VITE_* は client bundle に露出するため秘密値を入れてはいけません。([vitejs]3) GitHub Pages で repo 配下に配布する場合は base を /<REPO>/ にする必要があります。([vitejs]4) ただし 調査: baseline_vc_preflight rg exit2 判定と allowed_paths_review_gate fingerprint 必須要件の contract-review ブロック問題の対応方針を決定する #1324 の主対象は contract-review / review-gate なので、この話は 実装: M4 Upgrade Loop の E2E / preview evidence を追加する #1283 系の follow-up に寄せるのが妥当です。


    推奨する実装 Issue 分割

    Issue A: new-file VC preflight の決定論化

    対象は baseline_vc_preflight.py とその tests。目的は、新規ファイル追加 Issue の baseline VC が human_judgment で詰まらないようにすること。

    採用仕様:

    • generator 側は新規 file の existence check として test -f <path> を優先生成する。
    • rg exit 2 は missing Allowed Paths file と証明できる場合だけ new_file_missing_expected として扱う。
    • regex syntax error、config error、permission error、Allowed Paths 外 path、broad search は従来通り blocked / human_judgment。
    • classify_result() に allowed_paths / cwd / parsed argv evidence を渡すか、pre-execution static classification 側に寄せる。
    • _candidate_new_allowed_path_target() は current parser のまま使わず、成熟した path parser に置換する。

    Issue B: fingerprint refresh path の明文化

    対象は issue-contract-review 側。目的は、Allowed Paths 更新後に fresh go と expected fingerprint を再発行できるようにすること。

    採用仕様:

    • allowed_paths_review_gate.py の fingerprint 必須要件は維持する。
    • expected_contract_fingerprint 欠落時の canonical status: ok fallback は作らない。
    • 欠落時は “contract refresh required” のような action-oriented reason を返す、または orchestrator が issue-contract-review 再実行を決定論的に呼ぶ。
    • fresh fingerprint が発行された後のみ allowed_paths_gate.status: ok を許可する。

    GitHub に貼るコメント案

    敵対的レビュー: #1324 の採用方針

    判定: 要修正。ただし問題設定は正しい。

    #1324 は、Issue #1281 / PR #1318 で発生した「new file baseline VC が rg exit 2 で human_judgment になり、issue-contract-review の go が出ず、結果として pr-review-judge の allowed_paths_gate が fingerprint 欠落で indeterminate のまま残る」問題を正しく捉えている。

    ただし、採用案はそのままでは危険。

    Reject: 案(b) allowed_paths_review_gate の fingerprint 欠落 fallback

    allowed_paths_review_gate.py は worker report を canonical input にせず、expected contract fingerprint / contract_source_kind / contract_source_id の binding を merge-readiness の前提にしている。この設計を fallback で ok に昇格させると、stale Issue body、後編集された Allowed Paths、worker self-report の混入を検出できなくなる。

    許容できるのは manual_supplementary_audit を diagnostics として出すことまで。canonical status は indeterminate のまま維持すべき。

    採用: 案(c) を主、案(a) は極小特例

    新規ファイル追加 Issue では、まず test -f <new-file> を baseline-expect fail として生成する規約に寄せる。現行 preflight は test -f/-d/-s の exit 1 を file_not_found_expected として扱えるため、これが最も安全。

    rg exit 2 については、無条件に expected fail にしてはいけない。ripgrep の exit 2 は missing file だけでなく regex syntax error、read error、config/option error 等も含むため、次の条件を満たす場合だけ new_file_missing_expected として分類する。

    • command が static policy を通過済み
    • path operand を安全な argv parser で抽出済み
    • missing path がすべて normalized Allowed Paths 配下
    • stderr が missing path/read target 系に限定される
    • invalid regex / unsupported option / broad path / Allowed Paths 外 path は従来通り blocked または human_judgment

    Implementation Issue は2本に分割推奨

    1. 実装: new-file VC preflight を missing Allowed Paths file として決定論的に分類する

      • baseline_vc_preflight.py と tests が対象
      • test -f 優先生成
      • rg exit 2 は missing Allowed Paths file と証明できる場合だけ特例
      • _candidate_new_allowed_path_target() は現状の簡易 parser のまま使わず、統合・置換・削除のいずれかを明示
    2. 実装: issue-contract-review fingerprint refresh path を明示する

      • fingerprint 必須要件は弱めない
      • expected fingerprint 欠落時は fallback OK ではなく、fresh contract-review go を再発行する回復経路を作る
      • allowed_paths_gate.status: ok は expected fingerprint と computed fingerprint が一致した場合のみ許可

    この分割にしないと、rg exit 2 の分類修正と Allowed Paths gate の信頼境界変更が混ざり、レビュー不能になる。

    このままなら、#1324 は「調査 Issue」としては進められますが、implementation Issue 起票前に (b) を明示 rejectし、(c)+(a極小特例) の採用仕様まで本文に固定した方がよいです。

  2. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  3. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-04T11:07:05Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1324
      body_sha256: "sha256:c6f1950eecffca6d3702d431c2d0296a15300cc76a19aa56c467b24ef22a62b2"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  4. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: https://github.com/squne121/loop-protocol/issues/1324#issuecomment-4881737852
        generated_at: '2026-07-04T11:16:00Z'
        body_sha256: sha256:c6f1950eecffca6d3702d431c2d0296a15300cc76a19aa56c467b24ef22a62b2
      metadata:
        title_prefix_ready: true
        phase_label_ready: true
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: '2026-07-04T11:16:00Z'
  5. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    完了報告: 採用方針の確定と implementation Issue の起票

    AC1: baseline_vc_preflight.py の rg exit code 分類ロジックの該当箇所

    ファイル: .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py

    • classify_result() 関数定義: L2067-2314
    • rg no-match の唯一の expected fail 経路(L2245-2246):
      # expected baseline fail patterns
      # rg with no match returns 1
      if "rg " in command and exit_code == 1:
          return "expected_fail", "expected_baseline_fail", "go", None, "baseline_fail_expected"
    • generic grep/rg 系 exit_code==1 分岐(L2287-2305): grep/rg/ag/ack/fgrep/egrep を含むコマンドで exit_code == 1 の場合に expected_fail とするが、grep error pattern(No such file or directory / Invalid regular expression 等)を検出した場合は human_judgment に倒す。
    • 最終 unknown/human_judgment fallback(L2307-2314):
      # Unknown: cannot classify
      return (
          "human_judgment",
          "unknown",
          "human_judgment",
          "Unable to automatically classify exit code",
          "baseline_fail_expected"
      )
    • exit_code == 2 を明示的に扱う分岐は classify_result() 内に存在しない(_is_pytest_invocation 経路の pytest exit 4/5 判定を除く)。したがって rg が missing file で exit 2 を返すケースは無条件に上記の最終 fallback(human_judgment/unknown)に落ちる。
    • _candidate_new_allowed_path_target()(L1701-1739): strict mode 専用の helper であり、test -f|-e|-s PATH と rg ... PATH の非オプション positional path のみを拾う簡易 parser。classify_result() 側では未使用(strict mode の pre-execution 分岐 L2844-2866 でのみ使用され、baseline-expect 未付与かつ新規 Allowed Path file を検出した場合に missing_baseline_expect_for_new_allowed_path として blocked にする)。baseline-expect: fail が付与された後の実行結果分類には接続されていない。

    AC2: allowed_paths_review_gate.py の fingerprint 必須要件の該当箇所

    ファイル: .claude/skills/pr-review-judge/scripts/allowed_paths_review_gate.py

    • evaluate() 関数定義: L647-765
    • contract_source_kind/contract_source_id 欠落時の fail-closed(L671-675):
      if not self.contract_source_kind or not self.contract_source_id:
          result.status = GateStatus.INDETERMINATE.value
          result.reason = "contract_source_kind/source_id missing (merge-blocking)"
          result.errors.append(result.reason)
          return result
    • expected_contract_fingerprint 欠落時の fail-closed(L677-681):
      if self.expected_contract_fingerprint is None:
          result.status = GateStatus.INDETERMINATE.value
          result.reason = "expected_contract_fingerprint_missing (merge-blocking)"
          result.errors.append(result.reason)
          return result
    • fingerprint mismatch 時の stale_snapshot(L692-696):
      if self.expected_contract_fingerprint != result.contract_fingerprint:
          result.status = GateStatus.STALE_SNAPSHOT.value
          result.reason = "contract fingerprint diverged from snapshot (stale_snapshot, merge-blocking)"
    • CLI parser(main(), L768-818): --expected-contract-fingerprint / --contract-source-kind / --contract-source-id はすべて required=True。

    AC3: 対応方針候補 (a)/(b)/(c) の比較

    • (a) rg exit2 + Allowed Paths 新規ファイルの極小特例: 採用(極小特例として)。ただし exit 2 は regex syntax error / read error 等も含むため無条件では危険。classify_static_command() 通過済み・path operand を安全な argv parser で抽出済み・missing path が全て normalized Allowed Paths 配下・stderr が missing/read-target 系に限定、を全て満たす場合のみ専用 category(new_file_missing_expected 等)とする。
    • (b) allowed_paths_review_gate.py の fingerprint 欠落 fallback: reject。この gate の価値は「Issue body と changed files がたまたま一致すること」ではなく「レビュー対象の contract snapshot と PR head が同じ根拠に binding されていること」であり、fallback で bypass すると stale snapshot / worker self-report混入を検出できなくなる。許容できるのは診断用の補助情報提示までで、status: ok への昇格はしない。
    • (c) 新規ファイル用 VC 記述規約の明確化: 主採用案。新規ファイル追加を伴う Issue では test -f <new-file> を baseline-expect: fail で先に置くことを規約化し、content assertion の rg は runtime/regression 側に寄せる。(a) の極小特例は既存 Issue 互換のための補助策として併用する。

    AC4: implementation Issue の起票

    重複起票がないことを check_issue_overlap.py(decision: safe_new_issue)で確認した上で、以下 2 本を起票済み。

    いずれも本 Issue(#1324)を Refs として明記済み。

    AC5: close 可能性

    本 Issue は research-only(change_kind: research-only)であり、Out of Scope で明示した通りコード変更自体は対象外。AC1〜AC4 が本コメントで満たされ、追加調査要件はない。implementation は起票済みの #1328 / #1329 で扱う。


    採用判断まとめ

    • reject: (b) fingerprint 欠落 fallback
    • adopt: (c) 新規ファイル VC 規約の明確化(主) + (a) 極小特例(補助)
    • fingerprint 必須要件(expected_contract_fingerprint/contract_source_kind/contract_source_id)は一切弱めない

    追加調査要件なし。implementation は起票済み Issue(#1328 / #1329)で扱う。本 Issue を close する。

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions