[Bug] JSON Parse Error with Zhipu GLM-4.7: Stream chunks are concatenated incorrectly #4668

Open
opened 2026-02-16 17:44:57 -05:00 by yindo · 11 comments
Owner

Originally created by @yangshenlong on GitHub (Jan 10, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Description: I encountered a JSON Parse Error when using the Zhipu GLM-4.7 model. It seems like the stream parser fails to handle the boundary between two data chunks correctly, leading to invalid JSON.

The Error: The error message shows that the end of the previous message and the start of the next data: chunk are stuck together without proper separation.

Error Log / Evidence:

AI_JSONParseError: JSON parsing failed: Text: ... "role":"assistant"data: {"id": ... Error message: JSON Parse error: Expected '}'

As seen in the log, the string "role":"assistant" is immediately followed by data:, missing the closing brace } and likely a newline character.

Environment:

Model: Zhipu GLM-4.7 (configured via zhipu/glm-4.7)

Plugin: OMO / OpenCode

Image

Plugins

Z.ai/GLM-4.7 ; OhMyOpencode

OpenCode version

1.0.152

Steps to reproduce

  1. Configure the OMO plugin to use Zhipu GLM-4.7 as the default model for the 'Sisyphus' agent (or set it in the model configuration).
  2. Open the OMO interface and select the 'Sisyphus' mode.
  3. Input a task to trigger the agent (e.g., "Analyze this project" or "Write a simple snake game").
  4. Wait for the model to start streaming the response.
  5. The AI_JSONParseError occurs immediately when the model returns a response, interrupting the stream.

Screenshot and/or share link

No response

Operating System

window11

Terminal

WindowsTerminal in Trae

Originally created by @yangshenlong on GitHub (Jan 10, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description Description: I encountered a JSON Parse Error when using the Zhipu GLM-4.7 model. It seems like the stream parser fails to handle the boundary between two data chunks correctly, leading to invalid JSON. The Error: The error message shows that the end of the previous message and the start of the next data: chunk are stuck together without proper separation. Error Log / Evidence: AI_JSONParseError: JSON parsing failed: Text: ... "role":"assistant"data: {"id": ... Error message: JSON Parse error: Expected '}' As seen in the log, the string "role":"assistant" is immediately followed by data:, missing the closing brace } and likely a newline character. Environment: Model: Zhipu GLM-4.7 (configured via zhipu/glm-4.7) Plugin: OMO / OpenCode <img width="777" height="132" alt="Image" src="https://github.com/user-attachments/assets/e191786c-6b74-4e1e-8e47-da8d9e30fc86" /> ### Plugins Z.ai/GLM-4.7 ; OhMyOpencode ### OpenCode version 1.0.152 ### Steps to reproduce 1. Configure the OMO plugin to use Zhipu GLM-4.7 as the default model for the 'Sisyphus' agent (or set it in the model configuration). 2. Open the OMO interface and select the 'Sisyphus' mode. 3. Input a task to trigger the agent (e.g., "Analyze this project" or "Write a simple snake game"). 4. Wait for the model to start streaming the response. 5. The `AI_JSONParseError` occurs immediately when the model returns a response, interrupting the stream. ### Screenshot and/or share link _No response_ ### Operating System window11 ### Terminal WindowsTerminal in Trae
yindo added the windowsbug labels 2026-02-16 17:44:57 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 10, 2026):

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

  • #2188: JSON parsing failed: Text - shows the same JSON parsing error pattern with incomplete JSON (Expected '}')
  • #5890: Incomplete JSON when writing out files - reports similar incomplete JSON issues when handling model responses
  • #2840: Empty SSE Events Leak Through Opencode Stream Processor - related to SSE stream handling and data concatenation
  • #3596: SSE Stream Bug: Out-of-Order thinking_delta via LiteLLM → AWS Bedrock - related to stream chunk ordering issues

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 10, 2026): This issue might be a duplicate of existing issues. Please check: - #2188: JSON parsing failed: Text - shows the same JSON parsing error pattern with incomplete JSON (`Expected '}'`) - #5890: Incomplete JSON when writing out files - reports similar incomplete JSON issues when handling model responses - #2840: Empty SSE Events Leak Through Opencode Stream Processor - related to SSE stream handling and data concatenation - #3596: SSE Stream Bug: Out-of-Order thinking_delta via LiteLLM → AWS Bedrock - related to stream chunk ordering issues Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Jan 10, 2026):

I think this is the plugin failign to send back valid stuff when proxied through it perhaps?

@rekram1-node commented on GitHub (Jan 10, 2026): I think this is the plugin failign to send back valid stuff when proxied through it perhaps?
Author
Owner

@yangshenlong commented on GitHub (Jan 10, 2026):

I think this is the plugin failign to send back valid stuff when proxied through it perhaps?我怀疑这可能是插件在通过代理时无法返回有效数据导致的?

Thanks for the response!

To help you narrow down the issue, I'd like to clarify my setup details. I think this might be a specific parsing issue rather than a general network failure:

  1. Custom API Key: I am using my own API Key (configured in the zhipu provider), NOT the free built-in service provided by OpenCode. So the request should be going directly from my client to Zhipu.
  2. Proxy Environment: I am indeed using a local network proxy (VPN).
  3. Control Group (Crucial): Under the exact same proxy and custom API key settings, the Minimax model works perfectly fine. The connection is stable and the response is parsed correctly.

The JSON Parse Error only happens with GLM-4.7. This makes me suspect that the issue is specific to how the plugin handles GLM-4.7's data stream (perhaps the plugin isn't handling concatenated JSON chunks/sticky packets correctly), while Minimax's stream format is handled fine.

