[Bug] LSP auto-discovery blocks the event loop at startup with up to 19 sequential `where`/`which` spawns and cannot be disabled
Description
Right after the prompt appears, initializeLSPServers() runs auto-discovery, which spawns one blocking where/which process per known language server (up to 19) using execFileSync, one after another. The event loop is frozen the whole time, so typing and rendering stall. Process creation is slow on Windows and slower with antivirus or on an HDD. There is no way to turn auto-discovery off: autoDiscover: true is hard-coded.
Environment
- OS: Windows 11 (10.0.26300), host heavily loaded by other apps
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 5c2e6935)
Steps to Reproduce
- Wrap
child_process.execFileSyncto log duration and caller (or useprocmon/strace -f). - Start
nanocoderin any project. - Count the
where/whichspawns after the first frame.
Evidence
- 19
execFileSync where <server>calls fromfindCommand(source/lsp/server-discovery.ts:249-253, called at:380), 231-687 ms each: 7.0 s of blocking in total on the loaded host.yaml-language-serverandgraphql-lspare probed twice because two table entries share a command. - Micro-benchmark, same conditions, 17 commands:
wherespawns 4.7-5.8 s vs 1.0-1.8 s for an in-process scan of the 59 PATH directories. - The call is
void initializeLSPServers()atsource/hooks/useAppInitialization.tsx:709;autoDiscover: trueis at:300-304and:328.source/types/config.ts:329,401only definelspServers. - Not measured: an unloaded Linux/macOS machine (a
whichfork is much cheaper there). The structure (serial, blocking, up to 19 processes) holds regardless.
Proposed Change
- Replace
findCommandwith one async PATH scan:readdireach PATH directory once into aSet, honourPATHEXTon Windows, cache for the process. - De-duplicate by command name before probing.
- Make
verifyServer(execFileSync <server> --version, line 280) async with a timeout. - Add
lsp.autoDiscover: false(config) and an env var such asNANOCODER_LSP=off; document both.
Expected Behavior
- No
where/whichspawns during startup. - A 100 ms heartbeat timer started at first frame never drifts by more than 50 ms while discovery runs.
discoverLanguageServersreturns the same list as before on a machine with several servers installed.- With
lsp.autoDiscover: false, no discovery runs and/lspsays so.
Additional Context
- Effort: S. Start with
source/lsp/server-discovery.ts,source/hooks/useAppInitialization.tsx:298-380,source/types/config.ts. - Adds an opt-out config key (additive). Related but different: #1523, #1690 (keep the Windows
.cmdbehaviour). Specs:server-discovery.spec.ts,lsp-manager.spec.ts. - Follow-up (separate issue): start servers only for languages present in the project, and lazily on first use.
LSPManager.initializecurrently starts every discovered server in parallel (source/lsp/lsp-manager.ts:109-116), including heavy ones such asrust-analyzerandclangd --background-index.
@addyCooks I would like to take this issue. I will first reproduce the startup stall and verify the current discovery path, then keep the fix focused on non-blocking, de-duplicated executable discovery (including Windows PATH/PATHEXT behavior) and an explicit opt-out if that remains in scope. I will add regression coverage and validate the relevant LSP tests and checks before opening a PR. Could you assign the issue to @ducanhnguyen223 if this scope looks right? I will wait for assignment before opening a PR.