Skip to content

UI overlay breaks when Vertex AI returns truncated JSON responses #7985

Closed

Description

@Skeptomenos

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.

Activity

  1. github-actions commented on Jan 12, 2026

    @github-actions
    Contributor

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

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

  2. thdxr commented on Jan 12, 2026

    @thdxr
    Member

    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

  3. Skeptomenos commented on Jan 12, 2026

    @Skeptomenos
    Author

    @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.

  4. Skeptomenos commented on Jan 13, 2026

    @Skeptomenos
    Author

    Image

  5. Skeptomenos commented on Jan 13, 2026

    @Skeptomenos
    Author

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

  6. a1danpryde commented on Jan 13, 2026

    @a1danpryde

    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?

  7. Skeptomenos commented on Jan 13, 2026

    @Skeptomenos
    Author

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

    Image

  8. thdxr commented on Mar 25, 2026

    @thdxr
    Member

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

zenRelates to Zen

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions