Skip to content

test: outer-timeout 統合 test の固定 0.6s deadline を readiness 同期の fault injection へ置換する - #2885

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-2883-process-group-cancellation-test-0-6s-out
Oct 3, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-2883-process-group-cancellation-test-0-6s-out

Conversation

@squne121

@squne121 squne121 commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • 固定 _OUTER_DEADLINE_SECONDS = 0.6 の経過時間に依存していた outer-timeout 統合 test を、readiness 同期後に production の outer-timeout 処理経路を fault injection で発火させる構造へ置き換えました。
  • 注入するのは supervisor の Popen.communicate(timeout=...) が TimeoutExpired を送出する時点だけです。SIGTERM 送信、grace 待機、SIGKILL escalation、reap、typed timeout result の構築、run_baseline_vc_preflight() の呼び出し経路は production 実装をそのまま通します。
  • readiness を release file で旧 0.6 秒超まで遅らせる決定論的 regression test test_outer_timeout_fault_injection_waits_for_ready_process_tree を追加しました。
  • OWNER 指摘(P1)への対応として、fault injection を一切使わず real 経過時間で communicate(timeout=...) が自然に timeout する test_outer_timeout_natural_elapsed_timeout_returns_typed_timeout_result を追加しました(AC7)。
  • OWNER 指摘(P2)への対応として、injection の内部検証失敗を記録するだけにして必ず TimeoutExpired を送出し、production cleanup(SIGTERM、grace、SIGKILL、reap)を完遂させた後に failure を表面化する構造へ変更し、回帰 test test_outer_timeout_fault_injection_validation_failure_still_reaps_process_tree を追加しました(AC8)。
  • 変更ファイルは test 1 ファイルのみで、production script と CI 設定は変更していません。

受け入れ条件の達成状況

  • AC1: test_outer_timeout_fault_injection_waits_for_ready_process_tree を追加済み。self.pid と grandchild.pid を同期観測した後にだけ timeout を発火する
  • AC2: 同一 run_baseline_vc_preflight() 呼び出しの中で、typed result、SIGTERM handler marker、wrapper / VC leader / grandchild の full reap を一続きで検証している
  • AC3: real baseline_vc_preflight.py、real VC leader、real SIGTERM 無視 grandchild、_OUTER_DEADLINE_REPEAT_COUNT 回の repeat を維持。注入は TimeoutExpired 発生点のみ
  • AC4: release file で readiness を旧 0.6 秒超まで遅延させる regression を追加。CPU 負荷を使わず PASS する
  • AC5: production script、.github/ci/python-test-plan.json、pyproject.toml、uv.lock に diff なし
  • AC6: 単体実行と -n 4 --dist loadscope の両方で PASS
  • AC7: test_outer_timeout_natural_elapsed_timeout_returns_typed_timeout_result を追加済み。fault injection fixture と readiness 待機を使わず、real run_baseline_vc_preflight() の communicate(timeout=2.0) が実経過時間で自然に timeout し、typed result と elapsed >= timeout を検証する
  • AC8: 意図的に不一致な expected timeout を injection に与えても production cleanup が完遂し、wrapper / VC leader / grandchild の full reap と typed timeout result が成立すること、および検証失敗が cleanup 後に記録・表面化されることを両方 assert する

検証コマンド結果

$ uv run --locked pytest .../test_vc_process_group_cancellation.py::test_outer_timeout_fault_injection_waits_for_ready_process_tree -q
1 passed

$ uv run --locked pytest .../test_vc_process_group_cancellation.py::test_outer_timeout_natural_elapsed_timeout_returns_typed_timeout_result -q
1 passed(baseline origin/main ではこの test 名が存在せず fail)

$ uv run --locked pytest .../test_vc_process_group_cancellation.py::test_outer_timeout_fault_injection_validation_failure_still_reaps_process_tree -q
1 passed(baseline origin/main ではこの test 名が存在せず fail)

$ uv run --locked pytest .../test_vc_process_group_cancellation.py -q
7 passed(約 11 秒)

$ uv run --locked pytest .../test_vc_process_group_cancellation.py -n 4 --dist loadscope -q
7 passed

$ rg -n -F 'assert result["timeout_phase"] == "baseline_vc_preflight_aggregate"' <test file>
550 行目と 769 行目で一致

$ rg -n "= crc\.run_baseline_vc_preflight\(" <test file>
537 行目と 760 行目で一致

$ git diff --quiet origin/main...HEAD -- <production scripts / python-test-plan.json / pyproject.toml / uv.lock>
exit 0

$ uv run --locked ruff check <test file>
All checks passed

追加確認として、AC7 と AC8 の新 test 2 本を 3 回連続で実行し、すべて PASS しました。

mutation 確認:

  • injection の fire() が検証失敗時に TimeoutExpired の前で例外を送出する構造へ戻す mutation では、AC8 の test が fail します。
  • injection が timeout 値不一致を記録しない mutation では、AC8 の test が「failure が記録されていない」として fail します。
  • production の communicate(timeout=...) に巨大な固定値を渡す一時 mutation では、AC7 の test が runtime_error ではなく blocked となって fail します(確認後に元へ戻し、production の diff はありません)。

修正前の現コードでは、不一致な expected timeout を与えると fire() が production cleanup を迂回して AssertionError を送出し、baseline_vc_preflight.py の wrapper process が orphan として残ることを再現で確認しました。

