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
23 changes: 19 additions & 4 deletions .agents/scripts/pulse-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1908,15 +1908,25 @@ ${type_breakdown}
local high_critical_delta=$((sweep_high_critical - prev_high_critical))
local trigger_active=false
local trigger_reasons=""
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
Comment on lines +1911 to +1919
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 | 🔴 Critical

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
 	fi

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


# Condition 1: Quality gate is failing (valid on first run and subsequent)
if [[ "$sweep_gate_status" == "ERROR" || "$sweep_gate_status" == "WARN" ]]; then
trigger_active=true
trigger_reasons="quality gate ${sweep_gate_status}"
fi

# Condition 2: Issue count spiked by threshold or more
if [[ "$issue_delta" -ge "$CODERABBIT_ISSUE_SPIKE" ]]; then
# Skip on first run — delta vs 0 is not a real spike (t1392)
if [[ "$is_first_run" == false && "$issue_delta" -ge "$CODERABBIT_ISSUE_SPIKE" ]]; then
trigger_active=true
if [[ -n "$trigger_reasons" ]]; then
trigger_reasons="${trigger_reasons}, issue spike +${issue_delta}"
Expand All @@ -1926,7 +1936,8 @@ ${type_breakdown}
fi

# Condition 3: New high/critical severity findings
if [[ "$high_critical_delta" -gt 0 ]]; then
# Skip on first run — delta vs 0 is not a real increase (t1392)
if [[ "$is_first_run" == false && "$high_critical_delta" -gt 0 ]]; then
trigger_active=true
if [[ -n "$trigger_reasons" ]]; then
trigger_reasons="${trigger_reasons}, +${high_critical_delta} high/critical"
Expand All @@ -1948,9 +1959,13 @@ ${type_breakdown}
"
echo "[pulse-wrapper] CodeRabbit: active review triggered for ${repo_slug} (${trigger_reasons})" >>"$LOGFILE"
else
local baseline_note=""
if [[ "$is_first_run" == true ]]; then
baseline_note=" (first run — baseline established, deltas will be computed from next sweep)"
fi
coderabbit_section="### CodeRabbit

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