fix(triage): read imperfect batch answers and retry unanswered findings once #453

Merged
sharang merged 1 commits from fix/triage-batch-parse into main 2026-10-05 18:15:19 +00:00
Owner

What was wrong

Staging logged Failed to parse batch triage response for chunk starting at 0 on a .NET fixture scan (9 findings), and every finding then went through untriaged. The batch answer was only accepted as a bare JSON array (a fence was stripped only at position 0), with strict field types. Any of these failed the whole chunk:

  • prose before/after the array, or a fence not at the very start
  • trailing commas, an object wrapping the array, a bare object for one finding
  • an answer cut off at max_tokens (4096), or an empty answer (without_reasoning drops an unterminated <think> block)
  • one strict field: "id": 1 (finding number instead of fingerprint), "confidence": "7", "rationale": null

The old warn line printed the full response; it shows which of these hit staging.

What changed (compliance-agent/src/llm/triage.rs only)

  • parse_triage_response: pure, tolerant parser. Handles fences and prose, trailing commas, wrapper object, single verdict object, and salvages the complete leading verdicts of a truncated array. Verdicts stay positional; the first unreadable one ends the list so no verdict lands on the wrong finding.
  • TriageResult: lenient fields (null, numeric strings); the unused echoed id is no longer deserialized.
  • Findings a chunk got no verdict for (call failed, unreadable, or fewer verdicts) are retried once in chunks half the size. What is still unanswered stays as reported; no finding is ever dropped.
  • Warn lines say how many findings are affected; a 500-char sample of an unreadable answer goes to DEBUG (never the prompt).

Tests

  • New unit tests: plain, fenced, prose around, trailing commas, wrapper object, single object, truncated array salvage, unreadable verdict ends list, empty [] in prose skipped, garbage errors, lenient fields, retry halving.
  • cargo fmt --all --check, cargo clippy -p compliance-agent --all-targets -- -D warnings clean; cargo test -p compliance-agent --lib: 582 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

## What was wrong Staging logged `Failed to parse batch triage response for chunk starting at 0` on a .NET fixture scan (9 findings), and every finding then went through untriaged. The batch answer was only accepted as a bare JSON array (a fence was stripped only at position 0), with strict field types. Any of these failed the whole chunk: - prose before/after the array, or a fence not at the very start - trailing commas, an object wrapping the array, a bare object for one finding - an answer cut off at `max_tokens` (4096), or an empty answer (`without_reasoning` drops an unterminated `<think>` block) - one strict field: `"id": 1` (finding number instead of fingerprint), `"confidence": "7"`, `"rationale": null` The old warn line printed the full response; it shows which of these hit staging. ## What changed (compliance-agent/src/llm/triage.rs only) - `parse_triage_response`: pure, tolerant parser. Handles fences and prose, trailing commas, wrapper object, single verdict object, and salvages the complete leading verdicts of a truncated array. Verdicts stay positional; the first unreadable one ends the list so no verdict lands on the wrong finding. - `TriageResult`: lenient fields (null, numeric strings); the unused echoed `id` is no longer deserialized. - Findings a chunk got no verdict for (call failed, unreadable, or fewer verdicts) are retried **once** in chunks half the size. What is still unanswered stays as reported; no finding is ever dropped. - Warn lines say how many findings are affected; a 500-char sample of an unreadable answer goes to DEBUG (never the prompt). ## Tests - New unit tests: plain, fenced, prose around, trailing commas, wrapper object, single object, truncated array salvage, unreadable verdict ends list, empty `[]` in prose skipped, garbage errors, lenient fields, retry halving. - `cargo fmt --all --check`, `cargo clippy -p compliance-agent --all-targets -- -D warnings` clean; `cargo test -p compliance-agent --lib`: 582 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-05 17:46:56 +00:00
fix(triage): read imperfect batch answers and retry unanswered findings once
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m24s
543a2b155d
A batch triage answer was only accepted as a bare JSON array (fences at the
very start stripped), with strict field types. Prose around the array,
trailing commas, a wrapping object, an answer cut off at max_tokens, or a
single field such as "id": 1, "confidence": "7" or "rationale": null failed
the whole chunk, and every finding in it went through untriaged.

- parse_triage_response: tolerant, pure parser (fences/prose, trailing
  commas, wrapper object, single verdict object, truncated array salvage);
  verdicts stay positional, the first unreadable one ends the list
- TriageResult: lenient fields (null, numeric strings); the unused echoed
  id is no longer deserialized
- findings a chunk got no verdict for are retried once in chunks half the
  size; whatever is still unanswered stays as reported (never dropped)
- warn lines name how many findings are affected; a 500-char sample of an
  unreadable answer goes to DEBUG, the prompt never does

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 81699b2111 into main 2026-10-05 18:15:19 +00:00
Sign in to join this conversation.