Skip to content

実装: opt-in Step 2 canary live path の pipe 待機順序による潜在 deadlock を解消する #2907

Open

Description

@squne121

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

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

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

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

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

Required Skills

  • なし

Required Design References

  • docs/dev/runtime-verification-policy.md

Delivery Rule

Notes for Reviewer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions