fix(optimize): preserve inherited NODE_OPTIONS in agent installer#1435
Open
John-David Dalton (jdalton) wants to merge 1 commit into
Open
fix(optimize): preserve inherited NODE_OPTIONS in agent installer#1435John-David Dalton (jdalton) wants to merge 1 commit into
John-David Dalton (jdalton) wants to merge 1 commit into
Conversation
runAgentInstall set the child's NODE_OPTIONS to only our own Node flags (harden / no-warnings / disable-sigusr1). A child process' NODE_OPTIONS REPLACES the parent's rather than extending it, so any NODE_OPTIONS the user configured globally was silently dropped when `socket optimize` ran the package-manager install. Merge the inherited process.env.NODE_OPTIONS ahead of our added flags via a new pure `mergeNodeOptions` helper in util/process/cmd.mts, unit-tested in isolation. The value is left unquoted (it is assigned to an env var, not passed through a shell). Same class of NODE_OPTIONS-clobber bug as the v1.x shadow-npm fix for #1160/#1036, but a different code path: this is the `socket optimize` agent installer on main, not the `socket npm` shadow wrapper. On main `socket npm` hands off to Socket Firewall and no longer builds Node flags itself, so this is the remaining place on main that needed it.
John-David Dalton (jdalton)
force-pushed
the
jdalton/fix-optimize-node-options-clobber
branch
from
July 24, 2026 21:49
ed6e872 to
e471aca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
socket optimizeruns the package-manager install viarunAgentInstall, which set the child'sNODE_OPTIONSto only Socket's own Node flags:A child process'
NODE_OPTIONSreplaces the parent's rather than extending it, so anyNODE_OPTIONSthe user configured globally (e.g.--max-old-space-size=4096) was silently dropped for the install.How
Merge the inherited
process.env.NODE_OPTIONSahead of our added flags, via a new puremergeNodeOptions()helper inutil/process/cmd.mts:The value is left unquoted — it's assigned directly to an env var (no shell), and quotes would break consumers that re-tokenize
NODE_OPTIONSon whitespace.Relationship to the v1.x #1160/#1036 fix
Same class of
NODE_OPTIONS-clobber bug, different code path — do not conflate:socket npmshadow-npm wrapper (src/shadow/npm-base.mts), addressing the user-reported socket npm run build crashes with ERR_MISSING_OPTION: --permission on Node v24 + Next.js #1160 (Node 24--permissioncrash) and 'socket npm' overrides NODE_OPTIONS #1036 (override).socket optimizeagent installer (agent-installer.mts) onmain. It was found while fixing those issues.On
main,socket npmhands off to Socket Firewall and no longer builds Node flags itself, so the agent installer is the remaining place onmainthat needed the merge. (It's also the path an earlier fork PR,kimjune01/socket-cli#1, aimed at.)Tests
test/unit/util/process/cmd.test.mts— 6 new cases formergeNodeOptions(prepend order, undefined/empty NODE_OPTIONS, no added flags, never quoted, all-empty).test/unit/commands/optimize/agent-installer.test.mts— new case asserting an inheritedNODE_OPTIONSreaches the spawn env instead of being clobbered.Verification
vitest runon both files — 41/41 pass.oxfmt -c .config/fleet/oxfmtrc.json --list-differenton changed files — clean.oxlinton changed files — 0 errors.packages/clitypecheck errors (unrelated files:output-scan-view.mts,glob.mts,parse.mts) are gated onmainand not touched here.Note
Low Risk
Small, localized CLI spawn-env change with dedicated unit tests; no auth, data, or security surface.
Overview
socket optimizepackage-manager installs no longer wipe the user’s globalNODE_OPTIONSwhen spawning npm/pnpm/yarn.runAgentInstallused to set the child’sNODE_OPTIONSto only Socket’s hardening/warning flags. Because a child env replaces the parent’s value, settings like--max-old-space-size=4096were dropped for the install. The installer now buildsNODE_OPTIONSwith a newmergeNodeOptions()helper that keeps existingprocess.env.NODE_OPTIONSfirst and appends Socket’s flags (unquoted, for direct env assignment).Unit coverage was added for
mergeNodeOptionsand for asserting inheritedNODE_OPTIONSreaches the spawn env in the agent installer tests.Reviewed by Cursor Bugbot for commit ed6e872. Configure here.