Skip to content

module: add a read-only mode to the compile cache - #65302

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:compile-cache-read-only
Open

module: add a read-only mode to the compile cache#65302
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:compile-cache-read-only

Conversation

@codebytere

Copy link
Copy Markdown
Member

A compile cache generated ahead of time and shipped inside an application package should only ever be read: the package may be immutable (an Electron app.asar, a read-only image) or covered by an integrity check, and a cache directory that appears at run time next to shipped code is a surprise either way. Today enabling the cache always implies writing: the tag directory is created on enable, and every module without an accepted entry is serialized and persisted at exit or on flushCompileCache().

This adds readOnly to module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1. With it, existing entries are looked up and loaded exactly as before; nothing is serialized into the in-memory store or written to disk, flushCompileCache() is a no-op, the write-permission check is skipped, and the cache directory is used as found rather than created, so enabling against a directory that does not exist fails (FAILED, with a message) instead of making one.

EnableOption becomes a small flag set (PORTABLE, READ_ONLY) since the two combine. Docs cover the option, the environment variable (cli.md, node.1) and a short section in module.md; test-compile-cache-api-readonly covers the missing-directory case, reading a previously generated cache without writing new entries, and the environment variable.

Context: same application as #65293 (an Electron app shipping its main-process cache in the package); review there asked that production launches never attempt writes.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 15, 2026
@codebytere
codebytere force-pushed the compile-cache-read-only branch 2 times, most recently from 447fb62 to 133e37b Compare August 15, 2026 09:09
@codebytere
codebytere force-pushed the compile-cache-read-only branch 2 times, most recently from d57ec48 to dc597d8 Compare August 16, 2026 18:31
@codebytere codebytere added request-ci Add this label to start a Jenkins CI on a PR. and removed needs-ci PRs that need a full CI run. labels Aug 16, 2026
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.10448% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.13%. Comparing base (bc813a7) to head (f201d83).
⚠️ Report is 140 commits behind head on main.

Files with missing lines Patch % Lines
src/compile_cache.cc 75.60% 5 Missing and 5 partials ⚠️
src/env.cc 50.00% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65302      +/-   ##
==========================================
- Coverage   90.32%   90.13%   -0.19%     
==========================================
  Files         751      751              
  Lines      249960   252344    +2384     
  Branches    47204    47452     +248     
==========================================
+ Hits       225774   227448    +1674     
- Misses      15564    16193     +629     
- Partials     8622     8703      +81     
Files with missing lines Coverage Δ
lib/internal/modules/helpers.js 98.94% <100.00%> (+<0.01%) ⬆️
src/compile_cache.h 100.00% <100.00%> (ø)
src/node_modules.cc 80.22% <100.00%> (-0.01%) ⬇️
src/env.cc 85.24% <50.00%> (-0.18%) ⬇️
src/compile_cache.cc 79.94% <75.60%> (+0.85%) ⬆️

... and 119 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codebytere
codebytere requested a review from Renegade334 August 16, 2026 20:23
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codebytere codebytere added the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 18, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Aug 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/65302
✔  Done loading data for nodejs/node/pull/65302
----------------------------------- PR info ------------------------------------
Title      module: add a read-only mode to the compile cache (#65302)
Author     Shelley Vohr <shelley.vohr@gmail.com> (@codebytere)
Branch     codebytere:compile-cache-read-only -> nodejs:main
Labels     c++, lib / src, commit-queue
Commits    1
 - module: add a read-only mode to the compile cache
Committers 1
 - Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65302
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/65302
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 15 Aug 2026 08:56:32 GMT
   ✔  Approvals: 1
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/65302#pullrequestreview-4948260342
   ✘  This PR needs to wait 91 more hours to land (or 0 minutes if there is one more approval)
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-08-17T03:52:44Z: https://ci.nodejs.org/job/node-test-pull-request/75904/
- Querying data for job/node-test-pull-request/75904/
✔  Build data downloaded
- Querying failures of job/node-test-commit/90633/
✔  Data downloaded
   ✘  1 failure(s) on the last Jenkins CI run
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/32149688331

@codebytere codebytere removed the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Aug 20, 2026
@codebytere

Copy link
Copy Markdown
Member Author

@aduh95 PTAL when you have a moment!

Comment thread doc/api/module.md Outdated
Comment thread src/compile_cache.cc
Comment on lines +594 to +599
if (!is_dir) {
result.message =
"Cache directory does not exist (read-only): " + cache_dir_with_tag;
result.status = CompileCacheEnableStatus::FAILED;
return result;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this emit a warning?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think so, for consistency: none of the other FAILED paths here (can't create the directory, not writable) warn either. through module.enableCompileCache() the caller gets { status, message } back and can decide what to do with it, and for NODE_COMPILE_CACHE the existing behavior is an inherited env var never adds output to a program that didn't ask for the cache; NODE_DEBUG_NATIVE=COMPILE_CACHE prints it. happy to add one if you feel strongly, but i'd rather do it for all the FAILED cases at once in a follow-up than special-case read-only.

A compile cache generated ahead of time and shipped inside an
application package should only ever be read: the package may be
immutable or covered by an integrity check, and a cache directory that
appears at run time would be a surprise. Add readOnly to
module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1: existing
entries are loaded as before, nothing is serialized or persisted,
flushCompileCache() is a no-op, and the cache directory is used as found
rather than created, so enabling against a missing directory fails
instead of making one.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@codebytere
codebytere force-pushed the compile-cache-read-only branch from dc597d8 to f201d83 Compare August 21, 2026 18:17
@codebytere codebytere added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 21, 2026
@Renegade334 Renegade334 added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Aug 21, 2026
@codebytere codebytere removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 22, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants