Skip to content

[Bug]: Opencode server frequently disconnects / connection lost #2579

@fadilsflow

Description

@fadilsflow

Description

When using opencode as a provider in t3code, the connection to the opencode server frequently drops/disconnects. Sessions suddenly die with no automatic reconnection.

Root Cause (from source code analysis)

  1. No reconnect logic - t3code spawns opencode serve as a child process. When that process crashes or exits, the session dies immediately with no auto-restart. (apps/server/src/provider/Layers/OpenCodeAdapter.ts)

  2. SSE event stream is fragile - Real-time communication uses Server-Sent Events (long-lived HTTP streaming) with no heartbeat/keepalive mechanism.

  3. Short startup timeout (5 seconds) - DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 5000. If the server is slow to start (e.g., due to many plugins/MCP/LSP servers), it times out.

  4. Text generation server idle TTL of 30 seconds - OPENCODE_TEXT_GENERATION_IDLE_TTL = "30 seconds". The shared server is killed after 30 seconds of inactivity. (apps/server/src/textGeneration/OpenCodeTextGeneration.ts)

  5. No clear error message in UI - Users only see "disconnected" without knowing the actual cause.

Environment

  • t3code version:
  • opencode version:
  • OS:

Steps to Reproduce

  1. Open t3code, select opencode as provider
  2. Start a session and use it for a while
  3. Let it sit idle, or just let the server run
  4. Session suddenly disconnects / connection lost

Expected Behavior

  • Stable connection or auto-reconnect when disconnected
  • Clear error messages when something goes wrong
  • Server should not be killed after short idle periods

Additional Context

Related issues: #2378 (t3code should resume same conversation after idle timeout)

Metadata

Metadata

Assignees

No one assigned

    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