Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 48 additions & 29 deletions .agents/scripts/pulse-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1888,12 +1888,18 @@ ${type_breakdown}
fi
fi

# --- 5. CodeRabbit trigger (conditional — t1390) ---
# --- 5. CodeRabbit trigger (conditional — t1390, t1392) ---
# Only trigger @coderabbitai active review when quality degrades:
# - Quality gate status changes to FAIL/ERROR
# - Issue count increases by CODERABBIT_ISSUE_SPIKE+ since last sweep
# - New high/critical severity findings appear
# Otherwise post a passive monitoring line to avoid repetitive requests.
#
# IMPORTANT (t1392): On first run (no previous state file), prev_gate is
# "UNKNOWN" and prev_issues/prev_high_critical are 0. Computing deltas
# against zero treats the entire existing issue count as a "spike",
# unconditionally triggering CodeRabbit. Fix: when prev_gate is UNKNOWN,
# this is a baseline-setting run — save state and skip delta triggers.
local coderabbit_section=""
local prev_state
prev_state=$(_load_sweep_state "$repo_slug")
Expand All @@ -1904,39 +1910,51 @@ ${type_breakdown}
[[ "$prev_issues" =~ ^[0-9]+$ ]] || prev_issues=0
[[ "$prev_high_critical" =~ ^[0-9]+$ ]] || prev_high_critical=0

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=""

# 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))
Comment on lines 1913 to +1928

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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=""


# 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
Comment on lines +1916 to 1934
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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
 else

Based 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.

Suggested change
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.

fi

# Condition 3: New high/critical severity findings
if [[ "$high_critical_delta" -gt 0 ]]; then
trigger_active=true
if [[ -n "$trigger_reasons" ]]; then
trigger_reasons="${trigger_reasons}, +${high_critical_delta} high/critical"
else
trigger_reasons="+${high_critical_delta} high/critical findings"
# 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}"
fi
fi
fi

if [[ "$trigger_active" == true ]]; then
coderabbit_section="### CodeRabbit
# Condition 3: New high/critical severity findings
if [[ "$high_critical_delta" -gt 0 ]]; then
trigger_active=true
if [[ -n "$trigger_reasons" ]]; then
trigger_reasons="${trigger_reasons}, +${high_critical_delta} high/critical"
else
trigger_reasons="+${high_critical_delta} high/critical findings"
fi
fi

if [[ "$trigger_active" == true ]]; then
coderabbit_section="### CodeRabbit

**Trigger**: ${trigger_reasons}

Expand All @@ -1946,12 +1964,13 @@ ${type_breakdown}
- Code duplication and maintainability
- Documentation accuracy
"
echo "[pulse-wrapper] CodeRabbit: active review triggered for ${repo_slug} (${trigger_reasons})" >>"$LOGFILE"
else
coderabbit_section="### CodeRabbit
echo "[pulse-wrapper] CodeRabbit: active review triggered for ${repo_slug} (${trigger_reasons})" >>"$LOGFILE"
else
coderabbit_section="### CodeRabbit

_Monitoring: ${sweep_total_issues} issues (delta: ${issue_delta}), gate ${sweep_gate_status}, ${sweep_high_critical} high/critical — no active review needed._
"
fi
fi
tool_count=$((tool_count + 1))

Expand Down
Loading