Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "skill_runtime_exec.py の outer child execution を、TimeoutExpired 事後捕捉ではなく起動直後から PID/PGID を保持する Popen supervisor へ置換し、descendant process-group の bounded cleanup を保証するようにする"
change_kind: codeParent Issue
なし(単独改善)。ただし Issue #1601(AC4 で skill_runtime_exec.py の worker/child/grandchild process-tree cancellation を所有)の predecessor として位置づける(詳細は Notes for Reviewer 参照)。
Parent Goal Ref
- Goal:
skill_runtime_exec.pyの outer child 起動は現在subprocess.run(child_argv, ..., timeout=timeout_seconds)を使っており、TimeoutExpired捕捉時点ではsubprocess.runが内部で direct child を既にkill()→wait()済みのため、捕捉後に安全に使える PID/PGID が残っていない。したがってexcept TimeoutExpired: os.killpg(...)という事後対応方式は成立しない。 - Desired Destination: 起動直後から caller が PID/PGID を保持し続ける
subprocess.Popen(..., start_new_session=True)supervisor に置換し、execution 待機用の monotonic deadline とは分離した、cleanup 専用の bounded monotonic deadline(execution deadline 超過を検知した時点から新規に開始する)の下でSIGTERM→ bounded grace →SIGKILLの staged escalation を行い、その後 process-group absence を再検証してから direct child を reap する。保証対象は executor-owned process group に属する descendant に限り、descendant 自身が別 session/process group へ移動した場合の回収までは主張しない。
Current Validated Scope
scripts/agent-guards/skill_runtime_exec.pyの outer child 起動・timeout・cleanup 経路(現在 L1647 付近のsubprocess.run(...)/ L1454 付近の_emit_timeout_failure())
Remaining Parent Gaps
- なし
Outcome
skill_runtime_exec.py の outer child 起動を、subprocess.run(..., timeout=timeout_seconds) の TimeoutExpired 事後捕捉ではなく、起動直後から caller が PID/PGID を保持し続ける subprocess.Popen(child_argv, ..., start_new_session=True) supervisor へ置換する。execution 待機用の monotonic deadline とは分離した、cleanup 専用の bounded monotonic deadline(execution deadline 超過を検知した時点から新規に開始し、TERM grace 待機・process-group absence 再検証・KILL・leader reap・pipe drain/close の全 cleanup operation をこの単一 cleanup deadline の残り予算内で行う。固定の join(timeout=...) を cleanup deadline の外側に積み上げない)の下で、deadline 超過時は executor-owned process group(direct child が属する PGID、起動直後の proc.pid として保持し os.getpgid() による遅延取得は行わない)に対して SIGTERM → bounded grace 待機 → SIGKILL の staged escalation を行う。TERM grace 中から KILL への昇格判断は direct child(leader)の生死ではなく killpg(pgid, 0)(ProcessLookupError で absence 確認)による process-group absence の有無で行う(leader が grace 内に終了しても、同一 PGID に SIGTERM を無視する descendant が残っていれば SIGKILL へ進む)。KILL 後も同様に process-group absence を再検証してから direct child を wait() で reap する。cleanup の成否は signal 送出自体からではなく absence 確認結果に基づき、cleanup_scope=process_group / cleanup_status=confirmed_absent|unconfirmed|not_started / termination=term|term_then_kill|not_needed / leader_reaped=true|false の closed enum として _emit_timeout_failure() の telemetry / stderr 出力に記録する。deadline exhaustion 等で absence を確認できなかった場合は cleanup_status=unconfirmed とし、成功として扱わない。この保証は POSIX(start_new_session / os.killpg / os.setsid が利用可能な環境)に対するものであり、非対応環境を successful cleanup と誤判定しない。normal success(timeout が発生しないケース)では proc.communicate(timeout=...) による pipe EOF 待機・decode error 伝播を含め、stdout/stderr/returncode の既存 subprocess.run() semantics を変えない(direct child の poll() が non-None になっただけで success 扱いにせず、descendant が stdout/stderr の write file descriptor を保持している間は pipe が EOF にならず timeout する既存挙動を維持する)。Popen 起動成功後の全 exit path(normal success、timeout、KeyboardInterrupt を含む任意の例外)で process-group cleanup を通ってから元の結果/例外を返す。timeout 時に child の partial stdout/stderr を、既存の _emit_timeout_failure() の契約を超えて新規 telemetry として不用意に漏らさない。
In Scope
skill_runtime_exec.pyの outer child 起動箇所(現在subprocess.run(child_argv, ..., timeout=timeout_seconds))を、起動直後から PID/PGID を保持するsubprocess.Popen(child_argv, ..., start_new_session=True)supervisor へ置換する変更(subprocess.runを維持したままexcept TimeoutExpiredでos.killpgを追加する方式は採らない)- execution 待機用の monotonic deadline とは分離した、cleanup 専用の bounded monotonic deadline(execution deadline 超過時点から新規に開始する)で
SIGTERM→ bounded grace 待機 →SIGKILLの staged escalation を行う cleanup ロジックの追加(KILL への昇格判断は leader の生死ではなく process-group absence を基準にする) - cleanup 後に
killpg(pgid, 0)等で process-group absence を再検証し、cleanup_scope=process_group/cleanup_status=confirmed_absent|unconfirmed|not_started/termination=term|term_then_kill|not_needed/leader_reaped=true|falseの closed enum telemetry を_emit_timeout_failure()の出力に追加する変更(deadline exhaustion 時はunconfirmedとし成功扱いにしない) - direct child(leader)を
wait()で確実に reap する変更(zombie 化防止) - Popen 起動成功後の全 exit path(normal success / timeout /
KeyboardInterruptを含む任意の例外)で process-group cleanup を通してから元の結果・例外を返す変更(except BaseException等での cleanup-then-reraise) - normal success path で
proc.communicate(timeout=...)を用い、pipe EOF 待機・decode error 伝播を含む既存subprocess.run()semantics を維持する変更(direct child のpoll()のみで success 判定しない) start_new_session/os.killpg/os.setsidが利用できない non-POSIX 環境での fallback 挙動(successful cleanup と誤判定しない)の追加- timeout 時に child の partial stdout/stderr を既存契約を超えて新規 telemetry として漏らさないようにする変更
- 上記変更を検証する real-subprocess ベースの unit test の追加(Acceptance Criteria 参照)
Out of Scope
run_refinement_preflight.py側のPLANNER_TIMEOUT実装や inner timeout の変更command_registry.pyのtimeout_seconds値そのものの変更skill_runtime_exec.py以外の subprocess 起動箇所(他 skill script)への同種修正の横展開- PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074(マージ済み)が対象とした CI serial lane 分離の見直し。本 Issue はマージ済み PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 の成果物を前提として構築する
- 起動元 caller が別 session/process group へ自ら移動した descendant process の回収を保証すること(保証対象は executor-owned process group 内の descendant に限る)
- Linux cgroup v2
cgroup.kill等、POSIX process-group signal 以外の primitive の導入 - Issue 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 が所有する
scope_rollup.run固有の bounded streaming / profile 統合 / global deadline の worker 実装。本 Issue は 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 が再利用する generic な outer-child supervisor primitive の確立に限定し、実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 側の worker 統合作業自体は行わない
Acceptance Criteria
- AC1:
skill_runtime_exec.pyの outer child 起動がsubprocess.Popen(..., start_new_session=True)による supervisor 実装に置換されており、起動直後から caller が child の PID/PGID を保持する(subprocess.run+except TimeoutExpiredでの事後killpg方式ではない)。 - AC2: leader プロセスが同一 PGID で sleeping grandchild を fork するシナリオで、global deadline 超過後に executor-owned process group の absence が確認できる(real subprocess を使った統合テストで検証する)。
- AC3: SIGTERM を ignore する leader/descendant に対し、bounded grace 経過後に SIGKILL escalation が実際に行われる(real subprocess テストで検証する)。
- AC4: normal success(timeout が発生しないケース)で stdout/stderr/returncode の既存 semantics が変更前と一致する。
- AC5: direct child(leader)が
wait()で確実に reap され、zombie として残らない。 - AC6: cleanup deadline exhaustion を注入した場合(absence 確認が完了する前に deadline を使い切った場合)、
cleanup_status=unconfirmedとして記録され、成功として扱われない。 - AC7: timeout 発生時、child の partial stdout/stderr が
_emit_timeout_failure()の既存契約を超えて新規 telemetry として漏れない。 - AC8:
start_new_session/os.killpg/os.setsidが利用できない non-POSIX 環境をシミュレートした場合、successful cleanup として誤判定されない(fallback 経路がテストで検証される)。 - AC9: cleanup 結果が
cleanup_scope=process_group/cleanup_status=confirmed_absent|unconfirmed|not_started/termination=term|term_then_kill|not_needed/leader_reaped=true|falseの closed enum で_emit_timeout_failure()の telemetry / stderr 出力に記録される。 - AC10: 既存の
scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.pyが regression なく PASS する。scripts/agent-guards/tests/全体の regression は CI required lane(pnpm test経路とは別の python test job)で確認する。
Verification Commands
# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_outer_child_uses_popen_start_new_session -q# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_timeout_process_group_isolation -q# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_sigterm_escalates_to_sigkill -q# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_normal_success_semantics_unchanged -q# AC5
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_direct_child_reaped -q# AC6
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_deadline_exhaustion_unconfirmed -q# AC7
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_partial_stdout_stderr_not_leaked -q# AC8
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_non_posix_fallback_not_false_success -q# AC9
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_status_telemetry_enum -q# AC10
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.py -qAllowed Paths
scripts/agent-guards/skill_runtime_exec.pyscripts/agent-guards/tests/
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Python subprocess / process-group management(
os.setsid/start_new_session/os.killpg/Popensupervision) - pytest(real-subprocess integration test 設計)
Required Design References
- OWNER review comment(immutable): https://github.com/squne121/loop-protocol/issues/2075#issuecomment-5248341387(本 Issue の実装方式・保証範囲・telemetry enum・POSIX 境界を確定した review。
subprocess.Popensupervisor 化、process-group スコープへの保証範囲の限定、telemetry closed enum、POSIX-only 境界の根拠) - OWNER review comment(immutable): https://github.com/squne121/loop-protocol/pull/2082#issuecomment-5249045572(PR 実装: skill_runtime_exec.py の outer child cleanup を Popen supervisor 化する #2082 head
b47aacaeに対する REQUEST_CHANGES。process-group liveness ベースの SIGKILL escalation、communicate()semantics 維持、Popen 成功後の全 exit path での cleanup、execution/cleanup 分離 deadline モデルを確定した review)
docs/dev/ac10-pid-proof-flake-root-cause.md は Issue #2073 / PR #2080 で削除された orphan document のため、Required Design Reference から除去した(2026-08-11 改訂)。
Runtime Verification Applicability
- decision: not_applicable
- reason: 本 Issue の AC はすべて
scripts/agent-guards/tests/配下の pytest(uv run --locked pytest)で完結する。real subprocess を fork し signal を送るテストを含むが、それらはテスト自身が起動・制御する hermetic な fixture プロセスであり、外部サービス・ネットワーク・本番ランタイムプロセスへの依存はない。同ディレクトリの既存 subprocess/timeout テスト(例:test_skill_exec_timeout)も同様に runtime-verification タグなしで扱われており、本 Issue も同じ扱いとする。
Notes for Reviewer
- 発端: Issue 実装: test_ac10_real_executor_chainがCI並列負荷下でpid_proof_plannerのFileNotFoundErrorで不安定になる問題を解消する #2073 / PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 の OWNER レビュー(コメント)で、
skill_runtime_exec.pyの timeout cleanup が通常のsubprocess.runに依存しており descendant process の process-group cleanup を保証していないことが指摘され、別 Issue での対応が明示的に推奨された。PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 は現在 main にマージ済み。 - 2026-08-11 の OWNER review(issuecomment-5248341387、REQUEST_CHANGES、P1×4/P2×3)を受けて本文を全面改訂した。主な変更点:
subprocess.run+ 事後except TimeoutExpired: killpg方式を撤回し、起動直後から PID/PGID を保持するsubprocess.Popen(..., start_new_session=True)supervisor 方式へ変更した(subprocess.runはTimeoutExpired送出前に内部で direct child を kill/wait 済みのため、事後方式は成立しない)。- 保証範囲を「process tree 全体の reap」から「executor-owned process group 内の descendant absence 確認 + direct child leader の reap」に narrowing した(別 session/process group へ移動した descendant の回収までは主張しない)。
- cleanup の状態遷移を
execution timeout → SIGTERM → grace deadline → SIGKILL → absence verification → leader reapに固定し、execution budget と cleanup budget を分離せず単一 monotonic deadline で管理する設計にした。 - telemetry を
cleanup_scope=process_group/cleanup_status=confirmed_absent|unconfirmed|not_started/termination=term|term_then_kill|not_needed/leader_reaped=true|falseの closed enum に固定した(SIGKILL 送出自体を成功とせず、absence 確認できた場合のみconfirmed_absentとする)。 - POSIX-only 境界を Outcome/AC(AC8)に明記した。
- Required Design Reference の依存先だった PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 はマージ済みのため、
docs/dev/ac10-pid-proof-flake-root-cause.mdは current main 上のドキュメントとして参照可能になった。加えて immutable な OWNER review comment 自体も Required Design Reference に追加した。
- Issue 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 との関係: 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601(
scope_rollup.runをskill_runtime_exec.pyの sibling exact profile へ統合する Issue、OPEN)の AC4 はskill_runtime_exec.pyの worker/child/new-session grandchild の process-tree cancellation・single global deadline・graceful-to-hard cancellation を既に所有しており、本 Issue の中心責務と直接重なる。OWNER review の推奨に従い、本 Issue(実装: skill_runtime_exec.py の outer timeout cleanup で descendant process の process-group cleanup を保証する #2075)を 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 の predecessor として位置づける: 実装: skill_runtime_exec.py の outer timeout cleanup で descendant process の process-group cleanup を保証する #2075 は generic な outer-child supervisor primitive(Popensupervision、staged escalation、process-group absence 確認、telemetry closed enum)を確立し、実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 はこれを再利用してscope_rollup.run固有の bounded streaming / profile 統合 / global deadline 拡張を追加する。実装: skill_runtime_exec.py の outer timeout cleanup で descendant process の process-group cleanup を保証する #2075 は 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 の worker 統合作業自体は扱わない(Out of Scope 参照)。実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 側のdependenciesフィールドへ 実装: skill_runtime_exec.py の outer timeout cleanup で descendant process の process-group cleanup を保証する #2075 を追加するかどうかは 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 自体の refinement で判断する。 - AC10 VC のスコープ限定(issue-refinement-loop iteration 2):
scripts/agent-guards/tests/全体を-n 4 --dist loadscopeで実行すると約103秒かかり、readiness/review 事前検証ツールの bounded window を超過して timeout する。加えてフル実行ではtest_skill_runtime_exec_session_manifest.py::test_external_session_manifest_peer_write_does_not_stop_preflightが本 Issue のスコープと無関係な.codex環境汚染により failing することを確認した(session-manifest write-path guard の既存 flake であり、本 Issue の outer subprocess timeout/cleanup 変更とは無関係)。そのため AC10 の VC は迅速に完結するtest_skill_runtime_preflight_bytecode_cache.py単体に限定し、full suite regression は CI required lane に委ねる。 - 2026-08-11 二度目の改訂(PR 実装: skill_runtime_exec.py の outer child cleanup を Popen supervisor 化する #2082 head
b47aacaeへの OWNER REQUEST_CHANGES、issuecomment-5249045572、P1×4/P2×3)を受けて Outcome / Parent Goal Ref / In Scope を再改訂した。主な変更点:- deadline モデルを「execution 待機と cleanup 待機を同一 deadline で管理する」単一 deadline 方式から、「execution deadline 超過を検知した時点で新規に開始する、cleanup 専用の bounded monotonic deadline」という分離 deadline 方式へ変更した(P1-4)。cleanup 側の全 operation(TERM grace・group absence 再検証・KILL・leader reap・pipe drain/close)はこの単一 cleanup deadline の残り予算内で行い、固定の
join(timeout=...)を deadline 外に積み上げない。 - SIGKILL への escalation 判断基準を、direct child(leader)の生死ではなく process-group absence(
killpg(pgid, 0))に明示した(P1-1)。leader が TERM grace 内に終了しても、同一 PGID の SIGTERM を無視する descendant が残っていれば SIGKILL へ進む。 - normal success path が
proc.communicate(timeout=...)を用いる(pipe EOF 待機・decode error 伝播を含む既存subprocess.run()semantics を維持する)ことを明記した(P1-2)。 - Popen 起動成功後の全 exit path(normal success / timeout /
KeyboardInterruptを含む任意の例外)が process-group cleanup を通ることを In Scope に追加した(P1-3)。 - PGID は
os.getpgid()による遅延取得ではなく、start_new_session=True起動直後のproc.pidとして保持することを明記した(P2-1)。 docs/dev/ac10-pid-proof-flake-root-cause.mdは PR docs: AC10 pid_proof flake root-cause文書を訂正し診断情報を追加 (#2073) #2080 で削除済みの orphan document であることが判明したため、Required Design References から除去した(P2-3)。
- deadline モデルを「execution 待機と cleanup 待機を同一 deadline で管理する」単一 deadline 方式から、「execution deadline 超過を検知した時点で新規に開始する、cleanup 専用の bounded monotonic deadline」という分離 deadline 方式へ変更した(P1-4)。cleanup 側の全 operation(TERM grace・group absence 再検証・KILL・leader reap・pipe drain/close)はこの単一 cleanup deadline の残り予算内で行い、固定の
- Scope Collision (C1, overlap_requires_comment):
check_issue_overlap.pyによりscripts/agent-guards/skill_runtime_exec.py/scripts/agent-guards/tests/を Allowed Paths に含む多数の OPEN Issue(実装: test_ac10_real_executor_chainがCI並列負荷下でpid_proof_plannerのFileNotFoundErrorで不安定になる問題を解消する #2073, 実装: repair_action candidate を controlled Issue transaction へ自動適用する main control-plane consumer を追加する #2039, 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601, 実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526, 実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363 等)との重複が検出された。non_conflict_reason: 本 Issue の実 edit_intent は outersubprocess.Popensupervisor 化と process-group cleanup ロジックの追加、対応する新規テストファイル(test_skill_runtime_exec_process_tree_cleanup.py)の追加のみに限定され、既存テストファイルの改変は行わない。実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 との関係は上記の通り predecessor として明示的に整理した。他 Issue が扱う機能追加・authority transport・contract 変更・attribution mode 等とは責務が異なる。edit_intent: 主対象は outer subprocess 起動箇所と新規テストファイルであり、既存テストファイルの改変は最小限(regression 修正のみ)に留める。
Activity
squne121 commentedon Aug 11, 2026
総合判定
REQUEST_CHANGES。P0 はありませんが、P1 を4件、P2を3件と判定します。#2075 が拾おうとしている問題自体は実在します。現行
skill_runtime_exec.pyはsubprocess.run(..., timeout=...)を使い、TimeoutExpiredでは_emit_timeout_failure()を返すだけで、process-group isolation / descendant cleanup を持っていません。ただし、Issue に現在書かれている実装方式では AC2/Outcome をそのまま実現できません。また既存 Issue #1601 と ownership が衝突しています。
Findings
subprocess.run()のままexcept TimeoutExpiredでkillpgする設計は成立しません。Python 3.12 の
subprocess.run()は timeout 発生時、内部Popenの direct child をkill()→wait()した後にTimeoutExpiredを再送出します。CPython 3.12.13 の実装も明示的にprocess.kill()→process.wait()→raiseです。またTimeoutExpiredが公開する属性はcmd/output/stdout/stderr/timeoutであり PID はありません。 ([docs.python.org]1)つまり #2075 の現在の記述、
では、捕捉時点で supervisor が安全に使える child PID/PGID を保持していません。Issue の In Scope を **「
subprocess.runにstart_new_session=Trueを足す」ではなく、「明示的なsubprocess.Popen(..., start_new_session=True)supervision へ置換する」**と修正すべきです。start_new_session=True自体は POSIX で child exec 前にsetsid()を行う正しい primitive です。 ([Python documentation]1)killpg()が signal を送る対象はあくまで同じ process groupです。start_new_session=Trueで起動した leader の子は通常その PGID を継承するので、普通に fork/exec する descendant は回収できます。 ([man7.org]2)実際、現在の planner は
run_refinement_preflight.pyから通常のsubprocess.run()で起動され、start_new_session/setpgidを使っていません。そのため、現在問題にしている preflight → planner chain に対しては process-group cleanup は適切です。しかし descendant 自身が新しい session/process group を作れば
killpg(original_pgid, ...)の対象外へ出られます。さらにwait()/waitpid()で直接 reap できるのは原則として caller の child であり、grandchild を outer executor が直接 reap するには Linux の subreaper のような追加機構が必要です。 ([man7.org]3)したがって AC2/Outcome は、
「executor-owned process group に残っている descendant の absence を確認し、direct child leader を reap する」
までに狭めるべきです。
もし本当に「session を脱出した descendant まで含む process tree 全体」を強い意味で保証したいなら、Linux cgroup v2 の
cgroup.killのような別 primitive が必要です。Kernel docs では cgroup subtree 全体への kill と concurrent fork/migration 対応まで定義されていますが、これは #2075 の portable Python/POSIX scope を大きく超えます。 ([Linuxカーネルアーカイブ]4)#2075 の Scope Collision は #1601 を列挙しつつ「責務が異なる」としていますが、その説明は不十分です。#1601 は既に
skill_runtime_exec.pyの outer executor について、を In Scope / AC4 として所有しています。しかも
cancellation_policy: staged_process_tree_v1まで宣言しています。これは #2075 の中心責務そのものです。
推奨は #2075 を #1601 の明示的 predecessor にすることです。 #2075 で generic outer-child supervisor の最小 primitive を確立し、#1601 はそれを再利用して bounded streaming/global deadline/profile integration を追加する、と dependency order を固定するのが最も小さいです。
そうしないなら #2075 を #1601 に統合し、duplicate scope として整理する方が安全です。現状の「non-conflict」は adversarial review を通しません。
#2075 は
docs/dev/ac10-pid-proof-flake-root-cause.mdを Required Design Reference としていますが、確認できた文書は PR #2074 の branch 側の成果物です。PR #2074 自体は現在も open / unmerged です。一方 #2075 は
parent_issue: none、Remaining Parent Gaps なしとして扱っています。ここは次のどちらかが必要です。
depends_on: #2073 / PR #2074 / required_state: mergedを契約化する。skill_runtime_exec.pyに変更し、PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 への実装依存を除く。後者の方が #2075 を独立して先行させやすいです。
現在は「bounded window」「
os.killpg等」としか決まっていません。repository 内には既に、より具体的な precedent があります。AGY permission-boundary runner は
Popen(start_new_session=True)、SIGTERM、bounded poll、残存時SIGKILL、その後 process-group absence の再検証という staged cleanup を実装し、real-subprocess test まで持っています。#2075 も少なくとも、
execution timeout → SIGTERM → grace deadline → SIGKILL → absence verification → leader reapを固定すべきです。Python の
communicate(timeout=...)は timeout 時に child を自動 kill しないため、明示 supervisor を組む場合はこの状態遷移を application が所有できます。 ([Python documentation]1)また cleanup 開始後に無制限の
communicate()/wait()を置くと「bounded cleanup」の保証を再び失います。execution budget と cleanup budget を分離し、全 cleanup operation を同じ monotonic deadline で制限するのがよいです。現行
_emit_timeout_failure()はreason_code=child_process_timeoutとtimeout_secondsだけを出します。少なくとも closed enum として、
程度を固定すべきです。
特に SIGKILL を送った = cleanup success にはしてはいけません。
killpg(pgid, 0)等による process-group absence が確認できた場合だけconfirmed_absentにし、permission error / deadline exhaustion はunconfirmedとして fail-closed にする設計が、repository 内の既存 cleanup precedent と整合します。Python の
start_new_sessionは POSIX-only です。 ([Python documentation]1)Issue は Required Skills では POSIX を示していますが、AC/Outcome 自体には platform boundary がありません。少なくとも「この safety guarantee は POSIX executor に対するもの」「unsupported platform では unsafe fallback で PASS にしない」を明記すると、将来的な Windows execution surface で false guarantee を作りません。
修正後の中心契約
#2075 は、次の意味に縮めるとかなり強くなります。
この契約なら Python/POSIX の実際の semantics と一致します。 ([Python documentation]1)
追加すべきテスト
最低限、AC は次のケースを要求した方がよいです。
cleanup_status=unconfirmedになり、成功扱いしない。特に既存 AGY cleanup tests には「leader が先に正常終了して descendant だけが linger する」ケースまであります。#2075 の test design はこの precedent を参照して作る方が、独自の簡易 sleep test より強いです。
実装開始条件
現状のまま
impl-review-loopに渡すことは勧めません。少なくとも P1-1〜P1-4 を Issue refinement で直してからgoが妥当です。優先順位は、(1)
run→Popenを契約化、(2) reap/process-tree guarantee を process-group guarantee に修正、(3) #1601 との dependency ordering を固定、(4) #2074 由来 design reference の provenance を固定です。この4点が入れば、#2075 はかなり実装可能性の高い narrow hardening Issue になります。squne121 commentedon Aug 11, 2026
Contract Review Result
squne121 commentedon Aug 11, 2026
issue-refinement-loop 終了報告(Issue #2075)
経緯
## Runtime Verification Applicabilityセクション欠落(C9)が blocker。同時に OWNER anchor comment の技術指摘(subprocess.run+事後killpg方式は成立しない、保証範囲の過大主張、Issue 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 との scope 衝突、未マージ PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 依存)を反映して本文を全面改訂。scripts/agent-guards/tests/全体を-n 4 --dist loadscopeで実行する形になっており、readiness ツールの bounded window(実測 約103秒)を超過して timeout。AC10 の VC を高速に完結するtest_skill_runtime_preflight_bytecode_cache.py単体に限定し、full suite regression は CI required lane に委ねる形へ修正(実行中に本 Issue のスコープと無関係な.codex環境汚染由来の既存 flake も確認・記録した)。VERDICT: approve(contract ready、blocker 0件)。Final Gate
issue-contract-review(run_contract_review_once.py --mode execute):status: go(body_sha256:sha256:995db069f965f70b7fb2602821c6ebc77aa0b2204ac7d674f76fe82f517401fe)squne121 commentedon Aug 11, 2026
implement-issue: 実装完了 (2026-08-11)
.claude/worktrees/issue-2075-skill-runtime-exec-py-outer-timeout-cleaworktree-issue-2075-skill-runtime-exec-py-outer-timeout-cleaVerification Commands 実行結果
追加のローカル近似確認(
scripts/agent-guards/tests/全体、serial 実行): 1227 passed, 1 skipped, 1 deselected。実装概要
subprocess.run(..., timeout=timeout_seconds)+except TimeoutExpiredを、起動直後から PID/PGID を保持するsubprocess.Popen(..., start_new_session=True)supervisor に置換しました。SIGTERM→ bounded grace →SIGKILLの staged escalation を行い、killpg(pgid, 0)による process-group absence 再検証後に direct child をwait()で reap します。_emit_timeout_failure()の telemetry にcleanup_scope=process_group/cleanup_status=confirmed_absent|unconfirmed|not_started/termination=term|term_then_kill|not_needed/leader_reaped=true|falseの closed enum を追加しました。unconfirmedとし、successful cleanup と誤判定しません。test_ac13(subprocess.runmock 前提)とtest_skill_runtime_exec_anchor.pyの sitecustomize fixture(subprocess.runのuv呼び出しにのみ PYTHONPATH 伝播していた)を、outer child 起動がPopen経由になったことに合わせて最小限更新しました(詳細は PR 本文の Notes を参照)。後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
fix: OWNER review P1×4/P2×2をskill_runtime_exec.pyのcleanup state machi…
squne121 commentedon Aug 11, 2026
PR #2082 への OWNER の詳細レビュー(issuecomment-5249045572)を fix_delta として反映し、
scripts/agent-guards/skill_runtime_exec.pyの_run_child_with_supervision()(_stage_cleanup()等の関連関数を含む)を修正しました。commita171ec56、branchworktree-issue-2075-skill-runtime-exec-py-outer-timeout-clea(PR #2082 head を更新済み)。対応状況サマリ
P1 Blockers(4件、すべて対応済み)
_poll_group_absent_until()によるkillpg(pgid, 0)の group-liveness ポーリングへ変更。leader が先に終了しても SIGTERM を無視する descendant が残っていれば SIGKILL へ escalate します。proc.poll()ベースの success 判定がcommunicate()semantics を破壊): 対応済み。独自 reader thread + poll ループを廃しproc.communicate(timeout=timeout_seconds)方式へ置換。pipe EOF timeout・UnicodeDecodeError伝播を含めsubprocess.run()と同等の semantics を回復しました。try: communicate() / except TimeoutExpired: cleanup / except BaseException: cleanup; raise構造へ変更し、全 exit path が同一の cleanup state machine を通るようにしました。remaining(cleanup_deadline)で bound しました。固定join(timeout=1)等の積み上げは廃止しています。P2 所見
os.getpgid()の遅延取得を廃しproc.pidを pgid とする): 対応済み。起動直後のproc.pidを pgid として直接保持し、os.getpgid()は一切呼び出しません。test_leader_exits_but_term_ignoring_descendant_still_escalated_to_kill/test_leader_exit_with_descendant_holding_pipes_still_times_out/test_exception_after_popen_still_cleans_up_process_group/test_pgid_captured_from_proc_pid_without_getpgid_lookup/test_group_absence_check_permission_error_not_confirmed/test_malformed_child_output_raises_unicode_decode_error)。reader thread/pipe cleanup の観点はcommunicate()方式への変更で reader thread 自体が不要になったため該当なしです。docs/dev/ac10-pid-proof-flake-root-cause.mdは PR docs: AC10 pid_proof flake root-cause文書を訂正し診断情報を追加 (#2073) #2080 で既に削除済みの orphan ドキュメントです。この Issue 本文編集は本 Issue の Allowed Paths(scripts/agent-guards/skill_runtime_exec.py,scripts/agent-guards/tests/)の範囲外のため、fix_delta 実装担当(本 SubAgent)では実行していません。別途edit-issueskill 経由での Issue 本文更新を人間または担当エージェントにお願いします。PR 実装: skill_runtime_exec.py の outer child cleanup を Popen supervisor 化する #2082 本文のテスト件数は現行 head で再計測し、23 件→24 件、1227 件→1234 件に更新済みです(内訳: PR docs: AC10 pid_proof flake root-cause文書を訂正し診断情報を追加 (#2073) #2080 由来の +1 件、本 fix_delta で追加した P2-2 テスト +6 件)。検証結果
scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py15 件、うち 9 件が既存 AC1〜AC9、test_skill_runtime_preflight_bytecode_cache.py24 件で AC10 regression-free)。uv run --locked pytest scripts/agent-guards/tests/ -q(serial 実行): 1234 passed, 1 skipped, 1 deselected。uv run ruff check scripts/agent-guards/skill_runtime_exec.py scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py: All checks passed。PR #2082 の本文も上記内容を反映して更新しました。
実装: skill_runtime_exec.py の outer child cleanup を Popen supervisor 化する (