Repository navigation
fix(lsp): resolve Windows .cmd shims in spawnLspServerProcess - #75343
Conversation
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. source-reproducible: current main directly spawns configured LSP commands, bundle docs make stdio LSP servers a supported surface, and Node v22.14.0 documents that Windows .cmd/.bat files need shell or cmd.exe mediation. I did not run a live Windows repro in this read-only review. Next step before merge Security Review detailsBest possible solution: Land this PR after exact-head CI and maintainer validation, then let #75352 close through the merge. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main directly spawns configured LSP commands, bundle docs make stdio LSP servers a supported surface, and Node v22.14.0 documents that Windows .cmd/.bat files need shell or cmd.exe mediation. I did not run a live Windows repro in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing Windows spawn resolver with sanitized host exec env is the narrow maintainable fix, and the added tests cover the resolver/env/spawn wiring that prior review comments requested. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 0949f4fe5151. |
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows startup failures for bundle LSP servers by routing spawnLspServerProcess() through the existing Windows .cmd shim resolution helpers so npm-installed LSP binaries can be launched without shell: true in the common case.
Changes:
- Integrates
resolveWindowsSpawnProgram()+materializeWindowsSpawnProgram()intospawnLspServerProcess(). - Wires the resolved invocation’s
windowsHideandshelloptions into thespawn()call.
6845ff2 to
057a786
Compare
On Windows, child_process.spawn() without shell:true cannot find or execute .cmd wrapper scripts that npm installs globally. This causes LSP plugin servers (e.g. typescript-lsp) to fail on startup with: ENOENT: no such file or directory, uv_spawn 'typescript-language-server' resolveWindowsSpawnProgram() already exists in windows-spawn.ts and handles this exactly: it finds the .cmd shim via PATH+PATHEXT, parses it to extract the real Node.js entrypoint, and returns a direct spawn invocation that avoids shell execution. It is already used for Docker and memory-host spawning but was not wired up for LSP servers. This change uses that utility in spawnLspServerProcess() so all LSP servers resolve correctly on Windows.
Wrap the env merge with sanitizeHostExecEnv() to prevent workspace-config-derived env vars from overriding host vars and leading to code execution. Fixes Opengrep finding GHSA-vfw7-6rhc-6xxg.
Verifies: - Environment merge is passed through sanitizeHostExecEnv before spawn - Windows .cmd shims are resolved via resolveWindowsSpawnProgram - Merged env (not default process.env) is passed to resolver
- Pass baseEnv/overrides to sanitizeHostExecEnv instead of spreading
process.env and config.env into the params object; the old call silently
discarded all config.env entries because sanitizeHostExecEnv expects a
structured { baseEnv, overrides } param bag, not a flat env record
- Export spawnLspServerProcess so tests can call the production path
- Rewrite tests to invoke spawnLspServerProcess directly rather than
manually exercising the mock chain; each test now verifies a real
assertion about the production code path
- Add changelog contributor credit
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
\W was flagged by oxlint as unnecessary escape, and \n was silently becoming a newline character instead of a literal backslash-n. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
057a786 to
0f2b190
Compare
|
Maintainer landing complete. What changed:
Verification:
SHAs:
Thanks @ElliotDrel. |
Resolve Windows npm .cmd shim startup failures for bundled LSP servers by routing LSP process spawning through the shared Windows spawn resolver with a sanitized child environment. The change reuses existing PATH/PATHEXT and .cmd shim handling, keeps non-Windows behavior unchanged, and adds focused regression coverage for resolver wiring, env sanitization, and spawn materialization. Fixes openclaw#75352. Tests: - pnpm test src/agents/pi-bundle-lsp-runtime.windows-spawn.test.ts src/agents/pi-bundle-lsp-runtime.test.ts - pnpm check:changed Thanks @ElliotDrel. Co-authored-by: Elliot Drel <[email protected]> Co-authored-by: Brad Groux <[email protected]>
Resolve Windows npm .cmd shim startup failures for bundled LSP servers by routing LSP process spawning through the shared Windows spawn resolver with a sanitized child environment. The change reuses existing PATH/PATHEXT and .cmd shim handling, keeps non-Windows behavior unchanged, and adds focused regression coverage for resolver wiring, env sanitization, and spawn materialization. Fixes openclaw#75352. Tests: - pnpm test src/agents/pi-bundle-lsp-runtime.windows-spawn.test.ts src/agents/pi-bundle-lsp-runtime.test.ts - pnpm check:changed Thanks @ElliotDrel. Co-authored-by: Elliot Drel <[email protected]> Co-authored-by: Brad Groux <[email protected]>
Resolve Windows npm .cmd shim startup failures for bundled LSP servers by routing LSP process spawning through the shared Windows spawn resolver with a sanitized child environment. The change reuses existing PATH/PATHEXT and .cmd shim handling, keeps non-Windows behavior unchanged, and adds focused regression coverage for resolver wiring, env sanitization, and spawn materialization. Fixes openclaw#75352. Tests: - pnpm test src/agents/pi-bundle-lsp-runtime.windows-spawn.test.ts src/agents/pi-bundle-lsp-runtime.test.ts - pnpm check:changed Thanks @ElliotDrel. Co-authored-by: Elliot Drel <[email protected]> Co-authored-by: Brad Groux <[email protected]>
Fixes #75352
Problem
On Windows, LSP plugin servers (e.g.
typescript-lsp) fail on startup with:child_process.spawn()withoutshell: truecannot find or execute.cmdwrapper scripts that npm installs globally on Windows. Even whentypescript-language-server.cmdis present inPATH,uv_spawncallsCreateProcessdirectly and cannot locate or execute.cmdfiles without shell mediation.Root Cause
spawnLspServerProcess()inpi-bundle-lsp-runtime.tscallsspawn(config.command, ...)directly with no Windows PATH/PATHEXT resolution. This works on macOS/Linux where the npm shim is a proper executable, but fails on Windows where npm installs.cmdwrappers.Fix
resolveWindowsSpawnProgram()already exists insrc/plugin-sdk/windows-spawn.tsand handles this exactly:typescript-language-server.cmdvia PATH + PATHEXT search.cmdshim to extract the real Node.js entrypoint (cli.mjs){ command: node.exe, leadingArgv: [cli.mjs] }— a direct spawn that needs no shellThe utility is already used for Docker and memory-host process spawning. This PR wires it up for LSP servers, which were the only remaining spawn site missing it.
Testing
Verified manually on Windows 11 with
typescript-language-serverinstalled vianpm install -g typescript-language-server typescript.Before:
ENOENT: no such file or directory, uv_spawn 'typescript-language-server'After: LSP server initializes and responds correctly
Notes
resolveWindowsSpawnProgram()is a no-op (returns{ command, leadingArgv: [] }) so there is no behavioral change on macOS/Linux.allowShellFallback: trueensures that even edge-case.cmdshims that can't be fully resolved still work via shell, rather than hard-failing.