Skip to content

実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2207

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "review pipeline の timeout budget を、実際に起動され得る VC subprocess 数の保守的上限に基づく動的値へ再設計し、budget denominator と実起動回数の不一致・pure VC 未計上・process group 残留を解消する"
change_kind: code

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: review pipeline (run_root_review_pipeline.py produce → reviewer_transport.py → contract_readiness_check.py → baseline_vc_preflight.py) の timeout budget を、固定の「near-cap VC 最大2本」前提から、pinned Issue body から抽出される 実際に起動され得る VC subprocess occurrence 数の保守的上限(unique dedup 数ではない)に応じた動的導出へ移行する。
  • Desired Destination: budget derivation と VC executor が同一の canonical planner / body bytes を共有し、pure/non-pure を問わず全 VC occurrence を数え、outer timeout 時に process group 残留を残さない状態。

Current Validated Scope

  • .claude/skills/issue-contract-review/scripts/contract_readiness_check.py の _MAX_SEQUENTIAL_NEAR_CAP_VCS_ASSUMED / BASELINE_VC_PREFLIGHT_AGGREGATE_TIMEOUT_SECONDS / CONTRACT_READINESS_CHECK_TIMEOUT_SECONDS を、side-effect-free な canonical VC planner が算出する occurrence 数ベースの動的値へ置き換える
  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py に、budget derivation と executor が共有する canonical planner(body_sha256 / parser_contract_version / command_occurrence_count / launch_upper_bound / per_command_timeout_seconds / max_workers / policy_cap を含む)を追加する
  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py に、SIGTERM 受信時に現在管理している全 VC process group(direct child・grandchild を含む)を終了・回収する cooperative cancellation を追加する
  • .claude/skills/issue-refinement-loop/scripts/reviewer_transport.py の module-level fallback constants (PER_ATTEMPT_DEADLINE_SECONDS=480 / TOTAL_DEADLINE_SECONDS=520) は変更せず、run_root_review_pipeline.py が pinned body から算出した invocation-local ReviewBudget を run_reviewer_transport() へ明示引数として渡す経路を追加する
  • .claude/skills/issue-refinement-loop/scripts/run_root_review_pipeline.py 側で、既に一度取得・SHA-256 固定済みの body bytes に canonical planner を適用し、policy ceiling を検査したうえで invocation-local budget を下位 phase へ配線する

Remaining Parent Gaps

なし(単独改善のため親 Issue なし)

Outcome

run_root_review_pipeline.py が pinned body bytes(既存の SHA-256 固定 tempfile)に対して canonical VC planner を適用し、pure/non-pure を問わず実際に起動され得る VC subprocess occurrence 数の保守的上限(N = max(2, occurrence_count))を算出する状態になる。budget derivation はこの N から per_vc_slot = 150 + 15(command cap 150 秒 + SIGTERM/SIGKILL/pipe-drain cleanup tail 15 秒)を用いた式で baseline aggregate / readiness wrapper / per-attempt / total の 4 値を導出し、N <= 2 では現行値 (350s/400s/480s/520s) を維持する。導出した invocation-local ReviewBudget は run_root_review_pipeline._cmd_produce() から run_reviewer_transport() へ明示引数として渡され、reviewer_transport.py の module-level fallback constants (PER_ATTEMPT_DEADLINE_SECONDS / TOTAL_DEADLINE_SECONDS) は変更されない。N が policy ceiling (MAX_VC_EXECUTION_SLOTS) を超える場合、subprocess 起動前に typed non-retryable verification_budget_exceeds_policy で終了する。baseline_vc_preflight.py は SIGTERM を受けた場合に現在管理している全 VC process group を終了・回収する cooperative cancellation を実装し、outer deadline → active VC descendant absent を scaled fault-injection test で検証する。対応する pytest が新規/更新されて全て PASS している状態。

Safety Claim(per-command cap の限界、明示): 本 Issue は wrapper/transport の premature timeout(aggregate/outer deadline が inner VC の完走前に発火する問題)を防止する。per-command cap(150 秒)を超える単一 VC 自体は引き続き typed timeout となり、command 分割または別 Issue が必要。本 Issue の budget 拡張は「outer environment failure になる」問題を解消するものであり、「150 秒を超える単一 VC が完走する」問題を解消するものではない。

Schema boundary(明示、diagnostic 分離): 同一 non-pure コマンドの重複を diagnostic として検出・報告する機能は、baseline_vc_preflight/v1 の producer JSON schema 変更(diagnostics[] 追加等、複数 consumer に影響)を要するため、本 Issue のスコープからは除外し、follow-up Issue に分離する(下記 Out of Scope 参照)。本 Issue は baseline_vc_preflight/v1 の既存 schema フィールドを追加・変更しない。

Runtime Verification Applicability

decision: immediate
reason: >
  本 Issue の中心的主張は (a) nested subprocess が算出済みの invocation-local deadline を実際に受け取ること、
  (b) outer wrapper が inner VC の完走前に先に timeout しないこと、
  (c) outer timeout/SIGTERM 発火後に VC process tree(direct child・grandchild)が残留しないこと、
  という runtime behavior であり、typecheck/lint/unit test/build のみでは production wiring と process 回収を
  証明できない(docs/dev/runtime-verification-policy.md の「process 起動・通信・I/O が実質的な検証対象なら
  immediate」に該当)。数百秒規模の live test は不要で、50〜200ミリ秒程度に scale down した fixture subprocess
  階層を用いた fault-injection test(AC9/AC10)で immediate 要件を満たす。
applicable_acs:
  - AC9
  - AC10
execution_environment:
  cli_tools:
    - python3
    - uv
  auth_required: false
  network_required: false
skip_conditions:
  - "local repository checkout が存在しない場合は SKIP ではなく environment blocked として扱う"
  - "OS が POSIX process group semantics (os.killpg / start_new_session) を提供しない環境では SKIP ではなく environment blocked として扱う"
fallback_policy:
  fallback_success_is_pass: false
  notes: "fallback 経由の成功(例: mock だけの検証)を PASS に変換しない。実 subprocess 階層での検証を要求する。"
artifact_requirements:
  - "AC9/AC10 pytest の stdout/stderr(プロセス終了・回収タイミングを含む)"
  - "contract_readiness_check.py / baseline_vc_preflight.py の実行 JSON output"

In Scope

  • baseline_vc_preflight.py に、budget derivation と executor が共有する side-effect-free canonical VC planner を追加する設計・実装(pinned body bytes と executor が実際に使う normal execution parser から、body_sha256 に binding された VC occurrence 数を算出する)
  • 予算計算の入力を「dedup 後の unique non-pure VC 数」から「pure/non-pure を問わず、実行 dedup されない duplicate command は occurrence 数分をそのまま数える保守的上限」へ置き換える
  • 同一 pure command が non-pure barrier(state_epoch を進めるコマンド)の前後に存在する場合、現行 executor と同じく別 launch として数える state barrier semantics の実装
  • N <= 2 で現行 budget 値 (350s/400s/480s/520s) を維持し、N >= 3 で command cap だけでなく timeout cleanup tail(SIGTERM 5秒 + SIGKILL 5秒 + pipe drain 5秒 = 15秒/VC)も比例拡張する formula の実装
  • policy ceiling (MAX_VC_EXECUTION_SLOTS 等) を固定し、超過時に subprocess 起動前に typed non-retryable verification_budget_exceeds_policy で拒否する実装
  • run_root_review_pipeline._cmd_produce() が pinned body から invocation-local ReviewBudget を算出し、run_reviewer_transport() へ明示引数として渡す配線(reviewer_transport.py の fallback constants 480/520 は不変のまま)
  • baseline_vc_preflight.py が SIGTERM を受けた場合に、現在管理している全 VC process group(start_new_session=True で生成された direct child・grandchild を含む)を終了・回収する cooperative cancellation の実装
  • outer deadline → active VC descendant absent を検証する、50〜200ミリ秒 scale の fixture subprocess を用いた実 process fault-injection test(immediate runtime AC)
  • 上記の formula・低本数互換性・拡張・policy ceiling・明示配線・cancellation を固定する正負の pytest

