Skip to content

SSE streaming parse error with GLM-4.7 responses #8282

Closed as duplicate
Closed as duplicate

Description

@rankobp

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

Activity

  1. github-actions commented on Jan 13, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    The core issue appears to be SSE/streaming response handling when models produce multi-chunk responses. Feel free to ignore if your specific SSE concatenation issue differs from these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions