Skip to content

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
mksglu:nextfrom
hakanbaysal:fix/stale-fs-preload-951
Open

fix(batch): re-create the fs-preload temp file if an OS cleaner removed it (#951)#969
hakanbaysal wants to merge 2 commits into
mksglu:nextfrom
hakanbaysal:fix/stale-fs-preload-951

Conversation

@hakanbaysal

Copy link
Copy Markdown

What / Why / How

Fixes the stale-preload half of #951.

The cm-fs-preload-<pid>.js FS-tracking snippet is written once at module load
into the OS temp dir. macOS $TMPDIR periodic purges (and systemd-tmpfiles on
Linux) 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. 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_execute injection site so a
deleted 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
existsSync per batch call.

The /reload-plugins worker-accumulation aggravation described in #951 is a
host lifecycle concern and intentionally out of scope here.

Affected platforms

  • All platforms

Test plan

  • New test: delete the preload file externally, call 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 25
    runBatchCommands cases).
  • npx tsc --noEmit → clean.

Checklist

  • Tests added/updated (TDD: red → green)
  • npm test passes (server suite; full build requires Node >=22.5)
  • npm run typecheck passes
  • Docs updated if needed — n/a
  • No Windows path regressions (uses existing join(tmpdir(), ...) path)
  • Targets next branch

hakanbaysal and others added 2 commits July 17, 2026 23:28
…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.
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