openclaw - 💡(How to fix) Fix pi-agent-core: assistantMessage.content.filter() crash when content is not an array [3 comments, 4 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
openclaw/openclaw#51390Fetched 2026-04-08 01:11:52
View on GitHub
Comments
3
Participants
4
Timeline
6
Reactions
0
Timeline (top)
commented ×3cross-referenced ×3

Error Message

TypeError: toolMsg.content.filter is not a function

Code Example

TypeError: toolMsg.content.filter is not a function

---

const toolCalls = message.content.filter((c) => c.type === "toolCall");

---

const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall");

---

const toolCalls = (Array.isArray(message.content) ? message.content : []).filter((c) => c.type === "toolCall");
RAW_BUFFERClick to expand / collapse

Bug Description

In @mariozechner/[email protected] (bundled with OpenClaw 2026.3.13), two call sites in dist/agent-loop.js call .filter() directly on message.content / assistantMessage.content without verifying it is an array.

When a sub-agent returns a tool message where content is not an array (e.g., a string or other non-array type), this throws:

TypeError: toolMsg.content.filter is not a function

The assistant response then has stopReason: "error" and the agent loop halts.

Affected Code

File: @mariozechner/pi-agent-core/dist/agent-loop.js

Site 1 — Line 112

const toolCalls = message.content.filter((c) => c.type === "toolCall");

Site 2 — Line 233

const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall");

Reproduction

  1. Spawn a sub-agent via sessions_spawn with runtime: "subagent"
  2. The sub-agent returns a message where content is a string (not an array)
  3. The parent agent loop crashes when processing the result

Environment

  • OpenClaw: 2026.3.13 (commit 61d171a)
  • @mariozechner/pi-agent-core: 0.58.0
  • Node.js: v22.22.1
  • OS: Linux 6.12.38+deb13-amd64 (x64)

Suggested Fix

Guard both call sites:

const toolCalls = (Array.isArray(message.content) ? message.content : []).filter((c) => c.type === "toolCall");

This matches the pattern already used elsewhere in the same file (e.g., line 153 in executeToolCallsParallel where content is safely iterated).

extent analysis

Fix Plan

To fix the issue, we need to ensure that .filter() is only called on message.content and assistantMessage.content if they are arrays.

Here are the steps:

  • Identify the two call sites in dist/agent-loop.js where .filter() is called directly on message.content and assistantMessage.content.
  • Modify these lines to check if the content is an array before calling .filter().

Example code for the fix:

// Site 1 — Line 112
const toolCalls = (Array.isArray(message.content) ? message.content : []).filter((c) => c.type === "toolCall");

// Site 2 — Line 233
const toolCalls = (Array.isArray(assistantMessage.content) ? assistantMessage.content : []).filter((c) => c.type === "toolCall");

Verification

To verify that the fix worked:

  • Spawn a sub-agent via sessions_spawn with runtime: "subagent" and have it return a message where content is a string (not an array).
  • Check that the parent agent loop no longer crashes when processing the result.
  • Test with different types of content (e.g., array, string, object) to ensure the fix is robust.

Extra Tips

  • This fix uses the Array.isArray() method to check if the content is an array, and if not, defaults to an empty array [] to avoid errors.
  • This pattern is already used elsewhere in the same file, so it's consistent with existing code.

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