Sdm0 commited on
Commit
34ed9eb
·
verified ·
1 Parent(s): c945ae0

preserve static findings on provider failure

Browse files
Files changed (1) hide show
  1. nodes/correctness_reviewer.py +28 -26
nodes/correctness_reviewer.py CHANGED
@@ -120,12 +120,38 @@ def correctness_reviewer_node(state: OpenCodeReviewState) -> dict:
120
  logger.info("No diff to review — skipping correctness review")
121
  return {}
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  # --- Build the LLM (Gemini primary → Groq fallback) -----------------------
124
  try:
125
  llm = create_llm(endpoint=state.endpoint or None)
126
  except ValueError as exc:
127
  logger.warning("LLM unavailable — skipping correctness review: %s", exc)
128
- return {}
129
  structured_llm = llm.with_structured_output(CorrectnessReview)
130
 
131
  # --- Build the prompt ----------------------------------------------------
@@ -147,34 +173,10 @@ def correctness_reviewer_node(state: OpenCodeReviewState) -> dict:
147
  result: CorrectnessReview = structured_llm.invoke(messages) # type: ignore[assignment]
148
  except Exception as exc:
149
  logger.warning("Correctness review LLM call failed: %s", exc)
150
- return {}
151
 
152
  # Deterministic guard for a high-impact async anti-pattern that LLMs can
153
  # miss: promises created by forEach are not awaited by the caller.
154
- static_findings = []
155
- current_file = "unknown"
156
- current_line = 0
157
- for raw_line in (state.diff or "").splitlines():
158
- if raw_line.startswith("+++ b/"):
159
- current_file = raw_line[6:].strip()
160
- current_line = 0
161
- elif raw_line.startswith("@@"):
162
- match = re.search(r"\+(\d+)", raw_line)
163
- current_line = int(match.group(1)) if match else current_line
164
- elif re.search(r"\.forEach\s*\(\s*async\b", raw_line):
165
- static_findings.append(Finding(
166
- file_path=current_file,
167
- line_start=max(1, current_line),
168
- line_end=max(1, current_line),
169
- severity=Severity.HIGH,
170
- category="correctness",
171
- comment="An async callback passed to forEach is not awaited, so cleanup or side effects can run after the function returns and errors can bypass surrounding try/catch handling.",
172
- confidence=0.99,
173
- suggested_fix="Replace forEach(async ...) with a for...of loop or await Promise.all(items.map(async ...)).",
174
- ))
175
- if raw_line.startswith("+") and not raw_line.startswith("+++"):
176
- current_line += 1
177
-
178
  result.findings.extend(static_findings)
179
 
180
  # --- Log and return findings ---------------------------------------------
 
120
  logger.info("No diff to review — skipping correctness review")
121
  return {}
122
 
123
+ # Run deterministic checks before the model call so provider failures do
124
+ # not erase high-confidence findings.
125
+ static_findings = []
126
+ current_file = "unknown"
127
+ current_line = 0
128
+ for raw_line in (state.diff or "").splitlines():
129
+ if raw_line.startswith("+++ b/"):
130
+ current_file = raw_line[6:].strip()
131
+ current_line = 0
132
+ elif raw_line.startswith("@@"):
133
+ match = re.search(r"\+(\d+)", raw_line)
134
+ current_line = int(match.group(1)) if match else current_line
135
+ elif re.search(r"\.forEach\s*\(\s*async\b", raw_line):
136
+ static_findings.append(Finding(
137
+ file_path=current_file,
138
+ line_start=max(1, current_line),
139
+ line_end=max(1, current_line),
140
+ severity=Severity.HIGH,
141
+ category="correctness",
142
+ comment="An async callback passed to forEach is not awaited, so cleanup or side effects can run after the function returns and errors can bypass surrounding try/catch handling.",
143
+ confidence=0.99,
144
+ suggested_fix="Replace forEach(async ...) with a for...of loop or await Promise.all(items.map(async ...)).",
145
+ ))
146
+ if raw_line.startswith("+") and not raw_line.startswith("+++"):
147
+ current_line += 1
148
+
149
  # --- Build the LLM (Gemini primary → Groq fallback) -----------------------
150
  try:
151
  llm = create_llm(endpoint=state.endpoint or None)
152
  except ValueError as exc:
153
  logger.warning("LLM unavailable — skipping correctness review: %s", exc)
154
+ return {"findings": static_findings} if static_findings else {}
155
  structured_llm = llm.with_structured_output(CorrectnessReview)
156
 
157
  # --- Build the prompt ----------------------------------------------------
 
173
  result: CorrectnessReview = structured_llm.invoke(messages) # type: ignore[assignment]
174
  except Exception as exc:
175
  logger.warning("Correctness review LLM call failed: %s", exc)
176
+ return {"findings": static_findings} if static_findings else {}
177
 
178
  # Deterministic guard for a high-impact async anti-pattern that LLMs can
179
  # miss: promises created by forEach are not awaited by the caller.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  result.findings.extend(static_findings)
181
 
182
  # --- Log and return findings ---------------------------------------------