Skip to content

Streaming ECONNRESET / "socket connection was closed unexpectedly" with SGLang OpenAI-compatible provider during tool-using agent runs (Qwen3.5 + reasoning content) #22803

Closed as not planned

Description

@derlajsch

Description

What happened?

When using opencode with a self-hosted SGLang server serving Qwen3.5-27B-FP8 as a custom OpenAI-compatible provider, streaming chat completions fail intermittently during agent/build-mode runs with:

  • ECONNRESET on POST /v1/chat/completions
  • UI message: Cannot connect to API: The socket connection was closed unexpectedly. For more i...
  • Auto-retry loops indefinitely (Connection reset by server, retrying in 25s - attempt #21)

There is no nginx / reverse proxy / load balancer between opencode and SGLang — it is a direct TCP connection from the opencode sidecar to http://<host>:8000/v1/chat/completions.

Sidecar error logs

ERROR service=llm providerID=aifactory modelID=qwen3.5-27b-fp8
  sessionID=... agent=build mode=primary
  error={"error":{"code":"ECONNRESET","path":"http://<host>:8000/v1/chat/completions","errno":0}}
  stream error

ERROR service=session.processor
  error=The socket connection was closed unexpectedly.
  For more information, pass `verbose: true` in the second argument to fetch()

Plugins

none

OpenCode version

1.4.3

Steps to reproduce

  1. Start SGLang serving Qwen3.5-27B-FP8 with an OpenAI-compatible endpoint:
   python3 -m sglang.launch_server \
     --model-path Qwen/Qwen3.5-27B-FP8 \
     --host 0.0.0.0 --port 8000 \
     --tp-size 2 \
     --mem-fraction-static 0.9 \
     --context-length 92000 \
     --chunked-prefill-size 8192 \
     --max-running-requests 12 \
     --reasoning-parser qwen3 \
     --tool-call-parser qwen3_coder \
     --api-key sk-
  1. Configure opencode with a custom OpenAI-compatible provider pointing directly at http://<host>:8000 (no proxy in between), model id qwen3.5-27b-fp8.

  2. Start a build-mode / agent session and give it a task that triggers tool use, e.g. "continue working on the frontend — explore the existing code structure first".

  3. Observe:

    • First few tool rounds may succeed.
    • After 1–3 rounds the stream drops with ECONNRESET / "socket connection was closed unexpectedly".
    • opencode enters an infinite retry loop (Connection reset by server, retrying in 25s - attempt #21).

Workarounds we tried

  • Switching SGLang to --tool-call-parser qwen3 (instead of qwen3_coder) changes the parser routing and appears to reduce the frequency of drops, but the issue still occurs on longer agent runs.
  • Disabling reasoning entirely (either by removing --reasoning-parser qwen3 from SGLang, or by sending chat_template_kwargs: {"enable_thinking": false} in the request) makes the ECONNRESET go away — the stream completes cleanly every time.
    However, this is not a real solution for our use case: without reasoning enabled, the model does not reliably plan or chain tool calls anymore, i.e. it is no longer agentic. Build-mode sessions become single-shot replies instead of multi-step tool-using runs, which defeats the purpose of using opencode with a reasoning model. So reasoning has to stay on, and the crash has to be fixed on the streaming-client side.

Screenshot and/or share link

Image Image

Operating System

Server (SGLang host): Ubuntu 22.04, 2× NVIDIA GPUs, SGLang in a venv, launched via systemd - Client (opencode host): Windows 11

Terminal

No response

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Apr 16, 2026
  2. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of (or closely related to) existing issues. Please check:

  3. Klausmd5 commented on Apr 16, 2026

    @Klausmd5

    having the same issue with OpenCode Desktop v1.4.6 also using Qwen3.5 via vllm

  4. mwroffo commented on Apr 17, 2026

    @mwroffo

    Having this issue on 1.3.13 CLI with Claude 4.5 sonnet via bedrock.

  5. removed
    bugSomething isn't working
    perfIndicates a performance issue or need for optimization
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. github-actions commented on Jul 5, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 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

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions