Repository navigation
Open
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "opt-in Step 2 canary の live path が child の pipe 出力量に依存して待機不能にならない"
change_kind: code
dedupe_key: "follow-up:squne121/loop-protocol:2903-canary-pipe-wait-deadlock:v1"Parent Issue
なし(単独改善)
Parent Goal Ref
- Goal: opt-in Step 2 canary の live path が、child process の出力量によって読み手不在のまま待機し続ける形(pipe 容量 deadlock)を持たない。
- Desired Destination: N/A(単独改善。実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 の collection / skip 判定修正は本 Issue の write scope ではない)。
Current Validated Scope
.claude/skills/issue-refinement-loop/tests/test_step2_execution_surface_canary.pyの live path(producer 起動から終了待ち・出力取得まで)の pipe 待機順序と、その focused regression のみを変更する。- 現行 main(
f5a13881ae1156309d21321573e15413f6eb6dae)の同 file では、subprocess.Popen(..., stdout=subprocess.PIPE, stderr=subprocess.PIPE, ...)(232〜233 行付近)の後、先にprocess.wait(timeout=_SUBPROCESS_TIMEOUT_SECONDS)(238 行付近)を呼び、その後にprocess.communicate()(269 行付近)で出力を読む順序になっている。
Remaining Parent Gaps
なし(単独改善)。
Background
- Source: 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 (comment) の「スコープ外の注意点」(OWNER 指摘)。実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 は Out of Scope として本リスクを明示的に分離している。
- Python 公式
subprocess文書は、stdout=PIPE/stderr=PIPEを使う場合にwait()を先に呼ぶと、child が pipe 容量を超える出力をしたとき deadlock し得ることを明示し、pipe 使用時はcommunicate()を使うよう説明している。現行 canary はこの順序に該当する 潜在 deadlock class である。 - 重要: この live 経路の hang は 再現していない。本 Issue は実際の hang の報告ではなく、現行コードの順序が既知の deadlock class に該当するという静的な指摘に基づく。実際に producer が pipe 容量を超える出力をするかも未確認である。
- 方針比較: 運用で出力量を抑える案は producer 側の挙動に依存し再発防止にならない。pipe を使う限り
communicate(timeout=...)等で drain しながら待つのが API 上の標準解であり、test-local の小変更で済む。timeout 時は child が kill されない点(公式文書)を踏まえ、既存の process group cleanup(SIGTERM → bounded grace → SIGKILL → reap)の後に残出力を読む。 - Dedupe: OPEN / CLOSED の Issue・PR を
PIPE/wait/communicate/deadlock/ canary 等で検索し、同一 Outcome の owner は見つからなかった(実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 は言及のみ、実装: root review outer timeout と invocation-local budget の parity を固定する #2610 は canary 導入、実装: Auto mode の固定 /tmp scratch 上書き false-deny を run-scoped temporary workspace で解消する #2860 は別 failure class)。
Outcome
test_step2_execution_surface_canary.py の live path が pipe を drain しながら child の終了を待つ構造になり、child が pipe 容量を超える出力をしても待機が進み、timeout 時の fail-closed 契約(process group cleanup・evidence log・FAIL)が維持されることを、実 producer・実 network を使わない focused regression で確認できる状態にする。
Runtime Verification Applicability
- decision: not_applicable
- reason: 完了は test-double の child process を用いた hermetic regression で確認する。実 live producer smoke の実行は 実装: root review outer timeout と invocation-local budget の parity を固定する #2610 の opt-in 境界のままで、本 Issue の AC として要求・代替しない。
In Scope
- live path の終了待ちを、pipe を drain する
communicate(timeout=...)(または同等に pipe を読み続ける方式)へ変更する。process.wait()を pipe 未読のまま先に呼ぶ順序を残さない。 - timeout 時は既存の
_terminate_process_group_and_reap()による process group cleanup を維持し、その後に残出力を読む。evidence log(FAIL)とpytest.failの既存契約を保つ。 - focused regression(新規 test file)で、実 producer の代わりの test-double child(pipe 容量を超える stdout / stderr を出力して終了する process、および終了しない process)を用い、上記を観測する。
Out of Scope
- 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 の collection / skip / exit 77 判定、stdout
SKIP:契約、xdist 検証(実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 が owner) - live producer(
run_root_review_pipeline.py produce)自体の振る舞い・出力量の変更 - 他 file の subprocess 待機パターンの調査・修正、汎用 subprocess helper / runner の新設
- 実 GitHub Issue/PR mutation、runtime policy の緩和、実 network を使う検証
Acceptance Criteria
- AC1: live path が pipe を drain しながら終了を待ち、child が pipe 容量を超える stdout / stderr(各 1 MiB 以上)を出力して正常終了しても、bounded な時間内に終了し、returncode と出力の末尾が取得される(
process.wait()を pipe 未読のまま先に呼ぶ順序が残らない)。 - AC2: child が終了しない場合、注入した小さな timeout で process group が SIGTERM(必要なら SIGKILL)で cleanup され reap されること、evidence log が
FAILで書かれること、pytest.failで失敗することが維持される。 - AC3: regression は実 producer・実 network・実 GitHub を使わず test-double のみで動作し、opt-in(
LOOP_CANARY_STEP2_LIVE_ENABLE=1)以外で live path に進まない既存挙動を変更しない。
Verification Commands
# AC1
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_step2_canary_live_pipe_drain.py -q
# AC2
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_step2_canary_live_pipe_drain.py -q
# AC3
# baseline-expect: fail
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_step2_canary_live_pipe_drain.py -q実装前は対象 test file が未作成のため exit 4 で fail する(baseline-expect: fail)。test-double の child は pytest の一時ディレクトリ内に作り、全体を bounded timeout で囲って、回帰時に test 自体が無期限に待たないようにする。
Allowed Paths
.claude/skills/issue-refinement-loop/tests/test_step2_execution_surface_canary.py.claude/skills/issue-refinement-loop/tests/test_step2_canary_live_pipe_drain.py(新規)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 が未マージの状態で同 file を並行編集する必要が生じた場合(実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 のマージ後に着手する)
Required Skills
- なし
Required Design References
docs/dev/runtime-verification-policy.md
Delivery Rule
- 1 Issue = 1 PR。linked worktree で実装し、Draft PR を既定とする。同じ test file を編集する 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 のマージ後に着手する(GitHub native dependency: 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 に blocked)。
Notes for Reviewer
- 本 Issue は 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 の refinement 完了後に、OWNER 指示の別 action として起票した follow-up である。hang の再現証拠はなく、「潜在 deadlock class」として扱う。
- Scope Collision (C1) advisory: 実装: opt-in Step 2 canary が通常 pytest 収集全体を exit 77 で中断しないようにする #2903 が同じ canary test file を Allowed Paths に持つ。直列化は blocked-by で表現する。実装: Auto mode の固定 /tmp scratch 上書き false-deny を run-scoped temporary workspace で解消する #2860 は
.claude/skills/issue-refinement-loop/testsを directory 単位で Allowed Paths に持つが、対象 file は異なる独立した目的であり、重複成果とは解釈しない(overlap preflight はoverlap_requires_comment/allowed_paths_overlapの advisory)。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity