fix(compressor): summary role can violate consecutive-role constraint#1720
Merged
fix(compressor): summary role can violate consecutive-role constraint#1720
Conversation
The summary message role was determined only by the last head message, ignoring the first tail message. This could create consecutive user messages (rejected by Anthropic) when the tail started with 'user'. Now checks both neighbors. Priority: avoid colliding with the head (already committed). If the chosen role also collides with the tail, flip it — but only if flipping wouldn't re-collide with the head.
teknium1
added a commit
that referenced
this pull request
Mar 30, 2026
…, tool error sanitization Three resilience features ported from Ironclaw: 1. Discard incomplete tool calls (ironclaw#1632) When finish_reason='length' and tool calls are present, they're likely incomplete. Discard them, inject a summarize notice. After 3 consecutive occurrences, temporarily disable tools. 2. Empty response recovery (ironclaw#1677 + #1720) When the LLM returns empty (no content, no tool calls): - If meaningful output exists earlier, treat as completion - Otherwise nudge once, then fail gracefully Max 2 consecutive empties before giving up. 3. Sanitize tool error results (ironclaw#1639) Strip XML boundary markers, CDATA sections, and code fences from error messages before sending to LLM. Cap at 2000 chars. Prevents injection attacks via crafted tool error messages. 18 new tests.
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
The context compressor's summary message role was determined only by the last head message's role, ignoring what the first tail message's role is. When the last head message was
assistantand the first tail message wasuser, the summary role was set touser— creating consecutiveusermessages that Anthropic's API rejects.What changed
agent/context_compressor.py: Now checks both the head and tail neighbors when choosing the summary role. Prioritizes not colliding with the head (already committed), then avoids the tail collision if possible without re-colliding with the head.Test plan
python -m pytest tests/ -n0 -q -k compress→ 61 passed, 14 skipped ✔test_summary_role_avoids_consecutive_user_messagesstill passes