Out of Scope

Acceptance Criteria

  • AC1: baseline_vc_preflight.py に、pinned body bytes と executor が実際に使う normal execution parser(extract_fenced_bash_blocks() / parse_commands_from_block() 系統)から VC occurrence 数を算出し、body_sha256 に binding された canonical plan(body_sha256 / parser_contract_version / command_occurrence_count / launch_upper_bound / per_command_timeout_seconds / max_workers / policy_cap を含む)を返す side-effect-free 関数が実装される
  • AC2: canonical plan の command_occurrence_count が、実行 dedup されない duplicate non-pure command について unique 数ではなく出現回数をそのまま数えることが検証される
  • AC3: canonical plan の command_occurrence_count が、distinct な pure command(rg / exact test -f|-d|-s)も budget 対象として含めることが検証される
  • AC4: 同一 pure command が non-pure barrier の前後に存在する入力に対し、canonical plan が現行 executor と同じく別 launch として数えることが検証される
  • AC5: N <= 2(N = max(2, command_occurrence_count))の入力に対し、contract_readiness_check.py が現行の budget 値 (BASELINE_VC_PREFLIGHT_AGGREGATE_TIMEOUT_SECONDS=350 / CONTRACT_READINESS_CHECK_TIMEOUT_SECONDS=400 相当 / per-attempt 480 / total 520) を維持することが検証される
  • AC6: N >= 3 の入力に対し、baseline_aggregate = N * (150 + 15) + 20 の formula で aggregate timeout が command cap だけでなくtimeout cleanup tail も含めて比例拡張されることが検証される
  • AC7: N が固定の policy ceiling (MAX_VC_EXECUTION_SLOTS) を超える入力に対し、subprocess 起動前に typed non-retryable verification_budget_exceeds_policy で拒否されることが検証される
  • AC8: run_root_review_pipeline._cmd_produce() が pinned body から算出した invocation-local ReviewBudget を run_reviewer_transport() へ明示引数として渡し、reviewer_transport.py の module-level fallback constants (PER_ATTEMPT_DEADLINE_SECONDS=480 / TOTAL_DEADLINE_SECONDS=520) がこの配線によって書き換えられないことが検証される
  • AC9: baseline_vc_preflight.py が SIGTERM を受けた場合に、現在管理している全 VC process group(direct child・grandchild を含む)が bounded time 内に終了・回収されることが実 subprocess を用いて検証される(正常系: process group が確実に回収される、異常系: 実行環境が POSIX process group semantics を提供しない場合は SKIP exit 77 で environment blocked とし、fallback 経由の成功を PASS に変換しない)
  • AC10: production と同じ subprocess 階層構造を持つ 50〜200ミリ秒 scale の fixture を用い、inner (per-command) timeout が outer (aggregate) deadline より先に typed classification され、outer deadline 発火後に active VC descendant が残存しないことが実 process fault-injection test で検証される(正常系: inner timeout が outer より先に発火し descendant が残らない、異常系: descendant 残留を検知した場合は FAIL とし SKIP/fallback で PASS 化しない)

Verification Commands

# AC1
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_planner.py::test_canonical_plan_binds_body_sha256 -q
# AC2
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_planner.py::test_conservative_count_counts_duplicate_non_pure_occurrences -q
# AC3
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_planner.py::test_pure_coverage_included_in_budget -q
# AC4
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_planner.py::test_state_barrier_separates_repeated_pure_command_launches -q
# AC5
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_formula.py::test_low_count_compatibility_preserves_existing_budget -q
# AC6
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_formula.py::test_cleanup_aware_growth_scales_with_occurrence_count -q
# AC7
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_review_budget_formula.py::test_policy_ceiling_rejects_before_subprocess_launch -q
# AC8
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_review_budget_wiring.py::test_root_pipeline_passes_invocation_local_deadline_to_transport -q
# AC9
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_vc_process_group_cancellation.py::test_sigterm_reaps_active_vc_process_groups -q
# AC10
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_vc_process_group_cancellation.py::test_scaled_fault_injection_inner_timeout_precedes_outer_deadline -q

Allowed Paths

  • .claude/skills/issue-contract-review/scripts/contract_readiness_check.py
  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
  • .claude/skills/issue-refinement-loop/scripts/reviewer_transport.py
  • .claude/skills/issue-refinement-loop/scripts/run_root_review_pipeline.py
  • .claude/skills/issue-contract-review/tests/
  • .claude/skills/issue-contract-review/scripts/tests/
  • .claude/skills/issue-refinement-loop/tests/

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合(baseline_vc_preflight/v1 producer schema・ISSUE_REVIEW_RESULT_COMPACT_V2 等、既存 consumer 契約を含む)
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 動作検証 AC(AC9/AC10)の VC が SKIP(exit 77)を返した場合(実行環境不可のためエスカレーション)
  • fallback 経由でのみ「成功」する場合(FAIL として扱い、実行環境を確認)

Required Skills

なし

Required Design References

  • docs/dev/runtime-verification-policy.md
  • docs/dev/agent-skill-boundaries.md
  • .claude/skills/issue-contract-review/scripts/contract_readiness_check.py
  • .claude/skills/issue-refinement-loop/scripts/reviewer_transport.py

Scope Delta(任意)

N/A

Background

PR #2177(Issue #2165 の修正、マージ済み)の Safety Claim Matrix は以下を明示的に "Implemented: no" として記録していた:

多数の VC(理論上無制限)を持つ Issue 本文に対しては、本 PR の固定 wrapper timeout(150/200/250/300/340秒)でも over-budget になり得る(動的 VC 数に応じた deadline 導出は未実装)
Follow-up: #2165 の Out of Scope に準ずる。将来必要になれば新規 Issue で対応

2026-08-16、Issue #2195 の refinement loop 実行でこの residual risk が実際に顕在化した。#2195 の ## Verification Commands に、baseline_vc_preflight.py の dedup 機構(test -f/-d/-s と検証済み rg のみを "pure" として dedup し、pytest/pnpm/gh/git は明示的に除外)の対象外である uv run --locked pytest .claude/skills/issue-refinement-loop/tests -v という同一 non-pure コマンドが AC1/AC3/AC4/AC5 の4箇所に重複記載されていた。この結果、baseline_vc_preflight.py は同一コマンドを4回独立実行し(各150秒cap)、想定された「near-cap VC最大2本」という前提を超過し、run_root_review_pipeline.py produce が2回連続(regular attempt + 1回のretry)で STATUS: input_or_runtime_error / error_code: reviewer_transport_environment_failure(reason_code: timeout, timeout_phase: contract_readiness_check)を返した。

