openclaw - 💡(How to fix) Fix [Bug]: SSE [DONE] terminator incorrectly passed to JSON parser — kills agentTurn cron jobs on stream end [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#71514Fetched 2026-04-26 05:12:02
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Timeline (top)
commented ×1cross-referenced ×1

Every agentTurn cron job that calls an LLM fails with a JSON parse error when the SSE stream ends. The SSE terminator data: [DONE] is incorrectly routed to the JSON parser instead of being handled as a terminal marker.

Error: Could not parse Anthropic SSE event data: Unexpected token D, [DONE] is not valid JSON; data=[DONE]


Error Message

Every agentTurn cron job that calls an LLM fails with a JSON parse error when the SSE stream ends. The SSE terminator data: [DONE] is incorrectly routed to the JSON parser instead of being handled as a terminal marker. Error: From cron runs: status=error, error=Could not parse Anthropic SSE event data: Unexpected token D, [DONE] is not valid JSON; data=[DONE], model=minimax/minimax-m2.5:free Same error across all 5+ jobs.

Root Cause

The SSE spec uses data: [DONE] (no event name) to signal stream end. OpenClaw unconditionally calls JSON.parse() on all data: lines without checking for [DONE] (not JSON). SyntaxError kills the agent run.


Fix Action

Fix / Workaround

High. Every agentTurn cron job fails at stream completion. No workaround.

RAW_BUFFERClick to expand / collapse

Bug: SSE [DONE] terminator passed to JSON parser — kills all agentTurn cron jobs

OpenClaw 2026.4.23 (a979721) Node.js: v24.14.1 OS: Linux 6.8.0-110-generic (x64)


Summary

Every agentTurn cron job that calls an LLM fails with a JSON parse error when the SSE stream ends. The SSE terminator data: [DONE] is incorrectly routed to the JSON parser instead of being handled as a terminal marker.

Error: Could not parse Anthropic SSE event data: Unexpected token D, [DONE] is not valid JSON; data=[DONE]


Root cause

The SSE spec uses data: [DONE] (no event name) to signal stream end. OpenClaw unconditionally calls JSON.parse() on all data: lines without checking for [DONE] (not JSON). SyntaxError kills the agent run.


Evidence

From cron runs: status=error, error=Could not parse Anthropic SSE event data: Unexpected token D, [DONE] is not valid JSON; data=[DONE], model=minimax/minimax-m2.5:free

Same error across all 5+ jobs.


Proposed fix

In SSE data: handler, check for [DONE] before JSON.parse(): const raw = line.trim(); if (raw === [DONE]) { return; } const data = JSON.parse(raw);


Related

#52679 (closed) — empty data event, [DONE] not covered


Impact

High. Every agentTurn cron job fails at stream completion. No workaround.

extent analysis

TL;DR

Check for the SSE terminator [DONE] before attempting to parse the data as JSON to prevent parsing errors.

Guidance

  • Verify that the error message Could not parse Anthropic SSE event data: Unexpected token D, [DONE] is not valid JSON; data=[DONE] is consistent across all failed agentTurn cron jobs.
  • Implement a check for the [DONE] terminator in the SSE data handler, as proposed in the issue, to prevent unnecessary JSON parsing.
  • Review related issues, such as #52679, to ensure that similar edge cases are handled correctly.
  • Test the updated SSE data handler with various input scenarios to ensure that it correctly handles both JSON data and the [DONE] terminator.

Example

const raw = line.trim();
if (raw === '[DONE]') { 
  return; 
}
const data = JSON.parse(raw);

Notes

The proposed fix assumes that the [DONE] terminator is always exactly [DONE] and that it is the only non-JSON data that will be encountered. Additional error handling or input validation may be necessary depending on the specific requirements of the application.

Recommendation

Apply the proposed workaround by checking for the [DONE] terminator before attempting to parse the data as JSON, as this directly addresses the root cause of the issue and prevents unnecessary parsing errors.

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