Skip to content

cli: opencode run hangs before session creation on Linux VPS (v2.1.4 / v2.0.32) #59287

Closed

Description

@georlitv-coder

Summary

On a Linux VPS, opencode run (V2, v2.1.4 and v2.0.32) hangs during initialization: no session is created, stdout stays empty, and no error is emitted. The same hang occurs with a clean HOME (no config, no credentials) using a free model. Direct calls to the provider API from the same host succeed, so the provider and network egress are functional.

This looks related to the V1 report in #38723 (hang before session creation; established connection to the model registry held open).

Environment

  • opencode version: 2.1.4 (also reproduced on 2.0.32)
  • OS: Ubuntu 24.04.4 LTS, Linux 6.8 x86_64 (VPS, direct outbound access, no proxy)
  • Terminal: none — non-interactive SSH (TERM unset), ssh host 'opencode run …'
  • Shell: /bin/bash (server default)
  • Install/channel: curl -fsSL https://opencode.ai/v2/install | bash (latest channel)
  • Active plugins: none. Config contains one remote MCP server; the bug also reproduces with no user config at all

Reproduction

  1. On a clean account/home (no ~/.config/opencode, no credentials):

    mkdir -p /tmp/oc-repro && cd /tmp/oc-repro
    HOME=/tmp/oc-clean timeout 90 opencode run --auto \
      -m opencode/deepseek-v4.1-flash-free "Reply with exactly: OK"
    echo "exit=$?"
  2. The process stays alive with zero stdout; it exits only via the external timeout (exit=124).

  3. With a configured instance (provider key + a remote MCP server), the same command hangs the same way; the server log stops after location/MCP initialization and never reaches session creation.

Expected Behavior

The run creates a session, performs the model request, and prints the model's answer (OK). Direct API calls from the same machine complete in ~2 seconds.

Actual Behavior

  • No output, no error, no session; only an external timeout ends it.

  • Server log tail during the hang (DEBUG level):

    message="location services booted" directory=/tmp/oc-repro
    message="mcp connected" server=… tools=4
    message="Sent HTTP response" http.method=GET http.url=/api/event http.status=200
    <nothing further>
    
  • While hung, the managed service holds ESTABLISHED connections to the model registry / provider endpoints, e.g.:

    ESTAB 185.x.x.x:39522 -> 8.6.112.5:443    (models.opencode.ai / api.opencode.ai)
    ESTAB 185.x.x.x:51566 -> 172.65.90.22:443 (opencode.ai)
    
  • curl https://api.models.dev from the host fails (connection error, http_code=000), while https://models.dev, https://models.opencode.ai/api.json and https://opencode.ai are reachable.

Additional Context

  • Direct provider check from the same host (no opencode involved):

    POST https://opencode.ai/inference/go/openai/v1/chat/completions  (stream:true)
    -> HTTP 200, first chunk in ~2.6s
    
  • Note: the gateway requires an x-opencode-session header; without it the API answers 400 MissingSessionID, with it the completion succeeds. This suggests the CLI stalls before/while sending the session-scoped request.

  • Read-only commands (--version, models, auth list) respond instantly, including while run hangs.

  • Worked exactly once immediately after a fresh install (free model returned OK), then every subsequent attempt hung — consistent with the intermittent behaviour described in opencode run intermittently hangs during init — no session created, no output, no error (~56% failure rate observed) #38723.

  • Tried without change: v2.0.32 vs v2.1.4, clean HOME (fresh DB/config), explicit opencode serve --port … + --server with OPENCODE_PASSWORD (server responds over HTTP), OPENCODE_DISABLE_AUTOUPDATE=1, OPENCODE_DISABLE_MODELS_FETCH=1, OPENCODE_DISABLE_FILEWATCHER=1, multiple models (free and paid).

  • No secrets or private addresses included in this report.

Activity

  1. opencode-agent commented on Oct 26, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I could reproduce this on 2.1.4, and it still happens on the latest dev (5bf3e82).

    When stdin is not a terminal, opencode run waits for stdin to close before it creates a session, even when the prompt is given as an argument. ssh host 'opencode run …' (without -n) gives the remote command a stdin pipe that never closes, so the run waits forever with no output and no error. That matches what you saw.

    With a clean HOME:

    • opencode run --auto -m <model> "Reply with exactly: OK" </dev/null gets past this point straight away. In my test it reaches the model lookup and fails at once, because I used a model that doesn't exist.
    • (sleep 60) | timeout 20 opencode run --auto -m <model> "…" prints nothing and is only stopped by timeout (exit 124).

    The script below reproduces it.

    Until this is fixed, ssh -n host 'opencode run …' or appending </dev/null to the command should avoid the hang. If either one still hangs for you, please tell us. That would point to a second cause, such as the model registry connections you saw.

    Related: #38723 is the v1 report of the same symptom; its comments trace it to the same stdin read.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #59287: `opencode run "<msg>"` blocks forever when stdin is a pipe that never closes
    # (what `ssh host 'opencode run ...'` without -n gives the remote command).
    # Usage: OC="opencode" ./repro.sh   (or OC="bun ... packages/cli/src/index.ts" for a checkout)
    OC=${OC:-opencode}
    export HOME=$(mktemp -d)            # clean home: no config, no credentials
    cd "$(mktemp -d)"
    $OC --version
    echo "--- stdin closed (</dev/null): returns immediately with a model error"
    timeout 40 $OC run --auto -m fake/none "Reply with exactly: OK" </dev/null; echo "exit=$?"
    echo "--- stdin is an open pipe that never sends EOF: hangs with no output until timeout"
    (sleep 60) | timeout 20 $OC run --auto -m fake/none "Reply with exactly: OK"; echo "exit=$? (124 = killed by timeout)"

    Run it: bash repro.sh

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions