Skip to content

実装: skill_runtime_exec.py の outer timeout cleanup で descendant process の process-group cleanup を保証する #2075

Closed

Description

@squne121

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: code

Parent 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

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 -q

Allowed Paths

  • scripts/agent-guards/skill_runtime_exec.py
  • scripts/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 / Popen supervision)
  • pytest(real-subprocess integration test 設計)

Required Design References

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

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Aug 10, 2026
  2. squne121 commented on Aug 11, 2026

    @squne121
    OwnerAuthor

    総合判定

    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

    1. P1 — 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 の現在の記述、

    subprocess.run(..., start_new_session=True) → TimeoutExpired 捕捉 → os.killpg

    では、捕捉時点で 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)

    1. P1 — 「process tree 全体を reap」「descendant が確実に終了」は process-group だけでは保証過剰です。

    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)

    1. P1 — 実装:scope_rollup.runをskill_runtime_execのsiblingexactprofileへ統合する #1601 と cancellation/supervision ownership が直接衝突しています。

    #2075 の Scope Collision は #1601 を列挙しつつ「責務が異なる」としていますが、その説明は不十分です。#1601 は既に skill_runtime_exec.py の outer executor について、

    • single global deadline
    • graceful cancellation
    • bounded grace
    • hard termination
    • process-tree cancellation
    • worker/child/grandchild の timeout 後残存なし

    を 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 を通しません。

    1. P1 — Required Design Reference が未merge PR fix: test_ac10_real_executor_chainをCPU飽和下のtimeout killからserial laneへ分離する #2074 の成果物に依存しています。

    #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 なしとして扱っています。

    ここは次のどちらかが必要です。

    後者の方が #2075 を独立して先行させやすいです。

    1. P2 — cleanup の boundedness が数値・状態遷移として未定義です。

    現在は「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 で制限するのがよいです。

    1. P2 — AC3 の telemetry が自由記述のままで、fail-open 判定が可能です。

    現行 _emit_timeout_failure() は reason_code=child_process_timeout と timeout_seconds だけを出します。

    少なくとも closed enum として、

    cleanup_scope=process_group
    cleanup_status=confirmed_absent|unconfirmed|not_started
    termination=term|term_then_kill|not_needed
    leader_reaped=true|false
    

    程度を固定すべきです。

    特に SIGKILL を送った = cleanup success にはしてはいけません。killpg(pgid, 0) 等による process-group absence が確認できた場合だけ confirmed_absent にし、permission error / deadline exhaustion は unconfirmed として fail-closed にする設計が、repository 内の既存 cleanup precedent と整合します。

    1. P2 — POSIX-only 契約を明示した方がよいです。

    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 は、次の意味に縮めるとかなり強くなります。

    skill_runtime_exec.py の outer child execution を、PID/PGID を caller が保持する subprocess.Popen(..., start_new_session=True) supervisor に置換する。execution timeout 時は executor-owned process group に SIGTERM → bounded grace → SIGKILL を行い、bounded deadline 内で process-group absence を再検証する。direct child は caller が reap する。cleanup の成功を signal dispatch 自体から推測せず、confirmed_absent / unconfirmed として telemetry に記録する。保証対象は executor-created process group に所属する descendants であり、自ら別 session/process group へ移動した process の回収までは主張しない。

    この契約なら Python/POSIX の実際の semantics と一致します。 ([Python documentation]1)

    追加すべきテスト

    最低限、AC は次のケースを要求した方がよいです。

    • normal success で stdout/stderr/returncode の既存 semantics が変わらない。
    • leader → sleeping grandchild を同一 PGID で生成し、timeout 後に group absence が確認される。
    • SIGTERM を ignore する leader/descendant で SIGKILL escalation が実際に走る。
    • direct child が確実に reap 済みになる。
    • cleanup deadline exhaustion を注入すると cleanup_status=unconfirmed になり、成功扱いしない。
    • timeout 時にも child の partial stdout/stderr を不用意に新規 telemetry として漏らさない。
    • POSIX capability がない環境を successful cleanup と誤判定しない。

    特に既存 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 になります。

  3. self-assigned this
    on Aug 11, 2026
  4. squne121 commented on Aug 11, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-08-11T03:03:31Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/2075
      body_sha256: "sha256:995db069f965f70b7fb2602821c6ebc77aa0b2204ac7d674f76fe82f517401fe"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        product_spec_check: {"schema":"product_spec_check/v1","applicability":"applicable","decision":"pass","triggers":{"docs_product_allowed_paths":false,"tasks_md_mentioned":false,"specify_artifact_mentioned":false,"generated_task_mentioned":false,"product_spec_context_present":false,"machine_readable_contract_present":true},"conditions":{"docs_product_requires_spec_evidence":{"status":"pass","evidence":[]},"tasks_md_not_direct_source":{"status":"pass","evidence":[]},"specify_not_canonical":{"status":"pass","evidence":[]},"diff_first_rationale_present":{"status":"pass","evidence":[]},"generated_task_trace_present":{"status":"pass","evidence":[]},"task_dependencies_materialized":{"status":"pass","evidence":[]}},"blocked_reasons":[],"body_sha256":"sha256:995db069f965f70b7fb2602821c6ebc77aa0b2204ac7d674f76fe82f517401fe","source_provenance":{"source_type":"body_file","body_file":"/tmp/contract_review_once_body__6fxveuk.md"}}
        vc_preflight:
          decision: pass
          classifications: '[{"ac":"AC1","line":2,"raw_command":"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","command_hash":"sha256:0e6c645209e490482d784a4ef0bdbe6cf9b7aada11ff29aa9d2e76226431382c","execution_key_hash":"sha256:a0377210f2bad8cdb2fdda096120390a92d0e125a4c1199a9dabe262a9aee625","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_outer_child_uses_popen_start_new_session"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":152,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC2","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_timeout_process_group_isolation -q","command_hash":"sha256:c9a04222ee3b78c76b993d64c39d78984d4a01307fcaa42ce097f4aed268accc","execution_key_hash":"sha256:f4929c4d7655479adbac00bf1cc6442b2175ba24f55fb6ec2d6b99d07470d40f","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_timeout_process_group_isolation"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":176,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC3","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_sigterm_escalates_to_sigkill -q","command_hash":"sha256:c44bc46786c9c9e59997c3ebbef7df3224f2ec425d1a322dc8d950721456d520","execution_key_hash":"sha256:d24dc079067db09c0fd612170829c34771994d1096870a431466fdbef2f4a699","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_sigterm_escalates_to_sigkill"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":179,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC4","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_normal_success_semantics_unchanged -q","command_hash":"sha256:cbc48e166791cc56d758a219a150ea5f4d2db65f7d8d31255e5b63db557d1a55","execution_key_hash":"sha256:4c76bf250a51ff91f16780685838a65d814b7637f01cc1320491b5771d746860","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_normal_success_semantics_unchanged"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":175,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC5","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_direct_child_reaped -q","command_hash":"sha256:4f4f6e8e72627a99537630e0712a22bcc70d829717e92882e4a1ef228c4be779","execution_key_hash":"sha256:5e883b3d0a16e7783b8c547cb7a328ae3bc6181cdb073f06ed096794d798c39f","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_direct_child_reaped"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":154,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC6","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_deadline_exhaustion_unconfirmed -q","command_hash":"sha256:35c4700357be43483c401d7428c31717b4d9cf5a3b1a0b6e20ce140e81bb9477","execution_key_hash":"sha256:419ad7a25cf7bbd98df8f962dd15e73e04322bb202519475f4e316506192f1c0","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_deadline_exhaustion_unconfirmed"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":165,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC7","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_partial_stdout_stderr_not_leaked -q","command_hash":"sha256:7ab9473af96ac6437fdd8722ae5756538b2a08147b3ef419c7691df3e50cf162","execution_key_hash":"sha256:ca62ed4ce838f239c28026d3bac381736f49eac06bc4fe7b92965dffb20411a9","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_partial_stdout_stderr_not_leaked"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":156,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC8","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_non_posix_fallback_not_false_success -q","command_hash":"sha256:2c26877b8421d8bfffbf3475df27552cf9e17b13804a177db0825e55358ea36b","execution_key_hash":"sha256:d6f7b2fbdb635bcc7319756f415efce665e814c4091f34ef783c069112dc0065","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_non_posix_fallback_not_false_success"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":157,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC9","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_status_telemetry_enum -q","command_hash":"sha256:6249cf89dd4441bbe340f75dbba93add260e9de5ac8a73b611ea9613ef2a3985","execution_key_hash":"sha256:75c3731e0e7c7f92770ea8d89cbf6cc53b2df89ce67c2c584004eeb3c9fd6600","runner":"exec","exit_code":4,"classification":"expected_fail","category":"expected_baseline_fail","decision":"go","scope_class":"baseline_fail_expected","confidence":"high","stdout_head":["no tests ran in 0.00s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":["ERROR: file or directory not found: scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_status_telemetry_enum"],"stderr_truncated":false,"stderr_original_line_count":3,"runner_env_delta":{},"duration_ms":168,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null},{"ac":"AC10","line":2,"raw_command":"uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.py -q","command_hash":"sha256:66ea27a82fdef0faa3855775b15e20d0c704f40cb58a2cdcd6683a855c64b265","execution_key_hash":"sha256:9f8a167b702f1534fefa0843862d159aaca154fb0e2abd53e984e1fc829a4aed","runner":"exec","exit_code":0,"classification":"expected_pass","category":"regression_gate","decision":"go","scope_class":"regression_gate","confidence":"low","stdout_head":[".......................                                                  [100%]","23 passed in 5.10s"],"stdout_truncated":false,"stdout_original_line_count":3,"stderr_head":[],"stderr_truncated":false,"stderr_original_line_count":1,"runner_env_delta":{},"duration_ms":5341,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null}]'
        declared_path_overlap: '{"schema":"declared_path_overlap/v1","advisory":true,"blocking":false,"decision":"advisory_only","disjoint":true,"overlapping_prs":[],"inventory":{"schema":"OPEN_PR_INVENTORY_V1","repo":"squne121/loop-protocol","state":"open","base_ref":"main","base_sha":"bae9cb81ae6802f1532bb8fd3810dc1e556360be","draft_policy":"include_drafts","prs":[{"number":1528,"title":"feat(cleanup): 同一実行内の branch-only fallback を追加","base_ref_name":"main","head_ref_name":"worktree-issue-1403-post-merge-cleanup-dedicated-branch-forc","head_ref_oid":"b29007580ae225eb9676c7f32c878ee2bb9ccaa9","is_draft":false,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/1528","changed_files_count_graphql":4},{"number":2068,"title":"fix(issue-refinement-loop): bind freeform OWNER scope authority end-to-end and expose routing telemetry","base_ref_name":"main","head_ref_name":"worktree-issue-2053-bind-freeform-authority-transport","head_ref_oid":"247e1024ff0f78048c66c1c012a5778e35c89540","is_draft":true,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2068","changed_files_count_graphql":16},{"number":2070,"title":"fix(contract-review): RVA 欠落を fail-closed に統一","base_ref_name":"main","head_ref_name":"worktree-issue-2040-implementation-issue-runtime-verificatio","head_ref_oid":"9d5c639de9e3d01c6260939c3b790f40616b911e","is_draft":true,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2070","changed_files_count_graphql":32},{"number":2072,"title":"fix: test_issue_1952回帰テストのrepo_root誤指定による.claude/.claude迷子ディレクトリ生成を修正する","base_ref_name":"main","head_ref_name":"worktree-issue-2071-repo-root-fix","head_ref_oid":"488bc8554a6f2d6e5187d0ea374034d19954a14f","is_draft":true,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2072","changed_files_count_graphql":1},{"number":2080,"title":"docs: AC10 pid_proof flake root-cause文書を訂正し診断情報を追加 (#2073)","base_ref_name":"main","head_ref_name":"worktree-issue-2073-flake-diagnostics","head_ref_oid":"899b9704ea10ec45d3a7d84afe0192ddbb4fd569","is_draft":true,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2080","changed_files_count_graphql":2}],"fetched_count":5,"totalCount":5,"has_next_page":false,"complete":true,"saturated":false,"limit":200,"page_count":1,"inventory_digest":"sha256:4bfd21665b7e592a4839cb4cf7ff7ab282102d3319ada83054451f7e03fbf9be","errors":[]},"inventory_digest_extended":"sha256:e879406760aa014b3488d6a0286d2de363be087415489c4ebd894daf9e10517f","errors":[],"note":"changed-file 名の単純な重なりのみを証明する advisory check。3-way merge・hunk 競合・rename/delete 競合は評価しない(実 Git merge 競合の判定は Issue #1792 の PAIRWISE_MERGE_OBSERVATION_V1 producer の責務)。単独では blocking にしない。disjoint は tri-state(true/false/null)— 観測が不完全な場合は null。"}'
      source: ensure_contract_snapshot_auto
      expected_contract_fingerprint: '{"issue_number":2075,"contract_source_kind":"issue_comment","contract_source_id":"5248512894","contract_body_sha256":"sha256:995db069f965f70b7fb2602821c6ebc77aa0b2204ac7d674f76fe82f517401fe","allowed_paths_normalized_sha256":"00479b14d086bd0497f09cb6b37c9f25a789c4a56e48fd1077a24caaef6515e2","base_ref":"main","base_sha_at_snapshot":"bae9cb81ae6802f1532bb8fd3810dc1e556360be"}'
  5. squne121 commented on Aug 11, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop 終了報告(Issue #2075)

    経緯

    1. iteration 0: 初回 review で ## 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 依存)を反映して本文を全面改訂。
    2. iteration 1: fresh review で C1〜C11 は全て pass となったが、AC10(regression gate)の VC が 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 も確認・記録した)。
    3. iteration 2: fresh review で VERDICT: approve(contract ready、blocker 0件)。

    Final Gate

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: https://github.com/squne121/loop-protocol/issues/2075#issuecomment-5248512894
        generated_at: "2026-08-11T03:03:31Z"
        body_sha256: "sha256:995db069f965f70b7fb2602821c6ebc77aa0b2204ac7d674f76fe82f517401fe"
      metadata:
        title_prefix_ready: true
        phase_label_ready: true
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: "2026-08-11T03:04:20Z"
      checked_body_sha256: "sha256:995db069f965f70b7fb2602821c6ebc77aa0b2204ac7d674f76fe82f517401fe"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
  6. squne121 commented on Aug 11, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-08-11)

    Verification Commands 実行結果

    $ 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
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_timeout_process_group_isolation -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_sigterm_escalates_to_sigkill -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_normal_success_semantics_unchanged -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_direct_child_reaped -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_deadline_exhaustion_unconfirmed -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_partial_stdout_stderr_not_leaked -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_non_posix_fallback_not_false_success -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py::test_cleanup_status_telemetry_enum -q
    1 passed
    
    $ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.py -q
    23 passed (AC10, regression なし)
    

    追加のローカル近似確認(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 に置換しました。
    • 単一の monotonic cleanup deadline の下で 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 を追加しました。
    • non-POSIX 環境では常に unconfirmed とし、successful cleanup と誤判定しません。
    • 既存 test_ac13(subprocess.run mock 前提)と test_skill_runtime_exec_anchor.py の sitecustomize fixture(subprocess.run の uv 呼び出しにのみ PYTHONPATH 伝播していた)を、outer child 起動が Popen 経由になったことに合わせて最小限更新しました(詳細は PR 本文の Notes を参照)。

    後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup

  7. squne121 commented on Aug 11, 2026

    @squne121
    OwnerAuthor

    PR #2082 への OWNER の詳細レビュー(issuecomment-5249045572)を fix_delta として反映し、scripts/agent-guards/skill_runtime_exec.py の _run_child_with_supervision()(_stage_cleanup() 等の関連関数を含む)を修正しました。commit a171ec56、branch worktree-issue-2075-skill-runtime-exec-py-outer-timeout-clea(PR #2082 head を更新済み)。

    対応状況サマリ

    P1 Blockers(4件、すべて対応済み)

    • P1-1(leader liveness ではなく process-group liveness で SIGKILL escalation を判定する): 対応済み。_poll_group_absent_until() による killpg(pgid, 0) の group-liveness ポーリングへ変更。leader が先に終了しても SIGTERM を無視する descendant が残っていれば SIGKILL へ escalate します。
    • P1-2(proc.poll() ベースの success 判定が communicate() semantics を破壊): 対応済み。独自 reader thread + poll ループを廃し proc.communicate(timeout=timeout_seconds) 方式へ置換。pipe EOF timeout・UnicodeDecodeError 伝播を含め subprocess.run() と同等の semantics を回復しました。
    • P1-3(Popen 成功後の例外・KeyboardInterrupt 経路での process group リーク): 対応済み。try: communicate() / except TimeoutExpired: cleanup / except BaseException: cleanup; raise 構造へ変更し、全 exit path が同一の cleanup state machine を通るようにしました。
    • P1-4(execution deadline と cleanup deadline の契約の相互矛盾): 対応済み。OWNER review が勧告するモデル(execution deadline とは独立の単一 cleanup deadline)へ統一し、cleanup 内の全ステップを remaining(cleanup_deadline) で bound しました。固定 join(timeout=1) 等の積み上げは廃止しています。

    P2 所見

    • P2-1(os.getpgid() の遅延取得を廃し proc.pid を pgid とする): 対応済み。起動直後の proc.pid を pgid として直接保持し、os.getpgid() は一切呼び出しません。
    • P2-2(safety property の独立検証テスト不足): 対応済み。新規テスト 6 件を追加しました(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 自体が不要になったため該当なしです。
    • P2-3(Issue 本文の orphan doc 参照・PR 本文のテスト件数): 報告のみ。本 Issue 本文が参照する 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-issue skill 経由での 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 件)。

    検証結果

    • 既存 AC1〜AC10 の VC はすべて PASS(scripts/agent-guards/tests/test_skill_runtime_exec_process_tree_cleanup.py 15 件、うち 9 件が既存 AC1〜AC9、test_skill_runtime_preflight_bytecode_cache.py 24 件で 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 の本文も上記内容を反映して更新しました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent/implementerenhancementphase/implementationtriage-required

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions