Skip to content

実装: issue-contract-review の VC preflight タイムアウト定数を実測実行時間に合わせて引き上げる #1333

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "issue-contract-review の VC preflight タイムアウト定数が実測実行時間より短く、contract snapshot の自動生成が構造的に失敗する問題を解消する"
change_kind: code

Parent Issue

none

Parent Goal Ref

  • Goal: contract snapshot 自動生成(ensure_contract_snapshot.py / run_contract_review_once.py / baseline_vc_preflight.py)が、実行時間の長い VC コマンドを持つ Issue でも構造的にタイムアウトしないようにする
  • Desired Destination: N/A(parent なし、単独改善)

Current Validated Scope

  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py の --timeout-seconds デフォルト値を named constant として引き上げる
  • .claude/skills/issue-contract-review/scripts/run_contract_review_once.py の _VC_PREFLIGHT_TIMEOUT を、per-command timeout との関係を named constant で明示した上で引き上げる
  • run_contract_review_once.py から baseline_vc_preflight.py へ --timeout-seconds を明示的に渡す
  • 上記の変更に対応するユニットテストの追加

Remaining Parent Gaps

なし

Outcome

.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py の per-command timeout デフォルト値(named constant、90秒以上)と .claude/skills/issue-contract-review/scripts/run_contract_review_once.py の _VC_PREFLIGHT_TIMEOUT が、既存の .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py の実測実行時間(約58秒)を安全に上回る値に更新され、かつ run_contract_review_once.py が baseline_vc_preflight.py へ --timeout-seconds を明示的に渡すことで両定数の drift を防いだ状態。対応するユニットテストが追加され全件 PASS している状態。

なお本 Issue は timeout 定数の整合性のみを対象とし、Issue #1328 の「同一の重い VC コマンドが複数 AC から重複参照される」構造的な総実行時間問題(dedup / bounded parallel execution)は Out of Scope とし、follow-up Issue #1338 に分離する。

In Scope

  • baseline_vc_preflight.py に DEFAULT_TIMEOUT_SECONDS(90 以上の named constant)を追加し、--timeout-seconds の argparse default に使う
  • run_contract_review_once.py に _VC_PREFLIGHT_TIMEOUT と per-command timeout の関係を named constant で表現する(例: per-command timeout 定数と乗数・オーバーヘッドの named constant から _VC_PREFLIGHT_TIMEOUT を導出し、固定値の独立引き上げによる drift を防ぐ)
  • run_contract_review_once.py から baseline_vc_preflight.py へ --timeout-seconds を明示的な argv として渡す
  • 上記の定数変更・関係性・argv 明示渡しに対応するユニットテストを追加する(実際に長時間 VC を実行する timing test ではなく、named constant の値・関係・argv 構築を検証する軽量テストとする)

Out of Scope

Acceptance Criteria

  • AC1: baseline_vc_preflight.py に DEFAULT_TIMEOUT_SECONDS >= 90 の named constant が追加され、--timeout-seconds の argparse default がこの定数を参照している(30 固定値のままではない)ことがユニットテストで固定されている
  • AC2: run_contract_review_once.py の _VC_PREFLIGHT_TIMEOUT が、per-command timeout の named constant を参照した関係式(例: per-command timeout × 想定コマンド数 + overhead の named constant)として定義され、単純な独立引き上げ値になっていないことがユニットテストで固定されている
  • AC3: run_contract_review_once.py が baseline_vc_preflight.py を subprocess 起動する際、--timeout-seconds を明示的な argv として渡すことがユニットテストで固定されている
  • AC4: AC1〜AC3 に対応するユニットテストが .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_default_seconds.py および .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py に追加され全件 PASS する

Verification Commands

# AC1
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_default_seconds.py

# AC2
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py

# AC3
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py

# AC4
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_default_seconds.py .claude/skills/issue-contract-review/tests/test_run_contract_review_once_wrapper_wiring.py

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue の変更は timeout 定数の named constant 化・値の関係定義・argv 構築のみで完結し、対応する pytest ユニットテスト(pnpm typecheck / lint / test / build と対象ファイルの pytest)のみで検証が成立する。プロセス起動・外部通信・実時間の I/O 待ちを伴う動作検証 AC は不要(実測 58 秒の再現待ちテストは意図的に避け、named constant の値と関係のみを検証する軽量テストとする)。

Allowed 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_default_seconds.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(任意)

N/A

