Skip to content

fix(lsp): resolve Windows .cmd shims in spawnLspServerProcess - #75343

Merged
BradGroux merged 6 commits into
openclaw:mainfrom
ElliotDrel:fix/lsp-windows-cmd-spawn
May 5, 2026
Merged

BradGroux merged 6 commits into
openclaw:mainfrom
ElliotDrel:fix/lsp-windows-cmd-spawn

Conversation

@ElliotDrel

@ElliotDrel ElliotDrel commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #75352

Problem

On Windows, LSP plugin servers (e.g. typescript-lsp) fail on startup with:

ENOENT: no such file or directory, uv_spawn 'typescript-language-server'

child_process.spawn() without shell: true cannot find or execute .cmd wrapper scripts that npm installs globally on Windows. Even when typescript-language-server.cmd is present in PATH, uv_spawn calls CreateProcess directly and cannot locate or execute .cmd files without shell mediation.

Root Cause

spawnLspServerProcess() in pi-bundle-lsp-runtime.ts calls spawn(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 .cmd wrappers.

Fix

resolveWindowsSpawnProgram() already exists in src/plugin-sdk/windows-spawn.ts and handles this exactly:

  1. Finds typescript-language-server.cmd via PATH + PATHEXT search
  2. Parses the .cmd shim to extract the real Node.js entrypoint (cli.mjs)
  3. Returns { command: node.exe, leadingArgv: [cli.mjs] } — a direct spawn that needs no shell

The 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-server installed via npm 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

  • On non-Windows platforms, resolveWindowsSpawnProgram() is a no-op (returns { command, leadingArgv: [] }) so there is no behavioral change on macOS/Linux.
  • allowShellFallback: true ensures that even edge-case .cmd shims that can't be fully resolved still work via shell, rather than hard-failing.

Copilot AI review requested due to automatic review settings May 1, 2026 01:40
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels May 1, 2026
@clawsweeper

clawsweeper Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR routes bundled LSP server spawning through the shared Windows spawn resolver, sanitizes the child environment, adds focused tests, and records a changelog entry.

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
No repair lane is needed; the active PR already contains the narrow code, test, and changelog changes and should proceed through normal maintainer review plus CI gating.

Security
Cleared: The diff touches child-process spawning but reuses the existing Windows resolver and sanitizeHostExecEnv, adds no dependencies or workflows, and introduces no concrete supply-chain concern.

Review details

Best 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:

  • current_main_direct_spawn: Current main still calls spawn(config.command, config.args ?? []) for bundled LSP servers and passes the merged environment directly to child_process.spawn. (src/agents/pi-bundle-lsp-runtime.ts:67, 0949f4fe5151)
  • bundle_lsp_supported_surface: The public bundle docs say enabled Claude bundles can contribute .lsp.json and manifest-declared lspServers to embedded Pi LSP defaults, with stdio-backed LSP servers runnable today. Public docs: docs/plugins/bundles.md. (docs/plugins/bundles.md:191, 0949f4fe5151)
  • node_windows_cmd_contract: Node v22.14.0 child_process docs state Windows .bat and .cmd files are not executable on their own without shell or cmd.exe mediation, matching the reported ENOENT failure mode.
  • shared_windows_resolver_contract: resolveWindowsSpawnProgram searches PATH/PATHEXT, unwraps .cmd/.bat wrappers to Node or executable entrypoints when possible, and materializes shell/windowsHide spawn options. (src/plugin-sdk/windows-spawn.ts:203, 0949f4fe5151)
  • env_sanitizer_contract: sanitizeHostExecEnv accepts structured baseEnv and overrides input, preserves safe inherited PATH, and blocks dangerous override keys including PATH by default. (src/infra/host-env-security.ts:249, 0949f4fe5151)
  • pr_head_wiring: The PR diff sanitizes the child env, passes that env to resolveWindowsSpawnProgram, materializes the invocation, and forwards command, argv, shell, windowsHide, cwd, and stdio into spawn. (src/agents/pi-bundle-lsp-runtime.ts:69, 057a7864b382)

Likely related people:

  • vincentkoc: GitHub path history shows the bundled LSP stdio JSON-RPC runtime and agent tool bridge were introduced and then optimized by vincentkoc. (role: introduced LSP runtime; confidence: high; commits: 8193af6d4ebf, e6c6aaa11b1f, 74e7b8d47b18; files: src/agents/pi-bundle-lsp-runtime.ts, src/agents/embedded-pi-lsp.ts, docs/plugins/bundles.md)
  • ai-hpc: Recent path history shows ai-hpc modified the same LSP runtime area for process-tree cleanup and lifecycle coverage. (role: recent LSP process lifecycle maintainer; confidence: high; commits: dc96886378d5; files: src/agents/pi-bundle-lsp-runtime.ts, src/agents/pi-bundle-lsp-runtime.test.ts)
  • steipete: Path history ties steipete to the shared Windows wrapper resolver and central host execution environment security seam reused by this PR. (role: Windows spawn and host env adjacent owner; confidence: high; commits: 12c12570238c, f202e73077a2, 4babd925c40d; files: src/plugin-sdk/windows-spawn.ts, src/infra/host-env-security.ts)
  • eleqtrizit: Path history shows eleqtrizit hardened unresolved Windows wrapper behavior, which is relevant to this PR's shell-fallback policy choice. (role: Windows wrapper policy contributor; confidence: medium; commits: 5874a387aefa, fa82193c7273; files: src/plugin-sdk/windows-spawn.ts, src/plugin-sdk/windows-spawn.test.ts, src/infra/host-env-security.ts)

Remaining risk / open question:

  • A live Windows LSP startup was not rerun in this read-only review; reproducibility is based on source inspection, Node documentation, and the reporter's Windows 11 manual verification.
  • Four exact-head checks were still in progress in the public check-run API at review time, so merge should remain gated on their completion.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 0949f4fe5151.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() into spawnLspServerProcess().
  • Wires the resolved invocation’s windowsHide and shell options into the spawn() call.

Comment thread src/agents/pi-bundle-lsp-runtime.ts Resolved
Comment thread src/agents/pi-bundle-lsp-runtime.ts Resolved
ElliotDrel and others added 6 commits May 4, 2026 19:59
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]>
@BradGroux
BradGroux force-pushed the fix/lsp-windows-cmd-spawn branch from 057a786 to 0f2b190 Compare May 5, 2026 01:03
@BradGroux
BradGroux merged commit 3e4f076 into openclaw:main May 5, 2026
93 checks passed
@BradGroux

Copy link
Copy Markdown
Contributor

Maintainer landing complete.

What changed:

  • Rebased the PR onto current main.
  • Kept the submitted LSP fix: bundled LSP process spawning now goes through the shared Windows .cmd shim resolver and sanitized host exec environment.
  • Preserved the focused regression tests and changelog entry.

Verification:

  • pnpm test src/agents/pi-bundle-lsp-runtime.windows-spawn.test.ts src/agents/pi-bundle-lsp-runtime.test.ts
  • pnpm check:changed
  • GitHub PR checks: green before merge

SHAs:

  • Prepared PR head: 0f2b190a377bcd5d4e42a40e6e59023fab7234de
  • Squash merge commit: 3e4f0767235b7df068836615d4755606d0ecba77

Thanks @ElliotDrel.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
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]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
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]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP servers fail on Windows with ENOENT: uv_spawn cannot resolve .cmd shims

4 participants