Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "issue-contract-review の baseline_vc_preflight.py が、同一の重い VC コマンドを複数 AC から重複実行することによる総実行時間超過を、dedup/replay と bounded parallel execution で解消する"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: N/A(parent なし)
- Desired Destination: N/A
Current Validated Scope
.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.pyへの同一 command dedup/replay 機構の追加.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.pyへの bounded parallel execution(--max-workers)の追加.claude/skills/issue-contract-review/scripts/run_contract_review_once.pyからbaseline_vc_preflight.pyへの--timeout-seconds/--max-workersの明示渡し- 上記に対応するユニットテストの追加
Remaining Parent Gaps
なし
Outcome
.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py が、同一 normalized command(argv + cwd + runner_env_delta + timeout_seconds が完全一致)を複数 AC から参照された場合に実プロセス起動を 1 回だけに抑え(2 件目以降は runner: dedup_replay として replay)、かつ safe read-only VC(rg / grep / test -f 等)に限定した bounded parallel execution(--max-workers、default 1 で既存互換)を実行できる状態になり、対応するユニットテストが追加されて全件 PASS している状態。run_contract_review_once.py は baseline_vc_preflight.py へ --timeout-seconds / --max-workers を明示的に渡す。
dedup/replay 機構は以下のとおり command_hash と execution_key_hash を明確に分離する。
command_hash: 既存互換の raw_command(コマンド文字列そのもの)の SHA-256。挙動・意味を変更しない。execution_key_hash: 新設。normalized argv + normalized cwd + sorted runner_env_delta + timeout_seconds を結合した値の SHA-256。dedup key として使う(command 文字列一致ではなく実行条件一致で判定する)。dedup.source_command_hash: replay 元 result の raw command_hash。dedup.source_execution_key_hash: replay 元の execution_key_hash。
In Scope
baseline_vc_preflight.pyに同一 command dedup/replay を追加する- dedup key は
execution_key_hash(normalized argv + normalized cwd + sorted runner_env_delta + timeout_seconds の SHA-256)とし、raw command 文字列一致(command_hash)とは別概念として扱う - dedup hit 時も AC ごとの result entry は残す(元 AC / line / raw_command / classification / decision を保持)
- replay された result には
runner: dedup_replay、dedup.source_command_hash、dedup.source_execution_key_hashを含める - dedup replay で他 AC 間で共有するのは実行結果(
exit_code/stdout/stderr/duration_ms/runner_env_delta/execution_key_hash)のみであり、classification / decision は source からコピーしない。各 AC の result 生成時には replay された実行結果を使って、その AC 自身のraw_command/annotation/baseline_expect/lineに基づき classification / decision を都度再計算する
- dedup key は
baseline_vc_preflight.pyに bounded parallel execution を追加する--max-workersを追加し、default は1(既存挙動と互換)- 並列対象は既存
_ALLOWED_COMMANDS(実行許可コマンド集合)から機械的に導出しない。並列実行の可否は専用 predicate(basename がrg/grep/egrep/fgrepのいずれか、または引数形状が exacttest -f PATH/test -d PATH/test -s PATHのいずれか)で判定し、これに合致するコマンドのみを並列対象とする - 初期実装では
pnpm系 /uv run pytest系 /pytest系 /gh系 /git系 /github_metadata_assert系コマンドは上記 predicate に合致しないため直列固定とする - status 集約優先順位(
blocked > human_judgment > pass)は並列化後も不変とする - 出力
resultsの順序は Issue 本文上の command 順を維持する(実行完了順にしない)
run_contract_review_once.pyからbaseline_vc_preflight.pyへ--timeout-secondsと--max-workersを明示的に渡すrun_contract_review_once.pyは named constant_VC_PREFLIGHT_MAX_WORKERS(初期値は2)を持ち、この値をbaseline_vc_preflight.py呼び出し時の--max-workersとして明示渡しする
- 上記変更に対応するユニットテストを追加する
Out of Scope
_VC_PREFLIGHT_TIMEOUT/--timeout-secondsの default 値自体の変更(Issue 実装: issue-contract-review の VC preflight タイムアウト定数を実測実行時間に合わせて引き上げる #1333 の対象)classify_result()の rg exit_code==2 分類ロジックの変更(Issue 実装: new-file VC preflight を missing Allowed Paths file として決定論的に分類する #1328 の対象)contract_readiness_check.py/check_blockers.sh/check_product_spec_contract.py側のロジック変更pytest-xdist等、baseline_vc_preflight.py内で実行される個別 VC コマンド自体の内部並列化
Acceptance Criteria
- AC1: 同一 normalized command(execution_key_hash: normalized argv + normalized cwd + sorted runner_env_delta + timeout_seconds 完全一致)が複数 AC に存在する場合、実プロセス起動は 1 回だけであり、2 件目以降の result は
runner: dedup_replayになる - AC2: dedup replay された result も、元 AC ラベル / line 番号 / raw_command / classification / decision を保持する。共有するのは実行結果(exit_code / stdout / stderr / duration_ms / runner_env_delta / execution_key_hash)のみであり、classification / decision は各 AC の raw_command / annotation / baseline_expect / line を使って都度再計算されたものである(source からコピーしたものではない)
- AC3: dedup key(execution_key_hash)は command 文字列(command_hash)だけでなく cwd / runner_env_delta / timeout_seconds を含み、いずれか一つでも異なれば別 command として扱われる。result には
command_hashとexecution_key_hashが別フィールドとして出力される - AC4:
--max-workersオプションが追加され、default は1であり、指定しない場合は既存の直列実行と出力が一致する - AC5:
--max-workers 2以上を指定した場合、専用 predicate(basename がrg/grep/egrep/fgrep、または exacttest -f/test -d/test -s PATH)に合致する safe read-only VC のみが並列実行され、pnpm/uv run pytest/pytest/gh/git/github_metadata_assertは並列対象から除外される - AC6: status 集約の優先順位(
blocked > human_judgment > pass)が--max-workersの値によらず不変である - AC7: 出力
resultsの順序が、実行完了順ではなく Issue 本文上の command 順を維持する - AC8: timeout した command は従来どおり
blocked/timeout分類になり、他 command の結果を破壊しない - AC9:
run_contract_review_once.pyは named constant_VC_PREFLIGHT_MAX_WORKERS(初期値2)を持ち、baseline_vc_preflight.py呼び出し時に--timeout-secondsと--max-workersを明示的な argv として渡す
Runtime Verification Applicability
- decision: not_applicable
- reason: 全 AC の Verification Command は
uv run --locked pytestによるユニットテストのみで完結し、外部サービス通信・実運用ネットワーク I/O・手動実行環境の準備を必要としない(docs/dev/runtime-verification-policy.mdのnot_applicable定義「静的検証(typecheck / lint / unit test / build)のみで完結し、プロセス起動・通信・I/O は不要」に合致する)
Verification Commands
# AC1
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_dedup.py
# AC2
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_dedup.py
# AC3
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_dedup.py
# AC4
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
# AC5
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
# AC6
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
# AC7
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
# AC8
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
# AC9
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.pyAllowed Paths
- .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.py
- .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
なし
Scope Delta(任意)
- 追加:
.claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py- 理由: AC9 が要求する「
run_contract_review_once.pyが named constant_VC_PREFLIGHT_MAX_WORKERSをbaseline_vc_preflight.pyへ--max-workersとして明示渡しする」という wiring 契約を検証する専用テストを、既存test_run_contract_review_once.pyとは別ファイルとして新設するため(review-issue Step2a P0#5 blocker 対応)。既存 Allowed Paths(test_run_contract_review_once.py)との重複領域を持たない新規ファイル追加であり、Current Validated Scope の他項目には影響しない。
- 理由: AC9 が要求する「
Required Design References
- .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
- .claude/skills/issue-contract-review/scripts/run_contract_review_once.py
- docs/dev/runtime-verification-policy.md
Notes for Reviewer
- 発端: Issue 実装: issue-contract-review の VC preflight タイムアウト定数を実測実行時間に合わせて引き上げる #1333(VC preflight タイムアウト定数の引き上げ)に対する外部レビューで、Issue 実装: new-file VC preflight を missing Allowed Paths file として決定論的に分類する #1328 が
uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.pyという同一の重いコマンドを AC1〜AC7, AC9〜AC11(計10個)から重複参照する構造であることが確認された。単純なタイムアウト定数引き上げ(実装: issue-contract-review の VC preflight タイムアウト定数を実測実行時間に合わせて引き上げる #1333)だけでは、この重複実行による総実行時間の問題は解決しない。 - 実装: issue-contract-review の VC preflight タイムアウト定数を実測実行時間に合わせて引き上げる #1333 は timeout 定数の整合性のみを対象とし、本 Issue(dedup/並列実行)を Out of Scope として明記した上で本 Issue に分離している。
baseline_vc_preflight.pyは各 command を直列にrun_command()で実行し、raw_command/command_hash/duration_msを既に出力している。dedup key(execution_key_hash)の実装はこの既存command_hashとは別フィールドとして追加する形で行う(既存command_hashの意味・値は変更しない)。- 「同じスクリプトなら pass」という粗い判定は禁止。dedup 対象は argv / cwd / env / timeout の完全一致 command のみ(例:
pytest file.py::test_aとpytest file.py::test_bは別 command として扱う)。 - 並列化は Python 標準
concurrent.futures.ThreadPoolExecutorを想定(外部プロセス起動待ちが支配的なため)。並列対象は既存_ALLOWED_COMMANDSからの導出ではなく、rg/grep/egrep/fgrepの basename 判定、または exacttest -f/test -d/test -s PATH判定を行う専用 predicate に限定する。pnpm/uv run pytest/pytest/gh/git/github_metadata_assertは rate limit / cache 競合の懸念があるため並列対象から除外する。 - 本 Issue 本文は review-issue Step2(2回目、VERDICT needs-fix)で確定した以下 2 件の blocker 反映のため改訂した: C5(AC番号フォーマットを角括弧形式 AC[D1]から AC[W1]までから、checker が要求する連番数字形式 AC1から AC9 へ統一。意味順は D1が AC1、D2が AC2、D3が AC3、P1が AC4、P2が AC5、P3が AC6、P4が AC7、P5が AC8、W1が AC9 の対応で維持)、AC9(旧 AC[W1])の Verification Command を -k パターン参照から未作成ファイル test_run_contract_review_once_wrapper_wiring.py への直接ファイルパス参照へ変更(-k 参照だと未作成時に pytest exit5 hard-block となり human_judgment 化するため、pytest exit4 の expected_baseline_fail go 扱いになる形へ修正。既存の -k test_baseline_vc_preflight_receives_max_workers_and_timeout 参照 VC 行と rg -q max_workers 参照 VC 行は削除し、ファイルパス直接参照の単一 VC に統合)。Anchor: 実装: issue-contract-review の VC preflight に同一command dedup/replay と bounded parallel execution を追加する #1338 (comment)
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
docs: _VC_PREFLIGHT_MAX_COMMAND_BUDGET のコメントが根本解決を主張しないよう修正
fix: VC preflight タイムアウトを named constant の関係式で定義し drift を防ぐ (#1335)
squne121 commentedon Jul 5, 2026
判定
要修正。#1338 の方向性は正しいが、このまま実装に渡すと、dedup の証跡破壊・並列対象の過拡大・wrapper 側で速度改善が発火しない実装が入り得ます。
#1338 は open で、コメントはありません。Issue 本文は「同一 normalized command の dedup/replay」と「safe read-only VC の bounded parallel execution」を目的にしています。関連する #1333/#1335 は timeout 値の引き上げと wrapper への
--timeout-seconds明示渡しを既に完了し、#1328/#1340 はrg exit_code==2の分類問題を完了済みです。ただし PR #1340 では、#1333 適用後も同じ重い pytest VC が 11 AC から重複参照され、wrapper timeout 600 秒境界に達するため、#1338 が根本対策だと明記されています。P0:
command_hashを dedup key に流用してはいけない現行
compute_command_hash()は raw command 文字列だけを SHA-256 化しています。さらに result item もcommand_hash: sha256(raw_command)として出力しています。#1338 の dedup key はargv + cwd + runner_env_delta + timeout_secondsなので、既存command_hashと意味が違います。修正仕様はこうするべきです。
dedup.source_command_hashだけだと、raw command hash なのか dedup key hash なのか曖昧です。schema consumer がcommand_hashを「Issue本文上のコマンド同一性」として使っている場合、ここを差し替えると監査証跡が壊れます。P0: dedup は「classification」ではなく「実プロセス実行」だけに掛けるべき
classify_result()はcommand文字列、cwd、runner_env_delta、allowed_paths、static_policy_passedを見ます。さらに main loop では実行後にbaseline_expectannotation の post-execution remap も行っています。そのため、dedup replay で source result の
classification/category/decisionをそのままコピーするのは危険です。キャッシュすべきなのは以下だけです。各 AC の result 生成時には、replay された実行結果を使って 元 AC の raw_command / annotation / baseline_expect / line で分類を再計算するべきです。#1338 は「元 AC / line / raw_command / classification / decision を保持」と書いていますが、ここは「classification を source からコピーしない」と明記した方が安全です。
P0: 並列対象は
_ALLOWED_COMMANDSではなく専用 allowlist に限定する現行
_ALLOWED_COMMANDSはrg/test/grepだけでなく、python3、uv、pnpm、pytest、git、gh、find、cat、ls、jqなども含みます。これをそのまま「read-only だから並列可」と扱うと、pnpmcache、ghAPI/rate limit、pytest の重い実行、git/gh の環境依存が混ざります。#1338 の並列対象は、専用 predicate で最小化すべきです。
少なくとも初期実装では
pnpm、uv run pytest、pytest、gh、git、github_metadata_assertは直列固定にしてください。github_metadata_assertは通常の実行バイナリではなく、内部で固定 argv のgh api --method GETを呼ぶ特殊経路です。P0: result order は completion order にしてはいけない
#1338 は「出力
resultsの順序は Issue 本文上の command 順」と明記しています。現行 code は単一のfor ... in commandsでresults.append()しているため順序が保たれています。ThreadPoolExecutorを使う場合、as_completed()は future が完了した順に返します。したがってas_completed()内でresults.append()すると AC-P4 を破ります。実装はoriginal_indexを持つ plan を作り、results_by_index[index] = projected_resultで復元してください。([Python documentation]1)P0: wrapper の
--max-workersが未定義だと、実装しても速度改善が発火しない現行
baseline_vc_preflight.pyの argparse には--timeout-secondsはありますが、--max-workersはまだありません。run_contract_review_once.pyも baseline 呼び出し時に--timeout-secondsだけを渡しています。#1338 の AC-W1 は
--max-workersを渡すと書いていますが、値の指定がありません。wrapper が--max-workers 1を渡しても AC は満たせてしまい、parallel execution は実運用で発火しません。dedup だけでも #1328 型の重複には効きますが、bounded parallel execution を配布物として成立させるなら、以下を明記すべきです。そして wrapper wiring test で
--max-workersとその値を固定するべきです。追加で、#1333 では wrapper argv 検証用に
.claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.pyが既に作られています。#1338 の Allowed Paths は.claude/skills/issue-contract-review/tests/test_run_contract_review_once.pyを指定していますが、実装者が自然に専用 wiring test ファイルへ追記すると Stop Conditions に触れます。Allowed Paths に wrapper wiring test を追加するか、あえて既存test_run_contract_review_once.pyに入れると明記してください。P1: timeout 設計は「ユニーク実行数 × wave 数」で考える
Python の
subprocess.run(..., timeout=...)は timeout 到達時に child process を kill して wait します。したがって、各 command の timeout 分類自体は並列化後も維持できます。([Python documentation]2)ただし wrapper timeout は別です。#1335 で
_VC_PREFLIGHT_TIMEOUT = 90 * 6 + 60 = 600の関係式に変更されています。並列化後の見積もりは概念的にこうです。
#1338 で wrapper timeout を変えないなら、それはそれでよいですが、少なくとも「dedup によって #1328 型の 11 重複は 1 実行になる。parallel は追加最適化であり wrapper timeout 算出式の変更は本 Issue では行わない」と明記した方がよいです。
P1:
ThreadPoolExecutorの使い方は narrow にする外部プロセス待ちが支配的なので、Python 側の CPU 並列ではなく
ThreadPoolExecutorは妥当です。ただし公式 docs は、Future 同士の待ち合わせが deadlock を作る例を明示しています。worker 内ではrun_command()と純粋な分類補助だけを行い、worker から別 future を待たない構造にしてください。with ThreadPoolExecutor(max_workers=...)で shutdown を保証するのがよいです。([Python documentation]1)推奨する #1338 修正版の要点
Issue 本文に最低限この差分を入れるべきです。
最終判断
#1338 は採用すべきです。ただし、実装前に Issue 契約を上記の通り硬くしてください。
特に P0 は 5 点です。
command_hashと dedup key を分離する。_ALLOWED_COMMANDSから導かず、専用 allowlist に限定する。as_completed()の completion order をresultsに漏らさない。--max-workers値とテスト配置を明記する。squne121 commentedon Jul 13, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 13, 2026
Contract Review Result
merge: origin/main を取り込み #1497 の current-head 証跡拡張と #1338 の dedup/並列実…
squne121 commentedon Jul 13, 2026
impl-review-loop 完了: PR #1508 が pr-review-judge により APPROVE(merge_ready: true)判定済みです。人間のマージ判断待ちです。
squne121 commentedon Jul 13, 2026
impl-review-loop 完了(fix_delta後再承認): 敵対的レビューのP0 2件・P1 2件・P2 2件を修正し、PR #1508 head e4fb631 が pr-review-judge により再度 APPROVE(merge_ready: true)判定済みです。人間のマージ判断待ちです。