hermes - ✅(Solved) Fix Session compression corrupts tool_call arguments, truncating JSON to 214 chars [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#12731Fetched 2026-04-20 12:17:12
View on GitHub
Comments
1
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
commented ×1

Error Message

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

Fix Action

Fix / Workaround

  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
Original SessionToolOriginal ArgsAfter Compression
20260418_125807_1da1c108patch7085 chars VALID214 chars INVALID
20260419_091949_e28764f6execute_code6089 chars VALID214 chars INVALID

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

PR fix notes

PR #13057: fix(session): validate and repair tool_call arguments before persisting

Description (problem / solution / changelog)

Summary

Fixes #12731 - Session compression was corrupting tool_call JSON arguments when the conversation was interrupted mid-tool-call (e.g., by a slash command).

Problem

The arguments field in tool_calls was being truncated to exactly 214 characters (200 + "...[truncated]"), producing invalid JSON that caused all subsequent API calls to fail with errors like:

Error code: 400 - {'error': {'message': "'content' is a required property...

Root Cause Analysis

While the _truncate_tool_call_args_json function in context_compressor.py correctly preserves JSON validity when truncating, corrupted arguments can still enter the session through other paths:

  1. Provider malformation (Minimax via OpenRouter reported in the issue)
  2. Interrupt timing - when a slash command interrupts a streaming tool call
  3. Race conditions during message persistence

Fix

Added validation in _flush_messages_to_session_db to detect and repair corrupted tool_call arguments before persisting to SQLite. Uses the existing _repair_tool_call_arguments helper to fix malformed JSON.

The validation:

  1. Checks each tool_call's arguments field for valid JSON
  2. If invalid, attempts repair using _repair_tool_call_arguments
  3. Logs warnings when repairs are made
  4. Ensures only valid JSON is persisted to the database

Testing

  • All existing tests pass (17 tests in test_repair_tool_call_arguments.py)
  • Compression persistence tests pass (6 tests)
  • No regressions introduced

Test Plan

  1. Run existing test suite: pytest tests/run_agent/test_repair_tool_call_arguments.py tests/run_agent/test_compression_persistence.py
  2. Manual test: Start a session with a provider, trigger a tool call, interrupt with slash command, verify session continues correctly

Changed files

  • run_agent.py (modified, +24/-0)

Code Example

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

---

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
RAW_BUFFERClick to expand / collapse

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 SessionToolOriginal ArgsAfter Compression
20260418_125807_1da1c108patch7085 chars VALID214 chars INVALID
20260419_091949_e28764f6execute_code6089 chars VALID214 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.

extent analysis

TL;DR

Modify the compression logic in context_compressor.py to preserve complete tool call arguments and prevent truncation.

Guidance

  • Review the context_compressor.py code to identify the exact location where the truncation occurs and adjust the logic to handle tool call arguments without truncating them.
  • Consider implementing validation checks for tool call arguments during session replay to detect and reject incomplete JSON.
  • Add validation in tool call serialization to ensure arguments are valid JSON before storing to prevent corruption.
  • Implement a startup check to validate session files for corrupted tool calls and warn or auto-delete them to prevent issues.

Example

No specific code example can be provided without the actual code from context_compressor.py, but the goal is to modify the compression logic to handle tool call arguments without truncating them, potentially by checking the length of the arguments and handling them differently if they exceed a certain threshold.

Notes

The provided evidence suggests that the issue is consistently related to the truncation of tool call arguments to exactly 214 characters, which implies a fixed byte limit in the compression logic. The suggested fixes aim to address this issue directly.

Recommendation

Apply a workaround by modifying the context_compressor.py to preserve complete tool call arguments during compression. This approach directly addresses the identified root cause of the issue and should prevent the corruption of tool call arguments during session compression.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Session compression corrupts tool_call arguments, truncating JSON to 214 chars [1 pull requests, 1 comments, 1 participants]