Skip to content

fix: reject incomplete summaries in SummarizationCompactor - #13737

Open
HYYAlex wants to merge 1 commit into
deepset-ai:mainfrom
HYYAlex:fix/summarization-compactor-incomplete-summary
Open

HYYAlex wants to merge 1 commit into
deepset-ai:mainfrom
HYYAlex:fix/summarization-compactor-incomplete-summary

Conversation

@HYYAlex

@HYYAlex HYYAlex commented Nov 13, 2026

Copy link
Copy Markdown

Summary (in my own words)

When compacting chat history, the summary can be cut off or filtered, but the compactor only checks whether the summary has any text, not why it ended. Any text counts as success, so a half-written summary replaces the complete old history. My fix: before using a summary, check its finish reason; if it did not end normally, treat the compaction as failed and keep the original history unchanged.

Related Issues

Proposed Changes:

SummarizationCompactor._apply_summary only checked that the summary reply had text and that it shrank the conversation. A reply cut off by the generator's output limit (finish_reason="length") or by a content filter ("content_filter") was wrapped in <conversation_summary> and replaced the original messages. Everything the summary had not reached yet was lost for the rest of the run, and the Agent still finished normally.

_apply_summary now raises a RuntimeError for those two finish reasons, before the text is used. The error goes through the existing failure policy: by default it is logged and the previous history (or the last successful partial compaction) is kept, and with raise_on_failure=True it is propagated. The sync and async paths share _apply_summary, so both are covered. Replies without a finish_reason keep today's behavior. The raise_on_failure docstring and a release note describe the change.

How did you test it?

  • New unit tests in test/hooks/compaction/test_summarization.py. For length and content_filter: the conversation is kept by default (sync and async), and raise_on_failure=True raises with the finish reason in the message. A control test checks that a summary with finish_reason="stop" is still applied. The new incomplete-summary tests fail without the fix.
  • hatch run test:unit test/hooks/compaction/test_summarization.py: 38 passed.
  • hatch run test:unit (full unit suite): 7563 passed, 0 failed.
  • hatch run fmt and hatch run test:types: clean.
  • Manual check with a real Agent + CompactionHook + SummarizationCompactor (script in the linked issue). The history contains ORDER-7319, and the summary generator returns a partial summary with the given finish_reason:
before: stop -> reference kept=True | length -> reference kept=False | content_filter -> reference kept=False
after:  stop -> reference kept=True | length -> reference kept=True  | content_filter -> reference kept=True

Notes for the reviewer

Only length and content_filter are treated as incomplete, matching the finish reasons Haystack's chat generators normalize to. A summary with no finish_reason (for example from a custom generator) is still accepted, to avoid breaking existing setups.

This PR was mostly generated with an AI assistant. I have reviewed the changes and run the relevant tests.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

SummarizationCompactor only checked that a summary reply had text and
shrank the conversation. A reply cut off by the output limit
(finish_reason "length") or a content filter ("content_filter") was
wrapped as a summary and replaced the original messages, silently losing
everything the summary had not reached yet.

Such a reply now raises in _apply_summary, so it goes through the existing
failure policy: by default the failure is logged and the previous history
is kept; with raise_on_failure=True the RuntimeError is propagated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HYYAlex
HYYAlex requested a review from a team as a code owner November 13, 2026 13:25
@HYYAlex
HYYAlex requested review from anakin87 and removed request for a team November 13, 2026 13:25
@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@HYYAlex is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Nov 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SummarizationCompactor accepts a truncated (length) or filtered (content_filter) summary and replaces the conversation with it

2 participants