{"record":{"id":"1493971a34b4bfec","repo":"can1357/oh-my-pi","slug":"lsp-mux-environment-is-incomplete","errorCode":null,"errorMessage":"LSP mux environment is incomplete","messagePattern":"LSP mux environment is incomplete","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/lsp/mux/server.ts","lineNumber":732,"sourceCode":"\t#disarmMuxIdle(): void {\n\t\tif (this.#idleTimer) clearTimeout(this.#idleTimer);\n\t\tthis.#idleTimer = undefined;\n\t}\n\n\t#armMuxIdle(): void {\n\t\tthis.#disarmMuxIdle();\n\t\tif (this.#shuttingDown || this.#sessions.size > 0) return;\n\t\tthis.#idleTimer = setTimeout(() => {\n\t\t\tif (this.#sessions.size === 0) this.onIdle?.();\n\t\t}, MUX_IDLE_MS);\n\t}\n}\n\n/** Start the detached LSP mux selected by the CLI worker host environment. */\nexport async function startLspMuxFromEnvironment(): Promise<void> {\n\tconst endpoint = process.env[LSP_MUX_SOCKET_ENV];\n\tconst projectDir = process.env[LSP_MUX_PROJECT_DIR_ENV];\n\tif (!endpoint || !projectDir) throw new Error(\"LSP mux environment is incomplete\");\n\tdelete process.env[LSP_MUX_SOCKET_ENV];\n\tdelete process.env[LSP_MUX_PROJECT_DIR_ENV];\n\tsetProcessName(\"omp lsp mux\");\n\tconst server = new LspMuxServer();\n\tconst stopped = Promise.withResolvers<void>();\n\tserver.onIdle = () => {\n\t\tvoid server.shutdown().finally(() => {\n\t\t\tstopped.resolve();\n\t\t\tprocess.exit(0);\n\t\t});\n\t};\n\tconst cancelCleanup = postmortem.register(\"lsp-mux\", () => server.shutdown());\n\ttry {\n\t\tawait server.listen(endpoint);\n\t\tprocess.stdout.write(`${lspMuxReadyBanner(endpoint)}\\n`);\n\t\tawait stopped.promise;\n\t} finally {\n\t\tcancelCleanup();","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/lsp/mux/server.ts#L714-L750","documentation":"startLspMuxFromEnvironment() is the entrypoint for the detached mux worker process and requires two environment variables: the socket endpoint and the project directory. It throws this error when either is missing, meaning the process was started as a mux worker without the spawning parent supplying its configuration.","triggerScenarios":"The CLI worker-host entrypoint dispatches to the LSP mux worker (via the omp worker argv selector) but LSP_MUX_SOCKET_ENV or LSP_MUX_PROJECT_DIR_ENV is unset — e.g. the mux was started directly (`bun server.ts` / `node server.ts`) instead of through ensureLspMuxDaemon.","commonSituations":"Running the mux server module by hand for debugging without exporting the env vars; a spawned child losing its env; broken worker-host dispatch where the parent forgot to pass the env mapping.","solutions":["Start the mux through the normal path (`omp lsp` / ensureLspMuxDaemon) so it injects LSP_MUX_SOCKET_ENV and LSP_MUX_PROJECT_DIR_ENV.","If launching manually, export both env vars before invoking the module: LSP_MUX_SOCKET=/path/sock LSP_MUX_PROJECT_DIR=/path/project.","Check for a bug in the spawn site that drops the env mapping passed to the child."],"exampleFix":"// before\nbun packages/coding-agent/src/lsp/mux/server.ts\n// after\nLSP_MUX_SOCKET=/tmp/omp-lsp.sock LSP_MUX_PROJECT_DIR=$PWD bun packages/coding-agent/src/lsp/mux/server.ts","handlingStrategy":"validation","validationCode":"const endpoint = process.env.LSP_MUX_SOCKET;\nconst projectDir = process.env.LSP_MUX_PROJECT_DIR;\nif (!endpoint || !projectDir) throw new Error(\"Refusing to start mux worker: set LSP_MUX_SOCKET and LSP_MUX_PROJECT_DIR\");","typeGuard":"function hasMuxEnv(env: NodeJS.ProcessEnv): env is NodeJS.ProcessEnv & { LSP_MUX_SOCKET: string; LSP_MUX_PROJECT_DIR: string } {\n  return Boolean(env.LSP_MUX_SOCKET && env.LSP_MUX_PROJECT_DIR);\n}","tryCatchPattern":null,"preventionTips":["Always start the mux through ensureLspMuxDaemon / the CLI worker host, not by invoking server.ts directly.","When spawning manually, spread the parent's relevant env into the child.","Log the worker env at spawn time in debug builds to catch dropped variables."],"tags":["lsp","environment","worker","ipc"],"backgroundTag":"missing-env-var","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}