fix: recover citations from truncated CITATIONS blocks

↗ view on GitHub · Eli Ziff · 2026-07-27 · bd7235ab

Live calls showed models sometimes drop the final "]" or the closing
</CITATIONS> tag while every citation object inside is well formed. The
final parse previously demanded a strict JSON array and discarded all
citations in that case, though parsePartialCitationObjects could already
recover them object-by-object for streaming previews.

parseCitationsWithDiagnostics now falls back to that recovery when the
strict parse fails or the close tag is missing; each recovered object
still passes normalizeCitation, so a truncated tail can never invent a
citation. Live harness (36 calls, gpt-5.5/5.4-mini/5.4-nano, old vs new
prompt arms): trimmed prompt 23/24, pre-trim 11/12, and the recovery
eliminated every truncation failure on both arms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUsMXzBsEJ27DjJVPSfW5o
Repository eliziff/Beaver
Author Eli Ziff <eliasziff@gmail.com>
Authored
Parents adb37a56
Stats 3 files changed , +166 , -29
Part of SourceDoc / DOCX engine: redlines, tracked changes, editing benchmark

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-bd7235ab.md from inside the repo you want the change in.

⬇ Download capture-commit-bd7235ab.md