Allowed Paths 遵守

  • 変更ファイル: .claude/skills/issue-contract-review/scripts/tests/test_vc_process_group_cancellation.py
  • Allowed Paths 逸脱: なし

Checks

  • uv run --locked pytest による対象 test の実行(上記)
  • ruff check による lint
  • この PR は Python test のみの変更のため、pnpm typecheck / pnpm lint / pnpm test / pnpm build の対象コードに変更はありません

Schema Change Applicability

  • decision: not_schema_change
  • reason: pytest の test 設計のみを変更しており、producer と consumer の間の machine-readable contract は変更しないためです。

Schema Consumer Inventory

N/A。schema を変更しないため、consumer の列挙は不要です。

Compatibility Decision(互換性判定)

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: schema 変更がないため該当しません。

Safety Claim Matrix

N/A。test ファイルのみの変更で、安全境界、権限、sandbox、transport、auth、workflow gate には触れないためです。

Claim Implemented? Not controlled Evidence Follow-up
N/A(test のみの変更で安全境界に触れない) yes 上記の検証コマンド結果 N/A

Notes

🤖 Generated with Claude Code により作成

IMPLEMENTATION_SCOPE_COVERAGE_V1:
  schema_version: "IMPLEMENTATION_SCOPE_COVERAGE_V1"
  issue_number: 2883
  issue_body_sha256: "sha256:150b653ca007ec8c6bf29ad4b7cfcafa1c9d05eedac11fb30984f4cd3a79854a"
  normalized_scope_manifest_sha256: "sha256:753f2e11c44cbe29ffba726cb1a01fbc18eb5958d5b49bb3cb8a3d9a4f93648b"
  pr_head_sha: "b56d06035767c232e46c18ca145af5f755af85b4"
  scope_manifest: {"acceptance_criteria": ["fixture readiness を同期 primitive で旧 0.6s を超えて確実に遅延させる deterministic delayed-readiness regression が存在し、CPU 負荷を一切かけない状態でも PASS する(旧 0.6s 固定 deadline 設計なら readiness 前に発火して破綻する条件である)。CPU 飽和(busy loop)を required test に含めない", "injection 内部検証が失敗した場合でも production の timeout cleanup branch が最後まで実行され(wrapper / VC leader / grandchild が reap される)、記録された injection failure が cleanup 完了後に test failure として表面化する。test_outer_timeout_fault_injection_validation_failure_still_reaps_process_tree がこれを deterministic に固定する(意図的に不一致な expected timeout を injection に与え、cleanup 後に failure が記録・表面化されることと、tree が reap されることの両方を assert する。reap のみの assert は不可)", "production script・CI 設定・.github/ci/python-test-plan.json・pyproject.toml・uv.lock に branch 起因の diff がなく、新規 dependency / pytest plugin が追加されていない", "run_baseline_vc_preflight() 経由・real baseline_vc_preflight.py / real VC leader / real SIGTERM-ignoring grandchild・_OUTER_DEADLINE_REPEAT_COUNT 回 repeat の production-shaped integration 構造が維持され、fault injection は TimeoutExpired の発生時点のみを注入し supervisor の SIGTERM / grace / SIGKILL / reap / typed result 構築を stub していない", "test_outer_timeout_natural_elapsed_timeout_returns_typed_timeout_result が存在し、fault injection fixture を使わず real run_baseline_vc_preflight() の communicate(timeout=...) が実経過時間で自然に timeout し、typed result(status == \"runtime_error\" / failure_class == \"timeout\" / timeout_phase == \"baseline_vc_preflight_aggregate\" / retryable is False)が返ること、および経過時間が指定 timeout 以上であることを検証する。readiness assertion / readiness marker wait を持たず、fault injection fixture を参照せず、elapsed >= timeout を assert する", "test_vc_process_group_cancellation.py に test_outer_timeout_fault_injection_waits_for_ready_process_tree が存在し、self.pid / grandchild.pid の readiness marker を観測した後にのみ outer-timeout handling path を test-local fault injection で発火させる。readiness 依存 assertion が固定 0.6s deadline 内に fixture が readiness へ到達する wall-clock 前提に依存しない", "同一 run_baseline_vc_preflight() invocation について、typed result(status == \"runtime_error\" / failure_class == \"timeout\" / timeout_phase == \"baseline_vc_preflight_aggregate\" / retryable is False)、SIGTERM handler marker、wrapper / VC leader / grandchild の full reap の assertion が一続きで存在する(timeout と reap を別 test に分離していない)", "対象ファイルが無負荷および xdist(-n 4 --dist loadscope)下で PASS する(xdist compatibility の secondary check であり、CPU 飽和 regression の authority ではない)"], "allowed_paths": [".claude/skills/issue-contract-review/scripts/tests/test_vc_process_group_cancellation.py"], "change_kind": "test", "goal_ref": "process-group cancellation 統合 test の固定 0.6s outer deadline が負荷下で readiness marker 未作成の flake を起こす問題を、readiness 観測後に production outer-timeout handling path を test-local deterministic fault injection で発火させる形へ置換して解消する(PR #2876 CI run 37068873394 の python-test-core failure 起点)", "in_scope": ["**#2207 / #2221 の integration guarantee を後退させない**: 責務分離を採用する場合でも、少なくとも1つの integration test は、同一 run_baseline_vc_preflight() invocation について「ready な real VC leader + grandchild → production outer-timeout handling path 発火 → baseline_vc_preflight.py の SIGTERM handler(marker)→ wrapper / VC leader / grandchild の full reap → typed timeout result(status == \"runtime_error\" / failure_class == \"timeout\" / timeout_phase == \"baseline_vc_preflight_aggregate\" / retryable is False)」を一続きで検証する。timeout と reap を完全に別 test へ分離して #2221 が埋めた coverage gap を再導入する変更は不可。_OUTER_DEADLINE_REPEAT_COUNT 回の repeat による register/unregister race 検出も維持する。", "**accepted mechanism(test-local deterministic fault injection)**: 既存 Allowed Path の test file 内だけで、real baseline_vc_preflight.py + real VC leader + real SIGTERM-ignoring grandchild + real readiness marker を使い、process tree が ready になったことを決定論的に確認した後で、production supervisor の outer-timeout handling branch(TimeoutExpired 後の SIGTERM → grace → SIGKILL → reap → typed timeout result)を test-local に発火させる。具体的な injection point(例: supervisor が Popen する baseline_vc_preflight.py 子プロセスに限定した Popen.communicate(timeout=...) の test-local subclass / monkeypatch)は current code で設計してよい。ただし注入してよいのは「TimeoutExpired が発生する時点」だけであり、supervisor 自身の SIGTERM 送信・grace 待機・SIGKILL escalation・reap・typed result 構築・run_baseline_vc_preflight() の呼び出し経路を stub / 再実装 / 迂回してはならない(production の outer-timeout handling path を実際に通すこと)。", "**deterministic delayed-readiness regression**: fixture の readiness(self.pid / grandchild.pid の書き込み)を test が制御する同期 primitive(release marker file / threading.Event 等)で旧 _OUTER_DEADLINE_SECONDS(0.6s)を超えて確実に遅延させ、旧設計(固定 0.6s で deadline を発火)なら必ず readiness 前に発火して破綻する条件を作る。新設計では readiness 観測後にのみ timeout path を発火するため、この条件でも決定論的に PASS する。実 CPU 飽和(busy loop 等)を required test に埋め込まない。", "**injection validation failure 時の cleanup(P2)**: fault injection 実装(例: PR #2885 の _OuterTimeoutFaultInjection.fire()。具体的な構造は実装時に決めてよい)は、自身の内部検証(例: timeout 値不一致、readiness wait 失敗)の失敗を記録しても、matched outer process に必ず TimeoutExpired を送出して production cleanup branch(SIGTERM → grace → SIGKILL → reap)を完遂させ、cleanup 完了後に記録した failure を test failure として表面化する。回帰 test test_outer_timeout_fault_injection_validation_failure_still_reaps_process_tree が、意図的に不一致の expected timeout を与えた injection でも wrapper / VC leader / grandchild が reap され、failure が記録されることを固定する。generic cleanup framework は追加しない。", "**natural outer-timeout regression(P1 訂正)**: 同 test file に test_outer_timeout_natural_elapsed_timeout_returns_typed_timeout_result を 1 本追加する。fault injection を一切使わず、readiness assertion / grandchild readiness 依存を持たず、real run_baseline_vc_preflight() に十分長く動く VC と小さな override_timeout_seconds を渡し、production の communicate(timeout=...) が実経過時間で自然に TimeoutExpired を起こす経路を通す。実装条件: override_grace_seconds に小さな値を渡して実行時間を bound し、VC は有限長 sleep 等で orphan を残さないものにする。検証は typed result(status == \"runtime_error\" / failure_class == \"timeout\" / timeout_phase == \"baseline_vc_preflight_aggregate\" / retryable is False)と、経過時間が指定 timeout 以上であること(下限のみ。上限・startup 速度は assert しない)に限る。grandchild の readiness / full reap の integration guarantee は fault-injection test 側が担う。", "この test は「0.6 秒という elapsed wall-clock deadline 自体」を試験するものではなく、「ready な real process tree に対して production outer-timeout handling path が実行された場合の cooperative cancellation / full reap / typed timeout result」を検証する fault-injection integration test であることを、test の docstring と本 Issue 上に明記する。これは synthetic timeout の禁止対象ではなく、accepted mechanism である。", "新規 regression test test_outer_timeout_fault_injection_waits_for_ready_process_tree を同 test file に追加する(命名は同 file の既存 test_scaled_fault_injection_* / test_outer_deadline_* の test_<subject>_<action>_<outcome> 規約に整合)。", "既存の test_outer_deadline_via_run_baseline_vc_preflight_reaps_full_process_tree が持つ readiness 依存 assertion(self.pid / grandchild.pid の存在確認と reap 確認)は、wall-clock deadline 依存のまま残さない。この test は新設計へ置換・改名するか、readiness 非依存の assertion(typed payload 等)のみへ縮小する。test_scaled_fault_injection_inner_timeout_precedes_outer_deadline は per-command の inner timeout のみを検証し、supervisor の outer communicate(timeout=...) を自然に時間切れにしないため、natural outer-timeout coverage を担わない(OWNER 指摘 PR #2885 issuecomment-5963140832 P1。前提誤りの訂正)。", "旧 600ms 設計根拠コメントを新設計に合わせて更新する。", "本 test file の docstring / コメントから「別 test が real elapsed timeout coverage を担う」という誤記述を除去し、natural outer-timeout regression を参照する。"], "schema_version": "IMPLEMENTATION_SCOPE_MANIFEST_V1"}

…njection へ置換する (#2883)

固定 _OUTER_DEADLINE_SECONDS=0.6 は fixture の readiness (interpreter 起動 + pytest import +
grandchild spawn) と wall-clock で競合し、CPU 負荷下で flake していた。
supervisor の outer communicate(timeout=...) arm 点だけを test-local に fault injection し、
real な VC leader と SIGTERM 無視 grandchild の readiness を同期観測した後にのみ
TimeoutExpired を発火させる。以降の SIGTERM / grace / SIGKILL / reap / typed result は
production 実装をそのまま通す。fixture readiness を release file で旧 0.6s 超まで遅延させる
決定論的 regression test を追加。production code / CI 設定は変更しない。

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

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Preview URL

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

The preview will be removed when this PR is closed.

@squne121

squne121 commented Oct 2, 2026

Copy link
Copy Markdown
Owner Author

Findings

  1. [P1 / Blocker] 自然発火する outer timeout の coverage が消えており、実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883 / PR test: outer-timeout 統合 test の固定 0.6s deadline を readiness 同期の fault injection へ置換する #2885 の「別 test で維持されている」という前提が成立していません。

    問題: PR test: outer-timeout 統合 test の固定 0.6s deadline を readiness 同期の fault injection へ置換する #2885 は、run_baseline_vc_preflight() の communicate(timeout=...) が実時間経過によって TimeoutExpired を起こす test を、readiness 後に TimeoutExpired を直接送出する fault injection へ全面置換しています。fault injection 自体の設計は妥当ですが、これで「timeout handling branch」と「実際に timeout parameter が timer として機能すること」が完全に同一 test から切り離されました。

    Evidence: base 37e1e365 の旧 test_outer_deadline_via_run_baseline_vc_preflight_reaps_full_process_tree は override_timeout_seconds=0.6 を渡し、production の process.communicate(timeout=timeout_seconds) を実際に時間切れにしていました。一方 HEAD ca0792e8 の _OuterTimeoutFaultInjection.fire() は readiness 確認後に raise subprocess.TimeoutExpired(...) を直接実行するため、最初の real communicate(timeout=600) は実行されません。

    さらに新 test の docstring は test_scaled_fault_injection_inner_timeout_precedes_outer_deadline が「Real elapsed-timeout coverage」を持つとしていますが、その既存 test 自身が this test does not need to reach [an outer aggregate deadline] と明記しています。実装も baseline_vc_preflight.py --timeout-seconds 3 の per-command inner timeout を試すだけで、outer supervisor の自然な timeout 発火は通しません。

    repo 横断検索でも、自然発火する run_subprocess_with_cooperative_supervisor() の outer timeout を代替検証する test は確認できませんでした。他にあるのは SupervisedSubprocessResult.timed_out=True を fake する test 等です。

    これは履歴上も重要です。PR 実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2221 の OWNER review #issuecomment-5307606264 では、manual SIGTERM と inner timeout だけでは不足として、merge condition に 「actual outer deadline を通す production integration test」 が明示され、それを受けて旧 test が追加されています。現在の 実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883 は「実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2207/実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2221 の integration guarantee を後退させない」としつつ、「real elapsed timeout coverage は別 test に存在する」という誤った前提で reframe されています。

    Python の公式契約でも Popen.communicate(timeout=...) は、指定時間内に終了しなければ TimeoutExpired を発生させる API です。直接例外を inject する test はその後段 branchを検証できますが、この timer semantics 自体は検証しません。[Python documentation](https://docs.python.org/3/library/subprocess.html?highlight=universal_newlines\&utm_source=chatgpt.com)

    Impact: たとえば production が誤った timeout_seconds を real communicate() へ渡す、timeout argument を落とす、自然な timer expiration 経路だけ壊す、といった regression が入っても test: outer-timeout 統合 test の固定 0.6s deadline を readiness 同期の fault injection へ置換する #2885 後の suite は green になれます。現在 HEAD の CI が全 green なのもこの finding を否定しません。実際 python-test-core は test_outer_timeout_fault_injection_reaps_full_process_tree を PASS していますが、その test は natural timeout を起こしていません。

    最小修正: 新しい readiness-synchronized fault-injection test はそのまま維持すべきです。その上で同じ既存 test file に、readiness assertion を一切持たない小さな natural outer-timeout regression を1本残すのが最小です。たとえば run_baseline_vc_preflight() に十分長く動く単純 VC と余裕を持った小さい override_timeout_seconds を渡し、runtime_error / timeout / baseline_vc_preflight_aggregate だけを確認する形です。grandchild readiness/reap の証明は新 fault-injection test に委譲できます。新 harness、dependency、CI job、production seam は不要です。

    ただしこれは current 実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883 の approved contract の前提誤りでもあるため、厳密には 実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883 を最小 reframe / Scope Delta して「natural outer-timeout coverage を1本維持する」ことを明示してから修正するのが repository-native です。

  2. [P2] fault injection 自身が失敗した場合、production cleanup branch に入れず wrapper process を orphan できます。

    問題: _OuterTimeoutFaultInjection.fire() は TimeoutExpired を投げる前に複数の assertion / readiness wait を実行しています。expected_timeout_seconds 不一致や _wait_for_file(..., 120) failure が起きると AssertionError が production supervisor の except subprocess.TimeoutExpired: を迂回して外へ抜けます。

    Evidence: HEAD の fire() は先に self.fired = True、timeout 値を assert、readiness marker を最大120秒待機し、その全てが成功した末尾で初めて TimeoutExpired を raise します。一方 production run_subprocess_with_cooperative_supervisor() が SIGTERM → grace → SIGKILL → reap を行うのは TimeoutExpired を捕捉した場合だけです。

    呼び出し側 _run_outer_timeout_fault_injection_iteration() の finally は self.pid / grandchild.pid が存在する場合の PID kill しか持たず、outer baseline_vc_preflight.py の Popen handle / PGID を保持していません。readiness 前に failure すれば wrapper を回収できません。

    pytest 公式も flaky test の典型原因として、未制御 state と teardown 不備を挙げています。今回の readiness synchronization 自体はその推奨方向と合っていますが、failure path の cleanup が欠けると別の flake source を作ります。[pytest ドキュメント](https://docs.pytest.org/en/latest/explanation/flaky.html?utm_source=chatgpt.com)

    Impact: 本来検出したい regression が起きたときほど wrapper / VC tree が後続 test や xdist worker に残り、CPU消費や二次 failure を発生させる可能性があります。「flake 解消 test が失敗時に suite を汚す」状態です。

    最小修正: injection 内部の検証失敗を一旦記録しても、matched outer process には必ず TimeoutExpired を送って production cleanup branch を完遂させ、その後で記録した injection failure を assertion にするのが最も小さいです。generic cleanup framework を作る必要はありません。代案として matched Popen を fixture teardown で確実に process-group cleanup する方法もありますが、前者の方が production cleanup を最後まで通せます。

判定

REQUEST_CHANGES 相当です。 主 blocker は1件目で、#2885 の中心設計である「readiness 後の deterministic fault injection」そのものを否定するものではありません。むしろ固定 600ms の readiness race をやめる方向は適切で、元 failure も live CI job 111043458302 で iter_2/self.pid 未生成、1 failed, 17580 passed と確認できました。pytest の guidance とも整合します。[pytest ドキュメント](https://docs.pytest.org/en/latest/explanation/flaky.html?utm_source=chatgpt.com)

現在 HEAD ca0792e8fa9cc9af52db29d1f6d6d6e8a7fc35d4 は変更1ファイルのみで、現行 CI は python-test-core / python-test / ci-verdict-summary を含め success です。Allowed Paths 逸脱や production / dependency / CI 設定変更もありません。したがって、新しい security gate、pytest plugin、generic harness、CPU saturation CI は不要です。

なお -n 4 --dist loadscope については current #2883 の扱いどおり secondary compatibility check で十分です。xdist の公式仕様上、loadscope は test function を module 単位に group 化するため、この1 moduleだけの invocation は4 workerが同 module を同時に奪い合う負荷試験にはなりません。[pytest-xdist](https://pytest-xdist.readthedocs.io/en/stable/distribution.html)

Scope外の確認事項

production の run_subprocess_with_cooperative_supervisor() は communicate(timeout=...) の TimeoutExpired 後に process.wait(timeout=grace_seconds) を呼んでいます。一方、現行 Python 3.14 公式 docs は PIPE 使用時について、communicate() timeout 後は wait() ではなく再度 communicate() を使うよう明示しています。[Python documentation](https://docs.python.org/3/library/subprocess.html?highlight=universal_newlines\&utm_source=chatgpt.com) これは #2885 が導入した問題ではないため、この PR の blocker にはしていません。今回の趣味開発・workflow優先の前提なら、具体的な pipe-pressure failure が確認されるまでは #2885 の scope を広げない方がよいです。

@squne121

squne121 commented Oct 2, 2026

Copy link
Copy Markdown
Owner Author

推奨アクションは、対象コメントを単なる fix_delta として直接実装するのではなく、current impl-review-loop の human-context intake → contract blocker triage → 必要な最小 Issue reframe → 既存 PR #2885 resume → fix/re-test/re-review の順です。#2883 は対象コメント後も旧い「real elapsed timeout coverage は別 test が担う」という前提を保持しているため、先に contract を直すのが妥当です。前回ログも旧 HEAD で Step 5 の main-drift routing により停止していました。貼り付けたテキスト(1)

また Python 3.14 の公式仕様では Popen.communicate(timeout=...) 自体が自然に TimeoutExpired を送出する契約で、timeout 後の pipe cleanup にも明示的な注意があります。pytest 公式も flake 対策として未制御 state と teardown 漏れを問題視しており、今回コメントの P1/P2 の方向性は技術的にも整合します。[Python documentation](https://docs.python.org/3/library/subprocess.html?highlight=universal_newlines\&utm_source=chatgpt.com)

以下を fresh・auto mode の対話的 Claude Code にそのまま貼り付けられます。

repo=squne121/loop-protocol

対象:

この対話は fresh Claude Code session で、既に auto mode で起動済みである。

Claude Code の現在の permission mode は変更しないこと。
bypassPermissions、--dangerously-skip-permissions、その他 permission bypass を要求・使用してはならない。

目的

PR #2885 の OWNER comment issuecomment-5963140832 を current impl-review-loop の human-supplied context として取り込み、必要な contract correction を先に完了させたうえで、既存 PR / branch / worktree を再利用し、

fresh intake → contract blocker triage → 必要なら minimal issue refinement → existing PR resume → implementation fix → independent verification → PR review → fix → re-test → fresh re-review → current-head CI/mergeability evaluation

を bounded に自律実行する。

人間による iteration ごとの承認は不要。
通常の test failure、reviewer REQUEST_CHANGES、修正可能 CI failure、stale evidence、main drift、BEHIND、PR body の stale binding、current-head re-review は停止理由にせず、current canonical routing に従って修正・再検証すること。

最終到達点は 人間が merge を判断できる直前。
実 merge、auto-merge、force push、history rewrite は行わない。


1. 最初に必ず fresh state を取得する

この prompt、過去 session、過去の APPROVE、旧 SHA、旧 CI、旧 LOOP_STATE を current authority とみなさない。

最初に live repository / GitHub から最低限以下を fresh 取得する。

  1. PR test: outer-timeout 統合 test の固定 0.6s deadline を readiness 同期の fault injection へ置換する #2885
    • state / draft
    • current HEAD / base SHA
    • mergeable / mergeStateStatus
    • changed files
    • commits
    • body
      -全 Conversation comments
    • reviews / unresolved threads
    • current-head CI/checks
  2. OWNER comment:
    https://github.com/squne121/loop-protocol/pull/2885#issuecomment-5963140832
  3. linked Issue 実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883
    • current body
    • state / labels
    • all comments
    • updatedAt
    • current body SHA256
  4. current main/default-branch HEAD
  5. 実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883 / test: outer-timeout 統合 test の固定 0.6s deadline を readiness 同期の fault injection へ置換する #2885 に対応する current branch / worktree
  6. current .claude/skills/impl-review-loop/SKILL.md
  7. SKILL.md が指定する current steps。最低限:
    • steps/preparation.md
    • steps/step-1-implementation.md
    • steps/step-2-verification.md
    • steps/step-4-pr-review.md
    • steps/step-5-feedback-and-termination.md
    • steps/step-5-mergeability-handling.md
  8. 実際に dispatch する current SubAgent definitions:
    • .claude/agents/implementation-worker.md
    • .claude/agents/test-runner.md
    • .claude/agents/pr-reviewer.md
    • follow-up Issue が具体的に必要な場合のみ .claude/agents/issue-creator.md
  9. 実装: process-group cancellation 統合 test の固定 0.6s outer deadline を readiness 同期へ置き換え、負荷下の timing flake を解消する #2883 が参照する production source / test file / 実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2207 / PR 実装: review pipeline の timeout budget を動的 VC 本数ベースに再設計する #2221 等の relevant history
  10. 必要なら current upstream Python / pytest 公式仕様

観測上、PR は既に旧 reviewed HEAD ca0792e8... から別 HEAD へ進んでいるが、必ず live 値を再取得すること。
旧 HEAD に対する test-runner / pr-reviewer / CI evidence は authorization として再利用しない。


2. OWNER comment を human context として正規 intake する

対象 comment は PR Conversation comment だが、linked PR #2885 は #2883 を close する PR である。

current impl-review-loop の Inputs / build_intake_capsule.py SSOT に従い、この URL を:

human_context_comment_urls

として明示的に渡すこと。

必要な canonical invocation では:

--human-context-comment-url https://github.com/squne121/loop-protocol/pull/2885#issuecomment-5963140832

相当の current supported route を使用する。

agent_report_comment_url として扱わない。
コメント投稿者名や本文の marker から provenance を独自推測しない。

fresh intake capsule と canonical routing result を authority とし、structured decision を prose で再実装しない。


3. 今回の human finding は contract defect を含む

OWNER comment の主要 finding は少なくとも次の2件である。ただし実行前に current HEAD で独立確認すること。

P1 / Blocker: natural outer-timeout coverage の消失

PR #2885 の fault-injection integration test は readiness race 解消としては妥当だが、Popen.communicate(timeout=...) が real elapsed time により自然に TimeoutExpired を送出する outer supervisor path の coverage を削除している。

Issue #2883 本文には現在、
「real elapsed timeout 自体の coverage は test_scaled_fault_injection_inner_timeout_precedes_outer_deadline 等の別 test が担う」
という前提があるが、OWNER comment はその test が inner timeout のみで natural outer timeout を通していないと指摘している。

したがって current live code でもこの finding が成立するなら、これは単なる implementation bug ではなく Issue #2883 の contract premise の誤りでもある。

P2: injection validation failure 時の process cleanup

_OuterTimeoutFaultInjection.fire() が TimeoutExpired を投げる前に assertion / readiness wait で失敗すると production supervisor の timeout cleanup branch を迂回し、outer wrapper/process tree が残る可能性がある。

最小方向は、validation failure を記録しても matched outer process には production TimeoutExpired path を最後まで通させ、cleanup 完了後に記録した validation failure を test failure として表面化させること。

generic cleanup framework は追加しない。


4. contract blocker triage を迂回しない

current intake が latest_blocked / run_contract_blocker_triage 等を返した場合、その canonical contract_snapshot.contract_blocker_triage を使用する。

raw finding を root が独自に再分類して Step 1 へ飛ばさない。

今回については、current user instruction により以下を明示的に承認済みとする:

したがって canonical triage が
issue_refinement_recommended
または同義の「Issue contract を先に修正すべき」という deterministic route を返した場合、単に人間へ許可を聞くために停止しない。

ただし、対象 OWNER comment とこの prompt で解消されていない新しい human_judgment_required、irreconcilable scope conflict、policy boundary が発生した場合は停止する。


5. 必要なら #2883 を minimal reframe してから実装へ戻る

contract correction が必要なら current .claude/skills/issue-refinement-loop/SKILL.md を fresh に読み、repository-native workflow で #2883 を最小 reframe する。

この refinement は implementation scope を広げるためではない。

中心は以下。

  1. readiness-synchronized fault-injection integration test は維持する。
  2. 同じ既存 Allowed Path 内に、readiness assertion / grandchild readiness dependency を持たない 小さな natural outer-timeout regression を維持/追加する。
    • real run_baseline_vc_preflight() path を通す
    • real communicate(timeout=...) の elapsed timeout により自然に timeout させる
    • typed result の runtime_error / timeout / baseline_vc_preflight_aggregate 等、必要最小限を検証する
    • grandchild readiness/reap の integration guarantee は deterministic fault-injection test 側が担う
    • startup が遅いこと自体を failure にしない
  3. 「既存 inner-timeout test が natural outer-timeout coverage を担う」という false premise を本文/docstring/PR説明から除去する。
  4. injection validation failure 時でも production cleanup path が実行され、wrapper/process tree を残さないことを contract / regression で固定する。
  5. generic harness、新 dependency、新 pytest plugin、新 CI job、CPU saturation required test、production seam は追加しない。
  6. Allowed Paths は可能な限り現在の単一 test fileのまま維持する。

AC/VC は current authoring contract に従って concrete にすること。

新しい named regression test を追加する場合は、main に node-id が存在しないことを確認したうえで canonical な baseline-expect: fail VC を追加すること。
P2 cleanup failure class も false-green にならない deterministic VC/test を用意する。

refinement SubAgent を使用した場合は、各 SubAgent の terminal completion と final result の両方を取得してから次工程へ進む。

refinement が approved terminal に到達したら、その handoff artifact 自体を implementation authorization にせず、current impl-review-loop の Root-Owned Synchronous Entry Transition を fresh に再実行する。


6. 既存 PR #2885 を必ず再利用する

fresh landing disposition では既存 PR #2885 が存在する。

canonical disposition が existing_pr_resume を返す場合:

  • 新規 PR を作らない
  • duplicate branch を作らない
    -既存 branch / worktree を安全に再利用する
  • foreign dirty worktree を変更・削除しない

contract reframe により Issue body SHA / scope manifest / AC / VC が変わった場合、PR body に残る旧 IMPLEMENTATION_SCOPE_COVERAGE_V1、旧 Issue body SHA、旧 AC 達成記述を stale のまま残さない。

current canonical PR-body/update route に従って current contract と整合させる。


7. implementation-worker に fix を委譲する

root thread が直接 implementation file を編集しない。

current .claude/agents/implementation-worker.md と implement-issue contract に従って implementation-worker を起動し、次を具体的に渡す:

worker には最低限以下を実施させる。

  • current code を読んで P1/P2 を再現/確認
  • natural outer-timeout regression の追加/維持
  • deterministic fault-injection coverage の維持
  • injection failure cleanup の修正
  • misleading comment/docstring の是正
    -必要な regression tests
  • Allowed Paths compliance
  • lint/test
  • commit
  • normal push
  • PR body の current contract への更新

SubAgent を background dispatch しただけで Step 1 完了扱いにしない。
terminal completed と final structured result を取得するまで待つこと。


8. 独立 Verification を fresh HEAD で行う

implementation commit/push 後、PR current HEAD を再取得する。

current step-2-verification.md に従い test-runner SubAgent を fresh dispatch する。

test-runner には:

を明示する。

Issue 本文の Verification Commands は逐語実行させる。
勝手な省略・簡略化・類似コマンド置換は禁止。

旧 ca0792e8...、旧 test-runner report、旧 CI を PASS evidence として流用しない。

test-runner の terminal completion と final result の両方を取得する。
current head / body SHA / literal command hashes を canonical adapter/adjudication で照合し、Step 4 current-head gate が開いた場合のみ review へ進む。


9. pr-reviewer に fresh adversarial review を委譲する

Step 2 が nonblocking の場合のみ、current .claude/agents/pr-reviewer.md / pr-review-judge に従って pr-reviewer を起動する。

reviewer には今回の OWNER findings を明示するが、結論を強制しない。
current HEAD の実コード・Issue contract・diff・tests・CI evidence から独立判定させる。

特に確認させる:

pr-reviewer の terminal completion と final verdict の両方を取得する。

REQUEST_CHANGES は停止理由ではない。
canonical Step 5 が continue_loop を返したら blockers を fix_delta として Step 1 に戻し、修正 → test-runner → fresh review を繰り返す。


10. CI / main drift / mergeability

current HEAD で required CI が開始されたら current canonical evaluator に従って完了まで処理する。

pending を PASS とみなさない。
旧 head の green run を使わない。

main drift / BEHIND が発生したら:

  • root が独自に merge/rebase しない
  • current Step 5 router の structured decision を使う
  • route_to_update_branch の場合のみ canonical implementation-worker/update_branch route を使用
  • head が変わったら Step 2 と Step 4 の evidence は stale とし、fresh verification / review を行う

BLOCKED / UNSTABLE / DRAFT を actual Git conflict と同一視しない。
actual conflict は current conflict runbook に従う。


11. Scope外 observation

OWNER comment 末尾の Python 3.14 communicate() timeout 後の wait() / pipe handling observation は、#2885 が導入した defect ではない。

この PR に勝手に production fix を追加しない。

ただし作業中に:

  • concrete reproduction
  • current runtime failure
    -既存 CI failure
    -同一 root cause の反復 evidence

が得られた場合のみ、既存 Issue を検索・dedupe する。

同一問題の canonical Issue がなければ、issue-creator を使用して再発防止 Issue を起票してよい。
docs mismatch だけで generic hardening Issue を作らない。

同様に、今回 P1/P2 のような「test coverage claim と実 coverage の semantic divergence」が repository 内で反復する concrete evidence が見つかった場合のみ、最小の再発防止策を別 Issue として materialize する。

follow-up Issue を起票した場合も、issue-creator の terminal completion と final result を取得してから報告する。


12. 明示的に承認する作業

以下の非破壊的作業は追加の人間確認なしで実施してよい。

これらについて iteration ごとの承認を求めないこと。


13. 停止境界

以下の場合のみ停止/escalationする。

  • current canonical authority が、今回の OWNER comment とこの user authorization では解消できない human_judgment_required を返す
  • destructive operation が必要
  • secret / credential の取得・変更・公開が必要
  • force push / history rewrite が必要
  • permission/policy bypass が必要
  • Allowed Paths 外の変更が不可避で、current refinement contract でも許可されない
  • foreign dirty worktree / unrelated work を壊さないと進められない
  • evidence integrity を維持できない
  • actual conflict が canonical runbook で自動解決不能
  • irreconcilable scope conflict
  • canonical bounded iteration 上限到達

通常の test failure、CI failure、REQUEST_CHANGES、stale evidence、main drift、BEHIND、PR body stale binding、fixable process leak regression は停止理由ではない。


14. merge 直前まで進める

最終的に current impl-review-loop が定義する approved / draft_pr_ready 相当まで進める。

最低限:

  • current Issue contract が fresh / coherent
  • target OWNER findings が解消済み
  • current PR HEAD に independent Verification PASS
  • required current-head CI が policy を満たす
  • pr-reviewer が current HEAD を fresh review
  • blockers 空
  • Allowed Paths compliant
  • actual conflict なし
  • unresolved REQUEST_CHANGES なし
  • current Step 5/router が terminal route

ここまで到達したら停止する。

merge / auto-merge は実行しない。


15. 最終報告

terminal completion 後、以下を簡潔に報告する。

調査、計画、Issue reframe、SubAgent dispatch のどこかだけで終了しないこと。
current canonical workflow の terminal state、または上記の正当な停止境界に到達するまで実作業を継続すること。

この構成では、現在の OWNER finding を human_context_comment_urls として正規 intake しつつ、#2883 の誤った contract premise を直さず実装だけ進める false-green を避けています。PR #2885 は新規作成せず、そのまま resume させる前提です。

squne121 and others added 2 commits October 3, 2026 08:47
…失敗時の cleanup 完遂を追加する (#2883)

- fault injection fire() は内部検証失敗を記録しても必ず TimeoutExpired を送出し、production cleanup branch を完遂させる
- cleanup と reap 確認後に記録 failure を test failure として表面化する (AC8 回帰 test 追加)
- natural elapsed timeout を通す test_outer_timeout_natural_elapsed_timeout_returns_typed_timeout_result を追加 (AC7)
- docstring の誤記 (別 test が real elapsed timeout を担う) を訂正

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

squne121 commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

PR レビュー結果: APPROVE(head b56d060)

OWNER の指摘(https://github.com/squne121/loop-protocol/pull/2885#issuecomment-5963140832)への対応を、current head で fresh に独立レビューした結果です。

判定根拠

独立検証の証跡

  • test-runner が current head で Verification Commands 8 件を逐語実行し、全件 PASS でした。literal command の hash は live Issue と一致しています。
  • 有効な CI run 37080096952 は success です。PR の rollup に残る CANCELLED と FAILURE は、同じ head で取り消された旧 run 37080045727 の stale な結果です。
  • mergeable は MERGEABLE、mergeStateStatus は CLEAN です。
verdict: APPROVE
reviewed_head_sha: b56d06035767c232e46c18ca145af5f755af85b4
blockers: []
warnings:
  - "PR は Draft のままです(blocker ではありません)"
  - "rollup の CANCELLED/FAILURE は取り消された旧 run 37080045727 の stale 結果です"

@squne121
squne121 marked this pull request as ready for review October 3, 2026 00:21
@squne121
squne121 merged commit db6d65d into main Oct 3, 2026
55 of 68 checks passed
@squne121
squne121 deleted the worktree-issue-2883-process-group-cancellation-test-0-6s-out branch October 3, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant