Skip to content

fix: reviewer transport の deadline/retry policy を長時間 VC に整合させる - #2177

Merged
squne121 merged 10 commits into
mainfrom
worktree-issue-2165-reviewer-transport-deadline
Aug 15, 2026
Merged

squne121 merged 10 commits into
mainfrom
worktree-issue-2165-reviewer-transport-deadline

Conversation

@squne121

@squne121 squne121 commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

reviewer_transport.py の PER_ATTEMPT_DEADLINE_SECONDS(旧90秒)を含む複数層の
timeout 値が、baseline_vc_preflight が実行する正当な長時間 Verification Command
(issue-refinement-loop skill 自身の full pytest suite、実測111.07秒)を吸収できず、
root_review_pipeline.produce が reviewer_transport_environment_failure を誤って
返していた(#2165)。単純な deadline 数値の引き上げのみに依存せず、以下を組み合わせて
解消する。

  • baseline_vc_preflight.py: per-VC-command timeout(DEFAULT_TIMEOUT_SECONDS)を
    90→150秒に拡大(実測111.07秒に約35%の安全マージン)。
  • contract_readiness_check.py: baseline_vc_preflight wrapper timeout を120→200秒
    に拡大し、内側の値と整合させる。
  • run_root_review_pipeline.py: contract_readiness_check wrapper timeout を60→250秒
    に拡大し、内側の値と整合させる。
  • reviewer_transport.py:
    • PER_ATTEMPT_DEADLINE_SECONDS を90→300秒、TOTAL_DEADLINE_SECONDS を240→340秒に
      拡大し、層ごとの budget 合成根拠を docstring に明記する。
    • retry_matrix() を backend-aware にし、backend="deterministic"(checker-pipeline
      child)では timeout / 新設の inner_timeout を再試行対象から除外する。同一 VC を
      同一 body に対して再実行しても結果は変わらず、旧設計は 3 attempt × 90秒 = 270秒 > 240秒 total deadline という算数的破綻を抱えていた(OWNER指摘)。
    • 子プロセス(run-checker-attempt)が内部で検出した構造化 timeout
      ({"error_code": "timeout"})が汎用 nonzero_exit に潰されず、inner_timeout として
      区別可能になるよう分類ロジックを追加した(OWNER指摘)。

Checks

  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_ac1_live_issue_no_environment_failure.py -v — PASS(実サブプロセス、live Issue 実装: issue-refinement-loop の anchor scope reframe payload 不在判定を fail_closed から freeform lane 継続へ変更する #2156 に対する run_root_review_pipeline.py produce 実行、153.76秒、reviewer_transport_environment_failure を発生させず VERDICT に到達することを確認)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_deadline_matches_vc_worst_case.py -v — PASS(7 tests、deadline 整合性・backend-aware retry policy を検証)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_environment_failure_regression.py -v — PASS(7 tests、spawn_failure/signal/timeout の既存分類が新 deadline でも維持されること、inner_timeout 分類の正誤を検証)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q — PASS(1357 passed, 245.37s。AC4)
  • uv run ruff check (変更ファイル一式)— PASS

Schema Change Applicability

  • decision: not_schema_change
    (スキーマ変更ではない。フィールド集合・型は不変)

REVIEWER_TRANSPORT_RESULT_V1 / REVIEWER_ATTEMPT_RESULT_V1 のフィールド集合・型は変更していない。reason_code の値ドメインに inner_timeout を追加したが、これは既存フィールドの許容値集合への追加であり、フィールド・スキーマ形状自体の変更ではない。

Schema Consumer Inventory

n/a(not_schema_change のため)

Safety Claim Matrix

このPRは .claude/skills/ 配下(transport / checker pipeline)を変更するため safety-sensitive として扱う。

Claim Implemented? Not controlled Evidence Follow-up
正当な長時間 VC(full pytest suite 実測111.07秒)を持つ Issue の re-review が reviewer_transport_environment_failure を発生させなくなる yes none test_ac1_live_issue_no_environment_failure.py(live Issue #2156、153.76秒、PASS) none
既存の transport-failure 検知(spawn_failure / signal / 真の hang)は deadline 拡大後も environment_failure として検出され続ける yes none test_reviewer_transport_environment_failure_regression.py 全7 test PASS(production defaults での spawn_failure、小 deadline での real hang/signal を含む) none
deterministic backend の timeout/inner_timeout は再試行されず、無意味な load 増幅(3 attempt × 旧90秒 > 旧240秒 total deadline の算数的破綻)を再発させない yes none test_reviewer_transport_deadline_matches_vc_worst_case.py::test_deterministic_backend_does_not_retry_timeout_or_inner_timeout PASS none
子プロセスが検出した構造化 timeout({"error_code": "timeout"})は nonzero_exit に潰されず inner_timeout として区別できる yes none test_reviewer_transport_environment_failure_regression.py::test_given_child_detected_timeout_json_on_stderr_then_classified_inner_timeout_not_nonzero_exit PASS none
多数の VC(理論上無制限)を持つ Issue 本文に対しては、本 PR の固定 wrapper timeout(150/200/250/300/340秒)でも over-budget になり得る(動的 VC 数に応じた deadline 導出は未実装) no 理論上無制限に多い VC 数を持つ Issue body(本 PR の scope 外、固定値ベースの設計を維持) Issue #2165 In Scope に列挙された代替案(動的 deadline 導出)は本 PR では採用せず、固定値+backend-aware retry policy で解消した #2165 の Out of Scope に準ずる。将来必要になれば新規 Issue で対応

Notes

Closes #2165(本 Issue を解決する)

fix_delta 第2回対応(OWNER 指摘への再対応)

本 PR のコメント issuecomment-5299813915 にある OWNER の再度の指摘事項へ対応した内容を記す。

## Summary は元コミット時点(PER_ATTEMPT_DEADLINE_SECONDS=90→300 等)の記述のままだが、その後の同一 PR 内の追加コミットで deadline はさらに 300→480秒 / 340→520秒 に拡大され、retry_matrix() の deterministic backend 除外対象へ timeout も追加された(OWNER 2026-08-15 一次 REQUEST_CHANGES 対応済み)。本 iteration はその次の OWNER REQUEST_CHANGES に対応する。

(a) merge condition #5 / P1-2(VC subprocess の孫プロセス reaping)— 解決(fix_delta 第3回で対応)

第2回 fix_delta 時点では、正しい修正(Popen+communicate(timeout=...)+killpg())に必要な test_pnpm_gate_security_boundary.py(baseline.subprocess.run を直接 monkeypatch する既存テスト)が Issue #2165 の Allowed Paths 外であり、Stop Conditions(「Allowed Paths 外の変更が必要と判明した場合」)に該当するため未解決として開示していた。

human/OWNER が Issue #2165 の Allowed Paths を明示的に拡張し、test_pnpm_gate_security_boundary.py を追加した(8番目のエントリとして live Issue 本文に反映済み)ため、本 iteration(fix_delta 第3回)でこの merge condition を解消した。

  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py::run_command() を subprocess.run(argv, timeout=...) から subprocess.Popen(argv, start_new_session=True) + communicate(timeout=...) へ変更した。timeout 時は新設の _kill_process_group() が os.getpgid(process.pid) で取得した pgid に対し os.killpg(pgid, SIGTERM) → (bounded grace period 後)os.killpg(pgid, SIGKILL) を送り、process group 全体(直接子+孫プロセス)を回収する。start_new_session=True により各 Popen 呼び出しは独立した session/pgid を持つため、ThreadPoolExecutor(max_workers>1) 経由で複数 VC が並行実行されても、ある VC の timeout-kill が別の VC の process group を誤って巻き込むレースは構造的に発生しない(各呼び出しが自分自身の pgid のみを対象にするため、共有/グローバルな state は存在しない)。
  • test_pnpm_gate_security_boundary.py の3テスト(test_noncanonical_pnpm_requests_are_blocked_without_launch / test_manifest_hook_and_closure_drift_blocks_before_launch / test_producer_evidence_round_trips_to_triage)は、monkeypatch 対象を baseline.subprocess.run から baseline.subprocess.Popen へ変更した。セキュリティ境界の assertion 自体(noncanonical request は launch 前に block される・manifest drift は launch 前に block される・producer evidence が triage へ正しく round-trip する)は一切変更していない。
  • 新規 fault-injection test test_run_command_timeout_reaps_grandchild_process_not_just_direct_child を追加した。実際に grandchild process を spawn する fixture script を使い、run_command() の timeout 後に直接子・孫プロセスの両方の pid が bounded time(5秒)内に消滅することを検証する。mutation test で確認済み: _kill_process_group() を「直接子のみ kill する」旧実装相当(os.killpg を os.kill(process.pid, ...) に置換)へ一時的に戻すと、このテストは実際に FAIL する(孫プロセスが生き残る)ことを確認し、元の実装に復元した。

(b) merge condition #8(非deterministic backend への retry budget guard の一律適用)— 解決

run_reviewer_transport() 自身の attempt ループは元々 backend 非依存で MIN_RETRY_ATTEMPT_BUDGET_FRACTION guard を適用していた(backend == "deterministic" の分岐は存在しない)。実際のギャップは別レイヤーの run_root_review_pipeline.py::retry_once_on_transport_failure()(transport failure 時に invoke_child() を無条件に1回だけ retry する、run_reviewer_transport() とは別のリトライループ)で、残り budget を一切考慮せず retry していた点だった。

  • reviewer_transport.py に has_sufficient_retry_attempt_budget() を新設し、run_reviewer_transport() の既存 guard をこの共有関数に委譲するようリファクタした(backend 非依存であることをコードで担保)。
  • run_root_review_pipeline.py::retry_once_on_transport_failure() に任意引数 elapsed_seconds / total_deadline_seconds / per_attempt_deadline_seconds を追加し、供給された場合は同じ guard を適用して budget 不足時は retry をスキップする(retry_skipped_reason: "insufficient_retry_budget")。3引数のいずれかが省略された場合は既存の無条件 retry-exactly-once 挙動を維持する(後方互換)。
  • test_reviewer_transport_deadline_matches_vc_worst_case.py に新規4テストを追加し、backend 非依存性(has_sufficient_retry_attempt_budget() に backend 引数が存在しないこと自体を検証)と retry_once_on_transport_failure() の budget guard 有効時/無効時の挙動を確認した。

検証結果(第2回 fix_delta 追加分)

  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_deadline_matches_vc_worst_case.py -v — PASS(19 tests)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_environment_failure_regression.py -v — PASS(9 tests、回帰なし)
  • uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pnpm_gate_security_boundary.py -v — PASS(15 tests、Allowed Paths 外だが回帰なきことを確認)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q — PASS(AC4、後述の実測値を参照)
  • uv run --locked pytest .claude/skills/issue-contract-review/tests/ -q — PASS(512 tests、baseline_vc_preflight.py / contract_readiness_check.py の回帰チェック)
  • uv run ruff check(変更ファイル一式)— PASS

fix_delta 第3回対応(OWNER 指摘への再対応・Allowed Paths 拡張後)

human/OWNER が Issue #2165 の Allowed Paths を明示的に拡張し .claude/skills/issue-contract-review/tests/test_pnpm_gate_security_boundary.py を追加したことを受け、上記「fix_delta 第2回対応」(a) で未解決として開示していた merge condition #5 / P1-2 を本 iteration で解消した(詳細は上記 (a) セクションを更新済み)。

検証結果(第3回 fix_delta 追加分)

  • uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pnpm_gate_security_boundary.py -v — PASS(16 tests、新規 grandchild-reaping fault-injection test 1件を含む)
  • uv run --locked pytest .claude/skills/issue-contract-review/tests/ -q — PASS(513 tests、baseline_vc_preflight.py の回帰チェック)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_ac1_live_issue_no_environment_failure.py -v — PASS(5 tests、154.08秒。AC1、live Issue 実装: issue-refinement-loop の anchor scope reframe payload 不在判定を fail_closed から freeform lane 継続へ変更する #2156 に対する run_root_review_pipeline.py produce 実行)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_deadline_matches_vc_worst_case.py -v — PASS(19 tests。AC2)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_environment_failure_regression.py -v — PASS(9 tests。AC3)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q — PASS(1375 passed, 243.55秒。AC4)
  • uv run ruff check(変更ファイル一式: baseline_vc_preflight.py / test_pnpm_gate_security_boundary.py)— PASS

fix_delta 第4回対応(OWNER 追加 Allowed Paths 拡張後)

human/OWNER が Issue #2165 の Allowed Paths をさらに拡張し、
.claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py と
.claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py
の2ファイルを追加したことを受け、fix_delta 第3回(run_command() の
subprocess.run → subprocess.Popen 移行)で mock ターゲットがずれて
FAIL していた既存テスト5件を本 iteration で解消した。

(1) mock ターゲットずれ 4件 — 解決

test_p0_2_run_command_uses_stdin_devnull / test_fixed_env_injects_ci_true_for_pnpm_build /
test_fixed_env_applies_to_all_canonical_pnpm_gates / test_runner_env_delta_output_exposes_only_fixed_env
はいずれも subprocess.run を直接 monkeypatch していたが、fix_delta 第3回の
run_command() 実装変更により subprocess.Popen(...) + communicate(timeout=...) が
呼ばれるようになったため、mock が一切 intercept されず FAIL していた。
test_pnpm_gate_security_boundary.py(fix_delta 第3回で確立済み)と同じ
baseline.subprocess.Popen を直接 monkeypatch するパターン(FakeProcess
.communicate() / .returncode を持つ最小スタブ、または実 Popen を
subclass して起動 kwargs を記録する RecordingPopen)に retarget した。
セキュリティ/挙動 assertion 自体(stdin=DEVNULL の伝播・CI=true env
injection・runner_env_delta の漏洩防止)はいずれも変更していない。

(2) test_issue_393_snapshot_fixture_processed の90秒タイムアウト — 調査の結果、Popen 実装の real regression ではないことを確認

単体で pytest -v 実行すると subprocess.TimeoutExpired が正確に90.17秒で
発生することを確認した上で、同じ preflight 呼び出し(baseline_vc_preflight.py
本体を直接、外側の90秒 wrapper なしで実行)を単独で走らせたところ、
181秒でクリーンに完了し、内部で最も重い VC(issue-refinement-loop skill 自身の
uv run pytest ... -v、real full suite)が _kill_process_group() によって
per-VC timeout=150秒ちょうどで正しく打ち切られ(duration_ms=150438,
exit_code=-1, classification=blocked)、ハングやデッドロックは一切
発生していないことを確認した。

原因は run_command() の Popen 実装ではなく、テストヘルパー
run_preflight() 自身が持つ outer subprocess.run(..., timeout=90)
が、本 Issue の最初のコミット(iteration 1)で行われた
baseline_vc_preflight.py の DEFAULT_TIMEOUT_SECONDS 90→150 拡大に
追随していなかった(pre-existing test staleness、iteration 3 の
Popen 移行そのものとは無関係)ことだった。issue_393_body.md は
このテストスイート内で唯一、実際の regression-gate コマンド
(pnpm typecheck/lint/test/build + issue-refinement-loop の
full pytest suite)をシリアルに real 実行する fixture であり、
実測合計 wall-clock time は約181秒だった。実測値に安全マージンを
載せて run_preflight() の outer timeout を90秒→220秒へ更新した。

検証結果(第4回 fix_delta 追加分)

  • uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/ -q — 全体成功(313 passed, 1 skipped, 199.07秒、対象修正5件を含む)
  • uv run --locked pytest .claude/skills/issue-contract-review/tests/ -q — 全体成功(513 tests, 16.58秒、回帰なし)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_ac1_live_issue_no_environment_failure.py -v — 成功(5 tests, 154.64秒。Issue本文 AC1 に対応)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_deadline_matches_vc_worst_case.py -v — 成功(19 tests。Issue本文 AC2 に対応)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_reviewer_transport_environment_failure_regression.py -v — 成功(9 tests。Issue本文 AC3 に対応)
  • uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q — 全体成功(1375 passed, 259.14秒。Issue本文 AC4 に対応)

変更ファイルは Allowed Paths 内の新規2ファイルのみ(
.claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py /
.claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight_parallel.py)。

`PER_ATTEMPT_DEADLINE_SECONDS=90` を含む複数層の timeout 値が、
baseline_vc_preflight が実行する正当な長時間 Verification Command
(issue-refinement-loop skill の full pytest suite、実測111.07秒)を
吸収できず、root_review_pipeline.produce が
reviewer_transport_environment_failure を誤って返していた。

- baseline_vc_preflight.py: per-VC-command timeout を90→150秒に拡大
- contract_readiness_check.py: baseline_vc_preflight wrapper timeout を
  120→200秒に拡大(内側の値と整合)
- run_root_review_pipeline.py: contract_readiness_check wrapper timeout
  を60→250秒に拡大(内側の値と整合)
- reviewer_transport.py:
  - PER_ATTEMPT_DEADLINE_SECONDS を90→300秒、TOTAL_DEADLINE_SECONDS を
    240→340秒に拡大(層ごとの budget 合成を docstring に明記)
  - retry_matrix() を backend-aware にし、backend="deterministic" では
    timeout/inner_timeout を再試行対象から除外(同一 VC の再実行は結果を
    変えず、3 attempt × 90秒 > 240秒 total deadline の算数的破綻を招いて
    いたため)
  - 子プロセスが検出した構造化 timeout({"error_code": "timeout"})が
    汎用 nonzero_exit に潰されないよう inner_timeout として分類

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-2177/

The preview will be removed when this PR is closed.

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES — 現在の HEAD a80c6d7eac2c870ba1b863e60552a6701a8cf3ae はマージ不可です。

PRはDraftのままopenで、変更は7ファイルです。CIはgreenですが、後述のとおり、Issue #2165の中心的なruntime ACはcurrent-head CIでは実行されていません。方向性として、複数層のtimeoutを調整し、内部timeoutをnonzero_exitから分離しようとしている点は妥当です。しかし、実timeoutをsemantic needs-fixへ誤変換できる経路、AC1テストのfalse-pass、非合成的なdeadline設計、残存プロセス、retry契約違反が残っています。

確認対象は、Issue #2165とOWNERのREQUEST_CHANGES、Issue #2054/PR #2142、Issue #2040/PR #2070、Issue #2153、変更7ファイル、current-head CIおよびJUnit artifactです。


P0-1: 実際のtimeoutがsemantic needs-fixへ化け、STATUS: okで受理され得る

今回追加したinner_timeout分類が機能するのは、run-checker-attemptが失敗して、stderrへ正確に{"error_code":"timeout"}を出してexit 2した場合だけです。

ところが、contract_readiness_check.pyの200秒wrapperでbaseline_vc_preflight.py全体がtimeoutした場合、実際には次の経路になります。

baseline_vc_preflight wrapper が200秒でtimeout
  ↓
contract_readiness_check が
  status: blocked
  results: []
  errors: ["timeout"]
を通常JSONとして返す
  ↓
plain stringのエラーを
  category: no_commands_extracted
  readiness_status: needs_fix
へ変換
  ↓
run_root_review_pipeline は readiness の非ゼロexit codeを無視
JSONがparseできれば通常のmergeへ進む
  ↓
timeoutがsemantic needs-fixとして採用され得る

run_baseline_vc_preflight()のtimeout処理は、構造化されたruntime errorではなく、errors: ["timeout"]を持つ通常のblocked payloadを返します。そして、blocked + resultsなし + plain string errorはno_commands_extracted / needs_fixへ写像されます。

さらにroot pipelineは、run_contract_readiness_check()から返る_readiness_rcを判定に使用せず、payloadがNoneでない限り正常なmerge入力として扱っています。したがって、この経路ではrun-checker-attemptがexit 2にならず、reviewer transportのinner_timeout判定自体が呼ばれません。

これは単なる診断不足ではありません。実行環境障害がIssue本文の欠陥へ変換され、semantic verdictのauthorityを汚染します。 Issue #2165のAC1はapproveまたはneeds-fixのどちらでも合格するため、timeout由来の偽needs-fixでもAC1を満たしたように見えます。

必須修正

baseline_vc_preflightのaggregate timeoutは、少なくとも次のようなtyped failureとして返す必要があります。

{
  "status": "runtime_error",
  "failure_class": "timeout",
  "timeout_phase": "baseline_vc_preflight_aggregate",
  "retryable": false
}

errors: ["timeout"]のようなplain stringをno_commands_extractedへフォールバックさせてはいけません。root pipelineでは、payloadのstatusとprocess exit codeの整合性を検証し、runtime errorをsemantic mergeへ渡さないことが必要です。

回帰テストは、200秒を実際に待つのではなくscaled timeoutまたは注入可能clockを使い、

baseline aggregate timeout
→ semantic_verdict is null
→ needs-fix ではない
→ timeout_phase が保持される
→ deterministic backendでは再試行しない

を検証すべきです。


P0-2: AC1テストが任意の取得失敗を成功扱いし、CIでは0秒skipされている

Issue #2165のAC1は、live Issue #2156に対してSTATUS: okとなり、VERDICT: approve | needs-fixへ到達することを要求しています。Runtime Verification Applicabilityにも、GitHub通信が利用可能なのに結果を得られない場合はFAILであり、fallback successをPASSへ変換しないと明記されています。

しかし、新規テストは次を許容しています。

assert status in {"ok", "input_or_runtime_error"}

if status == "ok":
    assert verdict in {"approve", "needs-fix"}
else:
    assert unrelated_error_code is not None

つまり、認証自体は通るが、

  • 一時的なGitHub API障害
  • Issue取得失敗
  • repository解決失敗
  • body欠落
  • JSON parse失敗

などが起きても、reviewer_transport_environment_failure以外のerror codeならPASSします。これはAC1の検証ではなく、特定のerror stringが出なかったことだけを検証するテストです。

current-head CIのpython-test-coreは成功していますが、アップロードされたpython-test-junit-1 artifactを展開したところ、このテストは次の状態でした。

time="0.000"
skipped: gh auth not available in this execution environment (SKIP, not PASS)

したがって、PR本文に記載された「153.76秒PASS」はローカル自己申告であり、current-head CIによる再現証拠ではありません。CI jobとJUnit artifact自体はcurrent HEADに紐づいています。

必須修正

テストを二分してください。

  1. 決定論的integration test

    live GitHub Issueに依存せず、固定body・固定SHA・scaled timeoutを使って、必ずstatus == "ok"とverdict到達を検証します。timeoutをsemantic needs-fixへ変換していないことまで確認する必要があります。

  2. live runtime canary

    gh authなしの場合だけskipし、認証済み環境でのIssue取得失敗はFAILにします。artifactには少なくとも次を記録してください。

    • tested PR HEAD SHA
    • live Issue body SHA
    • subprocess exit code
    • root pipeline status
    • semantic verdict
    • attempt reason codes
    • compact artifact pathとdigest

AC1をmerge evidenceとして使うなら、認証済みcurrent-head canaryのartifactが必要です。


P1-1: deadline階層は依然として非合成的で、固定値の算数が成立していない

PRのコメント自身が、deterministic child内のphase上限を次のように記述しています。

check_issue_contract:        30秒
contract_readiness_check:   250秒
merge_readiness:             30秒
合計上限:                   約310秒

しかし、外側のPER_ATTEMPT_DEADLINE_SECONDSは300秒です。したがって、各内部phaseが自身の契約内で完了していても、外側が10秒早く子をkillできます。

さらに、baseline_vc_preflightはper-command 150秒ですが、そのaggregate wrapperは200秒です。VCはデフォルト--max-workers=1で逐次実行されるため、150秒近い正当なVCが2本あるだけでaggregate wrapperを超えます。「理論上無制限に多いVC」まで持ち出す必要はなく、2本で破綻します。

追加テストも、実測値111.07をハードコードして、

PER_ATTEMPT >= 111.07 * 1.35
TOTAL >= PER_ATTEMPT

だけを確認しています。phase合計、VC数、process startup、artifact I/O、cleanup、retry reserveは検証していません。テストsuiteが増えれば、定数とテストが同時に陳腐化します。

また、Claude/Codex backendではtimeoutを引き続きretryableとしていますが、

per-attempt: 300秒
total:       340秒

なので、1回目が300秒を消費すると2回目には最大40秒しか残りません。process-group cleanupやreader joinを含めるとさらに短くなります。これは「retry intent」は残しても、実用的なretry budgetを残していない状態です。実backendのresume canaryはIssue #2153として現在もopenです。

gRPCのdeadline設計では、独立した相対timeoutを各層へ手作業で置くのではなく、元のabsolute deadlineを伝播し、既に消費した時間を差し引いて下位へ渡す方式が推奨されています。長時間処理をspawnした側がcancel時の処理停止を担う点も明記されています。(gRPC)

AWSも、timeoutを単一実測値ではなく許容false-timeout率とlatency percentileから設定し、retryは負荷を増幅するため回数を制限し、原則一つの層で行うべきだとしています。([Amazon Web Services, Inc.]2)

必須修正

固定値の独立定義ではなく、次のいずれかが必要です。

  • monotonic absolute deadlineをrootで一度だけ生成し、全childへ伝播する
  • remaining = deadline - monotonic_now()を各層で使用する
  • VC数とper-command capからaggregate budgetを導出する
  • aggregate budget超過のIssueは、実行前に構造化されたover-budgetとして停止する
  • retryable backendでは、次attemptの最低実行時間・cleanup・backoffを事前予約する
  • 残時間が最低budget未満なら、新しいattemptをspawnしない

境界テストとして、2本の長時間VC、30+250+30のphase合成、1回目timeout後のretry budgetをscaled clockで検証してください。


P1-2: inner timeout時のprocess tree回収が実装されていない

reviewer transportがprocess groupへSIGTERM → SIGKILLを送るのは、外側自身のprocess.wait()がtimeoutした場合だけです。内部checkerがtimeoutを検出してexit 2した場合、外側のtimed_outはfalseなので、process-group回収処理へ入りません。

一方、最内層のbaseline_vc_preflight.run_command()は通常のsubprocess.run(..., timeout=...)を使用し、start_new_session=Trueや独自のprocess-group cleanupを設定していません。

Pythonの公式仕様が保証するのは、timeout時に直接のchild processをkillしてwaitすることです。spawnされたgrandchildを含むprocess tree全体の回収保証ではありません。([Python documentation]3)

新規regression testは、内部timeoutを模したPython processがJSONをstderrへ出してexit 2するだけです。nested subprocess、grandchild、pipe write-end保持、PID残存を一切検証していません。

影響

pytestやtoolingがchild processをspawnした場合、timeout後も次が残り得ます。

  • CPU・メモリ消費
  • workspaceへの遅延書き込み
  • stdout/stderr pipe保持
  • 次attemptとの同時実行
  • test serverやwatcherの残存
  • 同じIssueの再実行との干渉

必須修正

Linux/WSL2前提なら、最内層のVC実行もPopen(start_new_session=True)等で独立process groupとして起動し、timeout時にgroup全体を回収してください。preexec_fn=os.setsidではなく、thread-safeなstart_new_session=Trueを使うべきです。

fault injectionは次の構造が必要です。

reviewer transport
└─ run-checker-attempt
   └─ contract_readiness
      └─ baseline_vc_preflight
         └─ fixture child
            └─ escaped or normal grandchild

inner timeout後に、child PID、grandchild PID、pipe readerがすべてbounded time内に終了し、descendants_reapedまたは同等の証拠がtrueになることを確認してください。


P1-3: deterministic backendのvalidation failureが依然として最大3回再実行される

OWNERのREQUEST_CHANGESは、deterministic backendについて次のpolicyを要求しています。

structured_checker_timeout:
  retryable: false
validation_failure:
  retryable: false
spawn_failure:
  retryable: true
signal_or_transport_hang:
  retryable: true

しかしPRが非retryableにしたのはtimeoutとinner_timeoutだけです。nonzero_exit、malformed_output、capture_failureなどはdeterministic backendでもretryableのままです。

新規テストはこの不整合を修正するどころか、次の挙動を仕様として固定しています。

# deterministic backend
unrelated nonzero_exit
→ MAX_ATTEMPTSまで全attemptを消費する

{"error_code":"gh_auth_failed"}や非JSON stderrもnonzero_exitへ落とされます。malformed_json、body parse failure、schema validation failureなども専用分類がなければ同様です。

同じbody、同じargv、同じ固定環境で決定論的に失敗したcheckerを3回実行しても成功確率は上がらず、負荷だけが増えます。AWSのretry設計でも、client/validation系の失敗は同じrequestを再実行しても成功しないため、retry対象を明示的に制限することが重要とされています。([Amazon Web Services, Inc.]2)

必須修正

stderrの文字列推測ではなく、childから次を返してください。

{
  "schema": "CHECKER_ATTEMPT_FAILURE_V1",
  "failure_class": "validation_failure",
  "failure_phase": "contract_readiness",
  "reason_code": "malformed_checker_output",
  "retryable": false,
  "timeout_phase": null
}

deterministic backendのretryはclosed allowlistにし、少なくとも以下だけに限定すべきです。

spawn_failure
signal
transport_hang
一時的な明示済みI/O failure

nonzero_exitをretry理由として残すなら、exit codeだけで判断せず、その内部failure classを必須にしてください。


P1-4: inner_timeoutは実質的なschema変更であり、#2040のtaxonomyと衝突している

PR本文は次の理由でnot_schema_changeとしています。

field集合・型は不変で、reason_codeの値を追加しただけ

しかしIssue #2054は、attempt resultがclosed reason codeを持つことを明示したtransport contractです。閉じた値ドメインへinner_timeoutを追加することは、形状が同じでもconsumer contractの変更です。

さらに、Issue #2165自身がtimeout taxonomyとtimeout_phaseの構造化をIssue #2040へ委ねています。PR #2070は現在もopen Draftで、execution_time_summary等のtimeout診断schemaを扱っています。

この状態で#2177が独自に、

reason_code = inner_timeout

を導入すると、同じ事象について、

timeout
inner_timeout
timeout_phase
execution_time_summary

という競合する表現が並立します。

また、現在の判定はbounded stderr prefix全体を一つのJSON documentとしてparseします。そのため、JSONの前後にwarning、logging、traceback、別の診断行が1行入るだけでinner_timeout認識が失敗し、nonzero_exitへ戻ります。専用schema、version、producer identity、timeout phaseもありません。

必須修正

次のどちらかへ統合してください。

reason_code: timeout
timeout_phase: baseline_vc_command | baseline_vc_aggregate |
               contract_readiness | merge_readiness |
               reviewer_transport

またはattempt schemaをversion upして、consumer inventoryとunknown-value testを追加します。

stderrをcontrol protocolとして使う場合でも、少なくともmagic prefix付きのversioned envelopeが必要です。より堅牢なのは、専用result fileまたは専用FDを使用し、stderrは診断専用に戻す構成です。

#2040/PR #2070とのmerge順とschema authorityを確定するまで、Schema Consumer Inventory: n/aは受け入れられません。一般に閉じたenum-like値の追加は、旧consumerが未知値を受け取ることを前提にrollout設計する必要があります。Protocol Buffersの公式設計指針でも、client/serverは同時更新されないためunknown enum valueを考慮するよう求めています。これはProtobuf固有の実装指摘ではなく、閉じたdiscriminatorを進化させる際の同じ互換性問題です。(Protobuf)


マージ条件

このPRをmerge-readyにするには、最低限次が必要です。

  1. baseline_vc_preflight aggregate timeoutがsemantic needs-fixへ変換される経路を廃止する。
  2. AC1テストからinput_or_runtime_error成功分岐を削除し、認証済み取得失敗をFAILにする。
  3. current-head・pinned body SHA付きの認証済みlive canary artifactを提示する。
  4. deadlineをabsolute deadlineまたは導出可能なaggregate budgetへ変更し、2本の長時間VCと全phase合成をテストする。
  5. inner timeoutでも全process treeを回収し、grandchild残存fault injectionを追加する。
  6. deterministic retryをfailure classベースのclosed allowlistへ変更する。
  7. inner_timeoutを#2040のtimeout_phase設計と統合し、schema change判定とconsumer inventoryをやり直す。
  8. Claude/Codex backendについて、300秒消費後に40秒未満のattemptを無条件spawnしないbudget policyを定義する。
  9. 修正後のcurrent-headで全CIとIssue 実装: reviewer transport の固定90秒 deadline が長時間 Verification Command を environment_failure にする #2165 literal VCを再実行する。

現状のgreen CIは、既存suite非破壊の証拠にはなりますが、#2165の解決証拠にはなっていません。 特にP0-1の経路により、timeoutを消したのではなく、timeoutをsemantic verdictへ隠しただけでもAC1がgreenになり得るため、現実装のままCloses #2165とするのは不適切です。

squne121 and others added 4 commits August 15, 2026 10:58
…摘を解消する (#2165)

OWNER REQUEST_CHANGES (2026-08-15, PR #2177 iteration-1) の指摘に対応する fix_delta。

- P0-1: baseline_vc_preflight の aggregate timeout (200s) が
  `errors: ["timeout"]` の plain blocked payload として返り、
  `no_commands_extracted` -> `needs_fix` へ誤変換されて semantic merge へ
  素通りしていた構造的バグを修正。`contract_readiness_check.py` に
  `status: "runtime_error"` の typed failure(`failure_class: "timeout"`,
  `timeout_phase`, `retryable: false`)を追加し、`_raise_status()` の
  priority を runtime_error > human_judgment > needs_fix > go に変更。
  `run_root_review_pipeline.py` は readiness_result の runtime_error を
  検知して run_merge_readiness() を呼ばずに構造化 exit-2 failure として
  reviewer_transport へ伝播する。
- P0-2: AC1 テストを deterministic 統合テスト(scaled clock, gh 非依存,
  常時実行)と live canary(gh auth 利用可能時は status==ok 必須、
  fallback success を PASS に変換しない)に分割。live canary は実際に
  gh auth 済み環境で実行し 154 秒で status: ok / verdict: needs-fix に
  到達したことを確認済み(artifacts/issue-2165/ac1_live_canary/ に証跡)。
- P1-1: `PER_ATTEMPT_DEADLINE_SECONDS`/`TOTAL_DEADLINE_SECONDS` を
  layered budget(check_issue_contract + contract_readiness_check +
  merge_readiness + margin)から導出する構成に変更し、
  `baseline_vc_preflight.py` の per-VC-command cap から aggregate wrapper
  timeout を、`contract_readiness_check.py` の内部 budget から
  `run_root_review_pipeline.py` 側の wrapper timeout を、それぞれ SSOT
  定数として derive する。deterministic backend の retry 前に
  `MIN_RETRY_ATTEMPT_BUDGET_FRACTION` 分の残り budget を要求する guard を
  追加。
- P1-3: deterministic backend の retryable reason_code を closed
  allowlist(`spawn_failure`/`signal`/`capture_failure`)に変更し、
  `nonzero_exit`/`malformed_output`/`empty_output`/
  `artifact_validation_failure` を retry 対象から除外。
- P1-4: `inner_timeout` という新規 reason_code を導入せず、既存の
  `timeout` reason_code に additive な `timeout_phase` field を追加する
  設計へ変更し、Issue #2040 の timeout taxonomy 作業と競合しないようにした。
- P1-2: `baseline_vc_preflight.py` の `run_command()` に
  `Popen(start_new_session=True)` + `killpg()` によるグランドチャイルド
  回収を試みたが、この変更が既存の pre-#2165 テスト
  `test_pnpm_gate_security_boundary.py::test_producer_evidence_round_trips_to_triage`
  (本 Issue の Allowed Paths 外)が `subprocess.run` を直接
  monkeypatch している契約と衝突するため revert し、follow-up Issue へ
  委譲するとコメントで明記した。

検証: `.claude/skills/issue-refinement-loop/tests/` フルスイート 1371
件 pass。`.claude/skills/issue-contract-review/tests/` フルスイート 512
件 pass(回帰なし)。AC1-AC4 の Issue 本文記載 Verification Command を
個別実行しすべて pass。
…ition #8)

merge condition #8: reviewer_transport.py に has_sufficient_retry_attempt_budget()
を新設し、run_reviewer_transport() の既存 backend-agnostic budget guard を委譲する。
run_root_review_pipeline.py::retry_once_on_transport_failure()(別の外側retryループ、
budget非考慮で無条件に1回だけretryしていた)に同guardを任意引数で適用し、非
deterministic backend(claude/codex想定)でも残り budget 不足時は retry しないよう
にする(3引数省略時は既存の無条件retry-exactly-once挙動を後方互換で維持)。

merge condition #5 (P1-2, VC subprocess の孫プロセス reaping) は再調査の上、本 PR
では未解決のまま。subprocess.run() の呼び出し形を維持しつつ安全に process-group
kill を行う経路が存在せず、正しい修正 (Popen+killpg) は Allowed Paths 外の
test_pnpm_gate_security_boundary.py を書き換える必要があるため。/proc差分による
代替案も ThreadPoolExecutor 経由の並行実行下でレースがあり不採用。詳細は
baseline_vc_preflight.py のコメントと PR 本文 Notes を参照。

Ref: #2177 (comment)

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121 squne121 self-assigned this Aug 15, 2026
squne121 and others added 5 commits August 15, 2026 18:27
…ition #5 / P1-2)

Issue #2165 の Allowed Paths が human/OWNER の明示的な scope 拡張により
test_pnpm_gate_security_boundary.py を含むよう更新されたため、これまで
未解決だった merge condition #5 / P1-2(baseline_vc_preflight.run_command()
の grandchild process-tree reaping)を解消する。

- run_command() を subprocess.run(argv, timeout=...) から
  subprocess.Popen(argv, start_new_session=True) + communicate(timeout=...)
  へ変更し、timeout 時に _kill_process_group() で process group 全体
  (直接子だけでなく孫プロセスも)を SIGTERM→SIGKILL で回収するようにした。
  start_new_session=True により各 Popen 呼び出しは独立した session/pgid を
  持つため、ThreadPoolExecutor(max_workers>1) 経由の並行実行下でも他の
  VC 呼び出しの process group と混線しない。
- test_pnpm_gate_security_boundary.py の3テストが baseline.subprocess.run を
  直接 monkeypatch していたため、Popen を対象にするよう更新した
  (セキュリティ境界の assertion 自体は変更していない)。
- 新規 fault-injection test
  test_run_command_timeout_reaps_grandchild_process_not_just_direct_child を
  追加。実際に孫プロセスを spawn する fixture を使い、timeout 後に直接子・
  孫プロセスの両方が bounded time 内に終了することを検証する
  (mutation test で、孫プロセスのみを狙う旧実装ではこのテストが実際に
  FAIL することを確認済み)。
…lures on newly-widened Allowed Paths)

OWNER 追加 Allowed Paths 拡張により、iteration 3 の run_command()
subprocess.run -> subprocess.Popen 移行で mock ターゲットがずれた
既存テスト 4 件を、test_pnpm_gate_security_boundary.py と同じ
Popen 直接モックパターンに retarget した。

- test_baseline_vc_preflight.py:
  test_fixed_env_injects_ci_true_for_pnpm_build /
  test_fixed_env_applies_to_all_canonical_pnpm_gates /
  test_runner_env_delta_output_exposes_only_fixed_env
- test_baseline_vc_preflight_parallel.py:
  test_p0_2_run_command_uses_stdin_devnull

test_issue_393_snapshot_fixture_processed の90秒タイムアウトは調査の結果、
run_command() の Popen 実装のデッドロック/ハングではないことを確認した
(単体実行で181秒かけてクリーンに完了し、内部 per-VC timeout=150秒が
_kill_process_group() で最も遅い VC を正しく打ち切っていた)。原因は
run_preflight() ヘルパー自身の outer subprocess.run(timeout=90) が、
本 Issue の最初のコミットで既に行われた DEFAULT_TIMEOUT_SECONDS の
90->150拡大に追随していなかったこと(pre-existing test staleness)。
実測値(~181秒)に安全マージンを載せた220秒へ更新した。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

実装: reviewer transport の固定90秒 deadline が長時間 Verification Command を environment_failure にする

1 participant