Files
openclaw/packages
liuhao1024 9202dbb1b6 fix(llm): coerce stringified JSON arrays/objects in tool argument validation (fixes #96916) (AI-assisted) (#96922)
* fix(llm): coerce stringified JSON arrays/objects in tool argument validation

When LLMs serialize array or object tool parameters as JSON strings
(e.g. tags: '["test","debug"]' instead of tags: ["test","debug"]),
validateToolArguments now attempts JSON.parse coercion before
rejecting the value. This mirrors the existing numeric string
coercion path and fixes MCP tool calls from providers like MiMo,
Ollama, and others that stringify complex parameters.

Fixes #96916

* fix(llm): bound JSON.parse size for schema-gated array/object coercion

Add MAX_JSON_COERCE_LENGTH (64KB) guard before JSON.parse in the array
and object coercion branches. Oversized stringified arguments are left
for normal validation to reject rather than synchronously parsed.

Addresses Codex review finding: unbounded JSON.parse on model-controlled
tool arguments could block the event loop or spike memory.
2026-06-28 18:32:59 -07:00
..