refactor(lib): wait_with_timeout を 2 variant で lib-subprocess に extract (順位 173b) - #206
Conversation
📝 WalkthroughWalkthroughlib-subprocess へプロセス待機ユーティリティ関数を 2 つ追加し、cli-pr-monitor と cli-push-runner で分散していたローカル wait_with_timeout 実装を削除・置換。エラーパス処理が異なる 2 variant を導入し、ワークスペース全体で重複排除を実現。タスク記録を実装完了状況で詳細化。 Changeslib-subprocess 実装と既存 crate の統合
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/cli-push-runner/src/stages/bookmark_check.rs (1)
88-90: ⚡ Quick win共通根因:
_basicvariant の Err 契約に対して呼び出し側 cleanup が未実装です。
wait_with_timeout_basicはtry_waitエラー時に child を回収しない設計ですが、3箇所とも?で即 return しており、Err 経路の後始末が漏れます。
src/cli-push-runner/src/stages/bookmark_check.rs#L88-L90:_safeへ切替えるか、Err 分岐でkill + wait(必要に応じて reader 回収)を追加してください。src/cli-push-runner/src/stages/pr_size_check.rs#L160-L162: 同様に Err 分岐 cleanup を明示するか_safeを使用してください。src/cli-push-runner/src/stages/scratch_file_warning.rs#L234-L236: 同様に Err 分岐 cleanup を明示するか_safeを使用してください。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/cli-push-runner/src/stages/bookmark_check.rs` around lines 88 - 90, The three call sites use lib_subprocess::wait_with_timeout_basic which does not clean up the child on Err; for each site either switch to the safe variant (e.g. wait_with_timeout_safe) or explicitly perform the error-path cleanup by killing the child, waiting for it, and dropping/closing any associated reader handles: for src/cli-push-runner/src/stages/bookmark_check.rs (lines 88-90) replace the wait_with_timeout_basic call with the _safe variant or add an Err branch that calls child.kill()/child.wait() and closes the reader before returning the Err; for src/cli-push-runner/src/stages/pr_size_check.rs (lines 160-162) do the same (use _safe or add explicit kill+wait and reader reclamation on Err); and for src/cli-push-runner/src/stages/scratch_file_warning.rs (lines 234-236) apply the same fix (either swap to the _safe API or implement kill+wait and reader cleanup in the Err path) so no child or reader is leaked on failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/cli-push-runner/src/stages/bookmark_check.rs`:
- Around line 88-90: The three call sites use
lib_subprocess::wait_with_timeout_basic which does not clean up the child on
Err; for each site either switch to the safe variant (e.g.
wait_with_timeout_safe) or explicitly perform the error-path cleanup by killing
the child, waiting for it, and dropping/closing any associated reader handles:
for src/cli-push-runner/src/stages/bookmark_check.rs (lines 88-90) replace the
wait_with_timeout_basic call with the _safe variant or add an Err branch that
calls child.kill()/child.wait() and closes the reader before returning the Err;
for src/cli-push-runner/src/stages/pr_size_check.rs (lines 160-162) do the same
(use _safe or add explicit kill+wait and reader reclamation on Err); and for
src/cli-push-runner/src/stages/scratch_file_warning.rs (lines 234-236) apply the
same fix (either swap to the _safe API or implement kill+wait and reader cleanup
in the Err path) so no child or reader is leaked on failure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f3cec832-6a70-4afa-9fc3-6b4d928e7795
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (11)
docs/todo11.mdsrc/cli-pr-monitor/Cargo.tomlsrc/cli-pr-monitor/src/runner.rssrc/cli-pr-monitor/src/stages/push_jj_bookmark.rssrc/cli-push-runner/src/runner.rssrc/cli-push-runner/src/stages/bookmark_check.rssrc/cli-push-runner/src/stages/lint_screen.rssrc/cli-push-runner/src/stages/pr_size_check.rssrc/cli-push-runner/src/stages/push_jj_bookmark.rssrc/cli-push-runner/src/stages/scratch_file_warning.rssrc/lib-subprocess/src/lib.rs
Summary
wait_with_timeoutを polling 系 2 variant (_safe/_basic) としてlib-subprocessに extract2 variant の意味
wait_with_timeout_safechild.kill()+child.wait()後に Err 返却stages/push_jj_bookmark.rs(1 件)wait_with_timeout_basicrunner.rs内 1 件 +stages/{scratch_file_warning, push_jj_bookmark, pr_size_check, lint_screen, bookmark_check}.rs計 6 件timeout 経路の挙動は両 variant 同じ (kill+wait 実施)。
scope 調整 (実装時に判明)
当初計画では「cli-pr-monitor
classifier_runner.rs(2 callsites)」も_basicを共用する想定だったが、実コード確認の結果、classifier_runner.rsのwait_with_timeoutは:fn(Child, Duration) -> Option<Output>(polling 系のfn(&str, &mut Child, u64) -> Result<Option<ExitStatus>, String>と非互換)wait_with_output()を spawn thread 内で呼びmpsc::channelで結果を受ける channel-based。Child を thread に move するため kill 不可…と 完全に別系統の設計 であることが判明。本 sub では touch せず、
docs/todo11.md順位 173b section とlib-subprocess/src/lib.rsmodule doc に scope outside の明示を追記。必要なら 173e で channel-based variant の評価を行う。内訳 (12 files changed, +175 / -93)
lib-subprocess/src/lib.rscli-pr-monitor/Cargo.tomllib-subprocessdep 復活 (173a でcombine_output不使用のため remove していた)cli-pr-monitor/src/runner.rswait_with_timeoutimpl +use ExitStatus削除cli-pr-monitor/src/stages/push_jj_bookmark.rslib_subprocess::wait_with_timeout_safeにcli-push-runner/src/runner.rswait_with_timeoutimpl + 1 test +use ExitStatus/Instant削除、内部 callsite 1 件を_basicにcli-push-runner/src/stages/*.rs5 ファイルlib_subprocess::wait_with_timeout_basicに (lint_screen.rsは use import 経由、他 4 は直接修飾)docs/todo11.mdTest plan
cargo build --workspacepasscargo test --workspacepass (lib-subprocess 9 test 含む workspace 全体 pass)cargo clippy --workspace -- -D warningsclean (push-runner-config.toml の gate と同等)pre-push reviewer 所見への対応
F-1 (non-blocking):
_basicの doc コメントで「try_wait失敗時の child cleanup は呼び出し側が制御する設計」と記載したが、6 callsite いずれも明示的な cleanup を行っていない。try_wait()のErr経路は子プロセス spawn 成功後には実質 unreachable な path)、173e で variant merge 判断時に doc を実態ベース ("try_wait失敗は spawn 成功後には unreachable のため child を release せず Err を返す") に書き直す予定関連
combine_outputextract)docs/todo11.md順位 173 entry — 173c (drain_pipe) / 173d (run_cmd) / 173e (variant merge 判断) の計画lib-jj-helpers) — 異なる semantics を別 helper として export する先例Summary by CodeRabbit
リファクタリング
テスト