Skip to content

fix(cli-pr-monitor): 既レビュー済み HEAD への Add head review deduplication for Prevent duplicate @coderabbitai review posts for same HEAD review review 再トリガーを抑止 (WP-05 follow-up) - #247

Merged
aloekun merged 1 commit into
masterfrom
fix-review-retrigger-guard
Jul 5, 2026
Merged

Conversation

@aloekun

@aloekun aloekun commented Jul 5, 2026

Copy link
Copy Markdown
Owner

概要

WP-05 の follow-up。CodeRabbit の既レビュー済み HEAD への @coderabbitai review 再トリガーを抑止し、無駄なレート枠消費を防ぐ。ADR-019 amendment。

背景

CodeRabbit は「既にレビュー済みのコミットは再レビューしない」incremental 仕様のため、同一 HEAD への @coderabbitai review 再投稿は「already reviewed, nothing to do」を返すだけでレート枠を消費する無駄になる(2026-07-05 セッションで、手動 fix push 後に同一 HEAD へ複数回投稿しレート枠を無駄消費した実例)。OSS/public リポのレビュー枠は有償 Pro(5 レビュー/時)より低くプロジェクト人気度依存のため、構造的に避ける。

変更内容

  • 決定論層(機構): review_trigger.rstrigger_coderabbit_review に、投稿前ガードを追加。head_already_reviewed(pr, repo) で「現 HEAD がいずれかの CodeRabbit review の commit_id と一致するか」を gh 照会し、一致(レビュー済み)なら @coderabbitai review を skip。判定不能(gh 照会失敗 / repo 未確定)は fail-open(投稿)で再レビュー欠落を防ぐ。
  • is_head_in_reviewed 純粋判定 + 単体テスト追加。
  • ADR-019 amendment に「決定論層(ガード)+運用層(手動でも同一 HEAD に再投稿しない規律)」を追記。

新規コミット(別 SHA)への 1 回の明示トリガーは意図した消費であり抑止対象外(新しい修正はレビューされるべき)。ガードは「同一 HEAD への再トリガー」のみ抑止する。

テスト

  • cargo test -p cli-pr-monitor: 233 passed + --ignored 統合 13 passed / clippy clean

参照

  • ADR-019 amendment(再トリガー抑止ガード + 手動トリガー規律)
  • WP-03(.coderabbit.yaml auto_incremental_review:false + 明示トリガー)の consumption 削減を補完

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • 同一 PR・同一 HEAD への CodeRabbit レビュー依頼の重複送信を抑止するガードを追加(手動トリガー含む)。
  • Bug Fixes
    • 既にレビュー済みのコミットには再依頼せず、無駄なレート消費を削減。
    • 照会できない場合は投稿を止めず、レビュー機会の取りこぼしを回避。
  • Documentation
    • 「既知の制約」への追記で抑止方針を明確化。

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b0147dd2-9678-425d-a518-46fe81898574

📥 Commits

Reviewing files that changed from the base of the PR and between be34097 and fa5010c.

📒 Files selected for processing (2)
  • docs/adr/adr-019-coderabbit-review-hybrid-policy.md
  • src/cli-pr-monitor/src/stages/review_trigger.rs
✅ Files skipped from review due to trivial changes (1)
  • docs/adr/adr-019-coderabbit-review-hybrid-policy.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli-pr-monitor/src/stages/review_trigger.rs

📝 Walkthrough

Walkthrough

同一 HEAD への @coderabbitai review 再投稿を抑止するため、review_trigger.rs に判定処理を追加し、ADR-019 に運用方針を追記しています。gh 照会で現 HEAD と既存レビューの commit_id を照合し、一致時のみ投稿をスキップします。

Changes

再トリガー抑止ガード

Layer / File(s) Summary
head_already_reviewed 判定ロジックと呼び出し側統合
src/cli-pr-monitor/src/stages/review_trigger.rs
trigger_coderabbit_review の早期 return を整理し、head_already_reviewed(pr, repo)Some(true) の場合のみ投稿を skip し、照会不能時は fail-open で投稿を継続するようにしています。gh pr viewgh api で headRefOid と reviewer の commit_id を取得して比較します。
判定ロジックのユニットテストとADR方針追記
src/cli-pr-monitor/src/stages/review_trigger.rs, docs/adr/adr-019-coderabbit-review-hybrid-policy.md
is_head_in_reviewed の一致・trim・空集合ケースをテストし、ADR-019 に同一 HEAD への再投稿抑止と手動運用の規律を追記しています。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Trigger as trigger_coderabbit_review
  participant GhCli as gh CLI
  participant GhApi as gh api

  Trigger->>GhCli: gh pr view (headRefOid取得)
  GhCli-->>Trigger: headRefOid
  Trigger->>GhApi: gh api (coderabbitai[bot]のcommit_id一覧取得)
  GhApi-->>Trigger: commit_id集合
  Trigger->>Trigger: is_head_in_reviewed(headRefOid, commit_id集合)
  alt 既にレビュー済み
    Trigger->>Trigger: 投稿をskip
  else 未レビューまたは照会失敗
    Trigger->>GhCli: `@coderabbitai` review を投稿
  end
