Repository navigation
fix(agent): keep history when compaction cannot finish the turn - #126
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 wrote the summarized transcript before the reply, so a failed provider call replaced the stored session with a summary the user never accepted. When the kept tail already starts with a user turn, fold the summary into that turn so Anthropic does not reject the session for consecutive user roles. Co-authored-by: esadrianno <esadrianno@gmail.com>
adriannoes
added a commit
that referenced
this pull request
Oct 17, 2026
Compaction wrote the summarized transcript before the reply, so a failed provider call replaced the stored session with a summary the user never accepted. When the kept tail already starts with a user turn, fold the summary into that turn so Anthropic does not reject the session for consecutive user roles. Supersedes #126.
Collaborator
|
Superseded by #121: consolidated into the operator-authored branch fix/agent-summary-compaction (same fix, re-validated with make test_agent, CI=true make test, make static). Closing in favor of the consolidation. |
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.
Summary
Compaction saved a summarized transcript before the user turn finished, and it could store two user turns in a row. A failed reply then deleted history the user still needed, and an odd
max_context_messagesmade Anthropic reject that session on every later message.compact_session_via_llmcalledsession_saveas soon as the summary model returned. The follow-up chat had not run yet. A timeout, 429, or 5xx after that summary left the raw messages replaced by the summary, while the failed turn itself was not stored.usermessage. With an oddmax_context_messages(config allows 1–1000; example provider is Anthropic), the kept tail also starts on a user turn. The Messages API requires alternating roles and returns HTTP 400. Because the bad transcript was already saved, every later message on that session failed the same way until/reset.The compacted JSON now stays in memory until
agent_persist_sessionruns after a successful reply. If the kept tail already starts withuser, the summary is folded into that turn instead of adding a second user message.Testing
make test_agentthen./build/test_agent— passed, including:test_compaction_failure_keeps_original_session(summary call succeeds, follow-up chat fails,msg_0remains and the summary is not stored)test_compaction_merges_summary_when_tail_starts_with_user(max_context_messages = 5, roles alternate, summary is inside the leading user turn, success still persists compaction)test_context_compaction_when_history_exceeds_max