t1392: Fix CodeRabbit sweep unconditional trigger on first run#2833
t1392: Fix CodeRabbit sweep unconditional trigger on first run#2833alex-solovyev wants to merge 1 commit intomainfrom
Conversation
…te exists (t1392) On first run (or after state file deletion), _load_sweep_state() returns prev_gate=UNKNOWN with prev_issues=0. The delta computation then treats the entire existing issue count as a 'spike' (e.g., 113 - 0 = +113), unconditionally triggering @coderabbitai review — the exact regression reported after PR #2808 merged. Fix: when prev_gate is UNKNOWN, treat the sweep as a baseline-setting run — save current metrics and post a passive monitoring line. Delta triggers only fire from the second sweep onward, when a real previous state exists to compare against. Verified: 10 functional tests pass (baseline, stable, spike, gate fail, high/critical, exact bug reproduction scenario).
WalkthroughThe change fixes a regression in the CodeRabbit sweep trigger logic by introducing baseline behavior on first run to prevent unconditional trigger posting. When no prior state exists, the script saves current metrics as baseline and skips delta-based triggers. Subsequent runs compute deltas and apply existing trigger conditions only when metrics change significantly. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Mar 4 16:27:06 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the CodeRabbit integration that caused it to incorrectly trigger an active review on its initial execution within a repository. By correctly identifying and handling the first run as a baseline establishment, the system now accurately monitors for actual quality degradation, preventing unnecessary review requests and improving the efficiency of the automated review process. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a bug causing unconditional CodeRabbit triggers on the first sweep run. The fix, which involves detecting the first run and setting a baseline instead of computing deltas against zero, is logical and well-implemented. The code is clearer and more robust as a result. I have one minor suggestion to improve maintainability by refining variable scope.
| local trigger_active=false | ||
| local trigger_reasons="" | ||
|
|
||
| # Condition 1: Quality gate is failing | ||
| if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then | ||
| trigger_active=true | ||
| trigger_reasons="quality gate ${sweep_gate_status}" | ||
| fi | ||
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | ||
| # First run — no previous state to compare against. Treat as baseline: | ||
| # save current metrics and post a passive monitoring line. Without this | ||
| # guard, delta computation against zero fires false-positive triggers | ||
| # (e.g., 113 existing issues - 0 = +113 "spike"). (t1392) | ||
| coderabbit_section="### CodeRabbit | ||
|
|
||
| # Condition 2: Issue count spiked by threshold or more | ||
| if [[ "$issue_delta" -ge "$CODERABBIT_ISSUE_SPIKE" ]]; then | ||
| trigger_active=true | ||
| if [[ -n "$trigger_reasons" ]]; then | ||
| trigger_reasons="${trigger_reasons}, issue spike +${issue_delta}" | ||
| else | ||
| trigger_reasons="issue spike +${issue_delta}" | ||
| _Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._ | ||
| " | ||
| echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping triggers" >>"$LOGFILE" | ||
| else | ||
| local issue_delta=$((sweep_total_issues - prev_issues)) | ||
| local high_critical_delta=$((sweep_high_critical - prev_high_critical)) |
There was a problem hiding this comment.
To improve readability and limit variable scope, it's a good practice to declare variables as close as possible to where they are first used. The variables trigger_active and trigger_reasons are only used within the else block. Consider moving their declarations inside it.
| local trigger_active=false | |
| local trigger_reasons="" | |
| # Condition 1: Quality gate is failing | |
| if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then | |
| trigger_active=true | |
| trigger_reasons="quality gate ${sweep_gate_status}" | |
| fi | |
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | |
| # First run — no previous state to compare against. Treat as baseline: | |
| # save current metrics and post a passive monitoring line. Without this | |
| # guard, delta computation against zero fires false-positive triggers | |
| # (e.g., 113 existing issues - 0 = +113 "spike"). (t1392) | |
| coderabbit_section="### CodeRabbit | |
| # Condition 2: Issue count spiked by threshold or more | |
| if [[ "$issue_delta" -ge "$CODERABBIT_ISSUE_SPIKE" ]]; then | |
| trigger_active=true | |
| if [[ -n "$trigger_reasons" ]]; then | |
| trigger_reasons="${trigger_reasons}, issue spike +${issue_delta}" | |
| else | |
| trigger_reasons="issue spike +${issue_delta}" | |
| _Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._ | |
| " | |
| echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping triggers" >>"$LOGFILE" | |
| else | |
| local issue_delta=$((sweep_total_issues - prev_issues)) | |
| local high_critical_delta=$((sweep_high_critical - prev_high_critical)) | |
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | |
| # First run — no previous state to compare against. Treat as baseline: | |
| # save current metrics and post a passive monitoring line. Without this | |
| # guard, delta computation against zero fires false-positive triggers | |
| # (e.g., 113 existing issues - 0 = +113 "spike"). (t1392) | |
| coderabbit_section="### CodeRabbit | |
| _Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._ | |
| " | |
| echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping triggers" >>"$LOGFILE" | |
| else | |
| local issue_delta=$((sweep_total_issues - prev_issues)) | |
| local high_critical_delta=$((sweep_high_critical - prev_high_critical)) | |
| local trigger_active=false | |
| local trigger_reasons="" |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.agents/scripts/pulse-wrapper.sh:
- Around line 1916-1934: The baseline branch currently suppresses all triggers;
change it so that while prev_gate == "UNKNOWN" still records state
(coderabbit_section) and skips delta-based triggers, it must NOT suppress
immediate Quality Gate failures: detect sweep_gate_status == "ERROR" or "WARN"
inside that branch and set trigger_active=true and trigger_reasons="quality gate
${sweep_gate_status}" (and append this reason into coderabbit_section) so
CodeRabbit is mentioned for significant gate failures; keep existing baseline
logging and state-save behavior but ensure trigger_reasons/trigger_active are
populated for gate failures even on first run.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 387af45a-c916-41fb-b532-4b49f4d7d0d4
📒 Files selected for processing (1)
.agents/scripts/pulse-wrapper.sh
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | ||
| # First run — no previous state to compare against. Treat as baseline: | ||
| # save current metrics and post a passive monitoring line. Without this | ||
| # guard, delta computation against zero fires false-positive triggers | ||
| # (e.g., 113 existing issues - 0 = +113 "spike"). (t1392) | ||
| coderabbit_section="### CodeRabbit | ||
|
|
||
| # Condition 2: Issue count spiked by threshold or more | ||
| if [[ "$issue_delta" -ge "$CODERABBIT_ISSUE_SPIKE" ]]; then | ||
| trigger_active=true | ||
| if [[ -n "$trigger_reasons" ]]; then | ||
| trigger_reasons="${trigger_reasons}, issue spike +${issue_delta}" | ||
| else | ||
| trigger_reasons="issue spike +${issue_delta}" | ||
| _Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._ | ||
| " | ||
| echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping triggers" >>"$LOGFILE" | ||
| else | ||
| local issue_delta=$((sweep_total_issues - prev_issues)) | ||
| local high_critical_delta=$((sweep_high_critical - prev_high_critical)) | ||
|
|
||
| # Condition 1: Quality gate is failing | ||
| if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then | ||
| trigger_active=true | ||
| trigger_reasons="quality gate ${sweep_gate_status}" | ||
| fi |
There was a problem hiding this comment.
Baseline mode currently suppresses real Quality Gate failures.
The prev_gate == "UNKNOWN" branch skips all trigger logic, so a first-run WARN/ERROR gate won’t request CodeRabbit review. That delays actionable alerts by at least one sweep.
Suggested patch
if [[ "$prev_gate" == "UNKNOWN" ]]; then
- # First run — no previous state to compare against. Treat as baseline:
- # save current metrics and post a passive monitoring line. Without this
- # guard, delta computation against zero fires false-positive triggers
- # (e.g., 113 existing issues - 0 = +113 "spike"). (t1392)
- coderabbit_section="### CodeRabbit
+ # First run — no previous state to compare against.
+ # Skip delta-based checks, but still trigger on failing quality gate.
+ if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then
+ coderabbit_section="### CodeRabbit
+
+**Trigger**: quality gate ${sweep_gate_status} (baseline run)
+
+@coderabbitai Please run a full codebase review of this repository. Focus on:
+- Security vulnerabilities and credential exposure
+- Shell script quality (error handling, quoting, race conditions)
+- Code duplication and maintainability
+- Documentation accuracy
+"
+ echo "[pulse-wrapper] CodeRabbit: active review triggered for ${repo_slug} (baseline gate ${sweep_gate_status})" >>"$LOGFILE"
+ else
+ coderabbit_section="### CodeRabbit
_Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._
"
- echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping triggers" >>"$LOGFILE"
+ echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping delta triggers" >>"$LOGFILE"
+ fi
elseBased on learnings: the sweep should mention coderabbitai only for significant changes, including Quality Gate failure.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | |
| # First run — no previous state to compare against. Treat as baseline: | |
| # save current metrics and post a passive monitoring line. Without this | |
| # guard, delta computation against zero fires false-positive triggers | |
| # (e.g., 113 existing issues - 0 = +113 "spike"). (t1392) | |
| coderabbit_section="### CodeRabbit | |
| # Condition 2: Issue count spiked by threshold or more | |
| if [[ "$issue_delta" -ge "$CODERABBIT_ISSUE_SPIKE" ]]; then | |
| trigger_active=true | |
| if [[ -n "$trigger_reasons" ]]; then | |
| trigger_reasons="${trigger_reasons}, issue spike +${issue_delta}" | |
| else | |
| trigger_reasons="issue spike +${issue_delta}" | |
| _Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._ | |
| " | |
| echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping triggers" >>"$LOGFILE" | |
| else | |
| local issue_delta=$((sweep_total_issues - prev_issues)) | |
| local high_critical_delta=$((sweep_high_critical - prev_high_critical)) | |
| # Condition 1: Quality gate is failing | |
| if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then | |
| trigger_active=true | |
| trigger_reasons="quality gate ${sweep_gate_status}" | |
| fi | |
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | |
| # First run — no previous state to compare against. | |
| # Skip delta-based checks, but still trigger on failing quality gate. | |
| if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then | |
| coderabbit_section="### CodeRabbit | |
| **Trigger**: quality gate ${sweep_gate_status} (baseline run) | |
| `@coderabbitai` Please run a full codebase review of this repository. Focus on: | |
| - Security vulnerabilities and credential exposure | |
| - Shell script quality (error handling, quoting, race conditions) | |
| - Code duplication and maintainability | |
| - Documentation accuracy | |
| " | |
| echo "[pulse-wrapper] CodeRabbit: active review triggered for ${repo_slug} (baseline gate ${sweep_gate_status})" >>"$LOGFILE" | |
| else | |
| coderabbit_section="### CodeRabbit | |
| _Baseline run: recording ${sweep_total_issues} issues, gate ${sweep_gate_status}, ${sweep_high_critical} high/critical. Deltas will be computed from next sweep._ | |
| " | |
| echo "[pulse-wrapper] CodeRabbit: baseline run for ${repo_slug} — saving state, skipping delta triggers" >>"$LOGFILE" | |
| fi | |
| else | |
| local issue_delta=$((sweep_total_issues - prev_issues)) | |
| local high_critical_delta=$((sweep_high_critical - prev_high_critical)) | |
| # Condition 1: Quality gate is failing | |
| if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then | |
| trigger_active=true | |
| trigger_reasons="quality gate ${sweep_gate_status}" | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.agents/scripts/pulse-wrapper.sh around lines 1916 - 1934, The baseline
branch currently suppresses all triggers; change it so that while prev_gate ==
"UNKNOWN" still records state (coderabbit_section) and skips delta-based
triggers, it must NOT suppress immediate Quality Gate failures: detect
sweep_gate_status == "ERROR" or "WARN" inside that branch and set
trigger_active=true and trigger_reasons="quality gate ${sweep_gate_status}" (and
append this reason into coderabbit_section) so CodeRabbit is mentioned for
significant gate failures; keep existing baseline logging and state-save
behavior but ensure trigger_reasons/trigger_active are populated for gate
failures even on first run.
|
Closing in favour of PR #2835 (t1392: Fix CodeRabbit sweep first-run baseline detection) which takes a cleaner approach to the same underlying issue. The CodeRabbit feedback here has been incorporated into the newer PR's approach. |



Summary
@coderabbitaireview request firing unconditionally on the first sweep after PR t1390: Make CodeRabbit sweep conditional on quality gate changes #2808 merged_load_sweep_state()returnsUNKNOWN|0|0when no state file exists, causing delta computation against zero to treat the entire existing issue count (e.g., 113) as a "spike" (+113 >= threshold of 10)prev_gate == "UNKNOWN", treat the sweep as a baseline-setting run — save current metrics and skip delta triggersRoot Cause Analysis
PR #2808 (t1390) added conditional logic correctly, but missed the first-run edge case:
The same applies to
high_critical_delta: any existing high/critical issues appear as "new" on first run.Fix
Added a guard at the top of the CodeRabbit trigger section:
The
_save_sweep_state()call at the end still runs, so the next sweep has a real baseline to compare against.Verification
Closes #2832
Summary by CodeRabbit