Notes for Reviewer

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Jul 4, 2026
  2. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    you asked

    message time: 2026-07-05 00:16:23

    #1333
    内容について関連Issue、PR、リポジトリ資産、コメントを参照した上で敵対的レビューして。
    取り扱う技術や配布物の実装をWEB検索し高品質化してほしい。


    chatgpt response

    対象Issueを起点に、GitHub上の本文・コメント・関連PR/Issue・実装ファイルを確認し、外部実装例や公式情報で裏取りしてからレビューします。まずIssue #1333の意図と影響範囲を確定します。

    Issue #1333 はコメントなしで、#1328 起点のタイムアウト再発防止Issueです。次に #1328 と対象スクリプト、関連PR/Issue検索で、問題が「定数引き上げだけ」で閉じるかを確認します。

    コード上は、baseline_vc_preflight.py の CLI default は確かに 30 秒、run_contract_review_once.py 側の wrapper timeout は 180 秒です。加えて、#1333 の Allowed Paths には実在しない test path が含まれており、このままだと実装時に Stop Conditions に触れます。

    判定

    要修正。#1333 の問題設定は正しいが、このまま実装に渡すと「定数を少し上げただけで解決した」と誤判定する危険があります。

    確認した範囲では、#1333 はコメント 0 件の open Issue で、baseline_vc_preflight.py の per-command timeout default と run_contract_review_once.py の wrapper timeout を引き上げる単独改善です。
    コード上も、baseline_vc_preflight.py の CLI default は --timeout-seconds type=int, default=30、run_contract_review_once.py 側は _VC_PREFLIGHT_TIMEOUT = 180 であることを確認しました。


    P0: Allowed Paths が間違っている

    #1333 は test_run_contract_review_once.py を .claude/skills/issue-contract-review/scripts/tests/test_run_contract_review_once.py に追加する想定ですが、実在するテストファイルは .claude/skills/issue-contract-review/tests/test_run_contract_review_once.py です。検索結果でも実ファイルは scripts/tests/ ではなく tests/ 配下でした。
    実ファイル側も _HERE.parent / "scripts" で run_contract_review_once.py を読み込む構造なので、ここにテストを追加するのが自然です。

    修正必須:

    - .claude/skills/issue-contract-review/tests/test_run_contract_review_once.py

    に置き換えてください。現状の Allowed Paths のままだと、実装者は正しいテストを追加した瞬間に Stop Conditions に触れます。


    P0: _VC_PREFLIGHT_TIMEOUT の引き上げ根拠が足りない

    #1333 は「約 58 秒の実測に対して per-command timeout を 90 秒以上へ」と書いていますが、#1328 の発端は 重い pytest command が 10 個の AC から参照される構造です。Issue 本文にも「10×30秒超のタイムアウト + pnpm 系コマンドの合計が _VC_PREFLIGHT_TIMEOUT=180 に収まらない」とあります。

    ここで単に _VC_PREFLIGHT_TIMEOUT を 240 秒や 300 秒へ上げると、1〜3 個の重い VC には効いても、#1328 の 10 個重複パターンには再び不足します。run_contract_review_once.py は baseline_vc_preflight.py 全体を _VC_PREFLIGHT_TIMEOUT で包み、timeout すると JSON を得られず runtime_error にします。
    Python の subprocess.run(..., timeout=...) は timeout 期限到達時に child process を kill し、TimeoutExpired を送出する仕様です。(Python documentation)

    Issue に必要な仕様:

    _VC_PREFLIGHT_TIMEOUT >= per_command_timeout * expected_heavy_vc_budget + orchestration_overhead
    

    例:

    _VC_PREFLIGHT_PER_COMMAND_TIMEOUT = 90
    _VC_PREFLIGHT_MAX_COMMAND_BUDGET = 10
    _VC_PREFLIGHT_OVERHEAD_SECONDS = 120
    _VC_PREFLIGHT_TIMEOUT = (
        _VC_PREFLIGHT_PER_COMMAND_TIMEOUT * _VC_PREFLIGHT_MAX_COMMAND_BUDGET
        + _VC_PREFLIGHT_OVERHEAD_SECONDS
    )

    ただし、これは 17 分級の wrapper timeout になります。運用上重すぎるなら、#1333 は「定数引き上げで当面の runtime_error を緩和する」Issue に格下げし、VC dedup/cache は follow-up に分離すべきです。現 Issue は dedup/cache を Out of Scope にしているため、定数だけで #1328 の構造問題を完全解決すると主張してはいけません。


    P1: wrapper が --timeout-seconds を明示渡ししていない

    run_contract_review_once.py は baseline_vc_preflight.py を呼ぶ際、--issue と --repo だけ渡しており、--timeout-seconds は渡していません。
    argparse は optional argument が省略された場合に parser 側の default を使うため、baseline 側 default を上げれば間接的には効きます。(Python documentation)

    ただし、これは 2 つの timeout が将来 drift する設計です。run_contract_review_once.py のコメントは「baseline_vc_preflight may take up to 120s per VC」と書いていますが、実際には per-command timeout を明示制御していません。

    推奨:

    run_contract_review_once.py から明示的に渡す。

    [
        sys.executable,
        str(_BASELINE_VC_PREFLIGHT_PY),
        "--issue",
        str(issue_number),
        "--repo",
        repo,
        "--timeout-seconds",
        str(_VC_PREFLIGHT_PER_COMMAND_TIMEOUT),
    ]

    そして test_run_contract_review_once.py に、baseline 呼び出しの argv に --timeout-seconds が含まれること、かつ _run_script(..., timeout=...) が _VC_PREFLIGHT_TIMEOUT を使うことを固定するテストを追加してください。


    P1: AC が「負の grep」だけで、閾値を保証していない

    #1333 の AC1/AC2 は以下のような検証になっています。

    rg -n "type=int, default=30" ...
    rg -n "_VC_PREFLIGHT_TIMEOUT = 180" ...

    これは「30 / 180 ではない」ことしか検証しません。default=31 や _VC_PREFLIGHT_TIMEOUT = 181 でも AC 上は満たせます。実測 58 秒を上回る安全マージンという Issue 目的と一致していません。

    修正案:

    • AC1: baseline_vc_preflight.py の per-command default が 90 秒以上であることを Python unit test で assert する。
    • AC2: run_contract_review_once.py の wrapper timeout が per-command timeout と想定 VC 数から導出された下限以上であることを assert する。
    • AC3: wrapper が baseline preflight に --timeout-seconds を明示渡しすることを assert する。
    • AC4: readiness / blockers / product spec の _DEFAULT_TIMEOUT = 30 は変更しないことを assert する。

    P1: #1328 との境界をもっと明記すべき

    #1333 は #1328 の発端を正しく拾っていますが、timeout を上げても #1328 の分類問題は解決しません。現行 classify_result() は allowed_paths を受け取らないため、post-execution 分類だけでは「missing path が Allowed Paths 内」と証明できません。
    また、rg は exit_code == 1 の no-match だけ expected fail / go にしており、exit_code == 2 には専用分岐がなく、最終的に human_judgment / unknown に落ちます。

    ripgrep 仕様上も、exit status 2 は missing file だけでなく regex syntax error 等も含む error です。(Debian Manpages)
    そのため、#1333 は次の一文を明示すべきです。

    本 Issue は runtime_error timeout を解消するだけであり、rg exit 2 を expected_fail/go に分類する変更は #1328 の責務である。#1328 が未解決の場合、timeout 解消後も vc_preflight は human_judgment / blocked になり得る。

    P2: 既存 helper timeout も隠れた上限になっている

    test_baseline_vc_preflight.py の run_preflight() helper は subprocess timeout を 90 秒に固定しています。
    今回、per-command timeout を 90 秒以上へ上げるなら、テストが実際に長時間 VC を実行する設計になった場合、テスト harness の 90 秒が先に落ちる可能性があります。

    ただし、定数検証だけなら長時間実行テストは不要です。テストは sleep で時間を消費するのではなく、module import / parser default / wrapper argv を見る軽量テストにしてください。


    推奨する #1333 修正版

    ## In Scope
    
    - `baseline_vc_preflight.py` に `DEFAULT_TIMEOUT_SECONDS >= 90` の named constant を追加し、`--timeout-seconds` の default に使う
    - `run_contract_review_once.py` に `VC preflight per-command timeout` と `overall wrapper timeout` の関係を named constants で固定する
    - `run_contract_review_once.py` から `baseline_vc_preflight.py` へ `--timeout-seconds` を明示的に渡す
    - unit test で以下を固定する:
      - baseline CLI default が 90 秒以上
      - wrapper timeout が per-command timeout より十分大きい
      - wrapper が baseline に `--timeout-seconds` を渡す
      - readiness / blockers / product spec の timeout は変更しない

    Allowed 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.py
    - .claude/skills/issue-contract-review/tests/test_run_contract_review_once.py

    最終判断

    #1333 は採用してよいが、Issue 本文を修正してから実装すべきです。

    最低限の修正条件は 3 つです。

    1. test_run_contract_review_once.py の Allowed Path を実在パスへ直す。
    2. 30 / 180 でないこと ではなく、90 秒以上 と wrapper timeout の算出関係 を AC にする。
    3. 実装: new-file VC preflight を missing Allowed Paths file として決定論的に分類する #1328 の rg exit 2 分類問題とは別であり、実装: issue-contract-review の VC preflight タイムアウト定数を実測実行時間に合わせて引き上げる #1333 単独では contract-review go を保証しないと明記する。

    you asked

    message time: 2026-07-05 00:22:48

    並列実行するようにするとか、同じスクリプトはパスするとか、時間短縮策を出して。


    chatgpt response

    時間短縮策は入れるべきです。#1333 を「timeout 値を上げる」だけにすると、実行時間の上限を広げるだけで、根本の重複実行コストは残ります。並列化・dedup・分類先送りの3層で設計します。

    はい。#1333 は timeout 引き上げ Issue ではなく「VC preflight の重複・直列実行コスト削減 Issue」に寄せた方がよいです。優先順位はこうです。

    推奨順位

    1. 同一 VC の dedup / replay を最優先

    #1328 の実例は「同じ重い pytest command が複数 AC に出る」構造なので、最初に潰すべきはここです。現行 baseline_vc_preflight.py は各 command を直列に run_command() し、結果ごとに raw_command / command_hash / duration_ms を出力しています。

    実装方針:

    dedup_key = normalized argv + cwd + runner_env_delta + timeout_seconds
    

    同じ key の command は 1 回だけ実行し、2 回目以降は cached result を replay します。classification は同一でよいが、出力上は各 AC の result を残し、以下を追加するのがよいです。

    {
      "runner": "dedup_replay",
      "dedup": {
        "deduped": true,
        "source_command_hash": "sha256:...",
        "source_ac": "AC1"
      }
    }

    注意: 「同じスクリプトなら pass」は危険です。pytest test_file.py::test_a と pytest test_file.py::test_b は同じ script でも意味が違います。skip してよいのは「同じ script」ではなく、同じ argv / cwd / env / timeout の完全一致 commandだけです。


    2. 並列実行は「安全な subset」に限定

    Python 標準の concurrent.futures は ThreadPoolExecutor / ProcessPoolExecutor で callable を非同期実行でき、Executor.map() は複数 call を同時に実行できます。(Python documentation)
    ただし ThreadPoolExecutor は長時間 task には注意が必要で、deadlock caveat もあります。(Python documentation)

    この repo の VC は subprocess.run(..., shell=False, capture_output=True, timeout=..., cwd=...) で外部プロセスを起動しているので、Python 内 CPU 処理よりも外部 command 待ちが支配的です。 そのため、並列化は ThreadPoolExecutor(max_workers=N) で十分です。

    ただし、全部を並列化しない方がよいです。

    command 種別 並列可否 理由
    rg, grep, test -f/-d/-s 可 read-only・軽量
    uv run --locked pytest <specific file> 条件付き可 read-only だが CPU/IO 重い
    pnpm typecheck/lint/test/build 原則直列 cache / node_modules / stdout が重く、並列で遅くなる可能性
    gh issue view, gh pr view 原則直列または低並列 rate limit / auth / network 依存
    github_metadata_assert 低並列 gh api 経由なので rate limit 配慮

    Python の subprocess.run(timeout=...) は timeout 到達時に child process を kill して wait し、その後 TimeoutExpired を再送出する仕様です。(Python documentation) 現行コードは TimeoutExpired を捕捉して exit_code=-1, stderr="timeout" に変換しています。
    並列化しても per-command timeout の意味は維持できます。


    3. pytest-xdist は VC 内では原則使わない

    pytest-xdist は pytest -n auto により CPU 数に応じた worker process を起動してテストを分散できます。(pytest-xdist)
    ただし、baseline VC preflight の目的は「Issue 本文の VC が baseline で expected fail / pass / blocked のどれかを判定すること」です。ここで pytest -n auto を混ぜると、環境依存・worker 数依存・出力差分が増えます。

    使うなら、通常の開発・CI test の高速化に限定。baseline_vc_preflight.py の中では、まず dedup と controlled parallelism の方が安全です。


    #1333 に入れるべき時間短縮 AC

    #1333 は以下のように修正するのがよいです。

    ## In Scope 追加
    
    - `baseline_vc_preflight.py` に同一 command dedup/replay を追加する
      - dedup key は normalized argv + cwd + runner_env_delta + timeout_seconds
      - dedup hit 時も AC ごとの result entry は残す
      - replay result には `runner: dedup_replay` と `dedup.source_command_hash` を含める
    - `baseline_vc_preflight.py` に bounded parallel execution を追加する
      - default は conservative に `--max-workers 1`
      - opt-in で `--max-workers 2` または `4`
      - 並列対象は safe read-only VC に限定する
      - pnpm / gh / github_metadata_assert は直列または低並列にする
    - `run_contract_review_once.py` から `baseline_vc_preflight.py` へ `--timeout-seconds` と `--max-workers` を明示渡しする
    - timeout 引き上げは fallback として残すが、主目的は総実行時間削減とする
    ## Acceptance Criteria 追加
    
    - AC-D1: 同一 normalized command が複数 AC に存在する場合、実プロセス起動は 1 回だけで、2 件目以降は `runner: dedup_replay` になる
    - AC-D2: dedup replay された result も元 AC / line / raw_command / classification / decision を保持する
    - AC-D3: dedup key は command 文字列だけでなく cwd / runner_env_delta / timeout_seconds を含む
    - AC-P1: `--max-workers` が追加され、default は `1` で既存挙動と互換
    - AC-P2: `--max-workers 2` 指定時、safe read-only VC は並列実行される
    - AC-P3: status 優先順位 `blocked > human_judgment > pass` は並列化後も変わらない
    - AC-P4: 出力 `results` の順序は Issue 本文上の command 順を維持する
    - AC-P5: timeout した command は従来どおり `blocked / timeout` になり、他 command の結果を破壊しない

    現行 status 集約は blocked > human_judgment > pass の優先順位で決まるため、並列化後もこの集約順を固定する必要があります。


    実装設計の骨子

    Phase 1: parse / static classification は直列

    ここは今のままでよいです。preflight_scope、inline annotation、strict mode、static blocker は順序依存の診断があるため、最初に command plan を作るだけにします。

    ExecutionPlanItem(
        index=i,
        ac=ac_label,
        line=line_no,
        command=command,
        static_result=None | classification_tuple,
        executable=True | False,
        parallel_group="read_only" | "serial",
        dedup_key=...
    )

    Phase 2: executable command を dedup

    unique_jobs = {}
    for item in plan:
        if not item.executable:
            continue
        unique_jobs.setdefault(item.dedup_key, item)

    同一 key の command は 1 回だけ実行。

    Phase 3: safe read-only group だけ並列

    with ThreadPoolExecutor(max_workers=args.max_workers) as executor:
        futures = {
            executor.submit(run_command, item.command, args.timeout_seconds, args.cwd): item.dedup_key
            for item in parallel_jobs
        }

    concurrent.futures.Executor.submit() は callable を schedule して Future を返す API です。(Python documentation)

    Phase 4: 元の command 順に result を復元

    これが重要です。実行完了順で出力すると diff が揺れます。results は必ず元の Issue 本文順に戻すべきです。


    採用すべき Issue 分割

    一つに詰めるなら #1333 を拡張してよいですが、品質重視なら 2 Issue に分ける方が安全です。

    Issue A: timeout 定数の整合

    • per-command default を 90 秒以上
    • wrapper timeout を明示算出
    • run_contract_review_once.py から --timeout-seconds を渡す

    Issue B: VC preflight dedup / bounded parallel execution

    • 同一 command dedup
    • --max-workers
    • safe read-only subset のみ並列
    • result order 維持
    • status 集約不変

    敵対的には、#1333 に全部入れるなら timeout 引き上げより dedup を必須 AC にするべきです。#1328 の実例は「1 command が 58 秒」ではなく「同じ重い command を複数回踏む」問題なので、timeout だけでは上限を広げるだけです。

  3. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-04T16:14:03Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1333
      body_sha256: "sha256:72e2c01e38b98605975ab6ad77a1c4805d5ef2306ad51324989a30cd6050bd03"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. added a commit that references this issue on Jul 4, 2026
    47c58ca
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/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions