From 5d554eaddd67349a8cee687c3fc2466fb104f5d1 Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Mon, 29 Jun 2026 00:02:03 +0300 Subject: [PATCH] fix(opencode): never auto-attach to a pre-existing OpenCode instance A blind probe of the default port 4096 made the desktop hijack a user's separately-running OpenCode (e.g. the OpenCode desktop app): it attached as an external server instead of starting its own. That coupled OpenChamber's lifecycle to the foreign instance and broke initialization against an unexpected server version/config. Attaching to an external OpenCode now requires explicit opt-in via env (OPENCODE_HOST / OPENCODE_PORT / OPENCODE_SKIP_START). Without that, we always start our own managed instance on a freshly-allocated port. --- packages/web/server/lib/opencode/lifecycle.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/web/server/lib/opencode/lifecycle.js b/packages/web/server/lib/opencode/lifecycle.js index d01a9fd3..69339b7a 100644 --- a/packages/web/server/lib/opencode/lifecycle.js +++ b/packages/web/server/lib/opencode/lifecycle.js @@ -819,15 +819,15 @@ export const createOpenCodeLifecycleRuntime = (deps) => { state.lastOpenCodeError = null; state.openCodeNotReadySince = 0; syncToHmrState(); - } else if (!env.ENV_EFFECTIVE_PORT && await probeExternalOpenCode(4096)) { - console.log('Auto-detected existing OpenCode server on default port 4096'); - setOpenCodePort(4096); - state.isOpenCodeReady = true; - state.isExternalOpenCode = true; - state.lastOpenCodeError = null; - state.openCodeNotReadySince = 0; - syncToHmrState(); } else { + // We never auto-attach to an arbitrary pre-existing OpenCode instance. + // Attaching to an external server requires explicit opt-in via env + // (OPENCODE_HOST / OPENCODE_PORT / OPENCODE_SKIP_START), handled by the + // branches above. Without that opt-in we always start our OWN managed + // instance on a freshly-allocated port. A blind probe of the default + // port 4096 used to hijack a user's separately-running OpenCode (e.g. + // the OpenCode desktop app), coupling our lifecycle to theirs and + // breaking init against an unexpected server version/config. if (env.ENV_EFFECTIVE_PORT) { console.log(`Using OpenCode port from environment: ${env.ENV_EFFECTIVE_PORT}`); setOpenCodePort(env.ENV_EFFECTIVE_PORT);