Skip to content

fix(agent): keep history when the compaction summary is blank - #142

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-inspection-720a
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-inspection-720a

Conversation

@cursor

@cursor cursor Bot commented Nov 8, 2026

Copy link
Copy Markdown

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, and session_save wrote the wiped transcript. Those turns are gone, with no summary text left behind.

This happens when the summarizer returns HTTP 200 and content is "", whitespace, or JSON null. OpenAI-compatible parsers (provider_parse_chat_completions_json) turn null content into an allocated empty string, so the existing !resp.content failure check does not see it. A local model that ends the completion immediately does this, while a short follow-up such as hi can still succeed and persist the loss.

Root cause

compact_session_via_llm in src/core/agent.c only bails out when provider->chat fails or resp.content is NULL. An empty string is non-NULL, so the function builds a new session array, drops the summarized prefix, and copies that array into session_buf. agent_persist_session then saves it after the user turn.

Fix and validation

A blank summary (empty or only space, tab, CR, LF) now returns -1 before session_buf is modified. The loaded transcript stays in place, matching the existing failed-summary path.

make test_agent failed first on test_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 of test_agent passed.

Open in Web View Automation 

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

No deployments
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