summaryrefslogtreecommitdiffhomepage
path: root/packages/lsp/src/tool.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-25 18:11:17 +0900
committerAdam Malczewski <[email protected]>2026-06-25 18:11:17 +0900
commit7626c7f3adf940ee871c4fd2ba2d342f19d9d60b (patch)
tree17af00238fd8020bf27a482415f37fb79baf0b59 /packages/lsp/src/tool.ts
parentc1bc7bfaaca7bdf4d9b2973f5dc88605217a7866 (diff)
downloaddispatch-7626c7f3adf940ee871c4fd2ba2d342f19d9d60b.tar.gz
dispatch-7626c7f3adf940ee871c4fd2ba2d342f19d9d60b.zip
fix(lsp): stop per-edit hangs on dead/slow servers (10s cap + skip + self-heal)
The LSP diagnostics path hung up to 60s per edit whenever a configured Ruby language server was dead or slow (the reported Steep langserver case): a killed/crashed server was never detected (stayed "connected" forever), servers were queried sequentially with a 60s budget each, and a corrupted-but-alive server (Steep's ~3h phantom-SyntaxError drift) had no recovery. Four fixes, all in packages/lsp/ (the tool-edit-file call site lowered to 10s): 1. Dead-process detection: SpawnedProcess.onExit (Bun proc.exited) + stdout-end defence flip the client to error, dispose the rpc, kill the proc. The manager re-spawns a fresh server after the 30s backoff. Dead servers are now skipped (0s) instead of polled for 60s. 2. Concurrent fan-out + 10s hard cap: new aggregateDiagnostics queries all matching servers at once, each capped at 10s. A non-responder is skipped with "LSP took too long (>10s), skipped — raise this to the user" instead of blocking the fast server's results. Replaces the vague "unusually long" warning (now structurally impossible: slow is always false). 3. Corruption self-heal: a detector flags a server re-emitting identical non-empty diagnostics despite the file changing; after 5 repeats the client is marked broken and re-spawned. Clean files never trip it. (Acknowledged false-positive risk on persistent unfixed errors; CLI type-check gate stays authoritative.) 4. sendRequest timeout: hover/definition/references cap at 10s so they can't hang the turn against a dead server; the initialize handshake keeps its 45s race. Verification: typecheck clean; 1573 tests pass (96 files), +15 new LSP tests (86 in packages/lsp); biome clean. No kernel/contract changes; onExit is internal to packages/lsp.
Diffstat (limited to 'packages/lsp/src/tool.ts')
-rw-r--r--packages/lsp/src/tool.ts43
1 files changed, 21 insertions, 22 deletions
diff --git a/packages/lsp/src/tool.ts b/packages/lsp/src/tool.ts
index 8d282ec..be0d269 100644
--- a/packages/lsp/src/tool.ts
+++ b/packages/lsp/src/tool.ts
@@ -6,6 +6,7 @@
import { extname, resolve } from "node:path";
import type { ToolContract, ToolExecuteContext, ToolResult } from "@dispatch/kernel";
+import { aggregateDiagnostics } from "./aggregate.js";
import type { LspManager } from "./manager.js";
type Operation = "diagnostics" | "hover" | "definition" | "references" | "documentSymbol";
@@ -157,6 +158,8 @@ export function createLspTool(manager: LspManager): ToolContract {
switch (operation) {
case "diagnostics": {
+ // 10s hard ceiling per server (same policy as the edit path).
+ const DIAGNOSTICS_TIMEOUT_MS = 10_000;
// Query ALL connected servers whose extensions match this file.
const matching = statuses.filter(
(s) => s.state === "connected" && s.extensions.some((ext) => ext === fileExt),
@@ -179,31 +182,27 @@ export function createLspTool(manager: LspManager): ToolContract {
if (!client) {
return { content: "Language server client not available.", isError: true };
}
- const result = await client.waitForDiagnostics(absolutePath);
+ const result = await client.waitForDiagnostics(absolutePath, {
+ timeoutMs: DIAGNOSTICS_TIMEOUT_MS,
+ });
+ if (result.timedOut) {
+ return {
+ content: `⚠️ [${connected.name}] LSP took too long (>10s), diagnostics skipped — please raise this to the user.`,
+ };
+ }
return { content: result.formatted || "No diagnostics found." };
}
- // Query each matching server and merge results, tagged by source.
- const parts: string[] = [];
- let anyTimedOut = false;
- for (const s of matching) {
- const client = manager.getClient(s.id, s.root);
- if (!client) continue;
- const result = await client.waitForDiagnostics(absolutePath, { timeoutMs: 60_000 });
- if (result.timedOut) anyTimedOut = true;
- if (result.slow) {
- parts.push(
- `⚠️ LSP is taking unusually long. If this happens more than once, raise it to the user.`,
- );
- }
- if (result.formatted) {
- parts.push(`[${s.name}]\n${result.formatted}`);
- }
- }
- if (anyTimedOut && parts.length === 0) {
- parts.push("Diagnostics timed out (server may still be indexing).");
- }
- return { content: parts.length > 0 ? parts.join("\n\n") : "No diagnostics found." };
+ // Query matching servers concurrently, each capped at 10s;
+ // a non-responding server is skipped with a notice.
+ const agg = await aggregateDiagnostics(
+ (id, root) => manager.getClient(id, root),
+ matching,
+ absolutePath,
+ DIAGNOSTICS_TIMEOUT_MS,
+ {},
+ );
+ return { content: agg.formatted || "No diagnostics found." };
}
case "hover": {
const client = await getFirstMatchingClient(manager, statuses, fileExt);