Skip to content

Fix: Summarization - handle oversized messages and track statetool tokens#87

Merged
mattprintz merged 1 commit into
mainfrom
bugfix/summarization-bugs
Jul 2, 2026
Merged

Fix: Summarization - handle oversized messages and track statetool tokens#87
mattprintz merged 1 commit into
mainfrom
bugfix/summarization-bugs

Conversation

@mattprintz

Copy link
Copy Markdown
Collaborator

Resolves two summarization-related bugs, issues #85 and #86:

Issue #85 — oversized messages stalled summarization. When a single record at the head of the history was larger than the summarization threshold, the record-selection walk chose nothing, so summarization fired on every query but never made progress. Selection and context-fitting are now separate gates: get_records_up_to_threshold selects records (and falls back to the minimal oversized prefix when the head record alone exceeds the threshold), and fit_records_to_context middle-truncates only the copies sent to the summarizer when the selected records overflow the context window. A record above the threshold but below the window is summarized in full; originals are never mutated.

Issue #86 — statetool injections skewed token accounting. Statetool input/output pairs are ephemeral tail injections that never land in the persisted records, so their size was being absorbed into base_tokens and destabilizing estimates across loop steps. ChatHistory now tracks the last-known size of each statetool's injection separately (statetool_token_estimates) and folds it into token_overhead. Entries are updated when a statetool fires and retained (not zeroed) when it doesn't.

Also clarifies summarizers.py: a module docstring describing the select-then-fit pipeline, helper extraction for the tool-response boundary walks, and explanatory comments on the fit budget.

Adds tests/fake_model.py plus coverage for both fixes.

…kens

Two summarization-related bugs:

Issue #85 — oversized messages stalled summarization. When a single record
at the head of the history was larger than the summarization threshold, the
record-selection walk chose nothing, so summarization fired on every query
but never made progress. Selection and context-fitting are now separate
gates: get_records_up_to_threshold selects records (and falls back to the
minimal oversized prefix when the head record alone exceeds the threshold),
and fit_records_to_context middle-truncates only the copies sent to the
summarizer when the selected records overflow the context window. A record
above the threshold but below the window is summarized in full; originals
are never mutated.

Issue #86 — statetool injections skewed token accounting. Statetool
input/output pairs are ephemeral tail injections that never land in the
persisted records, so their size was being absorbed into base_tokens and
destabilizing estimates across loop steps. ChatHistory now tracks the
last-known size of each statetool's injection separately
(statetool_token_estimates) and folds it into token_overhead. Entries are
updated when a statetool fires and retained (not zeroed) when it doesn't.

Also clarifies summarizers.py: a module docstring describing the
select-then-fit pipeline, helper extraction for the tool-response boundary
walks, and explanatory comments on the fit budget.

Adds tests/fake_model.py plus coverage for both fixes.
@mattprintz
mattprintz merged commit 14a8ffd into main Jul 2, 2026
1 check 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.

1 participant