Skip to content

fix(wsl): keep a user's GLIBC_TUNABLES and delegate the launch-env wrapper - #34248

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-malloc-tunables-followup
Oct 27, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-malloc-tunables-followup

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

ELI5

#34187 made Orca's server in WSL start with a memory-allocator setting that saves about 50 MB. If you had already set that same setting yourself, Orca replaced your value. Now your own value always wins. There's also a small fix so the launch code keeps working if its connection object is ever written as a class.

What Changed

Two follow-ups to the #34187 review, both low severity.

  1. A user's own GLIBC_TUNABLES wins.
    • Launch env entries can now be marked keep-existing, rendered as NAME="${NAME:-value}". The value applies only when the launching shell has none.
    • The malloc tunables entry uses it. A value forwarded through WSLENV now stays in effect for orcad, and orcad's startup claim already leaves non-matching values in place, so its children keep it too.
    • Defaults that can't be written safely inside ${NAME:-…} are refused at build time.
  2. withOwnBuildLaunchEnv delegates instead of spreading. It now returns Object.create(conn, { orcadLaunchEnv }), so a class-based transport keeps its prototype methods. Today's WSL transport is a plain object, so behavior doesn't change.

Why

  • Before: the launch always set GLIBC_TUNABLES=glibc.malloc.mmap_threshold=16384, overriding a user's value for orcad. orcad's claim then removed it from orcad's env (it no longer matched the marker), so orcad's direct children also lost the user's setting.
  • After: orcad runs with the user's setting and leaves it in place.

Why a shell default: only the launching shell knows whether a value is already set; the desktop doesn't. A shell default needs no extra round trip.

Linked Issue

Follow-up to #34187.

Visual Proof

N/A: no UI change.

Testing

  • orcad-remote-launch-setsid.test.ts checks:

    • the rendered assignment;
    • a real sh run showing the default applies when unset and keeps a preset value;
    • refusal of a default containing a quote.
  • wsl-orcad-own-build-launch-env.test.ts: a class-based transport's prototype methods survive the wrapper.

  • Existing suites pass under pnpm test: host-malloc-tunables, daemon spawn, PTY env inheritance, WSL deploy, launch.

  • pnpm tc and pnpm run check:code-quality:changed pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • User-risk: none new. It only stops overriding a value the user set.
  • Flag-off: inert outside WSL. SSH launches pass no host env, and keep-existing is used only by the WSL malloc entry.
  • SSH and wire: unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5a644f4c-3ad9-4b0a-9533-296bd445aa97
Commits

Reviewing files that changed from the base of the PR and between c8c59a6 and e5a1f86.

Files selected for processing: 2
  • src/main/wsl/wsl-orcad-own-build-launch-env.test.ts
  • src/main/wsl/wsl-orcad-own-build-launch-env.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Walkthrough

Host malloc tunables now use keep-existing mode for GLIBC_TUNABLES. Launch command construction preserves a nonempty shell value, uses a validated default when the value is unset or empty, and rejects invalid defaults. The own-build launch environment wrapper now inherits from the original transport. Tests cover both behaviors.

Priority: Normal

Merge Risk: Low · up to e5a1f

The launch behavior has no established defect, but the unit test can fail on Windows machines without a POSIX shell. Guard the shell-dependent test before merging unless that test environment is guaranteed to provide one.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies both primary changes: preserving a user's GLIBC_TUNABLES value in WSL and delegating the launch-environment wrapper.
Description check Passed The description is complete and focused. It explains the user impact, implementation, rationale, linked issue, testing, scope, compatibility notes, and checklist status. Automated testing is documente…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and focused. It explains the user impact, implementation, rationale, linked issue, testing, scope, compatibility notes, and checklist status. Automated testing is documented, while manual testing and the full lint/typecheck/build checklist remain unchecked.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f5eb242-878d-4a9a-acb7-c1641041490a
Commits

Reviewing files that changed from the base of the PR and between 6357bd7 and c8c59a6.

Files selected for processing: 6
  • src/main/managed-server/install/orcad-remote-launch-setsid.test.ts
  • src/main/managed-server/install/orcad-remote-launch.ts
  • src/main/memory/host-malloc-tunables.ts
  • src/main/ssh/orcad-host-transport.ts
  • src/main/wsl/wsl-orcad-own-build-launch-env.test.ts
  • src/main/wsl/wsl-orcad-own-build-launch-env.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Comment on lines +75 to +76
return execFileSync('sh', ['-c', `${assignment} sh -c 'printf %s "$GLIBC_TUNABLES"'`], {
env: preset === undefined ? env : { ...env, GLIBC_TUNABLES: preset }

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.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '1,110p' src/main/managed-server/install/orcad-remote-launch-setsid.test.ts
rg -n 'skipIf|win32|platform|execFileSync' src/main/managed-server/install/orcad-remote-launch-setsid.test.ts

Repository: stablyai/orca

Length of output: 5929


Script executed:

set -eu
printf '%s\n' '--- test file remainder ---'
nl -ba src/main/managed-server/install/orcad-remote-launch-setsid.test.ts | sed -n '85,175p'
printf '%s\n' '--- Windows workflow references ---'
rg -n -i --glob '.github/workflows/**' -e 'windows' -e 'pnpm test' -e 'vitest' -e 'test:' -e 'managed-server' .
printf '%s\n' '--- test configuration references ---'
rg -n -i --glob 'package.json' --glob 'vitest*.{ts,js,mjs,cjs}' --glob 'config/**/*' -e 'include' -e 'exclude' -e 'windows' -e 'vitest' -e 'pnpm test' .

Repository: stablyai/orca

Length of output: 3583


Script executed:

set -u
printf '%s\n' '--- workflow files ---'
find .github/workflows -maxdepth 1 -type f -print 2>/dev/null | sort
printf '%s\n' '--- Windows/job/test references ---'
rg -n -i -e 'windows' -e 'pnpm test' -e 'vitest' -e 'test:' .github/workflows 2>/dev/null || true
printf '%s\n' '--- package test scripts ---'
python3 - <<'PY'
import json
from pathlib import Path
p = Path('package.json')
data = json.loads(p.read_text())
for key, value in data.get('scripts', {}).items():
    if 'test' in key.lower() or 'vitest' in value.lower():
        print(f'{key}: {value}')
PY
printf '%s\n' '--- Vitest config files ---'
find . -maxdepth 3 -type f \( -iname 'vitest.config.*' -o -iname '*vitest*.config.*' \) -print 2>/dev/null | sort

Repository: stablyai/orca

Length of output: 41579


Script executed:

set -u
printf '%s\n' '--- unit-tests workflow ---'
nl -ba .github/workflows/unit-tests.yml | sed -n '60,270p'
printf '%s\n' '--- node-server-tests workflow ---'
nl -ba .github/workflows/node-server-tests.yml | sed -n '145,245p'
printf '%s\n' '--- preflight-cli-platforms workflow ---'
nl -ba .github/workflows/preflight-cli-platforms.yml | sed -n '20,65p'
printf '%s\n' '--- shared Vitest config ---'
nl -ba config/vitest.config.ts | sed -n '1,220p'

Repository: stablyai/orca

Length of output: 26671


Script executed:

set -u
printf '%s\n' '--- callers of reusable unit-tests workflow ---'
rg -n -F -e 'unit-tests.yml' -e 'runner:' -e 'windows-2022' -e 'windows-11-arm' .github/workflows/pr.yml .github/workflows/*.yml 2>/dev/null | head -240
printf '%s\n' '--- UNIT_INCLUDE definition and target path ---'
rg -n -F -e 'UNIT_INCLUDE' -e 'orcad-remote-launch-setsid.test.ts' config/scripts src .github 2>/dev/null
nl -ba config/scripts/ci-unit-files.mjs | sed -n '1,260p'

Repository: stablyai/orca

Length of output: 12278


Script executed:

set -u
nl -ba config/scripts/run-node-server-tests.mjs | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 6620


Script executed:

set -u
nl -ba config/scripts/node-server-test-paths.mjs | sed -n '1,240p'

Repository: stablyai/orca

Length of output: 3214


Guard the shell-execution assertions on non-Linux hosts.

The new test calls execFileSync('sh', ...) without a guard. On a Windows host without sh on PATH, the test can fail before its assertions complete. Keep the rendering and rejection assertions outside the guard.

Suggested fix
--- "a/src/main/managed-server/install/orcad-remote-launch-setsid.test.ts"
+++ "b/src/main/managed-server/install/orcad-remote-launch-setsid.test.ts"
@@ -70,14 +70,16 @@
     ])
     const assignment = 'GLIBC_TUNABLES="${GLIBC_TUNABLES:-glibc.malloc.mmap_threshold=16384}"'
     expect(command).toContain(`${assignment} sh -c`)
-    const seen = (preset: string | undefined): string => {
-      const { GLIBC_TUNABLES: _drop, ...env } = process.env
-      return execFileSync('sh', ['-c', `${assignment} sh -c 'printf %s "$GLIBC_TUNABLES"'`], {
-        env: preset === undefined ? env : { ...env, GLIBC_TUNABLES: preset }
-      }).toString()
-    }
-    expect(seen(undefined)).toBe('glibc.malloc.mmap_threshold=16384')
-    expect(seen('glibc.malloc.arena_max=2')).toBe('glibc.malloc.arena_max=2')
+    if (process.platform === 'linux') {
+      const seen = (preset: string | undefined): string => {
+        const { GLIBC_TUNABLES: _drop, ...env } = process.env
+        return execFileSync('sh', ['-c', `${assignment} sh -c 'printf %s "$GLIBC_TUNABLES"'`], {
+          env: preset === undefined ? env : { ...env, GLIBC_TUNABLES: preset }
+        }).toString()
+      }
+      expect(seen(undefined)).toBe('glibc.malloc.mmap_threshold=16384')
+      expect(seen('glibc.malloc.arena_max=2')).toBe('glibc.malloc.arena_max=2')
+    }
     expect(() =>
       orcadLaunchCommand(host, spec('/d/orcad-1'), 'setsid', [['X', "a'b", 'keep-existing']])
     ).toThrow('orcad_launch_env_default_invalid')

This is a local Windows test failure, not a failure of the current Windows CI path. The pull-request unit-test job runs on Ubuntu, and the Windows node-server job does not select this file.

@nwparker
nwparker force-pushed the nwparker/wsl-malloc-tunables-followup branch from c8c59a6 to b11850e Compare October 27, 2026 04:25
…apper

The orcad launch now sets GLIBC_TUNABLES only when the launching shell has
none, so a value forwarded through WSLENV wins and the claim leaves it in
place. withOwnBuildLaunchEnv delegates to the transport instead of copying
its own properties, so a class-based transport keeps its methods.
withOwnBuildLaunchEnv now returns the transport's own type, so the test
calls the class method directly. The comment no longer claims #private
class fields survive delegation.
@nwparker
nwparker force-pushed the nwparker/wsl-malloc-tunables-followup branch from b11850e to e5a1f86 Compare October 27, 2026 05:02
@nwparker
nwparker merged commit 6d43596 into main Oct 27, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant