t1392: Fix CodeRabbit sweep first-run delta inflation#2834
t1392: Fix CodeRabbit sweep first-run delta inflation#2834alex-solovyev wants to merge 1 commit intomainfrom
Conversation
On first run (no state file), _load_sweep_state returns prev_issues=0. The delta calculation (e.g., 113 - 0 = 113) exceeds the spike threshold, causing an unconditional @coderabbitai trigger even when metrics are stable. Fix: detect first run via prev_gate==UNKNOWN and skip conditions 2 (issue spike) and 3 (high/critical increase). Condition 1 (gate status) remains active on first run since it doesn't depend on deltas. The first run now seeds the baseline; deltas are computed from the second sweep onward. Closes #2832
WalkthroughAdds first-run detection logic to the quality-sweep decision process, skipping delta-based triggers when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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:31:10 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 resolves an issue where the CodeRabbit review system would incorrectly trigger an active review on its initial run for a new pull request. The fix ensures that delta-based conditions (issue spikes, high/critical increases) are skipped during the first sweep, as there's no prior state to compare against, preventing misleading "spikes" and unnecessary review requests. Only the quality gate status is evaluated on the first run. 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.
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 1911-1919: The current first-run sentinel uses prev_gate ==
"UNKNOWN", which is ambiguous; instead detect first run by checking for the
presence of the persisted state file (or a persisted baseline_initialized flag)
and set is_first_run based on that. Update the is_first_run assignment to test
for state-file existence (e.g. [[ ! -f "$STATE_FILE" ]] ) or read a persisted
baseline_initialized boolean, and replace any other occurrences that rely on
prev_gate (including the analogous block around the later duplicate at lines
~1929-1940) so Conditions 2/3 are only suppressed when no prior baseline
actually exists.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d6576835-3c94-4c03-a2d7-fd2d56fea3dd
📒 Files selected for processing (1)
.agents/scripts/pulse-wrapper.sh
| local is_first_run=false | ||
|
|
||
| # Condition 1: Quality gate is failing | ||
| # Detect first run: prev_gate is UNKNOWN when no state file exists. | ||
| # On first run, delta comparisons are meaningless (comparing against 0 | ||
| # inflates every metric into a "spike"). Only condition 1 (gate status) | ||
| # is valid on first run. Conditions 2 and 3 require a prior baseline. | ||
| if [[ "$prev_gate" == "UNKNOWN" ]]; then | ||
| is_first_run=true | ||
| fi |
There was a problem hiding this comment.
First-run detection is coupled to gate_status and can suppress delta triggers indefinitely.
is_first_run currently depends on prev_gate == "UNKNOWN". But UNKNOWN is also a valid persisted state when gate data is unavailable, so Conditions 2/3 can stay disabled forever on later sweeps. Use state-file existence (or an explicit baseline_initialized flag) as the first-run sentinel instead.
Suggested fix
- local trigger_active=false
- local trigger_reasons=""
- local is_first_run=false
+ local trigger_active=false
+ local trigger_reasons=""
+ local slug_safe="${repo_slug//\//-}"
+ local state_file="${QUALITY_SWEEP_STATE_DIR}/${slug_safe}.json"
+ local is_first_run=false
- # Detect first run: prev_gate is UNKNOWN when no state file exists.
+ # Detect first run from state file existence (stable sentinel).
# On first run, delta comparisons are meaningless (comparing against 0
# inflates every metric into a "spike"). Only condition 1 (gate status)
# is valid on first run. Conditions 2 and 3 require a prior baseline.
- if [[ "$prev_gate" == "UNKNOWN" ]]; then
+ if [[ ! -f "$state_file" ]]; then
is_first_run=true
fiAlso applies to: 1929-1940
🤖 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 1911 - 1919, The current
first-run sentinel uses prev_gate == "UNKNOWN", which is ambiguous; instead
detect first run by checking for the presence of the persisted state file (or a
persisted baseline_initialized flag) and set is_first_run based on that. Update
the is_first_run assignment to test for state-file existence (e.g. [[ ! -f
"$STATE_FILE" ]] ) or read a persisted baseline_initialized boolean, and replace
any other occurrences that rely on prev_gate (including the analogous block
around the later duplicate at lines ~1929-1940) so Conditions 2/3 are only
suppressed when no prior baseline actually exists.
There was a problem hiding this comment.
Code Review
The pull request effectively addresses the issue of delta inflation on the first run of the CodeRabbit sweep by introducing an is_first_run flag. This flag correctly prevents delta-based trigger conditions (issue spikes and high/critical increases) from firing when no prior baseline exists. The implementation is clear, well-commented, and directly resolves the described bug, ensuring that only the quality gate status is evaluated during the initial sweep. The addition of a baseline_note for the first run also enhances clarity in the monitoring output.
Note: Security Review is unavailable for this PR.
|
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 being triggered unconditionally on the first sweep run after PR t1390: Make CodeRabbit sweep conditional on quality gate changes #2808 (t1390)_load_sweep_state()returnsprev_issues=0, so the delta calculation (113 - 0 = 113) exceeds the spike threshold of 10, triggering an active review even when metrics are stableprev_gate==UNKNOWNand skip delta-based conditions (issue spike, high/critical increase) — only quality gate status (condition 1) is evaluated on first run since it doesn't depend on deltasRoot Cause Analysis
PR #2808 added conditional logic with three trigger conditions:
The state persistence (
_load_sweep_state/_save_sweep_state) was correct, but the first run had no prior state file, so_load_sweep_statereturned defaults:UNKNOWN|0|0. This made the delta calculation compare current metrics against zero:issue_delta = 113 - 0 = 113(exceeds threshold of 10)high_critical_delta = 8 - 0 = 8(> 0)Both conditions 2 and 3 fired, triggering the
@coderabbitaimention.Verification
Closes #2832
Summary by CodeRabbit