Repository navigation
fix: fan-out timeout/cancellation テストを readiness sentinel 同期へ書き換える - #2373
Conversation
…2371) PR #2366 の CI 安定化調査で発見した readiness race に依存する fan-out timeout/cancellation テストを、pid sentinel 同期と責務分離された assert へ 書き換える。 - test_timeout_termination_recorded を test_running_process_cancellation_records_sigterm へ rename し、固定の overall_timeout_sec=0.3 deadline watcher 経路(Popen 前に発火しうる)で はなく、pid_file readiness sentinel を確認してから手動 cancel_event.set() する設計に変更。process_start/process_exit の PID 一致と termination_reason も assert する。 - test_sigkill_escalation_recorded も同じ readiness sentinel helper を使用 するよう変更し、time.sleep(0.3) による readiness race を除去。 - test_subprocess_runner_terminates_process_group_on_timeout の false-green (Popen 未到達でも ok is False と "timeout" in failure_class だけで PASS してしまう構造)を、pid sentinel で実 subprocess 起動を確認し、cancel 後に 実プロセスが本当に消えたことまで確認する形に修正。 - test_overall_timeout_cancels_pending_and_terminates_running を test_overall_timeout_cancels_pending_subtasks へ rename し、 overall_timeout_reached event と pending subtask の cancellation のみを assert する形に整理(起動済み process の termination までは主張しない)。 - 上記いずれも sentinel timeout・assertion failure・thread 内例外の全経路で thread / child process を finally で cleanup し、thread.join() 後に not thread.is_alive() を assert する。 production code (fan_out_orchestrator.py) には diff なし。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URLPreview removed (PR #2373 closed). |
敵対的レビュー結果Verdict: 対象 head: PRは open・Draft・mergeable で、変更はテスト2ファイルだけです。同一headのCIも成功しています。一方、PR上の通常コメントはpreview botのみで、GitHubの正式なreview threadはありません。Issue側の P1 —
|
OWNER 敵対的レビュー(PR #2373, reviewed_head_sha f664bfa)の REQUEST_CHANGES を反映する。 - test_running_process_cancellation_records_sigterm / test_sigkill_escalation_recorded / test_subprocess_runner_terminates_process_group_on_timeout の finally cleanup が、 検証対象そのものである cancel_event 協調キャンセル経路にのみ依存しており、runner thread 内で無処理例外が発生した場合や cancel_event セット後も runner がハングした 場合に non-daemon thread と child process がリークしうる構造上の欠陥を修正(P1)。 thread 内例外を別 list に捕捉し、finally 内で ctx.terminate_all(grace_period=0.1) を cancel_event 経路とは独立に必ず呼び、thread がまだ生きている場合または thread 内 例外が捕捉された場合のみ child_pid ベースの test-only fallback(os.getpgid 一致確認 後 os.killpg SIGKILL)で強制終了する。 - test_sigkill_escalation_recorded に process_start の件数(1件)と sentinel PID との 一致 assert を追加し、SIGTERM 側テストと対称な lifecycle pairing 検証にする(P1)。 Issue #2371 の全 Verification Commands を再実行して確認済み: - pytest 通常実行 50 passed - pytest -n4 --dist load 50 passed - 修正対象 3 テストのみ fresh pytest process で 20 回連続実行し flake なし - fan_out_orchestrator.py に diff なし(AC8) - ruff check クリーン Related: #2371
fix_delta 適用完了対象 head: P1 blocker 2件を解消
再検証結果(head e31647c)
PR 本文の Checks / Safety Claim Matrix / Notes を更新済み。 |
Summary
PR #2366(Issue #2308)の CI 安定化作業中に発見した、fan-out timeout/cancellation テストの readiness race を解消する。
time.sleepベースの固定タイムアウト・固定 sleep に依存する synchronization を、make_fake_provider_script()の既存pid_file引数による pid sentinel 同期へ書き換え、CI 負荷下での false failure を構造的に防ぐ。2026-08-28 の OWNER 敵対的レビューを反映し、overall_timeout_secの actual timeout watcher 経路(_watch_deadline())の検証も維持したまま、隣接する readiness race テスト(test_sigkill_escalation_recorded)と Popen 未到達でも通ってしまう false-green テスト(test_subprocess_runner_terminates_process_group_on_timeout)も同時に修正した。test_timeout_termination_recordedをtest_running_process_cancellation_records_sigtermへ rename し、readiness sentinel 確認後の手動cancel_event.set()により SIGTERM を検証する設計へ変更(AC1-AC3)test_sigkill_escalation_recordedも同じ pid sentinel readiness helper を使用するよう変更(AC4)test_subprocess_runner_terminates_process_group_on_timeoutの false-green を、pid sentinel で実 subprocess 起動を確認し、cancel 後に実プロセスが消滅したことまで確認する形に修正(AC5)test_overall_timeout_cancels_pending_and_terminates_runningをtest_overall_timeout_cancels_pending_subtasksへ rename し、overall_timeout_reachedevent と pending subtask cancellation のみを assert する形に整理(AC6)finallyで cleanup(AC7)fan_out_orchestrator.py)には diff なし(AC8)fix_delta (OWNER 敵対的レビュー対応, 2026-08-29, head e31647c)
review comment(reviewed_head_sha
f664bfa6, verdictREQUEST_CHANGES — fix_in_place)の P1 blocker 2件を解消した。test_running_process_cancellation_records_sigterm/test_sigkill_escalation_recorded/test_subprocess_runner_terminates_process_group_on_timeoutのfinallycleanup が、検証対象そのものであるcancel_event協調キャンセル経路にのみ依存しており、(a) runner thread 内で無処理例外が発生した場合、(b)cancel_eventセット後も runner がハングした場合に、non-daemon thread と child process がリークしうる構造上の欠陥だった。thread 内例外をresult_holderとは別の list に捕捉し、finally内でctx.terminate_all(grace_period=0.1)を cancel_event 経路とは独立に必ず呼び、thread がまだ生きている場合または thread 内例外が捕捉された場合のみ child_pid に対する test-only fallback(os.getpgid一致確認後os.killpg(pgid, signal.SIGKILL)、ProcessLookupErrorは握りつぶす)で強制終了するよう3テストとも書き換えた。thread.join(timeout=2)後にassert not thread.is_alive()を行い、捕捉した thread 例外があればその後で再送出する。test_sigkill_escalation_recordedがprocess_exitのみを assert しprocess_startの件数・PID 一致を確認していなかった点を修正し、SIGTERM 側テストと対称な lifecycle pairing assert を追加した。Checks
uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_orchestrator.py -q— 50 passed(head e31647c で再実行)uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_orchestrator.py -n 4 --dist load -q— 50 passed(head e31647c で再実行)git diff --quiet main -- .claude/skills/gemini-cli-headless-delegation/scripts/fan_out_orchestrator.py— 差分なし(AC8)rg -q "def test_running_process_cancellation_records_sigterm" .claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.py(AC1)test_running_process_cancellation_records_sigterm/test_sigkill_escalation_recorded/test_subprocess_runner_terminates_process_group_on_timeout)を fresh pytest process で 20 回連続実行しフレークがないことを確認(head e31647c、recommended_non_blockersP2 反映)ps auxで fixture child process(sigterm_target.py/stubborn.py/hang_forever.py)が残留していないことを確認Schema Change Applicability
PROCESS_LIFECYCLE_SCHEMAやdelegation_fanout_result_v1等の既存フィールド構造への変更は一切ない。Schema Consumer Inventory
N/A(
Schema Change Applicabilityの decision がnot_schema_changeのため、consumer inventory は対象外)Safety Claim Matrix
.claude/skills/配下のテストファイル変更のため safety-sensitive パスに該当するが、production code は変更していない。以下に本 PR が実際に検証した安全性関連の主張を記載する。fan_out_orchestrator.py)に diff がないgit diff --quiet main -- .claude/skills/gemini-cli-headless-delegation/scripts/fan_out_orchestrator.pyが exit 0(AC8)pytest-xdist -n4の両方で PASSfinallyブロックでcancel_event.set()に加えctx.terminate_all(grace_period=0.1)(cancel_event 経路とは独立)と、thread 生存時/thread内例外時のみ child_pid ベースの直接os.killpgfallback を実行し、thread.join()後not thread.is_alive()を assert(AC7、OWNER fix_delta 反映後)pid_file引数は既存 API の再利用)Notes
.claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_process_lifecycle.pyと.claude/skills/gemini-cli-headless-delegation/tests/test_fan_out_orchestrator.pyの 2 ファイルのみ(Allowed Paths と一致)test_subprocess_runner_terminates_process_group_on_timeoutは削除ではなく、pid sentinel 方式による修正を選択した(Issue 本文の「より強い lifecycle テストと責務が重複する場合は削除してもよい」旨の許容範囲内での判断だが、production runner に対する低レベル realism check としての価値を残す方を優先した)f664bfa6)の REQUEST_CHANGES を受け、heade31647c2で fix_delta を適用した(詳細は上記「fix_delta」節参照)