fix: tolerate the extra trailing summary models append for the next-turn anchor#8
Open
SApplefeld wants to merge 1 commit into
Open
Conversation
Summarizer models regularly append one unrequested <assistant> block for
the trailing next-turn <user> anchor in the compaction template. The
count-only validation then rejects an otherwise-correct response
("Expected 7 summaries, received 8"), aborting the compaction.
Parse by pairing each echoed <user> block with the <assistant> block
that follows it and taking exactly the first expectedCount pairs: the
extra trailing block is ignored, and a true miss or malformed structure
still fails loudly. The template also now marks the trailing <user>
anchor as not-to-be-summarized, reducing the extra block at the source.
Observed on Claude Code with Haiku 4.5 (3 of 3 failures on a ~380-row
transcript) and once with Sonnet 5; both plugins share the parse logic,
so both are fixed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
buildXmlTemplateends the compaction template with a trailing<user>block that anchors where summarization stops. Summarizer models regularly "complete" that anchor with one extra, unrequested<assistant>block.parseSummariesvalidates by counting<assistant>blocks, so the otherwise-correct response is rejected ("Expected 7 summaries, received 8") and the compaction aborts.Observed on the Claude Code plugin: with Haiku 4.5 as the summarizer, 3 of 3 attempts on a ~380-row transcript failed (this shape plus two other malformed-output shapes); with Sonnet 5, one occurrence of the +1 shape. Both plugins share the parsing logic, so both are affected.
Fix
parseSummariesnow pairs each echoed<user>block with the<assistant>block that follows it and takes exactly the firstexpectedCountpairs. The extra trailing block is ignored; a true miss or malformed structure still throws.<user>as not-to-be-summarized, reducing the extra block at the source.Verification
tsc --noEmit,eslint, andprettierall pass.One environment note in passing: the
.githooks/pre-commitnpxinvocations cannot resolve bun-installed binaries on Windows (bun's store has no npm-visible bin entries there), so the hook fails closed for Windows contributors even on a clean tree. Happy to file that separately if useful.