Repository navigation
fix(agent): keep history that does not fit the summary - #108
Closed
cursor[bot] wants to merge 1 commit into
Closed
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Compaction deleted every message before the kept tail even when the summary source filled up first. A later short line replaced the truncated long line, so that history was removed without being summarized. Co-authored-by: esadrianno <esadrianno@gmail.com>
This was referenced Oct 16, 2026
Collaborator
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.
Bug and impact
Session compaction deleted history that the summarizer never saw. After a long chat, a large earlier message (for example a pasted log) followed by a short one in the summarize window was removed from the session, and the summary was built only from the short line. That history is gone from
sessions.messages.Root cause
compact_session_via_llmwalks the oldest messages into a 64 KiB summary source, but it still drops every message before the kept tail. When a line does not fit,snprintfleaves a partial line and the used length does not advance, so the next shorter line overwrites it. The long message is neither summarized nor kept.Fix
Append a line only when the whole line fits, and roll back a partial write. If the summary source stops early, keep that message and everything after it. If nothing fits, leave the session unchanged.
Validation
make test_agentpasses. The new regression builds a session whose second summarize-window message is 65 KiB and checks thatBIG_MARKER_END!!remains after compaction while the short prefix is still summarized. Before the fix that test failed withcompacted session dropped the message that did not fit the summary.