fix(cli-pr-monitor): 並列テスト flaky を tempfile 一意化と state path DI で構造的に解消 - #227
Merged
Conversation
…pfile + dir injection 順位 230。convert_body_to_file は temp file 名を PID+ミリ秒で生成しており、並列 cargo test で body_with_literal_newline_converted 等が稀に衝突して fail していた。tempfile::Builder::tempfile_in による O_EXCL+乱数の一意名生成へ移行し、生成先 dir を注入可能化。テストは各自 tempfile::tempdir() を渡して本番 namespace から分離。tempfile を dev-dependency から通常依存へ昇格し、自前 TempFile struct を TempPath に置換。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…obal (fixes parallel-test flaky) 順位 229。PR_MONITOR_STATE_FILE_OVERRIDE (process-global env var) を複数 test module の独立 static LOCK が奪い合い、finalize_park_siblings_have_symmetric_write_state_handling が並列実行で約 50% fail してゲートを高確率で落としていた。env var seam と state_file_path の env 分岐、write_state/read_state ラッパ、4 つの env_override_lock を全廃。state path を PollContext + 関数引数で全面注入し、各テストは自前 path を渡す。共有グローバル可変状態を根絶し並列競合を構造的に解消。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
順位 229 (env_override_lock / state path DI) と順位 230 (create_pr tempfile) を解決済みのため、todo13.md の詳細エントリと todo-summary.md の該当行を削除。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
Changes明示的な state_path 注入リファクタリング
推定コードレビュー工数🎯 3 (Moderate) | ⏱️ ~25 minutes 関連する可能性のある PR
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/cli-pr-monitor/src/stages/create_pr.rs`:
- Around line 207-208: `write_early_reset_state()` is still resolving
`state_file_path()` internally, so it can’t be isolated from the other state
operations in `run_create_pr`. Update `run_create_pr` to accept and pass a
`state_path: &Path` into `write_early_reset_state()`, and change that helper to
use the provided path when calling `write_state_to()`. This will let tests
inject a tempdir-backed state file and avoid sharing state across parallel or
repeated runs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7e1a4830-62bf-4b65-a0b1-f1222f228f38
📒 Files selected for processing (11)
docs/todo-summary.mddocs/todo13.mdsrc/cli-pr-monitor/Cargo.tomlsrc/cli-pr-monitor/src/stages/create_pr.rssrc/cli-pr-monitor/src/stages/monitor.rssrc/cli-pr-monitor/src/stages/poll/iteration.rssrc/cli-pr-monitor/src/stages/poll/mod.rssrc/cli-pr-monitor/src/stages/poll/rate_limit.rssrc/cli-pr-monitor/src/stages/poll/review_recheck.rssrc/cli-pr-monitor/src/stages/poll/review_recheck_signal.rssrc/cli-pr-monitor/src/state.rs
💤 Files with no reviewable changes (2)
- docs/todo13.md
- docs/todo-summary.md
aloekun
added a commit
that referenced
this pull request
Aug 21, 2026
着手前に台帳と実装を突き合わせた。台帳が推定していた根因「pre-push の [diff] stage が jj diff -r @ を使う」は PR #311 で解消済みで、実在する根因は 別の 2 箇所だった。 台帳と実態のずれ: - [diff] stage は PR #311 で {{PR_RANGE}} プレースホルダ必須化 + 範囲カバレッジ 検査済み。config load 時に revset 直書きを reject するため、この経路は閉じている 実在した根因 2 件: - (i) .takt/facets/instructions/fix.md の refresh が `jj diff -r @` (tip 限定、 かつ --git なし) で review-diff.txt を上書きしていた。fix を挟んだ iteration は 祖先コミットが見えない diff を読む。pre-push / post-pr の両経路に影響し、 .claude/feedback-reports/348.md で実バグとして指摘されたが台帳未起票だった - (ii) post-pr-review の analyze は push の後に走るため、pre-push run が diff を 書かなかった場合 (DiffResult::Empty で takt skip 等) review-diff.txt に別 PR の 残骸が残る。実測: PR #434 マージ後も同ファイルに #434 の diff (5 ファイル) が 残存していた どちらも「code を含む PR」を docs-only と誤判定させ、CodeRabbit が PR 全体を見て 出した finding を ADR-035 filter で握り潰す (PR #227 実観測)。 対処 (ユーザー判断: 決定論化): - cli-pr-monitor が GitHub の PR 全体ファイル一覧 (gh pr view --json files) を lib_docs_policy で分類し、.takt/review-comments.json に docs_only として書く。 ローカル working copy 状態に一切依存しないため (i)(ii) が構造的に消える - lib-docs-policy に paths 版 API (is_docs_only_paths) を追加。status を持たない source からの入口で、判定規則は is_docs_only_path の単一実装に集約したまま (ADR-035 が防ごうとした drift の再生産を避ける) - fail-closed (ADR-043): 一覧を取得できなければ docs_only=false。docs-only 扱いは filter を緩める方向なので、取得失敗を true に倒すと finding を握り潰す - analyze-coderabbit.md は docs_only を読むだけにし、review-diff.txt を見ない。 フィールド不在時は false 扱い (exe 更新前の JSON に対する後方互換、ADR-051) fix.md の refresh も同時に修正 (ユーザー判断): - `jj diff --git -r 'trunk()..@'` に変更。trunk() は jj builtin でリモート trunk を 解決するため、default branch が main の派生プロジェクトでもそのまま動く - 実測 (read-only): 2 コミット範囲で tip-only 5 ファイル vs 範囲 9 ファイル。 code ファイル src/cli-docs-lint/src/preamble.rs を含む 4 件が tip-only から 見えないことを確認した 回帰テスト: - lib-docs-policy rank233_paths_entry_point 5 件 (docs のみ / 混在 / 除外パス / 空入力の fail-closed / summary 版との規則一致) - cli-pr-monitor rank233_docs_only_verdict 4 件 (incident 再現の混在ケース / docs のみの対照 / 取得失敗の fail-closed / 除外パスの委譲確認) 後始末: todo13.md 233 節 + todo-summary2.md 233 行を削除 検証: cargo test --workspace green / cargo clippy --workspace --all-targets green / pnpm lint:docs green / pnpm lint:md green
aloekun
added a commit
that referenced
this pull request
Aug 21, 2026
着手前に台帳と実装を突き合わせた。台帳が推定していた根因「pre-push の [diff] stage が jj diff -r @ を使う」は PR #311 で解消済みで、実在する根因は 別の 2 箇所だった。 台帳と実態のずれ: - [diff] stage は PR #311 で {{PR_RANGE}} プレースホルダ必須化 + 範囲カバレッジ 検査済み。config load 時に revset 直書きを reject するため、この経路は閉じている 実在した根因 2 件: - (i) .takt/facets/instructions/fix.md の refresh が `jj diff -r @` (tip 限定、 かつ --git なし) で review-diff.txt を上書きしていた。fix を挟んだ iteration は 祖先コミットが見えない diff を読む。pre-push / post-pr の両経路に影響し、 .claude/feedback-reports/348.md で実バグとして指摘されたが台帳未起票だった - (ii) post-pr-review の analyze は push の後に走るため、pre-push run が diff を 書かなかった場合 (DiffResult::Empty で takt skip 等) review-diff.txt に別 PR の 残骸が残る。実測: PR #434 マージ後も同ファイルに #434 の diff (5 ファイル) が 残存していた どちらも「code を含む PR」を docs-only と誤判定させ、CodeRabbit が PR 全体を見て 出した finding を ADR-035 filter で握り潰す (PR #227 実観測)。 対処 (ユーザー判断: 決定論化): - cli-pr-monitor が GitHub の PR 全体ファイル一覧を lib_docs_policy で分類し、 .takt/review-comments.json に docs_only として書く。ローカル working copy 状態に 一切依存しないため (i)(ii) が構造的に消える - lib-docs-policy に paths 版 API (is_docs_only_paths) を追加。status を持たない source からの入口で、判定規則は is_docs_only_path の単一実装に集約したまま (ADR-035 が防ごうとした drift の再生産を避ける) - fail-closed (ADR-043): 一覧を取得できなければ docs_only=false。docs-only 扱いは filter を緩める方向なので、取得失敗を true に倒すと finding を握り潰す - analyze-coderabbit.md は docs_only を読むだけにし、review-diff.txt を見ない。 フィールド不在時は false 扱い (exe 更新前の JSON に対する後方互換、ADR-051) fix.md の refresh も同時に修正 (ユーザー判断): - `jj diff --git -r 'trunk()..@'` に変更。trunk() は jj builtin でリモート trunk を 解決するため、default branch が main の派生プロジェクトでもそのまま動く - 実測 (read-only): 2 コミット範囲で tip-only 5 ファイル vs 範囲 9 ファイル。 code ファイル src/cli-docs-lint/src/preamble.rs を含む 4 件が tip-only から 見えないことを確認した CodeRabbit Major 対応 (自分が作った gate 自身の fail-open): - 初版は `gh pr view --json files` で一覧を取っていたが、これは 100 件で無言に 切り捨てる (cli/cli#13338)。先頭 100 件が docs、101 件目が source の PR で docs_only=true に倒れ、本 PR が塞ごうとしている誤フィルタを再生産していた - 実測 (rust-lang/rust#161453、185 ファイル): changedFiles=185 に対し `gh pr view --json files` は 100 件、`gh api --paginate .../files` は 185 件 - REST files endpoint を --paginate で辿る方式に変更し、加えて取得件数と PR 申告の changedFiles の一致を要求する。上限値 (100 / REST の 3,000) を定数に持たないのは、 上限が変わっても件数一致検査が成立し続けるようにするため - 変異テストで確認: 件数一致 guard を外すと該当テストが FAILED になる 回帰テスト: - lib-docs-policy rank233_paths_entry_point 6 件 (docs のみ / 混在 / 除外パス / 空入力の fail-closed / summary 版を委譲させない理由の seal / 規則一致) - cli-pr-monitor rank233_docs_only_verdict 6 件 (incident 再現の混在ケース / docs のみの対照 / 取得失敗の fail-closed / 除外パスの委譲確認 / 切り捨て一覧の検出 / 件数一致時は従来どおり判定する対照) 後始末: todo13.md 233 節 + todo-summary2.md 233 行を削除 検証: cargo test --workspace green / cargo clippy --workspace --all-targets green / pnpm lint:docs green / pnpm lint:md green
aloekun
added a commit
that referenced
this pull request
Aug 21, 2026
) 着手前に台帳と実装を突き合わせた。台帳が推定していた根因「pre-push の [diff] stage が jj diff -r @ を使う」は PR #311 で解消済みで、実在する根因は 別の 2 箇所だった。 台帳と実態のずれ: - [diff] stage は PR #311 で {{PR_RANGE}} プレースホルダ必須化 + 範囲カバレッジ 検査済み。config load 時に revset 直書きを reject するため、この経路は閉じている 実在した根因 2 件: - (i) .takt/facets/instructions/fix.md の refresh が `jj diff -r @` (tip 限定、 かつ --git なし) で review-diff.txt を上書きしていた。fix を挟んだ iteration は 祖先コミットが見えない diff を読む。pre-push / post-pr の両経路に影響し、 .claude/feedback-reports/348.md で実バグとして指摘されたが台帳未起票だった - (ii) post-pr-review の analyze は push の後に走るため、pre-push run が diff を 書かなかった場合 (DiffResult::Empty で takt skip 等) review-diff.txt に別 PR の 残骸が残る。実測: PR #434 マージ後も同ファイルに #434 の diff (5 ファイル) が 残存していた どちらも「code を含む PR」を docs-only と誤判定させ、CodeRabbit が PR 全体を見て 出した finding を ADR-035 filter で握り潰す (PR #227 実観測)。 対処 (ユーザー判断: 決定論化): - cli-pr-monitor が GitHub の PR 全体ファイル一覧を lib_docs_policy で分類し、 .takt/review-comments.json に docs_only として書く。ローカル working copy 状態に 一切依存しないため (i)(ii) が構造的に消える - lib-docs-policy に paths 版 API (is_docs_only_paths) を追加。status を持たない source からの入口で、判定規則は is_docs_only_path の単一実装に集約したまま (ADR-035 が防ごうとした drift の再生産を避ける) - fail-closed (ADR-043): 一覧を取得できなければ docs_only=false。docs-only 扱いは filter を緩める方向なので、取得失敗を true に倒すと finding を握り潰す - analyze-coderabbit.md は docs_only を読むだけにし、review-diff.txt を見ない。 フィールド不在時は false 扱い (exe 更新前の JSON に対する後方互換、ADR-051) fix.md の refresh も同時に修正 (ユーザー判断): - `jj diff --git -r 'trunk()..@'` に変更。trunk() は jj builtin でリモート trunk を 解決するため、default branch が main の派生プロジェクトでもそのまま動く - 実測 (read-only): 2 コミット範囲で tip-only 5 ファイル vs 範囲 9 ファイル。 code ファイル src/cli-docs-lint/src/preamble.rs を含む 4 件が tip-only から 見えないことを確認した CodeRabbit Major 対応 (自分が作った gate 自身の fail-open): - 初版は `gh pr view --json files` で一覧を取っていたが、これは 100 件で無言に 切り捨てる (cli/cli#13338)。先頭 100 件が docs、101 件目が source の PR で docs_only=true に倒れ、本 PR が塞ごうとしている誤フィルタを再生産していた - 実測 (rust-lang/rust#161453、185 ファイル): changedFiles=185 に対し `gh pr view --json files` は 100 件、`gh api --paginate .../files` は 185 件 - REST files endpoint を --paginate で辿る方式に変更し、加えて取得件数と PR 申告の changedFiles の一致を要求する。上限値 (100 / REST の 3,000) を定数に持たないのは、 上限が変わっても件数一致検査が成立し続けるようにするため - 変異テストで確認: 件数一致 guard を外すと該当テストが FAILED になる 回帰テスト: - lib-docs-policy rank233_paths_entry_point 6 件 (docs のみ / 混在 / 除外パス / 空入力の fail-closed / summary 版を委譲させない理由の seal / 規則一致) - cli-pr-monitor rank233_docs_only_verdict 6 件 (incident 再現の混在ケース / docs のみの対照 / 取得失敗の fail-closed / 除外パスの委譲確認 / 切り捨て一覧の検出 / 件数一致時は従来どおり判定する対照) 後始末: todo13.md 233 節 + todo-summary2.md 233 行を削除 検証: cargo test --workspace green / cargo clippy --workspace --all-targets green / pnpm lint:docs green / pnpm lint:md green
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
cli-pr-monitorの並列テストで断続的に発生していた flaky test を構造的に解消する。原因は独立した 2 系統あり、それぞれ別コミットで修正した。加えて完了済みの todo エントリを整理する。変更内容
1. create_pr temp-file flaky の解消 (tempfile crate + dir injection)
convert_body_to_fileが--body-file用一時ファイルをpid + ms命名で生成していたため、並列cargo test(同一プロセス・同一 ms)で名前が衝突し flaky 化していた。tempfilecrate を導入しO_EXCL+ ランダム名 + 衝突時リトライで一意名を生成std::env::temp_dir()、テストは専用tempdir()を注入して本番 namespace から分離)TempFilestruct からtempfile::TempPathに置換2. parallel-test flaky の解消 (state path DI + env-var global 除去)
state ファイルパスを env-var 経由の ambient global で解決していたため、並列テスト間で競合していた。共有グローバルやロックではなく依存注入で根本解決する方針に沿う。
3. docs(todo) の整理
完了済みエントリ(順位 229・230)を
todo-summary.md/todo13.mdから削除。テスト
push pipeline の品質ゲート(clippy / cargo test / cargo test --ignored)で検証済み。
Summary by CodeRabbit
Bug Fixes
Chores