[PR #314] [MERGED] fix(sidecar): preserve Windows PATH key casing to prevent CUDA backend failure #4556

Closed
opened 2026-10-22 04:08:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/314
Author: @Lochalan
Created: 4/29/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @LukaTheHero

Base: main ← Head: main


📝 Commits (1)

  • 2caf45f fix(sidecar): preserve Windows PATH key casing to prevent CUDA backend failure

📊 Changes

2 files changed (+25 additions, -2 deletions)

View changed files

📝 packages/server/src/services/sidecar/sidecar-runtime-env.ts (+8 -2)
📝 packages/server/test/sidecar-runtime-env.test.ts (+17 -0)

📄 Description

Closes #315

Why this change

On Windows, buildLlamaProcessEnv in sidecar-runtime-env.ts spreads process.env into a plain object. While process.env itself is a case-insensitive Proxy, the spread result is a plain object that preserves the native key casing — typically "Path" (title-case), not "PATH".

The original code writes to env.PATH, which creates a duplicate key when the existing key is "Path". The short uppercase PATH (containing only the runtime directory) takes precedence, stripping the child process of all system directories — including C:\Windows\System32 and NVIDIA driver paths.

This prevents ggml-cuda.dll from resolving its implicit dependencies (nvcuda.dll, cublas64_*.dll), causing silent CUDA load failure and automatic CPU fallback on every startup.

Before fix (old runtime b8851 without bundled CUDA DLLs)

image

Controlled A/B test — same machine, same session

=== OLD CODE (env.PATH = ...) ===
PATH-like keys in env: [ 'Path', 'PATH' ]   ← duplicate key
CUDA loaded: false

=== NEW CODE (env[pathKey] = ...) ===
PATH-like keys in env: [ 'Path' ]            ← single key
CUDA loaded: true
ggml_cuda_init: found 1 CUDA devices (Total VRAM: 16375 MiB)

What changed

  • sidecar-runtime-env.ts: Use Object.keys(env).find(k => k.toLowerCase() === "path") to detect the actual key casing before prepending. Falls back to "PATH" if no key exists.
  • sidecar-runtime-env.test.ts: Added regression test verifying that a "Path" key is modified in-place without creating a duplicate "PATH" key.

Compatibility

This fix is complementary to #270 (bundling CUDA DLLs). With bundled DLLs, the CUDA symptom is masked because DLLs are found via same-directory resolution. However, the child process still loses its entire system PATH, which could affect other functionality. This fix addresses the root cause.

Validation

  • pnpm check
  • Controlled test spawning llama-server --version with old vs new env construction
  • Verified GPU offload works with fix, breaks without it (on runtime b8851)
  • Regression test passes

Summary by CodeRabbit

  • Bug Fixes
    • Resolved Windows environment handling that could create duplicate PATH entries. Child processes now inherit the correct PATH, preventing issues with system libraries and GPU/DLL detection.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/314 **Author:** [@Lochalan](https://github.com/Lochalan) **Created:** 4/29/2026 **Status:** ✅ Merged **Merged:** 5/3/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`2caf45f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2caf45f2ad9eddac1b354918728e0aea4bc42fde) fix(sidecar): preserve Windows PATH key casing to prevent CUDA backend failure ### 📊 Changes **2 files changed** (+25 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/sidecar/sidecar-runtime-env.ts` (+8 -2) 📝 `packages/server/test/sidecar-runtime-env.test.ts` (+17 -0) </details> ### 📄 Description Closes #315 ## Why this change On Windows, `buildLlamaProcessEnv` in `sidecar-runtime-env.ts` spreads `process.env` into a plain object. While `process.env` itself is a case-insensitive Proxy, the spread result is a plain object that preserves the native key casing — typically `"Path"` (title-case), not `"PATH"`. The original code writes to `env.PATH`, which creates a **duplicate key** when the existing key is `"Path"`. The short uppercase `PATH` (containing only the runtime directory) takes precedence, stripping the child process of all system directories — including `C:\Windows\System32` and NVIDIA driver paths. This prevents `ggml-cuda.dll` from resolving its implicit dependencies (`nvcuda.dll`, `cublas64_*.dll`), causing silent CUDA load failure and automatic CPU fallback on every startup. ### Before fix (old runtime b8851 without bundled CUDA DLLs) <img width="1445" height="549" alt="image" src="https://github.com/user-attachments/assets/bba0e5d5-52fb-4028-8b89-cceab65de2dd" /> ### Controlled A/B test — same machine, same session ``` === OLD CODE (env.PATH = ...) === PATH-like keys in env: [ 'Path', 'PATH' ] ← duplicate key CUDA loaded: false === NEW CODE (env[pathKey] = ...) === PATH-like keys in env: [ 'Path' ] ← single key CUDA loaded: true ggml_cuda_init: found 1 CUDA devices (Total VRAM: 16375 MiB) ``` ## What changed - **`sidecar-runtime-env.ts`**: Use `Object.keys(env).find(k => k.toLowerCase() === "path")` to detect the actual key casing before prepending. Falls back to `"PATH"` if no key exists. - **`sidecar-runtime-env.test.ts`**: Added regression test verifying that a `"Path"` key is modified in-place without creating a duplicate `"PATH"` key. ## Compatibility This fix is complementary to #270 (bundling CUDA DLLs). With bundled DLLs, the CUDA symptom is masked because DLLs are found via same-directory resolution. However, the child process still loses its entire system PATH, which could affect other functionality. This fix addresses the root cause. ## Validation - [x] `pnpm check` - [x] Controlled test spawning `llama-server --version` with old vs new env construction - [x] Verified GPU offload works with fix, breaks without it (on runtime b8851) - [x] Regression test passes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Resolved Windows environment handling that could create duplicate PATH entries. Child processes now inherit the correct PATH, preventing issues with system libraries and GPU/DLL detection. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:42 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4556
No description provided.