Repository navigation
fix(agent): keep history when the compaction summary is blank - #142
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
A summarizer HTTP 200 with empty or whitespace content passed the NULL check and replaced the summarized turns. The follow-up chat then succeeded and session_save stored that loss. Treat a blank summary as a failed compaction and leave the loaded transcript unchanged. Co-authored-by: esadrianno <esadrianno@gmail.com>
This branch has not been deployed
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
Once a session grows past
max_context_messages(default 40), compaction asks the provider for a summary and then deletes the turns that went into that summary. A blank completion was treated as a successful summary. The follow-up chat still succeeded, andsession_savewrote the wiped transcript. Those turns are gone, with no summary text left behind.This happens when the summarizer returns HTTP 200 and
contentis"", whitespace, or JSONnull. OpenAI-compatible parsers (provider_parse_chat_completions_json) turn null content into an allocated empty string, so the existing!resp.contentfailure check does not see it. A local model that ends the completion immediately does this, while a short follow-up such ashican still succeed and persist the loss.Root cause
compact_session_via_llminsrc/core/agent.conly bails out whenprovider->chatfails orresp.contentis NULL. An empty string is non-NULL, so the function builds a new session array, drops the summarized prefix, and copies that array intosession_buf.agent_persist_sessionthen saves it after the user turn.Fix and validation
A blank summary (empty or only space, tab, CR, LF) now returns -1 before
session_bufis modified. The loaded transcript stays in place, matching the existing failed-summary path.make test_agentfailed first ontest_blank_compaction_summary_keeps_stored_history(FAIL: blank summary deleted stored history) for an empty body, then passed for both""and whitespace after the fix. The rest oftest_agentpassed.