Skip to content

Fail compaction when the summary is truncated instead of persisting it - #103

Merged
ernestrc merged 2 commits into
unstablebuild:mainfrom
ejb711:fix-truncated-compaction-summary
Sep 30, 2026
Merged

ernestrc merged 2 commits into
unstablebuild:mainfrom
ejb711:fix-truncated-compaction-summary

Conversation

@ejb711

@ejb711 ejb711 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #78.

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.

Changes:

  • Summarize 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. The
    auto-compaction path already logs and continues on a compaction error; the compact tool already
    reports the failure and continues without compacting.
  • cleanSummary tolerates 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 the
    resume 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 two
TestCleanSummary rows (unclosed tag, trailing tool-call tags).

@codecov

codecov Bot commented Sep 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread cmd/rune-agent/agent/agent.go Outdated
return "", err
}
if done != nil && done.FinishReason == llmapi.FinishReasonLength {
return "", fmt.Errorf("summary truncated after %d output tokens; raise /max_tokens",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a "current max_tokens %d", so the user has a reference point to raise from

Comment thread cmd/rune-agent/agent/agent.go Outdated
}
if done != nil && done.FinishReason == llmapi.FinishReasonLength {
return "", fmt.Errorf("summary truncated after %d output tokens; raise /max_tokens",
done.Usage.TokensReceived)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmd/rune-agent/agent/agent.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If no

tags are found" is no longer true

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ernestrc
ernestrc force-pushed the fix-truncated-compaction-summary branch from d34d647 to 657285a Compare September 30, 2026 12:21
ejb711 and others added 2 commits September 30, 2026 14:30
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
ernestrc force-pushed the fix-truncated-compaction-summary branch from 657285a to 1df7427 Compare September 30, 2026 12:31
@ernestrc
ernestrc merged commit 568e4cf into unstablebuild:main Sep 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction persists a length-truncated summary, and the resumed turn degenerates into a closing-tag loop

3 participants