(P.S. English is not my first language, so please excuse any unnatural phrasing.

@yangshenlong commented on GitHub (Jan 10, 2026): > I think this is the plugin failign to send back valid stuff when proxied through it perhaps?我怀疑这可能是插件在通过代理时无法返回有效数据导致的? Thanks for the response! To help you narrow down the issue, I'd like to clarify my setup details. I think this might be a specific parsing issue rather than a general network failure: 1. **Custom API Key**: I am using my **own API Key** (configured in the `zhipu` provider), NOT the free built-in service provided by OpenCode. So the request should be going directly from my client to Zhipu. 2. **Proxy Environment**: I am indeed using a local network proxy (VPN). 3. **Control Group (Crucial)**: Under the **exact same proxy and custom API key settings**, the **Minimax** model works perfectly fine. The connection is stable and the response is parsed correctly. The `JSON Parse Error` only happens with **GLM-4.7**. This makes me suspect that the issue is specific to how the plugin handles GLM-4.7's data stream (perhaps the plugin isn't handling concatenated JSON chunks/sticky packets correctly), while Minimax's stream format is handled fine. (P.S. English is not my first language, so please excuse any unnatural phrasing.
Author
Owner

@DarkPocket commented on GitHub (Jan 11, 2026):

尝试用最新版本1.1.13再试试 ,
1.0.152是旧版本

@DarkPocket commented on GitHub (Jan 11, 2026): 尝试用最新版本1.1.13再试试 , 1.0.152是旧版本
Author
Owner

@rekram1-node commented on GitHub (Jan 11, 2026):

Oh guys make sure you are on the latest version I think that's the issue here

@rekram1-node commented on GitHub (Jan 11, 2026): Oh guys make sure you are on the latest version I think that's the issue here
Author
Owner

@APE-147 commented on GitHub (Jan 12, 2026):

Currently, I am using version 1.1.13, and when using it with Oh My Opencode and connecting via /connect with OpenAI OAuth, the GPT series models frequently encounter the following situation.

Image
@APE-147 commented on GitHub (Jan 12, 2026): Currently, I am using version 1.1.13, and when using it with Oh My Opencode and connecting via /connect with OpenAI OAuth, the GPT series models frequently encounter the following situation. <img width="1636" height="812" alt="Image" src="https://github.com/user-attachments/assets/75bd677b-8f01-4327-832c-68156acc1d53" />
Author
Owner

@rekram1-node commented on GitHub (Jan 12, 2026):

Are you running through some proxy or something that isnt handling streams correctly?

@rekram1-node commented on GitHub (Jan 12, 2026): Are you running through some proxy or something that isnt handling streams correctly?
Author
Owner

@APE-147 commented on GitHub (Jan 12, 2026):

After the version update, I uninstalled the opencode-openai-codex-auth plugin and switched to using /connect for OAuth authentication, which should not involve a proxy in between.

@APE-147 commented on GitHub (Jan 12, 2026): After the version update, I uninstalled the opencode-openai-codex-auth plugin and switched to using /connect for OAuth authentication, which should not involve a proxy in between.
Author
Owner

@rekram1-node commented on GitHub (Jan 14, 2026):

which should not involve a proxy in between.

I meant network proxies

@rekram1-node commented on GitHub (Jan 14, 2026): > which should not involve a proxy in between. I meant network proxies
Author
Owner

@APE-147 commented on GitHub (Jan 14, 2026):

Thank you for your patient reply.
Based on my local environment, the system proxy on my machine: not enabled. scutil --proxy is empty; and I am directly connecting via /connect Oauth, there should be no remote reverse proxy.

@APE-147 commented on GitHub (Jan 14, 2026): Thank you for your patient reply. Based on my local environment, the system proxy on my machine: not enabled. scutil --proxy is empty; and I am directly connecting via /connect Oauth, there should be no remote reverse proxy.
Author
Owner

@chindris-mihai-alexandru commented on GitHub (Jan 27, 2026):

I'm also experiencing this exact issue with Devstral-2-123B-Instruct-2512 via NVIDIA NIM provider in OpenCode v1.1.36

Error message:

Invalid input for tool tavily_tavily_search: JSON parsing failed: Text: {"query": "current weather in Viseu de Sus, Romania, "max_results": 1{"query": "current weather in Viseu de Sus, Romania", "max_results": 1}.
Error message: JSON Parse error: Expected '}'

Observations:

  • The JSON payload is being duplicated/concatenated (notice the query appears twice)
  • Same stream chunk handling issue as reported for GLM-4.7
  • Not a proxy issue in my case - direct API call
  • Model loops infinitely retrying the same malformed tool call

This suggests the stream chunk concatenation issue affects multiple providers (Z.AI GLM-4.7, NVIDIA NIM Devstral-2), not just one.

@chindris-mihai-alexandru commented on GitHub (Jan 27, 2026): I'm also experiencing this exact issue with **Devstral-2-123B-Instruct-2512** via NVIDIA NIM provider in OpenCode v1.1.36 **Error message:** ``` Invalid input for tool tavily_tavily_search: JSON parsing failed: Text: {"query": "current weather in Viseu de Sus, Romania, "max_results": 1{"query": "current weather in Viseu de Sus, Romania", "max_results": 1}. Error message: JSON Parse error: Expected '}' ``` **Observations:** - The JSON payload is being duplicated/concatenated (notice the query appears twice) - Same stream chunk handling issue as reported for GLM-4.7 - Not a proxy issue in my case - direct API call - Model loops infinitely retrying the same malformed tool call This suggests the stream chunk concatenation issue affects multiple providers (Z.AI GLM-4.7, NVIDIA NIM Devstral-2), not just one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4668