Bug Report: Malformed tool call error leaked verbatim to user instead of being handled gracefully
Summary
When a tool call is malformed (invalid JSON in partialArgs), the JSON parsing error is surfaced directly to the user as a raw error message instead of being caught and handled gracefully by the framework.
Error Message Shown to User
Unexpected non-whitespace character after JSON at position 2 (line 1 column 3)
Steps to Reproduce
-
Setup: Configure OpenClaw with Venice.ai Kimi K2.5 as primary model:
{
"agents": {
"defaults": {
"model": {
"primary": "venice/kimi-k2-5",
"fallbacks": ["anthropic/claude-opus-4-5"]
}
}
},
"models": {
"providers": {
"venice": {
"baseUrl": "https://api.venice.ai/api/v1",
"api": "openai-completions"
}
}
}
}
-
Trigger: During a conversation, the model generated a malformed tool call with corrupted partialArgs:
{
"toolCall": {
"id": "read:20",
"name": "read",
"arguments": {},
"partialArgs": "{}{\"path\":\"~/clawd/AGENTS.md\",\"offset\":260,\"limit\":100}"
}
}
-
Observe: The JSON parsing error was sent directly to the user via Telegram instead of being caught and reformatted.
Technical Details
Session Data (from sessions_history):
{
"role": "assistant",
"content": [{
"type": "toolCall",
"id": "read:20",
"name": "read",
"arguments": {},
"partialArgs": "{}{\"path\":\"~/clawd/AGENTS.md\",\"offset\":260,\"limit\":100}"
}],
"errorMessage": "Unexpected non-whitespace character after JSON at position 2 (line 1 column 3)",
"stopReason": "error"
}
Root Cause Analysis:
- The
partialArgs field contains concatenated JSON: {} immediately followed by {"path":...}
- When parsed, this fails at position 2 (the
{ of the second object) because the parser expects the JSON to end after the first }
- The parsing error propagates uncaught to the user-facing output
Expected Behavior
The framework should:
- Catch JSON parsing errors in tool call arguments
- Log the error internally for debugging
- Surface a user-friendly message like: "Tool call failed: invalid arguments format"
- Optionally retry or request clarification from the model
Actual Behavior
The raw JSON parsing error message is sent directly to the user:
"Unexpected non-whitespace character after JSON at position 2 (line 1 column 3)"
Environment
- OpenClaw Version: 2026.2.1 (ed4529e)
- Primary Model: venice/kimi-k2-5 (Kimi K2.5 via Venice.ai)
- API: openai-completions
- Channel: Telegram
- OS: macOS 24.6.0 (Darwin)
- Node: v22.22.0
Additional Context
This occurred during model transition testing (Claude Opus → Kimi K2.5). The partialArgs corruption suggests either:
- Streaming/concatenation issue in tool call construction
- Model-generated malformed JSON that wasn't validated
- Race condition in argument assembly
Possible Fixes
- Validation Layer: Add JSON schema validation before parsing tool arguments
- Error Handler: Wrap tool call parsing in try-catch with user-friendly error messages
- Sanitization: Clean/merge
partialArgs with arguments more robustly
- Logging: Ensure raw errors go to logs, not user output
Impact
- Severity: Medium (functionality works, but UX is poor)
- User Experience: Confusing raw error messages that reveal implementation details
- Security: Low (no sensitive data leaked, but exposes internal error format)
Related: This may be specific to the openai-completions API mode with certain providers that use partialArgs for streaming tool calls.
Bug Report: Malformed tool call error leaked verbatim to user instead of being handled gracefully
Summary
When a tool call is malformed (invalid JSON in
partialArgs), the JSON parsing error is surfaced directly to the user as a raw error message instead of being caught and handled gracefully by the framework.Error Message Shown to User
Steps to Reproduce
Setup: Configure OpenClaw with Venice.ai Kimi K2.5 as primary model:
{ "agents": { "defaults": { "model": { "primary": "venice/kimi-k2-5", "fallbacks": ["anthropic/claude-opus-4-5"] } } }, "models": { "providers": { "venice": { "baseUrl": "https://api.venice.ai/api/v1", "api": "openai-completions" } } } }Trigger: During a conversation, the model generated a malformed tool call with corrupted
partialArgs:{ "toolCall": { "id": "read:20", "name": "read", "arguments": {}, "partialArgs": "{}{\"path\":\"~/clawd/AGENTS.md\",\"offset\":260,\"limit\":100}" } }Observe: The JSON parsing error was sent directly to the user via Telegram instead of being caught and reformatted.
Technical Details
Session Data (from
sessions_history):{ "role": "assistant", "content": [{ "type": "toolCall", "id": "read:20", "name": "read", "arguments": {}, "partialArgs": "{}{\"path\":\"~/clawd/AGENTS.md\",\"offset\":260,\"limit\":100}" }], "errorMessage": "Unexpected non-whitespace character after JSON at position 2 (line 1 column 3)", "stopReason": "error" }Root Cause Analysis:
partialArgsfield contains concatenated JSON:{}immediately followed by{"path":...}{of the second object) because the parser expects the JSON to end after the first}Expected Behavior
The framework should:
Actual Behavior
The raw JSON parsing error message is sent directly to the user:
Environment
Additional Context
This occurred during model transition testing (Claude Opus → Kimi K2.5). The
partialArgscorruption suggests either:Possible Fixes
partialArgswithargumentsmore robustlyImpact
Related: This may be specific to the
openai-completionsAPI mode with certain providers that usepartialArgsfor streaming tool calls.