fix(compressor): strip orphaned tool messages at compression boundary - #20886
fix(compressor): strip orphaned tool messages at compression boundary#20886liuhao1024 wants to merge 3 commits into
Conversation
…INSTALL_TIMEOUT Increase the default npm install timeout for WhatsApp bridge from 60s to 300s (5 minutes) to accommodate slower systems like Unraid NAS. Make it configurable via WHATSAPP_NPM_INSTALL_TIMEOUT environment variable for users who need even longer timeouts. Closes NousResearch#14980
- Add 'path', 'old_string', 'new_string', and 'patch' to required list - Update description to clarify mode-specific parameter requirements - This addresses issue where LLMs would omit these parameters because they were not marked as required in the schema, even though they are required depending on the mode Fixes NousResearch#15524
After context compression, the first message in the tail may be a tool message whose parent assistant was summarised away. Providers like DeepSeek require every tool message to be immediately preceded by the assistant that issued the corresponding tool_calls, causing HTTP 400. The existing _sanitize_tool_pairs handles orphaned call_id matching, but does not catch tool messages at the boundary where the parent assistant no longer has tool_calls (it was replaced by a summary). Add a third sanitization pass that removes tool messages not preceded by an assistant with tool_calls or a sibling tool message. Fixes NousResearch#20883
|
Reviewed the
One edge case worth noting: the existing step 1 (orphan removal by |
|
This looks implemented on current Automated hermes-sweeper review found that the compressor boundary failure described here is already fixed by the current boundary-alignment path:
I also checked the bundled non-compressor commits: the WhatsApp npm timeout change is already on main ( |
What does this PR do?
Fixes a crash where context compression produces invalid
tool/assistantmessage ordering, causing HTTP 400 errors from providers like DeepSeek.Root Cause
After compression, the first message in the tail section may be a
toolmessage whose parentassistant(which contained thetool_calls) was in the summarised region. The existing_sanitize_tool_pairs()handles orphanedtool_call_idmatching (removes tool results whose call_id has no matching assistant tool_call), but does not catch the ordering issue: some providers require everytoolmessage to be immediately preceded by theassistantmessage that issued the correspondingtool_calls.When the boundary lands on a
toolmessage:userorassistantwithouttool_calls)Messages with role 'tool' must be a response to a preceding message with 'tool_calls'Related Issue
N/A
Type of Change
Changes Made
How to Test
pytest tests/ -q— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture and workflows — or N/A