Skip to content

Session compression corrupts tool_call arguments, truncating JSON to 214 chars #12731

@ssjw

Description

@ssjw

Bug Description

Session compression (context summarization) corrupts tool_call JSON arguments when the conversation is interrupted mid-tool-call (e.g., by a slash command). The tool call’s arguments field is truncated to exactly 214 characters, producing invalid JSON. All subsequent requests in that session fail with:

Minimax midstream error: invalid params, invalid function arguments json string, tool_call_id: call_function_XXXX_1

Steps to Reproduce

  1. Start a Signal (or other messaging platform) conversation
  2. Model produces a tool call (e.g., execute_code, patch)
  3. While the model is processing, user sends a slash command (e.g., /usage, /queue) — the gateway discards it but the message enters the conversation
  4. Session compression runs automatically (triggered by token limit)
  5. New session is created via “session split”
  6. The compressed session now has the tool call with truncated 214-char arguments
  7. All subsequent API calls fail — only solution is to delete the session file and restart gateway

Evidence

Two confirmed instances — both truncations are exactly 214 chars:

Original Session Tool Original Args After Compression
20260418_125807_1da1c108 patch 7085 chars VALID 214 chars INVALID
20260419_091949_e28764f6 execute_code 6089 chars VALID 214 chars INVALID

Log evidence of the trigger sequence:

10:47:33 - User: please setup a task that runs every morning at 6:30am...
10:48:26 - User sends /usage while model is thinking
10:48:26 - Gateway: Discarding command /usage from pending queue
10:49:37 - User: /queue I tried using /usage while you were thinking...
10:52:57 - User: Please proceed...
10:57:40 - Compression runs (minimax/minimax-m2.7 via openrouter)
10:58:30 - Session split → corrupted tool call in new session (20260419_105817_b91660)
10:58:29 - First error: API call failed, msgs=42

Same pattern occurred the previous night at 00:06 with a patch tool call.

Environment

  • Hermes Agent: NousResearch/hermes-agent
  • Provider: OpenRouter (minimax/minimax-m2.7)
  • Platform: Signal gateway
  • Session storage: SQLite (~/.hermes/sessions/)

Suggested Fix

The compression logic in context_compressor.py appears to be truncating tool call arguments at a fixed byte limit (214). One of:

  1. Preserve complete tool call arguments during compression — do not truncate function.arguments
  2. Detect and reject tool calls with incomplete JSON during session replay
  3. Add validation in tool_call serialization to ensure arguments are valid JSON before storing

Additionally, consider adding a startup check that validates session files for corrupted tool calls and warns or auto-deletes them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/agentCore agent loop, run_agent.py, prompt buildertype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions