Repository navigation
fix(agent): retag a folded compaction head as a user turn - #141
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
An odd max_context_messages makes the first compaction window two messages. When the assistant line does not fit the summary source, the summary is folded into that line and the role stays assistant. Anthropic rejects the transcript with HTTP 400, fallback stops, and the turn is not saved, so every later turn rebuilds the same request. Retag the folded head to user and merge the following user turn so the roles still alternate. 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
Session compaction can fold a summary into an assistant message and leave that role in place. With an odd
max_context_messages, the stored count on the first compaction ismax_ctx + 1, so the folded head is inside the sent window. Anthropic rejects an assistant-first transcript with HTTP 400. The router treats 4xx as terminal,agent_runreturns beforesession_save, and every later turn rebuilds the same request. The session accepts no new turns until/reset.Trigger
max_context_messagesis any odd value from 3 to 39 (the agent clamps above 40). The oldest stored user line is about 60 KiB (CLI-mor an ASAP task) and the following assistant reply is a few KiB, so the two summary lines do not fit in the 64 KiB source. After enough later turns that the stored count exceeds the limit, the next message sticks.Root cause
compact_session_via_llmsetsfold_into_oversizedwhen a non-user line stops the summary pass at index 1, thenfold_summary_into_messagerewrites onlycontent. The kept head staysassistant. The user-tail path already folds into a user message to avoid this Anthropic 400. The assistant-head path did not.Fix
Retag that head to
user, droptool_use_id, and merge one following user turn so the roles still alternate. The oversized body stays in the head for the next stub pass.Validation
test_compaction_fold_keeps_alternating_user_headfailed before the fix (folded head role is assistant) and passes after it.CI=true make test_agentpasses.