openclaw - 💡(How to fix) Fix Recurring Anthropic streaming JSON parse errors (Sonnet 4.5 / Opus) — failover often fails to recover [1 comments, 2 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#60593Fetched 2026-04-08 02:49:22
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
1
Author
Timeline (top)
commented ×1

Error Message

embedded_run_failover_decision: stage=assistant, decision=fallback_model, model=claude-sonnet-4-5, rawErrorPreview="Expected ',' or '}' after property value in JSON at position 160"

lane task error: lane=session:agent:main:main durationMs=60457 error="FailoverError: Expected ',' or '}' after property value in JSON at position 160"

embedded_run_agent_end: model=claude-sonnet-4-5, isError=true, failoverReason=null, error="Expected ',' or '}' after property value in JSON at position 162"

Code Example

embedded_run_failover_decision: stage=assistant, decision=fallback_model, model=claude-sonnet-4-5, rawErrorPreview="Expected ',' or '}' after property value in JSON at position 160"

lane task error: lane=session:agent:main:main durationMs=60457 error="FailoverError: Expected ',' or '}' after property value in JSON at position 160"

embedded_run_agent_end: model=claude-sonnet-4-5, isError=true, failoverReason=null, error="Expected ',' or '}' after property value in JSON at position 162"
RAW_BUFFERClick to expand / collapse

Bug Description

Recurring JSON parse errors when OpenClaw calls Anthropic models (primarily Sonnet 4.5, occasionally Opus 4.5). The error Expected ',' or '}' after property value in JSON at position NNN surfaces to users as raw error messages in Telegram.

Frequency & Data

Over the past 2 days on our gateway (v2026.4.2):

  • April 2: 6 occurrences (all Sonnet 4.5, positions: 662, 694, 702, 845, 911, 920)
  • April 3: 9 occurrences (Sonnet 4.5 + 1x Opus 4.5, positions: 160, 162, 203, 233)

This is a recurring issue, not transient. The JSON truncation position varies, suggesting the API stream is being cut at different points.

Failover Behavior

  • When failoverReason=timeout: failover to next model works correctly
  • When failoverReason=null (majority of cases): no failover happens, the error is exposed directly to the user as a raw JSON parse error message
  • The embedded_run_agent_end events show isError=true with no recovery

Log Evidence

embedded_run_failover_decision: stage=assistant, decision=fallback_model, model=claude-sonnet-4-5, rawErrorPreview="Expected ',' or '}' after property value in JSON at position 160"

lane task error: lane=session:agent:main:main durationMs=60457 error="FailoverError: Expected ',' or '}' after property value in JSON at position 160"

embedded_run_agent_end: model=claude-sonnet-4-5, isError=true, failoverReason=null, error="Expected ',' or '}' after property value in JSON at position 162"

Related Issues

  • #59080 — Tool call JSON parse errors exposed to user after compaction
  • #46370 — Tool-call args JSON parse crashes on unescaped newlines/quotes
  • #33280 — Anthropic streaming JSON parse crash on invalid escape sequences
  • #60002 — JSON Parser Crash on Em-Dash Characters

Environment

  • OpenClaw: v2026.4.2 (d74a122)
  • Models: anthropic/claude-sonnet-4-5 (primary), anthropic/claude-opus-4-5 (fallback)
  • Channel: Telegram (streaming: partial)
  • OS: macOS 26.3.1 (arm64)

Expected Behavior

  1. JSON parse failures should trigger retry/failover consistently (not only when timeout is detected)
  2. Raw JSON.parse errors should never be surfaced to users
  3. Ideally: streaming JSON parser should be more resilient to truncated/malformed chunks

extent analysis

TL;DR

Implement a retry mechanism for JSON parse errors to trigger failover consistently, ensuring raw errors are not surfaced to users.

Guidance

  • Review the failoverReason logic to handle null cases, allowing failover to occur for all JSON parse errors, not just timeouts.
  • Modify the error handling to catch and retry JSON parse errors, preventing them from being exposed to users.
  • Consider enhancing the streaming JSON parser to be more resilient to truncated or malformed chunks, potentially by implementing a buffer or more robust parsing mechanism.
  • Investigate the related issues (#59080, #46370, #33280, #60002) to identify potential fixes or workarounds for similar JSON parsing problems.

Example

No specific code snippet can be provided without more context, but a possible approach might involve wrapping the JSON parsing code in a try-catch block and retrying the operation on failure:

try {
  // JSON parsing code
} catch (error) {
  if (error instanceof JSONParseError) {
    // Trigger retry or failover
  } else {
    // Handle other error types
  }
}

Notes

The provided information suggests that the issue is related to the JSON parsing mechanism and the failover logic. However, without more details about the implementation, it's difficult to provide a more specific solution.

Recommendation

Apply a workaround by implementing a retry mechanism for JSON parse errors to ensure consistent failover and prevent raw errors from being surfaced to users. This approach addresses the immediate issue and provides a more robust error handling mechanism.

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