fix(batch): re-create the fs-preload temp file if an OS cleaner removed it (#951) - #969
Open
hakanbaysal wants to merge 2 commits into
Open
fix(batch): re-create the fs-preload temp file if an OS cleaner removed it (#951)#969hakanbaysal wants to merge 2 commits into
hakanbaysal wants to merge 2 commits into
Conversation
…ed it (mksglu#951) The cm-fs-preload-<pid>.js tracker is written once at module load into the OS temp dir. macOS $TMPDIR purges and systemd-tmpfiles can delete it while the MCP server process is still alive; the server then keeps injecting `NODE_OPTIONS=--require <missing file>` into every batch command, so all node/npm/npx children die at preload with MODULE_NOT_FOUND until the affected server PID is killed (mksglu#951). Non-node commands are unaffected, which makes the failure look like a broken npm install rather than a stale temp file. Extract the preload write into ensureFsPreload(), keep the module-load write (same startup behavior and failure mode), and call it at the ctx_batch_execute injection site so a deleted file is restored before the prefix references it. The existence check is a single stat per batch call. The reload-plugins worker-accumulation aggravation described in mksglu#951 is a host lifecycle concern and intentionally out of scope here.
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 / Why / How
Fixes the stale-preload half of #951.
The
cm-fs-preload-<pid>.jsFS-tracking snippet is written once at module loadinto the OS temp dir. macOS
$TMPDIRperiodic purges (and systemd-tmpfiles onLinux) can delete it while the MCP server process is still alive. The server
then keeps injecting
NODE_OPTIONS=--require <missing file>into every batchcommand, so all node/npm/npx children die at preload with
MODULE_NOT_FOUNDuntil the affected server PID is killed. Non-node commands are unaffected,
which makes the failure look like a broken npm rather than a stale temp file.
Fix: extract the preload write into
ensureFsPreload()— write-if-missing,return the path — and call it at the
ctx_batch_executeinjection site so adeleted file is restored before the prefix references it. The module-load write
is kept (same startup behavior and failure mode); the added cost is a single
existsSyncper batch call.The
/reload-pluginsworker-accumulation aggravation described in #951 is ahost lifecycle concern and intentionally out of scope here.
Affected platforms
Test plan
ensureFsPreload(),assert the same path is restored with the real tracker content
(
__CM_FS__), not an empty placeholder.npx vitest run tests/core/server.test.ts→ 500 passed (incl. the 25runBatchCommandscases).npx tsc --noEmit→ clean.Checklist
npm testpasses (server suite; full build requires Node >=22.5)npm run typecheckpassesjoin(tmpdir(), ...)path)nextbranch