Skip to content

[global-sdk] event stream failed race condition on startup and after config hot-edit causes UI to hang indefinitely #41986

Closed as not planned

Description

@hopyrez366

Bug Description

After starting opencode or after editing opencode.json, the renderer logs show:

[error] [global-sdk] event stream failed [object Object]

This occurs ~281ms after server ready is logged in main.log. The UI displays "Reasoning" animation but no request is ever sent to the AI server. The only way to recover is to resend a message or create a new chat, which re-establishes the connection.

Steps to Reproduce

  1. Start opencode (or edit opencode.json while running)
  2. Send any message in a chat
  3. UI shows "Reasoning" spinner indefinitely
  4. Check renderer.log: [global-sdk] event stream failed [object Object]
  5. No HTTP request reaches the configured AI server

Expected Behavior

The SDK should retry establishing the event stream automatically, or wait for sidecar to be fully ready before attempting connection.

Actual Behavior

Connection fails silently on first attempt. UI state is not synchronized with actual connection status. User must manually "kick" by resending message or creating new chat.

Environment

  • opencode version: 1.18.16 (Tauri desktop)
  • Platform: Linux (Ubuntu/Debian)
  • Provider: custom OpenAI-compatible (@ai-sdk/openai-compatible)
  • Sidecar URL: http://127.0.0.1:46137

Logs

main.log:

[info] awaiting server ready
[info] server ready { url: "http://127.0.0.1:46137" }

renderer.log (281ms later):

[error] [global-sdk] event stream failed [object Object]

Root Cause Analysis

Race condition between sidecar server ready event and SDK initialization. The renderer attempts to establish an event stream before the internal connection pool is fully initialized, especially after config hot-edit when sidecar restarts but renderer does not receive a proper readiness notification.

Suggested Fix

  • Add retry logic with exponential backoff for [global-sdk] event stream failed errors
  • Ensure renderer waits for a confirmed ready state from sidecar before attempting SDK initialization
  • Sync UI "Reasoning" state with actual connection status to prevent indefinite spinner when connection is down

Activity

  1. github-actions commented on Aug 12, 2026

    @github-actions
    Contributor

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

    The core symptom — renderer losing the event stream with no recovery, sidecar appearing ready but connection failing — matches across all three reports, though your case specifically adds the startup race condition timing and config hot-edit trigger.

  2. axsuul commented on Aug 24, 2026

    @axsuul

    Seeing what looks like the same startup race with a headless opencode serve (1.18.18, Linux), driven by an SDK client (Paseo daemon), so this is not desktop-specific.

    Timeline from the client journal plus opencode.db timestamps: the server answers HTTP (session.create) 2 seconds after spawn, but a /global/event subscription opened right at startup delivers nothing, not even the initial greeting, for 30+ seconds. The client's 30s first-record deadline fires and the run dies. The consumer recovers on a later reconnect against the same server and session.

    Once a server is past startup, fresh subscribers get their first SSE record in a few ms (checked against 18 running servers), so the bad window is only right around boot. Happy to share logs and timestamps if useful.

  3. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions