Repository navigation
Open
Labels
Description
Summary
opencode run can hang indefinitely before creating a session when the client's connection buffers the initial server-sent event on GET /api/event. The CLI opens the event stream, never receives server.connected, and sends no subsequent request (no session creation, no prompt). It exits only when the caller times out or aborts; there is no diagnostic output.
Environment
- opencode version: 2.2.6 (client and server)
- OS (server): Darwin 27.0.0 arm64 (macOS)
- OS (client): Ubuntu 24.04.5 LTS (x86_64), cloud VM
- Terminal: non-interactive / no TTY (scripted invocation)
- Shell: /bin/bash (GNU bash 5.2.21)
- Install/channel: server via Homebrew (latest); client via the official v2 installer (https://opencode.ai/v2/install), npm package
@opencode/cli-linux-x64installed to~/.opencode/bin - Active plugins: none
Reproduction
- On a server, run
opencode serve --hostname 0.0.0.0 --port 4096withOPENCODE_SERVER_PASSWORDset. - From a client host whose egress path buffers SSE responses (in this case a cloud VM behind a Tailscale tunnel proxy), set
OPENCODE_PASSWORDand runopencode run --auto --server http://<server>:4096 "say pong"from a working directory that exists on the server. - Observe the CLI: no output, no session created, until the command is killed.
Expected Behavior
opencode run should either complete the turn, or fail with a clear error or timeout that identifies the stalled event subscription.
Actual Behavior
The CLI hangs indefinitely. No session is created on the server, and the only request recorded server-side is the event stream subscription:
GET /api/event 200 span=14283 (14.3s)
GET /api/event 200 span=45137 (45.1s)
GET /api/event 200 span=93069 (93.1s, matches a 90s caller timeout)
GET /api/event 200 span=59537 (59.5s)
--auto does not change the behavior, so this is not a wait on a permission prompt.
Additional Context
- The server sends an initial event immediately on subscribe (96 bytes):
data: {"type":"server.connected", ...}followed by: heartbeat. - Through the buffering proxy, an idle subscription received only response headers (~352 bytes in 12s) and no event data; events arrived only once another session produced traffic (~4.2KB in 18s).
- Against the same server from a client on the same host,
opencode runcompletes in ~1.6s, and the/api/eventrequest lives exactly that long. opencode modelsand session listing work when the client cwd exists on the server, so name resolution, authentication (Basicopencode:<password>), and model fetching are all fine.- Workaround: create the session and submit the prompt through
POST /api/session/<id>/promptand poll the session instead of usingopencode run. - Suggestion: log the startup phase (server resolved, subscribing to events, session created) at debug level, and add a timeout for the initial
server.connectedevent.
Activity
opencodejr commentedon Nov 8, 2026
Thanks for the detailed report. I was able to reproduce this on 2.2.6, and it still happens on the latest
dev(5a47777).What I did:
opencode servewith a password, plus a small reverse proxy in front of it. The proxy passes everything through, except that forGET /api/eventit sends the response headers and holds back the event data, like a buffering proxy would.opencode run --auto --server <proxy> "say pong". The CLI requested/api/infoand/api/location, created a session, opened/api/event, and then did nothing: no prompt was sent, nothing was printed, and it ran until it was killed. Exiting then took another 10 seconds.One small difference: here the session is created before the event subscription. The hang itself matches what you described.
It looks like the CLI waits for the initial
server.connectedevent with no timeout and no diagnostic output. The script below reproduces it.Reproduction script (repro.sh)
Run it:
bash repro.shr266-tech commentedon Nov 8, 2026
I prepared a focused CLI fix at
7682f5a4ca. It bounds the initial event wait to 10 seconds, closes the subscription on timeout or cancellation, and removes the deadline after the first event arrives.Real CLI subprocesses against local HTTP fixtures on macOS confirmed:
/api/eventbuffering.Validation: 390 CLI tests passed, 9 skipped; the 25 non-interactive tests passed 10 repetitions; repository lint and 33 typecheck tasks passed. The cancellation regression fails on unmodified dev. No model requests were made; the reported tunnel and Windows were not tested.
I have three open PRs here and previously hit the per-user submission limit, so I am sharing the tested branch in the meantime.
AI-assisted fix and validation.
fix(cli): bound the first event of a stalled stream and report it