Skip to content

fix: CompactionHook token over-count when no assistant message is present - #12581

Closed
RahilOp wants to merge 1 commit into
deepset-ai:mainfrom
RahilOp:fix/compaction-hook-overcount-no-assistant
Closed

fix: CompactionHook token over-count when no assistant message is present#12581
RahilOp wants to merge 1 commit into
deepset-ai:mainfrom
RahilOp:fix/compaction-hook-overcount-no-assistant

Conversation

@RahilOp

@RahilOp RahilOp commented Sep 3, 2026

Copy link
Copy Markdown

Fixes #12580\n\nWhen context_tokens > 0 but the conversation has no assistant message, _estimated_context_tokens was counting the entire message list on top of the provider's reported usage. This change short-circuits and returns context_tokens when there is no assistant message, matching the behavior described in the issue.\n\nChanges:\n- Updated _estimated_context_tokens in haystack/hooks/compaction/utils.py.\n- Added regression tests in test/hooks/compaction/test_utils.py.\n- Added release note.

…sent

Signed-off-by: Syed Ali Abbas Rahil <viperboom0786110@gmail.com>
@RahilOp
RahilOp requested a review from a team as a code owner September 3, 2026 04:00
@RahilOp
RahilOp requested review from julian-risch and removed request for a team September 3, 2026 04:00
@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @RahilOp, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from julian-risch September 3, 2026 05:07
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Sep 3, 2026
@HaystackBot
HaystackBot marked this pull request as draft September 3, 2026 05:07
@julian-risch julian-risch added this to the 3.1.1 milestone Sep 3, 2026
@sjrl

sjrl commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

hey @RahilOp thanks for opening the PR! we opted to go for a slightly different fix in this PR #12594 so I'll be closing this one

@sjrl sjrl closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-pending PR is in draft until the contributor signs the CLA topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompactionHook over-counts context tokens when no assistant message is in the conversation

5 participants