Loading

Possibly related PRs

  • aloekun/claude-code-hook-test#243: 同じ review_trigger.rs@coderabbitai review 投稿トリガー機構を扱っており、今回の再投稿抑止と同一経路に関係します。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-review-retrigger-guard

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot changed the title fix(cli-pr-monitor): 既レビュー済み HEAD への @coderabbitai review 再トリガーを抑止 (WP-05 follow-up) fix(cli-pr-monitor): 既レビュー済み HEAD への Add head review deduplication for @coderabbitai review review 再トリガーを抑止 (WP-05 follow-up) Jul 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/review_trigger.rs`:
- Around line 83-89: The review lookup in review_trigger.rs only queries the
first page of the GitHub reviews API, so it can miss older CodeRabbit reviews on
busy PRs. Update the gh api call in the logic that builds reviewed commit IDs to
include --paginate, keeping the existing jq filter and is_head_in_reviewed check
so all review pages are scanned.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 014b3b86-f3e2-439b-9db3-83459f95228d

📥 Commits

Reviewing files that changed from the base of the PR and between 7353dc6 and be34097.

📒 Files selected for processing (2)
  • docs/adr/adr-019-coderabbit-review-hybrid-policy.md
  • src/cli-pr-monitor/src/stages/review_trigger.rs

Comment thread src/cli-pr-monitor/src/stages/review_trigger.rs
@aloekun
aloekun force-pushed the fix-review-retrigger-guard branch from be34097 to fa5010c Compare July 5, 2026 08:42
@aloekun

aloekun commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aloekun

aloekun commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot changed the title fix(cli-pr-monitor): 既レビュー済み HEAD への Add head review deduplication for @coderabbitai review review 再トリガーを抑止 (WP-05 follow-up) fix(cli-pr-monitor): 既レビュー済み HEAD への Add head review deduplication for Prevent duplicate @coderabbitai review posts for same HEAD review review 再トリガーを抑止 (WP-05 follow-up) Jul 5, 2026
@aloekun
aloekun merged commit 9260f65 into master Jul 5, 2026
1 check passed
@aloekun
aloekun deleted the fix-review-retrigger-guard branch July 5, 2026 09:31
aloekun added a commit that referenced this pull request Jul 6, 2026
…順位258) (#249)

CodeRabbit は指摘ゼロで完了した (再) レビューでは formal review object を提出せず
commit status のみで完了通知する。reviews API 単独では拾えず 2 つの gap があった:

1. 助言層 (review_trigger): head_already_reviewed が reviews API のみで判定し、
   指摘ゼロでレビュー済みの HEAD へ @coderabbitai review を再投稿しレート枠を浪費し得た。
   reviews API + commit status の 2 系統を combine_reviewed で fail-open 合成する。
   純関数 parse_commit_status_reviewed / combine_reviewed に分離し三値テスト (None→投稿の
   反転テスト含む) を追加。

2. 決定論層 (check-ci-coderabbit): 完了検知は元々 commit status を照会していたが、head SHA
   を無指定 gh pr view (cwd auto-detection) で取得しており jj workspace 等で SHA 取得に失敗
   → not_found に倒れ指摘ゼロ完了の park ループが終了しなかった (PR #247 実測)。get_head_sha
   を monitor が渡す解決済み repo/PR での repos/{repo}/pulls/{pr} 照会に変更。真因は parse で
   なく SHA 取得経路のため parse_coderabbit_status は不変、PR #247 実測 status を回帰テスト化。

ADR-019 § 再トリガー抑止ガードを amendment。todo 順位258 を消化。
aloekun added a commit that referenced this pull request Jul 6, 2026
…s 化 (順位259) (#251)

現行 `cargo clippy --workspace -- -D warnings` は lib/bin ターゲットのみを検査し、
#[cfg(test)] ユニットテスト・integration test のコードが lint されない gap があった。
PR #247 で useless_format が cargo test 段階まで顕在化して手戻りが発生したことを受け、
rust-lint-test group の clippy を --all-targets --all-features 化する。

- push-runner-config.toml + templates/push-runner-config.toml を同スコープに更新
- 既存違反 1 件 (cli-merge-pipeline takt.rs の ORPHAN_THRESHOLD_SECS 不変条件 runtime
  test の clippy::assertions_on_constants) を const _: () = assert!(...) のコンパイル時
  検証へ移行 (定数条件は test 実行時 assert より compile-time assert の方が強い保証)
- cargo clippy --workspace --all-targets --all-features -- -D warnings が workspace 全体 PASS
- ADR-015 § clippy の lint スコープ を amendment。todo 順位259 を消化。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant