Skip to content

Tool call JSON parse errors exposed to user after session compaction #59080

@Etoilelune

Description

@Etoilelune

Bug Description

After session compaction, the model occasionally generates malformed tool call arguments (invalid JSON). When this happens, the framework surfaces the raw JSON.parse error message directly to the user as a chat message.

Example error message sent to user:

Expected ':' after property name in JSON at position 10 (line 1 column 11)

Steps to Reproduce

  1. Have a long session that triggers compaction
  2. After compaction, the model may generate a tool_use block with malformed JSON arguments (e.g., only 25 tokens output before the JSON becomes invalid)
  3. The JSON.parse error is sent as a user-visible message instead of being handled gracefully

Observed Behavior

The raw JavaScript JSON.parse error message is delivered to the user as a chat message. This exposes internal framework errors that users should never see.

Expected Behavior

  1. Internal errors should never be exposed to users. JSON parse failures on tool call arguments should be caught and handled gracefully (e.g., logged internally, retried, or presented as a user-friendly "something went wrong" message).
  2. Consider retrying when the model generates malformed tool call JSON, especially after compaction, since this appears to be a transient issue.

Environment

  • Model: claude-opus-4-6 via nex provider (anthropic-messages API)
  • Trigger: Session compaction (context refresh)
  • Framework version: current
  • Channel: Feishu

Context

This was observed after a session compaction event. The model's first tool call post-compaction had only ~25 tokens of malformed JSON arguments. The error was passed through errorMessage and delivered to the chat channel.

Related: #50292 (suppress intermediate text output)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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