opencode icon indicating copy to clipboard operation
opencode copied to clipboard

UI overlay breaks when Vertex AI returns truncated JSON responses

Open Skeptomenos opened this issue 1 month ago • 7 comments

Description

When using OpenCode heavily with Vertex AI Flash models, the UI breaks with an error overlay showing:

SyntaxError: Unexpected end of JSON input
at <parse> (native)
at json (unknown)
at <anonymous> (../sdk/js/src/v2/gen/client/client.gen.ts:167:33)

Environment

  • Provider: Vertex AI (Flash models)
  • Usage pattern: Heavy/concurrent usage

Root Cause Analysis

The error occurs at client.gen.ts:167 when response.json() is called on a truncated response body. This happens when:

  • Network connection drops mid-response
  • Vertex AI times out or rate-limits under load
  • Multiple concurrent requests strain the connection

While error handling exists in the SDK (lines 169-198), the error still surfaces to the UI and breaks the interface with an overlay.

Expected Behavior

Transient JSON parse errors from provider responses should be caught and retried gracefully without breaking the UI overlay.

Actual Behavior

Error overlay appears, blocking the UI and requiring manual dismissal or restart.

Screenshot

Error Screenshot

Suggested Fix

Consider catching SyntaxError specifically in the streaming/response handling layer and treating truncated JSON as a retryable error rather than surfacing it to the UI.

Skeptomenos avatar Jan 12 '26 11:01 Skeptomenos

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

  • #7889: SDK throws 'Unexpected end of JSON input' on empty response bodies (same error at client.gen.ts:167)
  • #7715: Unexpected end of json (same error, mentions fix PR #7618)
  • #7946: Crash on double-escape abort: JSON parse error from prompt response (same SyntaxError, different trigger)
  • #7692: JSON Parse Error with Zhipu GLM-4.7: Stream chunks are concatenated incorrectly (related streaming/JSON parsing issue)

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

github-actions[bot] avatar Jan 12 '26 11:01 github-actions[bot]

do you have a way to reproduce this? we need to figure out what server request this is failing for. answer might be in logs

thdxr avatar Jan 12 '26 17:01 thdxr

@thdxr this error appears randomly, I could not identify a pattern yet. I use Opus 4.5 and Gemini 3 both hosted on Vertex, sometimes I switch models within sessions.

Will paste more information and screenshots the next time the error occurs.

Skeptomenos avatar Jan 12 '26 19:01 Skeptomenos

Image

Skeptomenos avatar Jan 13 '26 00:01 Skeptomenos

The session compacted and continued. I canceld and performed an /undo

Skeptomenos avatar Jan 13 '26 00:01 Skeptomenos

Updated Post, incl. local resolution

UPDATE: I just realized, that my error might be local. I have a typescript tool, that seems to be the culprit. When I move it away from the project folder, opencode behaves as expected. Investigating further, which function could be an issue. Already ran into zod dependency issues last week, which I thought I had fixed.

UPDATE after recovery: For me it was completely local:

The rename_note.ts tool has been successfully repaired, verified, and restored to the vault.
Root Cause Analysis (RCA) Summary
*   Duplicate Variable: The vaultRoot variable was declared twice, causing potential runtime instability.
*   Missing Error Handling: Incomplete try-catch blocks led to silent failures or crashes when encountering inaccessible directories.
*   Registration Logic: The tool was not registering because the vault's governance protocol requires a corresponding test file in .opencode/tests/ to be present and passing.
*   Module Resolution: A minor ESM export issue in the test environment (missing .js extensions) was fixed to allow tests to run.

Original Post

Model Provider: openrouter.ai Models tried: Gemini 3 Flash, Gemini 3 Pro, Deepseek 3.2

Tried 'opencode --log-level DEBUG --print-logs' but could only get INFO level in ~/.local/share/opencode/log/ , where I cannot find any anomalies.

In UI I get the same as @Skeptomenos - here for easier copy and paste

[09:32:40] [LOG] 'bootstrapping'
[09:32:41] [LOG] 'resolveSystemTheme'
[09:32:41] [LOG] '{"type":"home"}'
[09:32:41] [LOG] [
      '#2d2a2e', '#ff6188',
      '#a9dc76', '#ffd866',
      '#fc9867', '#ab9df2',
      '#78dce8', '#fcfcfa',
      '#727072', '#ff6188',
      '#a9dc76', '#ffd866',
      '#fc9867', '#ab9df2',
      '#78dce8', '#fcfcfa'
    ]
[09:33:27] [LOG] 'navigate' { type: 'session', sessionID: 'ses_44d84d038ffeHid9DxrrgWEBCh' }
[09:33:27] [LOG] '{"type":"session","sessionID":"ses_44d84d038ffeHid9DxrrgWEBCh"}'
[09:33:27] [LOG] 'TSWorker:' 'Loading from local path: /$bunfs/root/tree-sitter-markdown-411r6y9b.wasm'
[09:33:27] [LOG] 'TSWorker:' 'Loading from local path: /$bunfs/root/highlights-r812a2qc.scm'
[09:33:27] [LOG] 'TSWorker:' 'Loading from local path: /$bunfs/root/injections-73j83es3.scm'
[09:33:27] [LOG] 'TSWorker:' 'Loading from local path: /$bunfs/root/tree-sitter-markdown_inline-j5349f42.wasm'
[09:33:27] [LOG] 'TSWorker:' 'Loading from local path: /$bunfs/root/highlights-x6tmsnaa.scm'
[09:34:50] [ERROR] Error: Unexpected end of JSON input
    SyntaxError: Unexpected end of JSON input
        at <parse> (:0)
        at json (unknown)
        at <anonymous> (../sdk/js/src/v2/gen/client/client.gen.ts:167:33)
        at processTicksAndRejections (native:7:39)

For me closing opencode, changing session, or creating a new one does not help. Is there a work around at the moment?

a1danpryde avatar Jan 13 '26 08:01 a1danpryde

Ok, seems to be consistent. After compaction OpenCode (probably a Sisyphus feature) auto response with "Continue" when i stop afterwards the issue appears.

Image

Skeptomenos avatar Jan 13 '26 11:01 Skeptomenos