[Bug] Parallel tool_use / tool_result mismatch permanently corrupts session state
Description
When an agent attempts multiple concurrent tool calls, there is a race condition or mismatch where tool_result blocks do not correctly pair with their respective tool_use IDs. This mismatch can break the session's context state, causing the agent to get stuck in a loop (hallucinating, repeating previous outputs, or failing with API errors due to malformed tool sequences).
Steps to Reproduce
- An agent triggers multiple parallel tool calls (e.g., concurrent I/O or content extraction).
- The tools complete and return their results to the gateway.
- The gateway attempts to merge the
tool_result blocks back into the session history.
- If a mismatch or out-of-order injection occurs, the LLM state becomes invalid.
- All subsequent messages to the agent result in degraded, repeated, or hallucinated responses.
Expected Behavior
The gateway should strictly validate and pair tool_use IDs with tool_result IDs, ensuring that concurrent tool executions resolve in a format compatible with the model's strict requirements for tool call sequences, without permanently corrupting the session context.
Logs / Evidence
- Occurred multiple times (at least 3 recorded incidents on our local instance on 2026-02-27 in a multi-agent environment).
- Affected agents: Various specialist agents during high-concurrency tasks (e.g., simultaneous file processing and API lookups).
- Temporary workaround: Requires manually pruning or resetting the recent session context to clear the corrupted blocks.
Environment
- OpenClaw version:
2026.2.25 (or latest)
- Models involved: Claude 3.5 Sonnet, Claude 3 Opus
- Platform: macOS ARM64
[Bug] Parallel tool_use / tool_result mismatch permanently corrupts session state
Description
When an agent attempts multiple concurrent tool calls, there is a race condition or mismatch where
tool_resultblocks do not correctly pair with their respectivetool_useIDs. This mismatch can break the session's context state, causing the agent to get stuck in a loop (hallucinating, repeating previous outputs, or failing with API errors due to malformed tool sequences).Steps to Reproduce
tool_resultblocks back into the session history.Expected Behavior
The gateway should strictly validate and pair
tool_useIDs withtool_resultIDs, ensuring that concurrent tool executions resolve in a format compatible with the model's strict requirements for tool call sequences, without permanently corrupting the session context.Logs / Evidence
Environment
2026.2.25(or latest)