Skip to content

bug: UI stuck on 'thinking' indefinitely after stream error, no error displayed or state recovery #32366

Description

@Superissac

Issue

When a stream error occurs (e.g., AI_APICallError, socket closed unexpectedly), the desktop UI gets stuck showing "thinking..." indefinitely. No error message is displayed, no state recovery happens, and the session becomes unusable. The user must restart the app to recover.

Root Cause Analysis

After analyzing multiple server logs from debug dumps:

  1. Stream errors are frequent but silently swallowed

    • AI_APICallError: <none> — empty error object, no details from the upstream API
    • AI_APICallError: The socket connection was closed unexpectedly — upstream proxy terminates the SSE stream mid-response
    • These errors are logged on the server side but never propagated to the UI
  2. UI state machine never transitions out of 'thinking'

    • After a stream error, the server logs show the session is dead (no further stream events)
    • But the desktop UI continues displaying "thinking..." with no cancel button or error indicator
    • The frontend apparently waits for a stream event that will never come
  3. No automatic retry or timeout

    • No retry mechanism after stream failure
    • No client-side timeout to abort stuck states
    • User must manually cancel or restart the app
  4. Server log stops processing

    • In one dump, the last log entry at 2026-06-15T01:46:02Z was a cancel event
    • After that, zero log entries despite the UI showing "thinking"
    • This confirms the server stopped processing but the UI never received this state change

Server Log Evidence

# Frequent silent stream errors (no error detail)
level=ERROR message="stream error" providerID=YerPlan modelID=qwen3.6-plus error.error="AI_APICallError: <none>"

# Socket-level failures
level=ERROR message="stream error" error.error="AI_APICallError: Cannot connect to API: The socket connection was closed unexpectedly"

# After stream errors, server stops responding but UI stays 'thinking'
level=INFO message=cancel session.id=ses_13898e204ffemfGewCcp9BrPCN
# ← zero further log entries after this point (01:46 UTC)

Steps to Reproduce

  1. Connect opencode desktop to an API provider via an openai-compatible proxy (e.g., https://api.xxx.com/v1)
  2. Use a worktree session on a local project directory
  3. Send a message that triggers a long-running response
  4. Wait for the upstream proxy to drop the connection (intermittent, but happens frequently with unstable proxies)
  5. Observe: UI stuck on "thinking...", no error shown, session unresponsive

Expected Behavior

  1. Display an error message when the stream fails (e.g., "Connection lost. Retry?")
  2. Provide a "Retry" or "Cancel" button
  3. Implement a client-side timeout to prevent indefinite stuck states
  4. Auto-recover when the server stops responding

Environment

  • opencode: 1.17.7 (Desktop app)
  • OS: macOS darwin arm64 (M-series)
  • Electron: 42.3.3 / Chrome 148
  • Provider: openai-compatible proxy (not direct Anthropic/OpenAI)
  • Model: qwen3.6-plus (via proxy)
  • Node: 24.15.0

Related Issues

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