Skip to content

実装: issue-contract-review の VC preflight に同一command dedup/replay と bounded parallel execution を追加する - #1508

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-1338-issue-contract-review-vc-preflight-comma
Jul 14, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-1338-issue-contract-review-vc-preflight-comma

Conversation

@squne121

Copy link
Copy Markdown
Owner

Summary

Issue #1338 の実装: baseline_vc_preflight.py に同一 command の dedup/replay 機構(execution_key_hash ベース)と、安全な read-only 述語(rg/grep/egrep/fgrep、exact test -f|-d|-s)に限定した bounded parallel execution(--max-workers)を追加した。dedup replay された result も各 AC 自身の raw_command/annotation から classification/decision を都度再計算し、source からのコピーは行わない。run_contract_review_once.py は named constant _VC_PREFLIGHT_MAX_WORKERS(初期値 2)を baseline_vc_preflight.py へ --timeout-seconds / --max-workers として明示的に渡す。

Issue #1333 の外部レビューで確認された、同一の重い VC コマンド(例: uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py)が複数 AC から重複参照される構造による総実行時間の問題を、dedup/replay と bounded parallel execution で緩和する。

Checks

Schema Change Applicability

  • decision: schema_change
  • reason: baseline_vc_preflight/v1 の JSON 出力に新規フィールド(execution_key_hash、dedup 時の dedup object、runner の新規値 dedup_replay)を追加する。既存フィールド(status/results[].classification/decision/command_hash 等)の意味・型は変更していない、後方互換な追加変更。

Schema Consumer Inventory

baseline_vc_preflight/v1 の results[] エントリに以下フィールドを追加した(既存フィールドの削除・改名・型変更なし、後方互換な追加のみ)。

# before
{
  "ac": "AC1",
  "raw_command": "...",
  "command_hash": "sha256:...",
  "runner": "exec",  # "exec" | "skipped"
  "classification": "...",
  ...
}
# after
{
  "ac": "AC1",
  "raw_command": "...",
  "command_hash": "sha256:...",
  "execution_key_hash": "sha256:...",  # 新規: dedup key
  "runner": "exec",  # "exec" | "skipped" | "dedup_replay"(新規値)
  "classification": "...",
  "dedup": {"source_command_hash": "...", "source_execution_key_hash": "..."},  # 新規: dedup_replay 時のみ
  ...
}
Consumer ファイル 更新有無 備考
.claude/skills/issue-contract-review/scripts/run_contract_review_once.py 更新した --max-workers / _VC_PREFLIGHT_MAX_WORKERS を明示的に argv 追加(AC9)。既存の status/results 参照ロジックは変更なし
.claude/skills/impl-review-loop/scripts/adjudicate_vc_result.py 更新不要 classification/decision/category を参照するのみ。runner フィールドの厳密な enum 照合はしていないため新規値 dedup_replay を追加しても影響なし
.claude/skills/impl-review-loop/scripts/triage_contract_blockers.py 更新不要 runner_env_delta を参照するのみで、runner フィールド自体は参照していない
.claude/skills/issue-contract-review/scripts/contract_readiness_check.py 更新不要 results/status を参照するのみで runner フィールドの厳密な enum 照合はしていない
.claude/skills/issue-refinement-loop/scripts/reviewer_claim_replay.py 更新不要 同上、runner フィールドの enum 照合はしていない

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
dedup replay は元の AC の classification/decision をコピーせず、各 AC 自身の raw_command/annotation から都度再計算する yes test_ac2_dedup_replay_recomputes_classification_per_ac_and_keeps_own_identity(baseline-expect annotation の違いで AC1/AC2 の classification が意図的に異なることを固定)
bounded parallel execution の対象は rg/grep/egrep/fgrep と exact test -f/-d/-s のみで、pnpm/uv run pytest/pytest/gh/git/github_metadata_assert は常に直列実行される yes test_ac5_parallel_eligible_predicate_allows_only_safe_read_only_shapes / test_ac5_parallel_eligible_predicate_excludes_stateful_or_ambiguous_shapes
--max-workers 省略時(デフォルト 1)は既存の完全直列実行と出力が一致する(後方互換) yes test_ac4_default_max_workers_matches_explicit_serial_output
出力 results の順序は実行完了順ではなく Issue 本文上の command 順を維持する yes test_ac7_result_order_matches_issue_body_command_order
1 コマンドの timeout が他コマンドの結果を破壊しない yes test_ac8_timeout_on_one_command_does_not_corrupt_others

Notes

squne121 and others added 2 commits July 14, 2026 06:35
…ded parallel executionを追加する

baseline_vc_preflight.py に execution_key_hash(argv/cwd/env/timeout の
SHA-256)ベースの dedup/replay 機構と、rg/grep/egrep/fgrep および exact
test -f|-d|-s に限定した --max-workers による bounded parallel execution
を追加する。dedup replay された result も、各 AC 自身の raw_command /
annotation から classification / decision を都度再計算し、source からの
コピーは行わない。run_contract_review_once.py は
_VC_PREFLIGHT_MAX_WORKERS(初期値2)を baseline_vc_preflight.py へ
--max-workers として明示的に渡す。

Closes #1338

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…行を両立させる

baseline_vc_preflight.py で、main 側 (#1497: adjudicate_vc_result.py の current PASS 認証を
regression-gate 以外の VC 種別へ拡張) が追加した classify_result() への evidence_mode 引数と
result item の certified_target_paths フィールドが、本ブランチ (#1338: 同一 command の
dedup/replay と bounded parallel execution) が導入した deferred job batch 実行フェーズでは
未反映のまま欠落する競合だったため、以下の方針で解消した。

- 2 箇所のコンフリクトは HEAD 側 (#1338 の pending_jobs/継続処理と batch dedup 実行フェーズ)
  を正として採用し、旧来の即時 classify_result 呼び出し・inline result dict 構築 (origin/main
  側、#1497 の変更を含む) は _build_result_item() ヘルパーへの統合によって既に重複しているため
  破棄した
- _build_result_item() に certified_target_paths パラメータとフィールドを追加し、即時実行
  パス・batch 実行パスの両方の呼び出し箇所に certified_target_paths 算出ロジックを追加した
- batch 実行フェーズの classify_result() 呼び出しに evidence_mode=args.evidence_mode を追加し、
  current-head モードでの証跡拡張が dedup/並列実行パス経由でも機能するようにした

検証: test_baseline_vc_preflight_current_head_non_regression.py (29 pass, CLI 経由の
certified_target_paths アサーションを含む)、test_baseline_vc_preflight.py (139 pass, 1 skip)、
test_baseline_vc_preflight_dedup.py / _parallel.py / _default_seconds.py / _pnpm_no_tty.py
(43 pass)、test_adjudicate_vc_result_non_regression_gate.py (7 pass)、Issue #1338 全 AC の
Verification Commands (dedup/parallel/wrapper_wiring, 計 18 pass) を実行し全 PASS を確認した。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1508/

The preview will be removed when this PR is closed.

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2 (pr-review-judge)

verdict: APPROVE / merge_ready: true

reviewed_head_sha: d9969e1

確認事項

  • Mergeability: MERGEABLE / mergeStateStatus: CLEAN
  • CI: 全required checks SUCCESS(head SHA一致確認済み)
  • Contract snapshot: Issue #1338 の CONTRACT_REVIEW_RESULT_V1 status: go と body_sha256一致、staleでない
  • Allowed Paths: 変更5ファイル全てIssue #1338のAllowed Paths内(違反なし)
  • AC1-AC9: diffレベルで個別検証済み(dedup key分離、classification再計算、parallel-eligible述語の安全性、result順序保持、timeout分離、--max-workers配線)、全てtest-runnerでもPASS確認済み
  • PR #1497(certified_target_paths/evidence_mode)との統合: _build_result_item()両呼び出し経路で正しく保持されていることを確認、regressionなし
  • Overlap preflight判断の再確認: #1053はAllowed Paths上の将来的な同一ファイル重複候補だが未実装(実装時にrebase注記推奨)。#944/#1396は広いglobによる誤検知。#1488はCLOSED。人間によるwrapper迂回判断は妥当だったと判断

allowed_paths_gate

status: ok
changed_files:
  - .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
  - .claude/skills/issue-contract-review/scripts/run_contract_review_once.py
  - .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_dedup.py
  - .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
  - .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py
violations: []

required_auto_actions: []
blockers: []

@squne121

Copy link
Copy Markdown
Owner Author

調査結果です。GitHubへの書き込み、レビュー送信、コード変更は行っていません。

PR #1508 敵対的レビュー

判定

REQUEST_CHANGES / merge_ready: false

  • P0 Blocker: 2件
  • P1 Major: 2件
  • P2 Minor: 2件

PRの狙いである「重複した重いVCの実行時間短縮」は妥当です。しかし現在の実装は、コマンド呼び出しの同一性を、観測対象の状態の同一性と誤認しています。そのため、VC間でファイルシステム等が変化するケースでは誤った実行結果をreplayします。

さらに並列実行対象のgrep系は、引数形状や入力元を検証せず、標準入力・FIFO・デバイスを読むコマンドまで「safe read-only」として並列化します。

CIはhead SHA d9969e1... で成功しており、PR内の自動レビューもAPPROVE判定です。ただし追加テストは後述の状態変化・標準入力・実並列性を検証していないため、green CIは以下の欠陥を否定しません。


P0-1: execution_key_hashは実行結果の同一性を保証しない

問題

execution_key_hashに含まれるのは次の4要素だけです。

  • argv
  • cwd
  • runner側で追加した環境変数
  • timeout

実装のdocstringは、キーが一致すれば「identical conditions」であり、安全に結果をreplayできると断定しています。

しかし、コマンド結果は次の状態にも依存します。

  • ファイルやディレクトリの存在・内容
  • Git worktree/index
  • pytest、Python、pnpm等が生成するキャッシュや成果物
  • 外部APIや時計等の外部状態
  • 先行VCが作った副作用

しかもこのpreflightは、python3 -m py_compile、pytest、pnpm build/test等を実行可能にしています。 Python公式仕様上、py_compileは通常__pycache__以下に.pycファイルを書き出します。([Python documentation]1)

再現可能な反例

空の一時fixtureにstate_probe.pyだけを作り、次のVCを並べます。

# AC1
$ test -d fixture/__pycache__

# AC2
$ python3 -m py_compile fixture/state_probe.py

# AC3
$ test -d fixture/__pycache__

Issue本文順に実行する既存仕様なら、raw exit outcomeは次の順です。

AC1: fail
AC2: pass(__pycache__を生成)
AC3: pass

ところが現実装は、同じtest -dを1つのexecution keyに集約します。最初の実行結果を、後のAC3にもreplayします。

結果は--max-workersによってさらに変わります。

  • --max-workers 1

    • unique command順にtest→py_compile
    • AC3へAC1の古いfailをreplay
  • --max-workers 2

    • 全serial commandを先に実行してからparallel commandを実行
    • py_compile→test
    • 本来先に観測すべきAC1まで、生成後の状態を観測してpassし得る

つまり、同じIssue本文からworker数によって観測結果が変わり、どちらもIssue本文の逐次意味と一致しません。並列分割が「serial全部→parallel全部」であることは実装から確認できます。

根本原因

Issue #1338自身が、「同じnormalized commandなら結果を共有できる」という前提を契約化しています。

これは呼び出しidentityの契約であって、観測snapshotのidentityではありません。したがってPRだけでなく、Issue契約も修正対象です。

必須修正

実行計画にstate epoch/barrierを導入してください。

execution_key =
  state_epoch
  + normalized argv
  + cwd
  + effective environment
  + timeout

少なくとも次をbarrierとしてepochを進める必要があります。

  • pytest / py_compile
  • pnpm typecheck / lint / test / build
  • Git状態またはファイル状態を変え得るコマンド
  • 外部状態を観測するコマンド
  • 純粋性を証明できないコマンド

dedupは、同一epoch内の、入力pathが検証済みの純粋な観測コマンドだけに限定すべきです。

並列実行も「全serial→全parallel」ではなく、Issue本文順に作った連続したpure batchだけを並列化し、serial/barrier commandを跨いで並べ替えてはいけません。

必須テスト

実際の一時ディレクトリで上記test → py_compile → testを実行し、次を固定してください。

  • AC1 fail、AC2 pass、AC3 pass
  • worker数1と2で意味上の結果が一致
  • AC1とAC3は同じcommandでも異なるepochとなり、dedupされない
  • 副作用を挟まない隣接duplicateのみ1回に集約される

P0-2: grep系のparallel predicateが標準入力・FIFO・デバイスを許可している

問題

並列対象判定は、コマンド名のbasenameが次のいずれかなら無条件でtrueです。

rg
grep
egrep
fgrep

grepについては引数数、path operand、標準入力、再帰、特殊ファイルを検証していません。

さらに既存のbroad path検査はrg専用であり、コードコメントでもgrep / egrep / fgrepは対象外と明記されています。

run_command()はstdinを明示していません。Pythonのsubprocessではstdin=Noneがデフォルトであり、リダイレクトされず親プロセスの標準入力を継承します。 ([Python documentation]2)

GNU grepの仕様では次の動作になります。

  • 入力ファイルがなければ標準入力を読む
  • -も標準入力を意味する
  • コマンドライン上のdevice、FIFO、socketはデフォルトで読み得る
  • grep -qはエラーが存在しても、一致を見つければexit 0を返し得る ([GNU]3)

反例

次のコマンドは現在parallel eligibleです。

$ grep -q first-pattern
$ grep -q second-pattern

両方が同一の継承stdinを同時に読む可能性があります。stdinがregular fileの場合には共有offsetの競合、pipeやterminalの場合には読み取り競合またはtimeoutが発生し得ます。

次も許可されます。

$ grep pattern -
$ grep pattern /path/to/fifo
$ grep -R pattern .

これらを単に「read-only」と分類しても、決定論的・独立・並列安全とは限りません。

PR #1497では、grep系についてpath parserが存在しないことを理由にcurrent-head PASS認証対象から除外し、-qの部分成功+I/O errorもfail-closedに修正しています。今回のpredicateはその設計判断と整合していません。

必須修正

初期版ではgrep / egrep / fgrepをparallel allowlistから外してください。

並列化する場合は専用parserを実装し、最低限次を要求すべきです。

  • 明示されたpath operandが1つ以上ある
  • -を拒否
  • 絶対path、..、repo外pathを拒否
  • regular fileまたは検証済みのbounded directoryだけを許可
  • FIFO、device、socketを拒否
  • recursionは明示されたAllowed Paths内だけ
  • stderrが非空のquiet successをfail-closed
  • subprocess側は原則stdin=subprocess.DEVNULL

必須テスト

以下がexecutorへsubmitされないことを固定してください。

grep pattern
grep pattern -
grep -R pattern .
grep pattern <FIFO>
grep -q pattern missing-file existing-match-file

P1-1: 「default 1は既存と出力・挙動が一致する」というAC4をテストできていない

PRは、--max-workers省略時は既存の完全直列実行と出力が一致すると主張しています。

しかしテストが比較しているのは次の2つだけです。

新実装のdefault
新実装の--max-workers 1

base commitや旧実装との比較ではありません。

実際には次の差があります。

  1. 全resultにexecution_key_hashが追加されるため、字面上の出力一致ではない
  2. 旧実装は各コマンドをIssue本文順に即時実行していた
  3. 新実装は通常コマンドを全てpendingにし、第一走査後に実行する
  4. github_metadata_assertは第一走査中に即時実行されるため、通常コマンドとの相対順序が変わる

旧実装の即時実行経路はbase commitで確認できます。 新実装のpending化とmetadata assertionの即時実行は現headで確認できます。

必須修正

  • max_workers=1では旧来の逐次意味を完全に維持する
  • または、全コマンドを単一のordered planに入れ、特殊経路もbarrierとして扱う
  • 「output-identical」は「新規additive fieldとvolatile fieldを除いたsemantic equivalence」等へ契約を正確化する

必須テスト

base SHA 3ad166c...相当のlegacy implementationと、同一fixtureを差分比較してください。

除外可能なのは明示的に次だけです。

  • generated_at
  • duration_ms
  • additiveな新規provenance field

exit code、classification、decision、実行呼び出し順は一致させる必要があります。


P1-2: テストが並列実行の主要主張を証明していない

現在のテストには以下の不足があります。

executor test

ThreadPoolExecutor(max_workers=2)が構築されたことしか確認していません。実際に2件が重なって実行されたか、同時実行数が2以下かは検証していません。

result-order test

結果のAC順は確認していますが、コマンドごとの完了順を意図的に逆転させていません。したがってas_completed()経路への回帰検出力が弱いです。 Python公式仕様上、as_completed()は完了した順にFutureを返します。([Python documentation]4)

timeout test

実プロセスのtimeoutではなく、monkeypatchが手作業で(-1, "", "timeout", ...)を返しているだけです。

dedup test

状態不変の隣接rgだけを対象としており、間に状態変更コマンドが入るケースがありません。

必須追加テスト

  • threading.BarrierまたはEventで2タスクが実際に重なること
  • active worker counterで1 < max_active <= max_workers
  • sleep時間を逆転させてもresultsがIssue順になること
  • 実subprocess timeoutで他resultが壊れないこと
  • stateful barrierを跨ぐduplicateがdedupされないこと
  • stdinを使うgrepがparallel対象外になること

P2-1: --max-workersが正値でも実用上の上限でも検証されない

argparseは任意の整数を受け入れます。

実装上は次の挙動です。

  • 0や負数: エラーにせずserial扱い
  • 非常に大きい数: 入力された値をそのままThreadPoolExecutorへ渡す

wrapperは2固定なので通常経路の危険は限定されますが、直接CLI実行時には「bounded」の上限が利用者入力だけです。wrapperの設定値は2であることを確認しています。

修正

def bounded_worker_count(value: str) -> int:
    parsed = int(value)
    if not 1 <= parsed <= 8:
        raise argparse.ArgumentTypeError("--max-workers must be between 1 and 8")
    return parsed

0、負数、上限超過のCLIテストを追加してください。


P2-2: dedup provenanceからreplay元のACを一意に特定できない

dedupに含まれるのは次だけです。

{
  "source_command_hash": "...",
  "source_execution_key_hash": "..."
}

同じraw commandが複数ACに存在する場合、全て同じcommand_hashです。そのため監査時に、どのAC・line・result indexがsource executionだったのかを特定できません。

Issue #1338の初期敵対的レビューではsource_indexとsource_acの追加も推奨されていましたが、最終契約には取り込まれていません。

修正

"dedup": {
  "source_result_index": 0,
  "source_ac": "AC1",
  "source_line": 123,
  "source_command_hash": "sha256:...",
  "source_execution_key_hash": "sha256:..."
}

関連Issue・PRとの整合性

Issue #1333 / PR #1335

timeout値を90秒、wrapper全体を600秒へ引き上げた先行修正です。重複実行の根本対策は明示的に#1338へ分離されていました。

Issue #1328 / PR #1340

同一の重いpytest VCが多数のACから参照され、timeout引き上げ後も累積時間が問題になることが#1338の動機です。一方、#1328/#1340では誤ったexpected-fail化を避けるため、argv/path/stderrを厳密に検証する方向が採用されています。

PR #1497

current-head PASSについて、単なるexit 0ではなく、closed allowlist、path scope、実ファイル存在、stderr空を要求する設計へ修正されています。今回のgrep無条件parallel化は、その安全設計より緩い境界になっています。


修正後の推奨アーキテクチャ

1. Issue本文順にExecutionPlanを構築
2. 各commandを分類
   - STATIC
   - PURE_OBSERVATION
   - SERIAL_BARRIER
   - EXTERNAL_OBSERVATION
3. PURE_OBSERVATIONだけを連続batch化
4. batch内でのみdedup
5. execution keyにepochを含める
6. serial/external commandの前後でepochを進める
7. pure batchのみbounded parallel実行
8. resultはoriginal indexへ投影

初期のparallel allowlistは次まで絞るのが妥当です。

- exact test -f|-d|-s <validated repo-relative path>
- rg <validated pattern and validated repo-relative regular-file operands>

grep / egrep / fgrepは専用path parserとstdin拒否が完成するまで除外すべきです。


最小のマージ条件

  1. dedupをstate epoch内へ限定する
  2. serial commandを跨いだreplayを禁止する
  3. Issue本文上のbarrier順序を維持する
  4. grep系をparallel対象から除外する、または入力pathを厳格に検証する
  5. subprocess stdinを明示的に閉じる
  6. legacyとのsemantic differential testを追加する
  7. 実並列性と逆完了順を検証する
  8. --max-workersを正値・上限付きにする

現状は、速度改善と引き換えにVCの観測意味を変える可能性があります。contract reviewの安全ゲートであることを考えると、P0の2件を解消するまではマージすべきではありません。

独立したローカルテスト実行は行っていません。確認範囲はPR headのコード、Issue/PR履歴、コメント、GitHub Actions結果、およびPython・GNU grep・pytestの公式資料です。GitHubへのレビュー投稿も行っていません。

敵対的レビュー(REQUEST_CHANGES)で指摘されたP0/P1/P2を修正する。

- P0-1: execution_key_hash に state_epoch を追加し、pytest/py_compile/pnpm等の
  非純粋(barrier)コマンド実行後にepochを進めることで、状態変化を跨ぐ
  dedup誤replayを防止する。
- P0-2: 並列/dedup対象からgrep/egrep/fgrepを除外し、rgはpath operand必須・
  stdin("-")拒否・絶対パス/repo外/FIFO・device・socket拒否・Allowed Paths
  bounded directoryのみ許可という検証を追加する。run_command()に
  stdin=subprocess.DEVNULLを明示する。
- P1-1: 全VCを一括デリファードするpost-loop方式を廃止し、Issue本文順の
  単一パス実行に統一する。state-epoch対応の実行キャッシュと、連続する
  純観測VCのみを対象にしたbounded parallel batchを導入し、
  github_metadata_assert等の即時実行経路との相対順序を保持する。
- P1-2: 実際の同時実行を証明するBarrierテスト、完了順序が逆転しても
  Issue本文順を維持するテスト、実subprocessタイムアウトテスト、
  epoch跨ぎdedup非対象テストを追加する。
- P2-1: --max-workers に bounded_worker_count(1-8)のargparse型を追加する。
- P2-2: dedup provenanceに source_result_index/source_ac/source_lineを追加する。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

敵対的レビュー(REQUEST_CHANGES)で指摘されたP0/P1/P2をすべて修正し、コミット e4fb631 として push しました。

P0-1: execution_key_hash の state epoch / barrier

compute_execution_key_hash() に state_epoch を追加(state_epoch + normalized_argv + cwd + effective_environment + timeout)。pytest / py_compile / pnpm / git 等の非純粋コマンド(barrier)実行後に epoch を進め、github_metadata_assert の外部観測実行後も epoch を進める。dedup は同一 epoch 内の純観測コマンド(test -f|-d|-s PATH、または検証済み bounded path を持つ rg)のみに限定した。

実処理は post-loop 一括デリファード方式を廃止し、Issue 本文順の単一パス実行+状態対応の実行キャッシュに再設計(P1-1 とも連動)。

テスト: test_p0_1_state_epoch_barrier_prevents_stale_dedup_replay(実一時ディレクトリで test -d fixture/__pycache__ → python3 -m py_compile → test -d fixture/__pycache__ を実行し、AC1 fail / AC2 pass / AC3 pass を --max-workers 1 と 2 の両方で固定)、test_p0_1_execution_key_hash_changes_with_state_epoch。

P0-2: grep 系 parallel predicate の無条件許可を修正

  • 並列/dedup 対象の allowlist から grep / egrep / fgrep を除外(rg のみ許可)。
  • rg は専用 path parser(_validate_rg_parallel_command / _rg_operand_is_safe_target)で以下を要求: 明示された path operand が1つ以上、-(stdin)拒否、絶対path・..・repo外拒否、regular file または Allowed Paths 内の bounded directory のみ許可、FIFO/device/socket 拒否。
  • run_command() に stdin=subprocess.DEVNULL を明示。
  • 並列実行結果が exit 0 かつ stderr 非空の場合は fail-closed(exit_code を 1 に上書き)。

テスト: test_p0_2_grep_family_never_parallel_eligible_even_with_valid_path、test_p0_2_rg_without_path_operand_is_not_eligible、test_p0_2_rg_explicit_stdin_operand_is_not_eligible、test_p0_2_rg_broad_repo_root_path_is_not_eligible、test_p0_2_rg_fifo_path_operand_is_not_eligible、test_p0_2_rg_missing_path_operand_target_is_not_eligible、test_p0_2_run_command_uses_stdin_devnull。

P1-1: max-workers=1 の legacy 出力一致・相対順序保持

post-loop 一括デリファード方式(全 VC を先にパース→まとめて実行)を廃止し、Issue 本文順に inline 実行する単一パス方式へ再設計。github_metadata_assert(即時実行経路)の前後にある通常 VC との相対実行順序が崩れないよう、barrier 検出時・github_metadata_assert 実行直前に並列バッチを flush する。

テスト: test_p1_1_max_workers_one_semantically_equivalent_to_legacy_baseline(e375b3a1^=Issue #1338 導入前の baseline_vc_preflight.py を legacy module としてロードし、additive/volatile field を除いた semantic equivalence を比較)、test_p1_1_execution_order_matches_issue_body_order_across_immediate_and_deferred_paths(rg→github_metadata_assert→rg の実行呼び出し順が Issue 本文順と一致することを固定。旧実装ではこの順序が壊れていた)。

P1-2: 並列実行主張の実証テスト

  • test_p1_2_proves_actual_concurrent_execution_via_barrier: threading.Barrier(2) で実際に2スレッドが同時到達することを証明(直列であれば timeout してテスト失敗)。
  • test_p1_2_reversed_completion_order_preserves_issue_body_result_order: 先頭コマンドの完了を意図的に遅延させても results が Issue 本文順であることを確認。
  • test_p1_2_real_subprocess_timeout_does_not_corrupt_sibling_result: 実 sleep プロセスに対する実 subprocess.TimeoutExpired を使用(monkeypatch tuple ではない)。
  • test_p0_1_state_epoch_barrier_prevents_stale_dedup_replay: epoch 跨ぎの dedup 非対象化を確認。

P2-1: --max-workers の範囲制限

bounded_worker_count() という argparse 型関数を追加し、1〜8 の範囲外・非整数を argparse.ArgumentTypeError で拒否。テスト: test_p2_1_bounded_worker_count_accepts_valid_range、test_p2_1_bounded_worker_count_rejects_out_of_range_or_invalid(0/-1/9/100/abc/空文字)、test_p2_1_max_workers_cli_rejects_zero、test_p2_1_max_workers_cli_rejects_above_eight。

P2-2: dedup provenance の source 特定情報

dedup オブジェクトに source_result_index / source_ac / source_line を追加(既存の source_command_hash / source_execution_key_hash に加えて)。テスト: test_p2_2_dedup_provenance_identifies_source_result_index_ac_and_line。

検証結果

変更ファイル

  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
  • .claude/skills/issue-contract-review/scripts/run_contract_review_once.py(コメントのみ更新)
  • .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_dedup.py
  • .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2 (pr-review-judge 再レビュー)

verdict: APPROVE / merge_ready: true

reviewed_head_sha: e4fb631

前回の敵対的レビュー指摘(P0 2件・P1 2件・P2 2件)への対応をコードレベルで再検証しました(テストpassだけでなくロジック自体を確認)。

  • P0-1(execution_key_hashが状態変化を捕捉しない): state_epoch概念を導入。barrier commandの実行後にepochを進め、dedupは同一epoch内のpure observationのみに限定。指摘の再現手順(test→py_compile→test)がfixtureベースのテストとして固定化されている
  • P0-2(grep系がstdin/FIFO/deviceを無条件許可): grep/egrep/fgrepをparallel対象から除外。rgのみ、path operand必須・stdin拒否・絶対/repo外/FIFO/device拒否のバリデーションを追加。stdin=subprocess.DEVNULL明示
  • P1-1(legacy比較未検証): git show e375b3a1^:...でPR以前の実装を実際にロードし、意味論的差分比較テストを追加(new-vs-newの無意味比較ではない)
  • P1-2(並列実行の主要主張が未証明): threading.Barrier(2)による実並列性証明、完了順逆転耐性テスト、実subprocess timeoutテストを追加
  • P2-1(--max-workers無制限): bounded_worker_count()で1-8に制限
  • P2-2(dedup provenanceでsource AC特定不可): dedupにsource_result_index/source_ac/source_lineを追加

CI: 全required checks SUCCESS(head SHA一致)。Mergeability: MERGEABLE/CLEAN。Allowed Paths: 変更5ファイル全て範囲内。

required_auto_actions: []
blockers: []

@squne121
squne121 marked this pull request as ready for review July 14, 2026 10:57
@squne121
squne121 merged commit 0e9bbb0 into main Jul 14, 2026
22 checks passed
@squne121
squne121 deleted the worktree-issue-1338-issue-contract-review-vc-preflight-comma branch July 14, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: issue-contract-review の VC preflight に同一command dedup/replay と bounded parallel execution を追加する

1 participant