{"record":{"id":"1cde13b3d0906a49","repo":"can1357/oh-my-pi","slug":"lsp-server-config-command-failed-to-initialize","errorCode":null,"errorMessage":"LSP server ${config.command} failed to initialize recently: ${recentFailure.message}","messagePattern":"LSP server (.+?) failed to initialize recently: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/lsp/client.ts","lineNumber":992,"sourceCode":"\t\t}\n\t\tconst clientAfterReload = clients.get(key);\n\t\tif (clientAfterReload && !invalidatedClientKeys.has(key)) {\n\t\t\tclientAfterReload.lastActivity = Date.now();\n\t\t\treturn clientAfterReload;\n\t\t}\n\t\tconst lockAfterReload = clientLocks.get(key);\n\t\tif (lockAfterReload) return lockAfterReload.promise;\n\t\tif (invalidatedClientKeys.has(key)) {\n\t\t\tthrow new Error(`LSP configuration was superseded during reload: ${config.command}`);\n\t\t}\n\t}\n\n\t// Fail fast on a recent deterministic init failure instead of re-spawning\n\t// a broken server (and paying its full init wait) on every call.\n\tconst recentFailure = initFailures.get(key);\n\tif (recentFailure) {\n\t\tif (Date.now() - recentFailure.at < INIT_FAILURE_BACKOFF_MS) {\n\t\t\tthrow new Error(`LSP server ${config.command} failed to initialize recently: ${recentFailure.message}`);\n\t\t}\n\t\tinitFailures.delete(key);\n\t}\n\n\t// Create new client with lock\n\tconst lockToken = Symbol();\n\tconst clientPromise = (async () => {\n\t\tconst baseCommand = config.resolvedCommand ?? config.command;\n\t\tconst baseArgs = config.args ?? [];\n\n\t\t// Wrap with lspmux if available and supported\n\t\tconst { command, args, env } = isLspmuxSupported(baseCommand)\n\t\t\t? await getLspmuxCommand(baseCommand, baseArgs)\n\t\t\t: { command: baseCommand, args: baseArgs };\n\n\t\t// Prefer the broker-shared server unless an external lspmux wrapper is\n\t\t// already multiplexing this command. Any shared-path failure falls back\n\t\t// to a private spawn so LSP never regresses on broker trouble.","sourceCodeStart":974,"sourceCodeEnd":1010,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/lsp/client.ts#L974-L1010","documentation":"The client tracks deterministic initialization failures per server key with a backoff window (INIT_FAILURE_BACKOFF_MS). If the server failed to initialize recently, the library refuses to respawn it immediately — respawning a broken server on every tool call wastes the full init timeout each time — and throws with the original failure message.","triggerScenarios":"An earlier attempt to start the LSP server failed (crash, bad command, timeout), and a new LSP-dependent call arrives within the backoff window.","commonSituations":"LSP binary not installed or not on PATH; server crashes on startup due to bad project state; server requires a newer runtime version than installed.","solutions":["Fix the root cause reported in the message (install the server binary, fix the project)","Wait out the backoff window (INIT_FAILURE_BACKOFF_MS) and retry","Explicitly reset/reload LSP config to clear the failure cache"],"exampleFix":"// before: immediate retry loop against dead server\nfor (;;) await lspDiagnostics(file);\n// after: back off and surface root cause\ntry { await lspDiagnostics(file); }\ncatch (e) { logger.warn(e.message); await Bun.sleep(BACKOFF_MS); }","handlingStrategy":"try-catch","validationCode":"// Verify the server command is runnable before invoking LSP\nconst bin = $which(config.command);\nif (!bin) throw new Error(`LSP command not on PATH: ${config.command}`);","typeGuard":null,"tryCatchPattern":"try {\n  const client = await getConfigOrCreate(config, cwd);\n} catch (err) {\n  if (err.message.startsWith(`LSP server ${config.command} failed to initialize recently`)) {\n    // Surface the root cause to the user instead of hammering the dead server\n    logger.warn('LSP init failing repeatedly', { command: config.command, cause: err.message });\n  }\n  throw err;\n}","preventionTips":["Install/verify the language server binary and its runtime before use","Fix the underlying init failure reported in the message — the backoff hides it, not solves it","Respect the backoff window rather than retrying in a tight loop"],"tags":["lsp","initialization","backoff"],"backgroundTag":"lsp-server-init-failure","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}