Skip to content

Malformed tool call error leaked verbatim to user instead of being handled gracefully #7867

@rex05ai

Description

@rex05ai

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

  1. 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"
          }
        }
      }
    }
  2. 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}"
      }
    }
  3. 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:

  1. The partialArgs field contains concatenated JSON: {} immediately followed by {"path":...}
  2. When parsed, this fails at position 2 (the { of the second object) because the parser expects the JSON to end after the first }
  3. The parsing error propagates uncaught to the user-facing output

Expected Behavior

The framework should:

  1. Catch JSON parsing errors in tool call arguments
  2. Log the error internally for debugging
  3. Surface a user-friendly message like: "Tool call failed: invalid arguments format"
  4. 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

  1. Validation Layer: Add JSON schema validation before parsing tool arguments
  2. Error Handler: Wrap tool call parsing in try-catch with user-friendly error messages
  3. Sanitization: Clean/merge partialArgs with arguments more robustly
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions