fix(s_full): consecutive user messages + microcompact read_file regression#247
Open
voidborne-d wants to merge 1 commit intoshareAI-lab:mainfrom
Conversation
…ssion Three fixes in s_full.py: 1. microcompact clears read_file results (regression from s06) s06's micro_compact preserves read_file outputs via PRESERVE_RESULT_TOOLS, but s_full's simplified microcompact clears ALL old tool_result content indiscriminately. This forces the agent to re-read files it already has in context, wasting tool calls and API tokens. Fix: port the tool_name_map lookup + _PRESERVE_RESULT_TOOLS set from s06. 2. Teammate _loop produces consecutive user messages When inbox messages arrive during the work phase, each one is appended as a separate user message. If multiple inbox messages arrive, or if the last message is already a user turn (tool_results), this creates consecutive user messages that violate the Anthropic API's strict alternation requirement (400 error). Same issue in idle-phase inbox handling and auto-claim injection. Fix: merge inbox messages into a single turn and insert assistant placeholders when last message is already user. 3. agent_loop bg notifications + inbox injection can stack user messages Both bg drain and inbox check independently append user messages before the LLM call. If both fire in the same iteration, or if the previous iteration ended with a user turn (tool_results), two+ consecutive user messages result. Fix: merge both into a single injection and fold into existing user turn when possible. 12 regression tests covering microcompact preservation, message alternation in all three contexts, and source code audit.
|
@voidborne-d is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
Three bugs in
s_full.pythat cause runtime crashes or degraded agent behaviour:1.
microcompactclearsread_fileresults (regression from s06)s06_context_compact.py'smicro_compactcorrectly preservesread_fileoutputs viaPRESERVE_RESULT_TOOLS, because compacting them forces the agent to re-read files it already has in context — wasting a tool call and API tokens each time. Buts_full.py's simplifiedmicrocompactclears ALL oldtool_resultcontent indiscriminately:This directly contributes to the looping behaviour reported in #62 — the agent reads a file, microcompact clears it, the agent needs the content again, re-reads it, microcompact clears it again, etc.
Fix: Port the
tool_name_maplookup and_PRESERVE_RESULT_TOOLSset from s06 into s_full'smicrocompact.2. Teammate
_loopproduces consecutive user messages (→ Anthropic 400 error)When inbox messages arrive during the work phase, each one is appended as a separate user message. If multiple inbox messages arrive simultaneously, or if the last message is already a user turn (tool_results), this creates consecutive user messages that violate the Anthropic API's strict alternation requirement:
Same issue exists in:
Fix: Merge all inbox messages into a single turn; insert assistant placeholder when the last message is already a user turn.
3.
agent_loopbg notifications + inbox injection can stack user messagesBoth background notification drain and inbox check independently append user messages before the LLM call. If both fire in the same iteration, or if the previous iteration ended with a user turn (tool_results), two+ consecutive user messages result.
Fix: Merge both into a single injection and fold into the existing user turn when possible (string concatenation for text content, text-part append for list content).
Tests
12 new regression tests in
tests/test_s_full_message_alternation.py:TestMicrocompactPreservesReadFileTestAgentLoopAlternationTestTeammateAlternationTestSourceAuditAll 27 tests pass (15 existing + 12 new):
Closes #62 (micro_compact looping) and addresses the alternation violations described in #234 and #239 (s_full.py production readiness).