fix(triage): stop asking a model that is down (#462) (#475)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 7m2s

The per-id retries of #472 ask about a finding up to three times, the
critical/high ones on their own. A model that accepts requests and never
answers would hold each call for the client's 300 s timeout: up to 720
calls instead of 60. When every call in flight fails at once, the model
is taken as down; what it answered so far is kept, the rest is recorded
as "skipped: no answer". An unreadable answer still counts as an answer
and is asked about again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit was merged in pull request #475.
This commit is contained in:
sharangandClaude Opus 5.5 committed 2026-10-05 22:48:15 +00:00
1 parent 6f2e278969
commit 0c0eedb242
1 file changed
+55 -13
+55 -13
View File
@@ -320,14 +320,19 @@ fn chunk_prompt(
///
/// # Returns
///
/// The verdicts the answer holds, by position in `findings`; none when the
/// call failed or its answer could not be read.
/// The verdicts the answer holds, by position in `findings`; none when its
/// answer could not be read.
///
/// # Errors
///
/// [`ModelDown`] when the call itself failed: the model could not be reached,
/// returned an error or gave no answer at all.
async fn triage_chunk<M: TriageModel>(
model: &M,
findings: &[Finding],
chunk: &[usize],
graph_context: Option<&GraphContext>,
) -> Vec<(usize, TriageResult)> {
) -> Result<Vec<(usize, TriageResult)>, ModelDown> {
let user_prompt = chunk_prompt(findings, chunk, graph_context);
let answer = match model.answer(TRIAGE_SYSTEM_PROMPT, &user_prompt).await {
Ok(answer) => answer,
@@ -337,7 +342,7 @@ async fn triage_chunk<M: TriageModel>(
this was the last try",
chunk.len()
);
return Vec::new();
return Err(ModelDown);
}
};
let verdicts = match parse_triage_response(&answer.content) {
@@ -358,7 +363,7 @@ async fn triage_chunk<M: TriageModel>(
tracing::debug!(
"Unreadable batch triage response (first {RESPONSE_SAMPLE_CHARS} chars): {sample}"
);
return Vec::new();
return Ok(Vec::new());
}
};
let fingerprints: Vec<&str> = chunk
@@ -383,9 +388,13 @@ async fn triage_chunk<M: TriageModel>(
},
);
}
matched
Ok(matched)
}
/// A triage call failed as a call (not an unreadable answer).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct ModelDown;
/// The verdict for each finding of a chunk (`fingerprints`, in chunk order),
/// matched by the `id` the model echoed: the finding's number in the chunk
/// (from 1), or its fingerprint. Only when no verdict carries an id that names
@@ -439,7 +448,7 @@ async fn ask_in_chunks<M: TriageModel>(
size: usize,
graph_context: Option<&GraphContext>,
calls: &mut usize,
) -> Vec<(usize, TriageResult)> {
) -> (Vec<(usize, TriageResult)>, Option<ModelDown>) {
let chunks: Vec<&[usize]> = ask.chunks(size.max(1)).collect();
let mut answered = Vec::new();
for group in chunks.chunks(TRIAGE_CONCURRENCY) {
@@ -450,9 +459,15 @@ async fn ask_in_chunks<M: TriageModel>(
.map(|chunk| triage_chunk(model, findings, chunk, graph_context)),
)
.await;
answered.extend(answers.into_iter().flatten());
// Every call at once failed: the model is down (or hangs until the
// client's timeout), not cutting answers short. Asking about the
// rest, chunk by chunk and then one by one, would only take hours.
if answers.iter().all(Result::is_err) {
return (answered, Some(ModelDown));
}
answered.extend(answers.into_iter().flatten().flatten());
}
answered
(answered, None)
}
/// The tries of the triage: the chunk size of each, and which findings still
@@ -466,7 +481,8 @@ const TRIES: [(usize, Severity); 3] = [
];
/// Ask the model about every finding at `sent`, and again by id about those it
/// gave no verdict (see [`TRIES`]).
/// gave no verdict (see [`TRIES`]). Once every call in flight fails at once,
/// the model is taken as down and nothing more is asked.
///
/// # Returns
///
@@ -495,10 +511,18 @@ async fn ask_all<M: TriageModel>(
size
);
}
for (i, verdict) in ask_in_chunks(model, findings, &ask, *size, graph_context, calls).await
{
let (answered, down) =
ask_in_chunks(model, findings, &ask, *size, graph_context, calls).await;
for (i, verdict) in answered {
verdicts.entry(i).or_insert(verdict);
}
if down.is_some() {
tracing::warn!(
"LLM triage: every call at once failed; the model is not answering, so the \
findings without a verdict are not asked again"
);
break;
}
}
verdicts
}
@@ -1525,8 +1549,26 @@ mod tests {
.all(|f| f.triage_action.as_deref() == Some(SKIPPED_ACTION)
&& f.status == FindingStatus::Open));
assert_eq!(summary.skipped_no_answer_severe, 3);
// One chunk, its retry, then each critical finding on its own.
// The first call fails: the model is down, nothing is asked again.
assert_eq!(summary.calls, 1);
}
#[tokio::test]
async fn a_model_that_goes_down_midway_keeps_what_it_answered() {
let mut findings: Vec<Finding> = (1..=45).map(|n| numbered(n, Severity::Medium)).collect();
let full: String = format!(
"[{}]",
(1..=10)
.map(|n| format!(r#"{{"id":{n},"action":"confirm","confidence":8}}"#))
.collect::<Vec<_>>()
.join(",")
);
// The first four chunks are answered, then the model is gone.
let model = FakeModel::scripted(&[&full, &full, &full, &full]);
let summary = triage_findings(&model, &mut findings, None).await;
assert_eq!(summary.calls, 5);
assert_eq!(summary.confirmed, 40);
assert_eq!(summary.skipped_no_answer, 5);
}
#[tokio::test]