fix: ensure tool result content is always array format#9
Open
yjjheizhu wants to merge 1 commit intoadoresever:mainfrom
Open
fix: ensure tool result content is always array format#9yjjheizhu wants to merge 1 commit intoadoresever:mainfrom
yjjheizhu wants to merge 1 commit intoadoresever:mainfrom
Conversation
OpenClaw core expects toolMsg.content to be an array of {type, text} objects.
When content is a raw string, the core's toolMsg.content.filter() call crashes
with 'filter is not a function', causing the agent session to crash and lose context.
Changes:
- Extract text from both string and array content formats
- Return [{type: 'text', text}] array for short messages
- Return [{type: 'text', text}] array for truncated messages
- Avoid JSON.stringify on array content (causes double-encoding)
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
OpenClaw core expects
toolMsg.contentto be an array of{type, text}objects. When the context compactor encounters a short tool result (≤6000 chars), it returns the original message unchanged. Ifmsg.contentis a raw string, the core code crashes:This causes the entire agent session to crash silently, losing all context and memory. The agent appears to "amnesia" after 2-3 rounds of conversation.
Root Cause
In
contextCompactor, the short message path:The truncated path also returns a plain string:
Fix
{type: "text", text}array elementscontentis always[{type: "text", text}]array formatTesting
Tested locally with graph-memory plugin loaded. Agent no longer crashes when context compactor processes tool results. Memory and conversation continuity preserved across multiple rounds.