実測: PR #2177 の最終記録(マージ直前の CI)では issue-refinement-loop の full suite は 1375 passed, 259.14s である。本 Issue のこれまでの草案に記載していた 1357 passed, 245.37s は途中 iteration の値であり、最終記録ではない。budget SSOT は特定 commit の実測時間ではなく、timeout cap と launch upper bound から導出するべきであり、pytest --durations は性能回帰の telemetry としてのみ用いる。

2026-08-16、リポジトリ OWNER(squne121)が本 Issue に対して REQUEST_CHANGES / reframe_in_place のコードレビューを実施(review comment、レビュー時点の main は 12ae5b868a0fab7b4563335c117e51fff97af284、それ以前の #2207 への直接コメントは 0 件)。指摘された 12 件の Blocker/High findings(予算計算の分母と実起動回数の不一致、pure VC 未計上、outer timeout 時の process group 残留、reviewer_transport.py module constants の責務境界違反、diagnostic schema change と schema-change 禁止の矛盾、実装前から PASS する rg VC、per-command cap 150 秒の限界、deadline 無制限拡張、budget/execution parser drift、Runtime Verification Applicability の not_applicable 誤り、相対値積み上げ deadline の drift 耐性、historical evidence の陳腐化)と、推奨する再設計(Canonical plan / Conservative count / Pure coverage / State barrier / Low-count compatibility / Cleanup-aware growth / Policy ceiling / Explicit wiring / Cancellation / Scaled integration の10項目、diagnostic schema 変更は follow-up Issue へ分離を推奨)を反映し、本 Issue 本文を全面的に書き換えた。

関連: #2165(predecessor, CLOSED)、PR #2177(predecessor, merged)、Refs #2195(今回この residual risk が顕在化した live trigger、human_escalation で停止中。Closes ではなく Refs — #2195 とは別スコープの独立 follow-up であるため)。

Notes for Reviewer

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Aug 16, 2026
  2. squne121 commented on Aug 16, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES。推奨 disposition は reframe_in_place です。

    #2207 が解こうとしている問題――「Verification Command 数が増えると、内側の VC 実行が終わる前に上位 wrapper / reviewer transport が timeout する」――は実在します。PR #2177 も、VC 数が理論上無制限である以上、固定 deadline では再発し得ることを未制御リスクとして明示していました。

    ただし、現契約のまま実装すると、次の危険な実装が自然に導かれます。

    重複した non-pure VC を 1 本として予算計算する一方、executor は同じ VC を 4 回起動する。

    これは #2195 の再現条件を解消せず、単に timeout の発生層をずらします。

    レビュー時点の main は 12ae5b868a0fab7b4563335c117e51fff97af284、#2207 の直接コメントは 0 件です。


    Blocker

    1. 予算計算の分母と、実際の subprocess 起動回数が一致しない

    #2207 は AC1 で「dedup 後の non-pure VC 数」を算出し、AC2 では同一 non-pure command の重複を diagnostic として検出しつつ、実行回数の削減自体は任意としています。さらに AC4 は「VC 数 2 本以下なら現行値維持」、AC5 は「3 本以上、または同一 command 重複なら拡張」としています。

    しかし現行 executor の dedup/replay 対象は、厳格に検証された rg と exact test -f|-d|-s だけです。pytest、uv run pytest、pnpm、git、gh 等の non-pure command は dedup されず、出現回数分だけ必ず起動され、各実行後に state_epoch を進める barrier として扱われます。

    したがって、例えば同じ pytest command が 4 回ある場合に、

    • diagnostic 上の unique count: 1

    • 実際の subprocess 起動回数: 4

    という乖離が発生します。

    また、同一 command が 2 回ある入力は、AC4 の「2 本以下なので現行値」と AC5 の「重複なので拡張」を同時に満たします。優先順位が定義されていないため、AC 自体も決定論的ではありません。

    必要な修正: 予算計算の入力は unique command 数ではなく、少なくとも 実際に起動し得る subprocess の保守的上限にしてください。non-pure command は、実行 dedup を本当に実装しない限り、出現回数をそのまま数える必要があります。重複 diagnostic と budget identity は分離すべきです。


    2. non-pure VC だけを数えても aggregate deadline の上限にならない

    現行 baseline_vc_preflight.py の --max-workers 既定値は 1 です。つまり production の strict 経路では、dedup されなかった distinct な pure command も直列に実行されます。

    現在の固定式は、

    • per-command cap: 150 秒

    • near-cap VC は最大 2 本と仮定

    • aggregate margin: 50 秒

    として 350 秒を導出しています。しかし「その他の rg 等は少数かつ高速」という前提はコメント上の仮定であり、Issue body に pure VC を大量に置くことを禁止する policy cap はありません。

    そのため、次の入力でも over-budget になります。

    • non-pure VC: 0 本

    • distinct pure VC: 数十本

    • budget 計算上の本数: 0

    • 実際の起動: 数十 subprocess、既定では直列

    必要な修正: 最小構成では、pure/non-pure を問わず 通常実行 parser が抽出した全 VC occurrence 数を数えてください。pure dedup や将来の並列化を正確に反映する最適化は、実行計画を SSOT 化する別段階として扱うべきです。


    3. outer timeout 時に、実行中の VC process group が残留し得る

    現行の VC executor は、各 command を start_new_session=True で起動します。per-command timeout では、SIGTERM、最大 5 秒待機、SIGKILL、最大 5 秒待機、さらに pipe drain を最大 5 秒実行します。したがって 150 秒の command cap とは別に、1 command 当たり最大 15 秒程度の timeout cleanup tail があります。

    一方、contract_readiness_check.py は baseline_vc_preflight.py 全体を subprocess.run(..., timeout=aggregate) で包んでいます。

    この組合せには次の failure mode があります。

    1. baseline process が VC を新しい session/process group で起動する。

    2. aggregate timeout が per-command timeout より先に発火する。

    3. Python の wrapper は直接子である baseline process を終了する。

    4. 別 session に移った VC process group は直接子 kill の対象外となり、継続する。

    Python の公式仕様でも、subprocess.run(timeout=...) は timeout 時に直接 child を kill/wait しますが、process creation 自体は timeout で中断できない場合があるとされています。(Python documentation)

    #2207 は outer timeout を発生しにくくしますが、cleanup tail、process creation delay、policy ceiling、将来の timing drift により outer timeout を完全には排除できません。

    必要な修正:

    • aggregate 式に per-command cleanup tail を含める。

    • policy ceiling 超過は subprocess 起動前に拒否する。

    • baseline process が SIGTERM を受けた場合、現在管理している全 VC process group を終了・回収する cooperative cancellation を実装する。

    • outer deadline → active VC descendant absent を実 process fault-injection test で検証する。


    4. reviewer_transport.py の module constants を動的化する設計は責務境界に反する

    現行の PER_ATTEMPT_DEADLINE_SECONDS=480 と TOTAL_DEADLINE_SECONDS=520 は、明示 deadline を渡さない caller のための generic fallback です。deterministic production path はこれらを直接使わず、run_root_review_pipeline.py が下位 phase の timeout を合成して、per-attempt / total を明示的に渡しています。

    したがって、AC3 の「reviewer_transport.py の PER_ATTEMPT_DEADLINE_SECONDS / TOTAL_DEADLINE_SECONDS が動的予算に整合する」は不適切です。module constant は Issue body に依存できません。実装者が global 値を書き換えると、同一 process 内で複数 Issue を処理する場合の race や test-order dependence を持ち込みます。

    必要な修正:

    • fallback constants 480/520 は不変にする。

    • pinned body から immutable な ReviewBudget を生成する。

    • run_root_review_pipeline._cmd_produce() が、その invocation 固有値を run_reviewer_transport() へ明示渡しする。

    • transport は渡された値を消費するだけにする。

    root pipeline はすでに Issue body を一度取得して SHA-256 と一緒に tempfile へ固定しているため、その同じ body bytes から budget を算出できます。


    5. duplicate diagnostic は schema change だが、Issue 自身が schema change を禁止している

    baseline_vc_preflight.py は baseline_vc_preflight/v1 の machine-readable JSON を producer として出力し、contract readiness、impl-review-loop、adjudicator、複数 test consumer が利用しています。リポジトリ内検索でも consumer は複数 skill にまたがっています。

    リポジトリの schema governance は、ファイル間・producer/consumer 間を横断する JSON、log、固定出力契約を schema と定義しています。schema の変更時には、before/after、全 consumer、各 consumer の更新状況を Schema Consumer Inventory に記載し、欠落時は APPROVE 禁止です。

    AC2 の structured diagnostic を実装するには、少なくとも次のどれかが必要です。

    • top-level diagnostics[] の追加

    • errors[] の新しい kind / rule / severity semantics

    • result item への duplicate metadata 追加

    いずれも consumer-facing contract の変更です。しかし #2207 の Stop Conditions は「固定契約のキー集合・schema・型定義の変更が必要なら停止」としており、schema 定義・consumer 更新用の Allowed Paths もありません。

    必要な修正: 次のどちらかに確定してください。

    1. 推奨: diagnostic schema 変更を follow-up Issue に分離し、実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2207 は budget derivation のみに限定する。

    2. 同一 Issue で扱うなら、diagnostic の exact shape、status への影響、compatibility decision、consumer inventory、必要な Allowed Paths を本文で固定する。


    6. 現在の Verification Commands は implementation evidence にならない

    AC1 の VC は _MAX_SEQUENTIAL_NEAR_CAP_VCS_ASSUMED を rg しますが、AC1 自身はその固定仮定を動的導出へ置換する要求です。正しく削除すると VC が失敗し、コメントや dead code に名前だけ残すと偽陽性になります。

    AC3 の VC が検索する PER_ATTEMPT_DEADLINE_SECONDS は現行 main にすでに存在します。AC2 の rg -n "duplicate" も現行 baseline_vc_preflight.py に既存の dedup/duplicate 関連記述があるため、実装前から一致します。

    つまり AC1〜AC3 の shallow rg は、

    • 実装前から PASS する

    • 正しい削除で FAIL する

    • コメントだけで PASS できる

    という状態です。

    さらに canonical な dedup test は .claude/skills/issue-contract-review/scripts/tests/ にありますが、#2207 の Allowed Paths は主に .claude/skills/issue-contract-review/tests/ を指定しており、既存 dedup regression test の更新経路が不足しています。

    必要な修正: rg による存在確認を撤去し、formula、production wiring、fallback preservation、duplicate semantics を関数出力と subprocess behavior で直接検証してください。


    High findings

    7. outer budget を増やしても、150 秒の per-command timeout は解消しない

    現行 per-command cap は 150 秒です。PR #2177 の最終記録では issue-refinement-loop の full suite は 1375 passed, 259.14s であり、#2207 に記載された 1357 passed, 245.37s は途中 iteration の値です。

    したがって #2195 のように full suite を VC として置くと、aggregate budget を 650 秒や 800 秒へ増やしても、各 occurrence は 150 秒で timeout します。改善されるのは「outer environment failure になる」問題であり、「VC が完走する」問題ではありません。

    これは #2207 の Outcome と Safety Claim Matrix に明示すべきです。

    本 Issue は wrapper/transport の premature timeout を防止する。per-command cap を超える VC 自体は引き続き typed timeout となり、command 分割または別 Issue が必要。


    8. Issue body に比例して無制限に deadline を拡張できる

    現状の契約には、VC 数や total review budget の hard ceiling がありません。Issue body に 100 本の VC を置くだけで、数時間規模の deadline を要求できる実装になり得ます。

    高すぎる timeout は process、memory、thread、file descriptor 等のリソースを長時間保持します。AWS の timeout 設計指針も、高すぎる timeout と多層 retry の負荷増幅を警告し、retry は stack 内の一箇所に集約することを推奨しています。(Amazon Web Services, Inc.)

    必要な修正:

    • MAX_VC_EXECUTION_SLOTS

    • MAX_BASELINE_AGGREGATE_SECONDS

    • MAX_DETERMINISTIC_ATTEMPT_SECONDS

    のいずれか、または複数を policy として固定してください。超過時は実行前に、typed・non-retryable な verification_budget_exceeds_policy で終了すべきです。


    9. budget parser と execution parser が drift する余地がある

    現行 baseline の normal execution path は legacy な extract_fenced_bash_blocks() / parse_commands_from_block() を使い、--static-only だけが別の unified parser を使います。

    budget derivation が別 parser を再実装すると、

    • budget は 2 本と認識

    • executor は 4 本抽出

    という arithmetic break が再発します。

    必要な修正: baseline_vc_preflight.py に side-effect-free な canonical planner を設け、budget derivation と executor の双方が同じ plan を使うべきです。最低限、plan には次を含めます。

    body_sha256
    parser_contract_version
    command_occurrence_count
    launch_upper_bound
    per_command_timeout_seconds
    max_workers
    policy_cap

    exact dedup 最適化まで行うなら、各 command の pure/non_pure、state_epoch、execution_key_hash、will_launch も planner の出力に含める必要があります。


    10. Runtime Verification Applicability は not_applicable ではない

    リポジトリの runtime verification policy では、not_applicable は typecheck・lint・unit test・build のみで完結し、process 起動や I/O が不要な場合です。process 起動・通信・I/O が実質的な検証対象なら immediate です。

    #2207 の中心的主張は、

    • nested subprocess が所定の deadline を受け取る

    • outer wrapper が先に timeout しない

    • timeout 時に process tree が残らない

    という runtime behavior です。mock だけでは production wiring を証明できません。

    数百秒の live test は不要ですが、50〜200 ミリ秒程度に scale down した fixture subprocess を用い、

    • inner timeout

    • outer deadline

    • cleanup grace

    • descendant reaping

    • typed timeout phase

    を一連で検証する immediate runtime AC が必要です。


    11. deadline は相対値の積み上げより、root の絶対 deadline として伝播すべき

    現在の実装は各層の timeout 上限を合算していますが、各 subprocess の開始までに消費した時間を次層が必ず差し引く契約にはなっていません。

    gRPC の deadline 設計では、root が deadline を設定し、下位 call へ伝播する際にはすでに経過した時間を差し引く方式が推奨されています。(gRPC)

    同一ホストの Python process 間では time.monotonic_ns() を利用できます。monotonic clock は後退せず、system clock 更新の影響を受けず、現在の Python では process 間で同じ clock を利用します。(Python documentation)

    推奨形は次です。

    deadline_ns = time.monotonic_ns() + per_attempt_budget_ns
    

    remaining_seconds = max(
    0.0,
    (deadline_ns - time.monotonic_ns()) / 1_000_000_000,
    )

    各 phase が独立に元の full timeout を受け取るのではなく、root deadline から remaining budget を算出する方が drift に強くなります。


    12. historical evidence が current main と一致していない

    #2207 の背景は main@a046fb37 と PR #2177 の途中値 1357 passed, 245.37s を使用していますが、レビュー時点の main は 12ae5b8... です。途中の commit では issue-refinement-loop の tests が多数追加され、PR #2177 自身の最終記録も 1375 passed, 259.14s へ更新されています。

    実測時間は hardware、cache、test 数で変動するため、budget SSOT に固定値として焼き付けるべきではありません。pytest の公式機能である --durations は性能回帰の telemetry として使い、budget contract は timeout cap と launch upper bound から導出する方が安定します。(pytestドキュメント)


    推奨する再設計

    最小で安全な案

    #2207 では exact dedup-aware planner まで実装せず、次の保守的なモデルに絞るのが適切です。

    N = max(
    2,
    normal execution parser が抽出した全 VC occurrence 数
    )

    現行 timeout path では、1 command 当たり次の上限があります。

    command execution cap       = 150 秒
    SIGTERM wait = 5 秒
    SIGKILL wait = 5 秒
    post-reap pipe drain = 5 秒

    そのため、少なくとも次の式が必要です。

    per_vc_slot = 150 + 15
    baseline_aggregate = N * per_vc_slot + 20
    readiness_wrapper = 30 + baseline_aggregate + 20
    deterministic_attempt = 30 + readiness_wrapper + 30 + 20
    transport_total = deterministic_attempt + 40

    この式は現在の 2-VC floor を維持します。

    VC occurrence 上限 N baseline aggregate readiness wrapper per-attempt total
    0〜2 350s 400s 480s 520s
    3 515s 565s 645s 685s
    4 680s 730s 810s 850s

    process creation delay は communicate(timeout=...) の外側で発生し得るため、この式だけで数学的な絶対保証にはなりません。したがって、hard ceiling、absolute deadline、cooperative cancellation を併用する必要があります。(Python documentation)

    推奨する責務配置

    run_root_review_pipeline
      ├─ live body を一度だけ取得・pin
      ├─ canonical VC planner を同じ body bytes に適用
      ├─ policy cap を検査
      ├─ immutable ReviewBudget を生成
      ├─ monotonic absolute deadline を生成
      └─ reviewer_transport へ invocation-local 値を明示渡し
    

    contract_readiness_check
    ├─ 同じ ReviewBudget / body SHA を検証
    └─ baseline subprocess へ remaining budget を渡す

    baseline_vc_preflight
    ├─ planner と executor が同じ command sequence を使用
    ├─ per-command timeout と cleanup tail を管理
    └─ SIGTERM 時に active VC process groups を回収

    reviewer_transport
    ├─ fallback constants 480/520 は不変
    └─ caller-supplied deadline を優先


    Issue 本文で置き換えるべき Acceptance Criteria

    1. Canonical plan: pinned body と同じ bytes、同じ normal execution parser から VC occurrence 数を算出し、body_sha256 と binding する。

    2. Conservative count: 実行 dedup されない duplicate non-pure command は occurrence 数分を数える。

    3. Pure coverage: distinct pure command も budget 対象に含める。

    4. State barrier: 同一 pure command が non-pure barrier の前後にある場合、現在の executor と同じく別 launch として扱う。

    5. Low-count compatibility: N <= 2 では 350/400/480/520 を維持する。

    6. Cleanup-aware growth: N >= 3 では command cap だけでなく timeout cleanup tail も比例拡張する。

    7. Policy ceiling: 上限超過時は subprocess 起動前に typed non-retryable failure となる。

    8. Explicit wiring: root pipeline が invocation-local deadline を transport に渡し、fallback module constants は変更しない。

    9. Cancellation: outer deadline 発火後、active VC direct child・grandchild が bounded time 内に消滅する。

    10. Scaled integration: production と同じ subprocess 階層で、inner timeout が outer timeout より先に typed classification される。

    11. Schema: duplicate diagnostic を残す場合は exact schema、consumer inventory、compatibility を固定する。


    最終結論

    動的 budget 導出そのものは、PR #2177 の残余リスクに対する正しい follow-up です。しかし #2207 の現契約は、

    • unique non-pure 数と実 launch 回数を混同している

    • pure VC の実行時間を無視している

    • timeout cleanup tail を計上していない

    • outer cancellation 時の descendant 残留を扱っていない

    • generic fallback constants と invocation-local budget を混同している

    • diagnostic schema change を要求しながら schema change を禁止している

    • 実装前から PASS する rg を VC としている

    • unbounded な Issue body から unbounded deadline を生成できる

    という状態です。

    実装着手前に reframe_in_place し、少なくとも budget denominator、policy ceiling、deadline ownership、cancellation、schema boundary、behavioral VC を確定すべきです。

    # 判定

    REQUEST_CHANGES。推奨 disposition は reframe_in_place です。

    #2207 が解こうとしている問題――「Verification Command 数が増えると、内側の VC 実行が終わる前に上位 wrapper / reviewer transport が timeout する」――は実在します。PR #2177 も、VC 数が理論上無制限である以上、固定 deadline では再発し得ることを未制御リスクとして明示していました。

    ただし、現契約のまま実装すると、次の危険な実装が自然に導かれます。

    重複した non-pure VC を 1 本として予算計算する一方、executor は同じ VC を 4 回起動する。

    これは #2195 の再現条件を解消せず、単に timeout の発生層をずらします。

    レビュー時点の main は 12ae5b868a0fab7b4563335c117e51fff97af284、#2207 の直接コメントは 0 件です。


    Blocker

    1. 予算計算の分母と、実際の subprocess 起動回数が一致しない

    #2207 は AC1 で「dedup 後の non-pure VC 数」を算出し、AC2 では同一 non-pure command の重複を diagnostic として検出しつつ、実行回数の削減自体は任意としています。さらに AC4 は「VC 数 2 本以下なら現行値維持」、AC5 は「3 本以上、または同一 command 重複なら拡張」としています。

    しかし現行 executor の dedup/replay 対象は、厳格に検証された rg と exact test -f|-d|-s だけです。pytest、uv run pytest、pnpm、git、gh 等の non-pure command は dedup されず、出現回数分だけ必ず起動され、各実行後に state_epoch を進める barrier として扱われます。

    したがって、例えば同じ pytest command が 4 回ある場合に、

    • diagnostic 上の unique count: 1
    • 実際の subprocess 起動回数: 4

    という乖離が発生します。

    また、同一 command が 2 回ある入力は、AC4 の「2 本以下なので現行値」と AC5 の「重複なので拡張」を同時に満たします。優先順位が定義されていないため、AC 自体も決定論的ではありません。

    必要な修正: 予算計算の入力は unique command 数ではなく、少なくとも 実際に起動し得る subprocess の保守的上限にしてください。non-pure command は、実行 dedup を本当に実装しない限り、出現回数をそのまま数える必要があります。重複 diagnostic と budget identity は分離すべきです。


    2. non-pure VC だけを数えても aggregate deadline の上限にならない

    現行 baseline_vc_preflight.py の --max-workers 既定値は 1 です。つまり production の strict 経路では、dedup されなかった distinct な pure command も直列に実行されます。

    現在の固定式は、

    • per-command cap: 150 秒
    • near-cap VC は最大 2 本と仮定
    • aggregate margin: 50 秒

    として 350 秒を導出しています。しかし「その他の rg 等は少数かつ高速」という前提はコメント上の仮定であり、Issue body に pure VC を大量に置くことを禁止する policy cap はありません。

    そのため、次の入力でも over-budget になります。

    • non-pure VC: 0 本
    • distinct pure VC: 数十本
    • budget 計算上の本数: 0
    • 実際の起動: 数十 subprocess、既定では直列

    必要な修正: 最小構成では、pure/non-pure を問わず 通常実行 parser が抽出した全 VC occurrence 数を数えてください。pure dedup や将来の並列化を正確に反映する最適化は、実行計画を SSOT 化する別段階として扱うべきです。


    3. outer timeout 時に、実行中の VC process group が残留し得る

    現行の VC executor は、各 command を start_new_session=True で起動します。per-command timeout では、SIGTERM、最大 5 秒待機、SIGKILL、最大 5 秒待機、さらに pipe drain を最大 5 秒実行します。したがって 150 秒の command cap とは別に、1 command 当たり最大 15 秒程度の timeout cleanup tail があります。

    一方、contract_readiness_check.py は baseline_vc_preflight.py 全体を subprocess.run(..., timeout=aggregate) で包んでいます。

    この組合せには次の failure mode があります。

    1. baseline process が VC を新しい session/process group で起動する。
    2. aggregate timeout が per-command timeout より先に発火する。
    3. Python の wrapper は直接子である baseline process を終了する。
    4. 別 session に移った VC process group は直接子 kill の対象外となり、継続する。

    Python の公式仕様でも、subprocess.run(timeout=...) は timeout 時に直接 child を kill/wait しますが、process creation 自体は timeout で中断できない場合があるとされています。([Python documentation]1)

    #2207 は outer timeout を発生しにくくしますが、cleanup tail、process creation delay、policy ceiling、将来の timing drift により outer timeout を完全には排除できません。

    必要な修正:

    • aggregate 式に per-command cleanup tail を含める。
    • policy ceiling 超過は subprocess 起動前に拒否する。
    • baseline process が SIGTERM を受けた場合、現在管理している全 VC process group を終了・回収する cooperative cancellation を実装する。
    • outer deadline → active VC descendant absent を実 process fault-injection test で検証する。

    4. reviewer_transport.py の module constants を動的化する設計は責務境界に反する

    現行の PER_ATTEMPT_DEADLINE_SECONDS=480 と TOTAL_DEADLINE_SECONDS=520 は、明示 deadline を渡さない caller のための generic fallback です。deterministic production path はこれらを直接使わず、run_root_review_pipeline.py が下位 phase の timeout を合成して、per-attempt / total を明示的に渡しています。

    したがって、AC3 の「reviewer_transport.py の PER_ATTEMPT_DEADLINE_SECONDS / TOTAL_DEADLINE_SECONDS が動的予算に整合する」は不適切です。module constant は Issue body に依存できません。実装者が global 値を書き換えると、同一 process 内で複数 Issue を処理する場合の race や test-order dependence を持ち込みます。

    必要な修正:

    • fallback constants 480/520 は不変にする。
    • pinned body から immutable な ReviewBudget を生成する。
    • run_root_review_pipeline._cmd_produce() が、その invocation 固有値を run_reviewer_transport() へ明示渡しする。
    • transport は渡された値を消費するだけにする。

    root pipeline はすでに Issue body を一度取得して SHA-256 と一緒に tempfile へ固定しているため、その同じ body bytes から budget を算出できます。


    5. duplicate diagnostic は schema change だが、Issue 自身が schema change を禁止している

    baseline_vc_preflight.py は baseline_vc_preflight/v1 の machine-readable JSON を producer として出力し、contract readiness、impl-review-loop、adjudicator、複数 test consumer が利用しています。リポジトリ内検索でも consumer は複数 skill にまたがっています。

    リポジトリの schema governance は、ファイル間・producer/consumer 間を横断する JSON、log、固定出力契約を schema と定義しています。schema の変更時には、before/after、全 consumer、各 consumer の更新状況を Schema Consumer Inventory に記載し、欠落時は APPROVE 禁止です。

    AC2 の structured diagnostic を実装するには、少なくとも次のどれかが必要です。

    • top-level diagnostics[] の追加
    • errors[] の新しい kind / rule / severity semantics
    • result item への duplicate metadata 追加

    いずれも consumer-facing contract の変更です。しかし #2207 の Stop Conditions は「固定契約のキー集合・schema・型定義の変更が必要なら停止」としており、schema 定義・consumer 更新用の Allowed Paths もありません。

    必要な修正: 次のどちらかに確定してください。

    1. 推奨: diagnostic schema 変更を follow-up Issue に分離し、実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2207 は budget derivation のみに限定する。
    2. 同一 Issue で扱うなら、diagnostic の exact shape、status への影響、compatibility decision、consumer inventory、必要な Allowed Paths を本文で固定する。

    6. 現在の Verification Commands は implementation evidence にならない

    AC1 の VC は _MAX_SEQUENTIAL_NEAR_CAP_VCS_ASSUMED を rg しますが、AC1 自身はその固定仮定を動的導出へ置換する要求です。正しく削除すると VC が失敗し、コメントや dead code に名前だけ残すと偽陽性になります。

    AC3 の VC が検索する PER_ATTEMPT_DEADLINE_SECONDS は現行 main にすでに存在します。AC2 の rg -n "duplicate" も現行 baseline_vc_preflight.py に既存の dedup/duplicate 関連記述があるため、実装前から一致します。

    つまり AC1〜AC3 の shallow rg は、

    • 実装前から PASS する
    • 正しい削除で FAIL する
    • コメントだけで PASS できる

    という状態です。

    さらに canonical な dedup test は .claude/skills/issue-contract-review/scripts/tests/ にありますが、#2207 の Allowed Paths は主に .claude/skills/issue-contract-review/tests/ を指定しており、既存 dedup regression test の更新経路が不足しています。

    必要な修正: rg による存在確認を撤去し、formula、production wiring、fallback preservation、duplicate semantics を関数出力と subprocess behavior で直接検証してください。


    High findings

    7. outer budget を増やしても、150 秒の per-command timeout は解消しない

    現行 per-command cap は 150 秒です。PR #2177 の最終記録では issue-refinement-loop の full suite は 1375 passed, 259.14s であり、#2207 に記載された 1357 passed, 245.37s は途中 iteration の値です。

    したがって #2195 のように full suite を VC として置くと、aggregate budget を 650 秒や 800 秒へ増やしても、各 occurrence は 150 秒で timeout します。改善されるのは「outer environment failure になる」問題であり、「VC が完走する」問題ではありません。

    これは #2207 の Outcome と Safety Claim Matrix に明示すべきです。

    本 Issue は wrapper/transport の premature timeout を防止する。per-command cap を超える VC 自体は引き続き typed timeout となり、command 分割または別 Issue が必要。


    8. Issue body に比例して無制限に deadline を拡張できる

    現状の契約には、VC 数や total review budget の hard ceiling がありません。Issue body に 100 本の VC を置くだけで、数時間規模の deadline を要求できる実装になり得ます。

    高すぎる timeout は process、memory、thread、file descriptor 等のリソースを長時間保持します。AWS の timeout 設計指針も、高すぎる timeout と多層 retry の負荷増幅を警告し、retry は stack 内の一箇所に集約することを推奨しています。([Amazon Web Services, Inc.]2)

    必要な修正:

    • MAX_VC_EXECUTION_SLOTS
    • MAX_BASELINE_AGGREGATE_SECONDS
    • MAX_DETERMINISTIC_ATTEMPT_SECONDS

    のいずれか、または複数を policy として固定してください。超過時は実行前に、typed・non-retryable な verification_budget_exceeds_policy で終了すべきです。


    9. budget parser と execution parser が drift する余地がある

    現行 baseline の normal execution path は legacy な extract_fenced_bash_blocks() / parse_commands_from_block() を使い、--static-only だけが別の unified parser を使います。

    budget derivation が別 parser を再実装すると、

    • budget は 2 本と認識
    • executor は 4 本抽出

    という arithmetic break が再発します。

    必要な修正: baseline_vc_preflight.py に side-effect-free な canonical planner を設け、budget derivation と executor の双方が同じ plan を使うべきです。最低限、plan には次を含めます。

    body_sha256
    parser_contract_version
    command_occurrence_count
    launch_upper_bound
    per_command_timeout_seconds
    max_workers
    policy_cap
    

    exact dedup 最適化まで行うなら、各 command の pure/non_pure、state_epoch、execution_key_hash、will_launch も planner の出力に含める必要があります。


    10. Runtime Verification Applicability は not_applicable ではない

    リポジトリの runtime verification policy では、not_applicable は typecheck・lint・unit test・build のみで完結し、process 起動や I/O が不要な場合です。process 起動・通信・I/O が実質的な検証対象なら immediate です。

    #2207 の中心的主張は、

    • nested subprocess が所定の deadline を受け取る
    • outer wrapper が先に timeout しない
    • timeout 時に process tree が残らない

    という runtime behavior です。mock だけでは production wiring を証明できません。

    数百秒の live test は不要ですが、50〜200 ミリ秒程度に scale down した fixture subprocess を用い、

    • inner timeout
    • outer deadline
    • cleanup grace
    • descendant reaping
    • typed timeout phase

    を一連で検証する immediate runtime AC が必要です。


    11. deadline は相対値の積み上げより、root の絶対 deadline として伝播すべき

    現在の実装は各層の timeout 上限を合算していますが、各 subprocess の開始までに消費した時間を次層が必ず差し引く契約にはなっていません。

    gRPC の deadline 設計では、root が deadline を設定し、下位 call へ伝播する際にはすでに経過した時間を差し引く方式が推奨されています。(gRPC)

    同一ホストの Python process 間では time.monotonic_ns() を利用できます。monotonic clock は後退せず、system clock 更新の影響を受けず、現在の Python では process 間で同じ clock を利用します。([Python documentation]4)

    推奨形は次です。

    deadline_ns = time.monotonic_ns() + per_attempt_budget_ns
    
    remaining_seconds = max(
        0.0,
        (deadline_ns - time.monotonic_ns()) / 1_000_000_000,
    )

    各 phase が独立に元の full timeout を受け取るのではなく、root deadline から remaining budget を算出する方が drift に強くなります。


    12. historical evidence が current main と一致していない

    #2207 の背景は main@a046fb37 と PR #2177 の途中値 1357 passed, 245.37s を使用していますが、レビュー時点の main は 12ae5b8... です。途中の commit では issue-refinement-loop の tests が多数追加され、PR #2177 自身の最終記録も 1375 passed, 259.14s へ更新されています。

    実測時間は hardware、cache、test 数で変動するため、budget SSOT に固定値として焼き付けるべきではありません。pytest の公式機能である --durations は性能回帰の telemetry として使い、budget contract は timeout cap と launch upper bound から導出する方が安定します。([pytestドキュメント]5)


    推奨する再設計

    最小で安全な案

    #2207 では exact dedup-aware planner まで実装せず、次の保守的なモデルに絞るのが適切です。

    N = max(
        2,
        normal execution parser が抽出した全 VC occurrence 数
    )
    

    現行 timeout path では、1 command 当たり次の上限があります。

    command execution cap       = 150 秒
    SIGTERM wait                =   5 秒
    SIGKILL wait                =   5 秒
    post-reap pipe drain        =   5 秒
    

    そのため、少なくとも次の式が必要です。

    per_vc_slot = 150 + 15
    baseline_aggregate = N * per_vc_slot + 20
    readiness_wrapper = 30 + baseline_aggregate + 20
    deterministic_attempt = 30 + readiness_wrapper + 30 + 20
    transport_total = deterministic_attempt + 40
    

    この式は現在の 2-VC floor を維持します。

    VC occurrence 上限 N baseline aggregate readiness wrapper per-attempt total
    0〜2 350s 400s 480s 520s
    3 515s 565s 645s 685s
    4 680s 730s 810s 850s

    process creation delay は communicate(timeout=...) の外側で発生し得るため、この式だけで数学的な絶対保証にはなりません。したがって、hard ceiling、absolute deadline、cooperative cancellation を併用する必要があります。([Python documentation]6)

    推奨する責務配置

    run_root_review_pipeline
      ├─ live body を一度だけ取得・pin
      ├─ canonical VC planner を同じ body bytes に適用
      ├─ policy cap を検査
      ├─ immutable ReviewBudget を生成
      ├─ monotonic absolute deadline を生成
      └─ reviewer_transport へ invocation-local 値を明示渡し
    
    contract_readiness_check
      ├─ 同じ ReviewBudget / body SHA を検証
      └─ baseline subprocess へ remaining budget を渡す
    
    baseline_vc_preflight
      ├─ planner と executor が同じ command sequence を使用
      ├─ per-command timeout と cleanup tail を管理
      └─ SIGTERM 時に active VC process groups を回収
    
    reviewer_transport
      ├─ fallback constants 480/520 は不変
      └─ caller-supplied deadline を優先
    

    Issue 本文で置き換えるべき Acceptance Criteria

    1. Canonical plan: pinned body と同じ bytes、同じ normal execution parser から VC occurrence 数を算出し、body_sha256 と binding する。
    2. Conservative count: 実行 dedup されない duplicate non-pure command は occurrence 数分を数える。
    3. Pure coverage: distinct pure command も budget 対象に含める。
    4. State barrier: 同一 pure command が non-pure barrier の前後にある場合、現在の executor と同じく別 launch として扱う。
    5. Low-count compatibility: N <= 2 では 350/400/480/520 を維持する。
    6. Cleanup-aware growth: N >= 3 では command cap だけでなく timeout cleanup tail も比例拡張する。
    7. Policy ceiling: 上限超過時は subprocess 起動前に typed non-retryable failure となる。
    8. Explicit wiring: root pipeline が invocation-local deadline を transport に渡し、fallback module constants は変更しない。
    9. Cancellation: outer deadline 発火後、active VC direct child・grandchild が bounded time 内に消滅する。
    10. Scaled integration: production と同じ subprocess 階層で、inner timeout が outer timeout より先に typed classification される。
    11. Schema: duplicate diagnostic を残す場合は exact schema、consumer inventory、compatibility を固定する。

    最終結論

    動的 budget 導出そのものは、PR #2177 の残余リスクに対する正しい follow-up です。しかし #2207 の現契約は、

    • unique non-pure 数と実 launch 回数を混同している
    • pure VC の実行時間を無視している
    • timeout cleanup tail を計上していない
    • outer cancellation 時の descendant 残留を扱っていない
    • generic fallback constants と invocation-local budget を混同している
    • diagnostic schema change を要求しながら schema change を禁止している
    • 実装前から PASS する rg を VC としている
    • unbounded な Issue body から unbounded deadline を生成できる

    という状態です。

    実装着手前に reframe_in_place し、少なくとも budget denominator、policy ceiling、deadline ownership、cancellation、schema boundary、behavioral VC を確定すべきです。

  3. squne121 commented on Aug 16, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 終了報告

    • termination_reason: approved
    • issue_kind: implementation
    • iterations: 2(Step 2 review 2 回。iteration 1: needs-fix / 6 blockers → Step 4 rewrite、iteration 2: approve)
    • reviewed_body_sha256(final): sha256:9d8d16af850b4ad268209ccb4b5e5824b38fe46d26d5de7819d0cfefac33d715

    経緯

    1. Step 0f preflight(preflight.run.with_human_context): STATUS: warn / NEXT_ACTION: proceed_with_notes、blockers なし。
    2. Step 1(codebase-investigator): OWNER レビュー(REQUEST_CHANGES / reframe_in_place)が指摘した 12 件の Blocker/High findings を現行コードで fact-check し、ほぼ全て CONFIRM(静的固定 budget、_MAX_SEQUENTIAL_NEAR_CAP_VCS_ASSUMED=2 固定、per-command timeout 150 秒、process group cleanup 実装済み、baseline_vc_preflight/v1 schema 変更が必要になる点等)。
    3. Step 2(review, iteration 1): VERDICT: needs-fix(6 blocker)。
    4. Step 4(rewrite): OWNER 推奨の再設計(Canonical plan / Conservative count / Pure coverage / State barrier / Low-count compatibility / Cleanup-aware growth / Policy ceiling / Explicit wiring / Cancellation / Scaled integration)を反映して AC1-AC10 へ全面置換。duplicate command diagnostic の schema 変更は OWNER 推奨 Option 1(follow-up Issue へ分離)を採用しスコープ外化。Runtime Verification Applicability を not_applicable → immediate へ変更(AC9/AC10 に <!-- runtime-verification: true --> タグ付与、applicable_acs / execution_environment / skip_conditions / fallback_policy / artifact_requirements を追加)。Background の historical evidence(1357 passed, 245.37s → 1375 passed, 259.14s、main SHA)を訂正。
    5. Step 2(review, iteration 2 / final review gate): readback で body hash 一致確認後、再レビュー実行。VERDICT: approve(blocker 0)。
    6. Step 4.5: delivery_rollup.applicable: false。follow-up candidate は既存 Issue 実装: fix: recover source evidence before refinement human escalation #2195 への参照のみで新規起票不要。

    主要な変更点(Issue 本文)

    • AC1-AC5(_MAX_SEQUENTIAL_NEAR_CAP_VCS_ASSUMED 動的化・duplicate diagnostic・PER_ATTEMPT_DEADLINE_SECONDS/TOTAL_DEADLINE_SECONDS 直接書き換え・shallow rg VC)を撤回し、AC1-AC10(canonical VC planner・conservative occurrence count・pure coverage・state barrier・low-count compatibility・cleanup-aware growth formula・policy ceiling・explicit invocation-local wiring・cooperative cancellation・scaled fault-injection runtime test)へ全面置換。
    • reviewer_transport.py の fallback constants (PER_ATTEMPT_DEADLINE_SECONDS=480/TOTAL_DEADLINE_SECONDS=520) は不変とし、run_root_review_pipeline._cmd_produce() から invocation-local ReviewBudget を明示引数で渡す設計に変更。
    • Allowed Paths に .claude/skills/issue-contract-review/scripts/tests/(canonical dedup/planner test の実配置場所)を追加。
    • Required Design References に docs/dev/runtime-verification-policy.md / docs/dev/agent-skill-boundaries.md を追加(RDR001 修正)。
    • Out of Scope に duplicate command diagnostic の schema 変更(follow-up Issue へ分離)を明記。
    • Safety Claim を明示: 本 Issue は per-command cap(150 秒)自体は解消しない。
    • Background の実測値・main SHA を最新化し、OWNER レビューの反映履歴を追記。

    Final Gate

    LOOP_HANDOFF_RESULT_V1.status: blocked(contract_review.gate_result: missing_go — issue-contract-review skill が本 Issue に対してまだ実行されておらず、CONTRACT_REVIEW_RESULT_V1 の go snapshot が存在しないため)。issue-refinement-loop 自体の判定は approved だが、impl-review-loop への handoff には別途 issue-contract-review の実行が必要。

    LOOP_HANDOFF_RESULT_V1:
      status: blocked
      routing_action: blocked
      contract_review:
        status: blocked
        gate_result: missing_go
        latest_comment_url: null
        generated_at: null
        body_sha256: "sha256:9d8d16af850b4ad268209ccb4b5e5824b38fe46d26d5de7819d0cfefac33d715"
      metadata:
        title_prefix_ready: true
      label_sync_observation:
        kind: presentation_sync
        result: noop
        detail: "issue-refinement-loop はラベル操作を行わない"
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers:
        - kind: contract_review_not_run
          description: "issue-contract-review skill が未実行のため CONTRACT_REVIEW_RESULT_V1 の go snapshot が存在しない(gate_result: missing_go)。impl-review-loop への handoff 前に issue-contract-review を実行すること。"
      permissions:
        unavailable: []
      generated_at: "2026-08-16T10:00:12Z"
      checked_body_sha256: "sha256:9d8d16af850b4ad268209ccb4b5e5824b38fe46d26d5de7819d0cfefac33d715"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues: []
      note_only_observations:
        - dedupe_key: "follow-up:squne121/loop-protocol:issues/2207:291fdcbbe670284a"
          source_url: "https://github.com/squne121/loop-protocol/issues/2207"
          source_note_id: "291fdcbbe670284a"
          summary: "Issue #2195 本体の contract reframe は既存 Issue #2195(OPEN, human_escalation で停止中)で扱われるため新規起票不要。"
        - dedupe_key: "follow-up:squne121/loop-protocol:issues/2207:duplicate-command-diagnostic-schema"
          source_url: "https://github.com/squne121/loop-protocol/issues/2207#issuecomment-5306506129"
          source_note_id: "owner-review-blocker-5"
          summary: "同一 non-pure コマンド重複の diagnostic 化(baseline_vc_preflight/v1 producer schema への diagnostics[] 追加と consumer inventory 更新)は本 Issue のスコープから除外した。OWNER レビュー推奨 Option 1 に従い、実装が具体化した段階で別途 follow-up Issue の起票を検討する。"
  4. squne121 commented on Aug 16, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-08-16T11:04:45Z)

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