SSE streaming parse error with GLM-4.7 responses #5432

Closed
opened 2026-02-16 17:52:36 -05:00 by yindo · 0 comments
Owner

Originally created by @rankobp on GitHub (Jan 13, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Using opencode with GLM-4.7 (Z.AI) causes frequent AI_JSONParseError during streaming. The SSE handler incorrectly concatenates chunks, creating malformed JSON.

Error:
AI_JSONParseError: JSON parsing failed: Text: {"id":"20260114043705b7f7de19603a48fd","created":1768336625,"object":"chat.completion.chunk","model":"glm-4.7","choices":[{"index":0,"delta":{"role":"adata: {"id":"20260114043917eff1a1dd435a4df0","created":1768336757,"object":"chat.completion.chunk","model":"glm-4.7","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"Now"}}]}. Error message: JSON Parse error: Expected '}'

Root Cause:
SSE chunks (each prefixed with data: ) are being concatenated instead of parsed separately. The result is {"id":"...data: {"id":"... - an incomplete first JSON object.

Expected:

  • Split on data: prefix
  • Parse each chunk as separate JSON
  • Handle models with reasoning_content

Actual:

  • Chunks concatenated without parsing, causing parse failure.

Plugins

No response

OpenCode version

1.1.18

Steps to reproduce

  1. Use opencode with GLM-4.7
  2. Run prompts that generate longer responses (multiple chunks)
  3. Occurs frequently with reasoning tokens

Screenshot and/or share link

No response

Operating System

Ubuntu 22.04.3

Terminal

GNOME Terminal 3.52.0

Originally created by @rankobp on GitHub (Jan 13, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description Using opencode with GLM-4.7 (Z.AI) causes frequent AI_JSONParseError during streaming. The SSE handler incorrectly concatenates chunks, creating malformed JSON. Error: `AI_JSONParseError: JSON parsing failed: Text: {"id":"20260114043705b7f7de19603a48fd","created":1768336625,"object":"chat.completion.chunk","model":"glm-4.7","choices":[{"index":0,"delta":{"role":"adata: {"id":"20260114043917eff1a1dd435a4df0","created":1768336757,"object":"chat.completion.chunk","model":"glm-4.7","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"Now"}}]}. Error message: JSON Parse error: Expected '}'` Root Cause: SSE chunks (each prefixed with data: ) are being concatenated instead of parsed separately. The result is {"id":"...data: {"id":"... - an incomplete first JSON object. Expected: - Split on data: prefix - Parse each chunk as separate JSON - Handle models with reasoning_content Actual: - Chunks concatenated without parsing, causing parse failure. ### Plugins _No response_ ### OpenCode version 1.1.18 ### Steps to reproduce 1. Use opencode with GLM-4.7 2. Run prompts that generate longer responses (multiple chunks) 3. Occurs frequently with reasoning tokens ### Screenshot and/or share link _No response_ ### Operating System Ubuntu 22.04.3 ### Terminal GNOME Terminal 3.52.0
yindo added the bug label 2026-02-16 17:52:36 -05:00
yindo closed this issue 2026-02-16 17:52:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5432