Reviewer.review() averages over surviving judge samples only, so partial judge failures shrink the denominator and can let one sample stand in for n_sample (ScoreRetryLoop)
sweagent/agent/reviewer.py:427-443 (class Reviewer, method review):
for _ in range(self._config.n_sample):
try:
answer = self._model.query(messages)["message"]
except Exception as e:
self.logger.warning(f"Query failed: {e}", exc_info=True)
continue
try:
score = self.interpret(answer)
except ValueError as e:
self.logger.warning(f"Could not interpret response: {answer!r}, got {e}")
continue
answers.append(answer)
accepts.append(score)
if not accepts:
answers = ["No valid scores found, failing submission"]
accepts = [-100.0]
accept = sum(accepts) / len(accepts) - penaltyAny judge sample that fails is continued and dropped from accepts. That covers a query() exception that escapes the model's own retry wrapper, a reply interpret() (lines 400-414) cannot parse because the last line has no number, and a score outside score_range. accept is then sum(accepts) / len(accepts), where len(accepts) is the number of survivors, not the configured n_sample. The code fails closed (accepts = [-100.0]) only when every sample is lost. A partial loss just shrinks the denominator, so the mean is taken over whichever samples happened to succeed. The reduce_by_std penalty (lines 445-446) has the same problem: with one survivor, np.std(accepts) is 0 and the penalty disappears.
The score_range field of ReviewerConfig documents that out-of-range reviews "will be ignored", so dropping those individual samples is intended. That comment does not address what happens to the mean when most samples are dropped. Replies with no number and escaped query exceptions are handled the same way, with no documentation.
Which exceptions reach this handler: LiteLLMModel.query (sweagent/agent/models.py:809-832) retries transient errors up to retry.retries times (default 20, 10-120 s random-exponential wait; RetryConfig, lines 55-63). Exceptions that reach the reviewer are therefore the classes the retry wrapper excludes, such as litellm.exceptions.APIError, ContentPolicyViolationError, RuntimeError, TypeError and IndexError, plus any error that is still failing after the retries run out. Unparseable replies go through no retry at all. At temperature > 0 the judge's reply format varies from sample to sample.
Scope: this code runs only when a run is configured with retry_loop: {type: score, ...} (ScoreRetryLoopConfig). The shipped config/benchmarks/250212_sweagent_heavy_sbl.yaml uses type: chooser, and no test or bundled config exercises the score loop. The change below is hardening for users who opt into the score-based retry loop.
Measured
A verbatim copy of interpret() and the sampling and averaging body of review() (lines 416-449) was run standalone against a hand-written fake model, with n_sample=5. No repository module was imported or executed. The fake model raises exceptions directly from query(); in a real run, case A corresponds to exceptions that are not retried or that exhaust the retries, as described above.
| Case | Samples counted | accepts |
final accept |
|---|---|---|---|
control-1: healthy judge, 5/5 reply Score: 2 |
5/5 | [2,2,2,2,2] |
2.0 |
control-2: healthy judge, 5/5 reply Score: 9 |
5/5 | [9,9,9,9,9] |
9.0 |
A: 4/5 query() calls raise, 1 survivor replies Score: 9 |
1/5 | [9] |
9.0 |
B: 4/5 replies unparseable ("I'm not able to assess this submission."), 1 replies Score: 9 |
1/5 | [9] |
9.0 |
B': score_range=(0,10), 4/5 reply Score: 42, 1 replies Score: 9 |
1/5 | [9] |
9.0 |
C: 5/5 query() calls raise |
0/5, override applied | [-100.0] |
-100.0 (fails closed) |
D: healthy judge, reduce_by_std=1, replies 2,2,2,2,9 |
5/5 | [2,2,2,2,9] |
0.6 |
E: reduce_by_std=1, same setup as B |
1/5 | [9] |
9.0 (std = 0, no std penalty) |
Cases A, B and B' produce the same score as a judge that returned 9 on all five samples, although four of five samples produced no score. Case C shows the method already fails closed when every sample is lost, but not when most of them are. Cases D and E show that with reduce_by_std enabled, a healthy but split judge scores 0.6, while a degraded run whose only survivor said 9 scores 9.0.
Consequence
ScoreRetryLoop._n_accepted (reviewer.py:595, r.accept >= self._config.accept_score) feeds retry(). The max_accepts exit in retry() (reviewer.py:632-634) stops the retry loop once enough attempts are accepted. get_best() (reviewer.py:647-658) picks the attempt with the highest accept as the final submission. Both are called from the run loop in sweagent/agent/agents.py (self._rloop.on_submit(...) / self._rloop.retry() around lines 417-428, and self._rloop.get_best() at line 368). In a score-loop run, an attempt whose judge coverage collapsed to one sample can clear accept_score and end the retry loop early. It can also outrank attempts that were scored on all n_sample samples, and nothing in the result distinguishes it from an attempt the judge approved consistently. ReviewerResult records only the surviving outputs, not how many samples were lost.
Suggested fix
Lines 440-442 already fail closed when every sample is lost. The same rule can cover partial losses:
- count each failed or unparseable sample as a fixed penalty value (for example the existing
-100.0, or a configurablefailed_sample_score) so thatlen(accepts)always equalsn_sample. A partial failure can then only lower the mean; or - require a minimum fraction of
n_sampleto survive (configurable, for examplemin_valid_samples) before trusting the mean, and fall back to the existing fail-closed value otherwise.
Either option also keeps reduce_by_std from turning off when coverage is lowest. Recording the number of valid samples on ReviewerResult would make the loss visible in trajectories. Out-of-range scores could keep their documented "ignored" treatment for the individual sample while still counting against the survivor threshold.
The currently open PR #1504 edits this same except Exception block in the Reviewer n-sample loop to re-raise CostLimitExceededError instead of treating it as one more failed sample. The change proposed here covers the other failures that the same block, and the ValueError branch after it, currently drop from the denominator.
Happy to open the PR.
Source: SWE-agent/SWE-agent