Repository navigation
Fail compaction when the summary is truncated instead of persisting it - #103
Merged
ernestrc merged 2 commits intoSep 30, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ernestrc
reviewed
Sep 20, 2026
| return "", err | ||
| } | ||
| if done != nil && done.FinishReason == llmapi.FinishReasonLength { | ||
| return "", fmt.Errorf("summary truncated after %d output tokens; raise /max_tokens", |
Contributor
There was a problem hiding this comment.
Add a "current max_tokens %d", so the user has a reference point to raise from
| } | ||
| if done != nil && done.FinishReason == llmapi.FinishReasonLength { | ||
| return "", fmt.Errorf("summary truncated after %d output tokens; raise /max_tokens", | ||
| done.Usage.TokensReceived) |
Contributor
There was a problem hiding this comment.
it's possible that a provider omits this field and it's just set to 0. I would handle this by printing a different error message maybe without the "after %d" part.
Contributor
There was a problem hiding this comment.
"If no
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ernestrc
force-pushed
the
fix-truncated-compaction-summary
branch
from
September 30, 2026 12:21
d34d647 to
657285a
Compare
Summarize ignored the stream's finish reason, so a summary cut off by the output-token limit was accepted. cleanSummary could not match the unterminated <summary> block, and the raw fragment, dangling tag included, was archived in place of the conversation as the resume prompt. The next turn was handed an unfinished document and spent itself repairing it, emitting runs of closing tags instead of resuming the task. Summarize now returns an error when the stream finishes with FinishReasonLength, naming the output-token count and pointing at /max_tokens. CompactDialogue returns before archiving, so the dialogue is kept, the error is surfaced, and the turn continues with its full context. cleanSummary also tolerates a <summary> tag that is never closed and strips a trailing run of </parameter> and </invoke> tags, so a degenerate response cannot leak stray markup into the resume prompt. Signed-off-by: Eric Brooks <[email protected]>
… advice A chat's /compact runs through that chat's own agentshell, which was built without a max-tokens getter. The summary request therefore carried no budget and fell back to the provider default (8192 on Anthropic), so the "raise /max_tokens" advice on a truncated summary could never take effect. The chat's agentshell now reads the chat agent's override. The truncation error reported TokensReceived, which is often 0, and always advised /max_tokens. It now names the budget that was hit, and suggests a model with longer output when the model cannot accept a larger budget, such as when the budget is already at the model ceiling or the provider rejects overrides. Co-Authored-By: Rune Agent (claude/claude-opus-5-5) <[email protected]> Signed-off-by: ernestrc <[email protected]>
ernestrc
force-pushed
the
fix-truncated-compaction-summary
branch
from
September 30, 2026 12:31
657285a to
1df7427
Compare
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.
Fixes #78.
Summarizeignored the stream's finish reason, so a summary cut off by the output-token limit wasaccepted.
cleanSummarycould not match the unterminated<summary>block, and the raw fragment,dangling tag included, was archived in place of the conversation as the resume prompt. The next
turn was handed an unfinished document and spent itself repairing it, emitting runs of closing tags
instead of resuming the task.
Changes:
Summarizereturns an error when the stream finishes withFinishReasonLength, naming theoutput-token count and pointing at
/max_tokens.CompactDialoguereturns before archiving, sothe dialogue is kept, the error is surfaced, and the turn continues with its full context. The
auto-compaction path already logs and continues on a compaction error; the
compacttool alreadyreports the failure and continues without compacting.
cleanSummarytolerates a<summary>tag that is never closed and strips a trailing run of</parameter>/</invoke>tags, so a degenerate response cannot leak stray markup into theresume prompt.
Not included: the optional retry with a larger budget from the issue. With #80 the session budget
reaches the summary request, which makes truncation rare; this change makes it non-destructive when
it still happens. A retry can follow separately.
Tests (all fail on
main):TestCompactDialogueRejectsTruncatedSummary,TestAutoCompact/auto-compact with a truncated summary keeps the full dialogue, and twoTestCleanSummaryrows (unclosed tag, trailing tool-call tags).