Skip to content

vscode-v2 extension: fixed port 4096 conflicts on reload, server never killed #53020

Closed

Description

@guilhermespamplona-prog

Summary

The sst-dev.opencode-v2 (0.1.1) VS Code extension always spawns opencode serve on the fixed port 4096 and never kills it on deactivate, so every window reload orphans the server and the next panel open fails with Is port 4096 in use?.

Environment

  • opencode version: 2.0.22
  • OS: Linux pop-os 7.1.5-76070105-generic x86_64
  • Terminal: TERM_PROGRAM=vscode, TERM=xterm-256color, COLORTERM=truecolor
  • Shell: /bin/bash
  • Install/channel: latest
  • Active plugins: none configured (global config has 2 local MCP servers jev / jev-paid, no plugins entries; no project-local config)

Reproduction

  1. Install extension sst-dev.opencode-v2 0.1.1 with opencode CLI 2.0.22.
  2. Run Open OpenCode Assistant (Ctrl+Esc). Extension spawns opencode serve --hostname=127.0.0.1 --port=4096 — panel opens fine.
  3. Run Developer: Reload Window (or restart VS Code). The spawned serve --port=4096 process survives (orphaned).
  4. Run Open OpenCode Assistant again.

Expected Behavior

Extension reuses the existing server, kills the orphan before respawning, or picks a free port — panel opens.

Actual Behavior

Panel fails to open:

Failed to open OpenCode panel: Server exited with code 1
Server output: ServeError: ... {
  [cause]: Error: Failed to start server. Is port 4096 in use?
}

opencode.log shows the second spawn failing while the first server is still alive and serving (returning 401 on /api/info as expected for an authed server):

timestamp=... run=e2c63ccc message="cli starting" args="[\"serve\",\"--hostname=127.0.0.1\",\"--port=4096\"]" role=cli
timestamp=... run=e2c63ccc message="Sent HTTP response" http.method=GET http.url=/api/info http.status=401
timestamp=... run=08d186c4 message="cli starting" args="[\"serve\",\"--hostname=127.0.0.1\",\"--port=4096\"]" role=cli
timestamp=... run=08d186c4 message="cli process failed" cause="Cause([Fail(ServeError (cause: Error: Failed to start server. Is port 4096 in use?))])" role=cli

ss/ps at failure time:

127.0.0.1:4096 LISTEN users:(("opencode",pid=590231,fd=10))
opencode serve --hostname=127.0.0.1 --port=4096   # orphan from previous session

Additional Context

  • Extension source (0.1.1 dist/extension.js) hardcodes the port in two places:
    • Be(d){d=Object.assign({hostname:"127.0.0.1",port:4096,timeout:5e3},d??{})...
    • Be({port:4096,timeout:15e3,config:t})
  • deactivate only disposes the webview panel, it never kills the spawned server process, so every reload leaks one serve process (~150 MB).
  • Consistently reproducible (every reload).
  • Local workaround verified: patch both occurrences to port:0 so the server picks a random free port (the extension already parses the real URL from stdout). Old servers still leak but the panel opens. Killing the orphan (kill <pid of opencode serve --port=4096>) before opening the panel also works for one session.

Activity

  1. guilhermespamplona-prog commented on Oct 3, 2026

    @guilhermespamplona-prog
    Author

    Update: encontrei uma segunda incompatibilidade que torna a extensão 0.1.1 inutilizável com a CLI 2.0.22 mesmo após resolver a porta.

    O parser de startup em dist/extension.js (Be()) espera:

    if(o.startsWith("opencode server listening"))

    mas a CLI 2.0.22 imprime:

    server listening on http://127.0.0.1:PORT
    server password ...
    

    Resultado: todo spawn novo sobe um servidor saudável e mesmo assim a extensão dá Timeout waiting for server to start after 15000ms, orfanando um processo serve --port=0 a cada tentativa. Workaround local: aceitar ambos os prefixos + usar port:0.

  2. guilhermespamplona-prog commented on Oct 3, 2026

    @guilhermespamplona-prog
    Author

    Update 2: após corrigir porta + parser, o painel quebra em this.app.agents.forEach is not a function. Causa raiz: o SDK embutido (@opencode-ai/sdk ^0.6.10) chama 42 endpoints no path raiz (/agent, /session, /config, /tui/*...), mas a CLI 2.0.22 serve a API em /api/* — /agent retorna o HTML do web app, então e.data vem string e .forEach falha. Ou seja, a extensão 0.1.1 é incompatível com a CLI 2.x em 3 camadas (porta fixa, prefixo de log, layout da API). Corrigir tudo localmente seria whack-a-mole; a extensão precisaria de um rebuild contra @opencode/client 2.x.

  3. github-actions commented on Oct 3, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    • #49006: The VS Code extension hardcodes port 4096, causing panel startup failures when it is already occupied; it also notes that the server outlives the webview and a reload is required.

    For keybind-related issues, please also check our pinned keybinds documentation: #4997

  4. rekram1-node commented on Oct 14, 2026

    @rekram1-node
    Contributor

    The "OpenCode Beta" extension (sst-dev.opencode-v2) is no longer maintained and won't be updated for V2. Please use the main opencode extension (sst-dev.opencode) v1.0.0 instead, which works with the V2 CLI. Closing.

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