Skip to content

cli: one file-identity rule for the in-process file caches - #12440

Merged
josephfarina merged 2 commits into
mainfrom
josephfarina/file-identity-cache-rule
Nov 18, 2026
Merged

josephfarina merged 2 commits into
mainfrom
josephfarina/file-identity-cache-rule

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

npm stamps the same modification time on every file it writes, so a file
it replaces with one of the same size keeps its size and mtime. A cache
keyed on those two alone kept serving the old content in a long-lived
process.

Every in-process file cache now keys on read-record's exported
fileStamp (size, mtime, ctime and inode):

  • component discovery: the family members read from a doc, and the doc
    values (whose private copy of the rule is gone);
  • module exports: module texts and parsed modules (private copy gone);
  • theme discovery: static theme and icon descriptor reads;
  • theme part data read from its cache file, which left out ctime.

fileStamp is a raw stat that read recording does not see, while the old
copies used the recorded fs.statSync. Each cache now records its file
with recordContentRead, as the TypeScript config reader does, so a kept
catalog still sees the dependency on a cache hit. An absent descriptor
still throws the error a stat gives.

Tests: each changed cache reads again a file rewritten with the same size and mtime, and a cache hit still records its file. Each of those tests fails without the fix. One more test, an absent descriptor still throws, guards behavior that is kept and passes on the base too.

npm stamps the same modification time on every file it writes, so a file
it replaces with one of the same size keeps its size and mtime. A cache
keyed on those two alone kept serving the old content in a long-lived
process.

Every in-process file cache now keys on read-record's exported
`fileStamp` (size, mtime, ctime and inode):

- component discovery: the family members read from a doc, and the doc
  values (whose private copy of the rule is gone);
- module exports: module texts and parsed modules (private copy gone);
- theme discovery: static theme and icon descriptor reads;
- theme part data read from its cache file, which left out ctime.

`fileStamp` is a raw stat that read recording does not see, while the old
copies used the recorded `fs.statSync`. Each cache now records its file
with `recordContentRead`, as the TypeScript config reader does, so a kept
catalog still sees the dependency on a cache hit. An absent descriptor
still throws the error a stat gives.

Tests: each changed cache reads again a file rewritten with the same size
and mtime, and a cache hit still records its file. Each new test fails
without the fix.
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 17, 2026 10:43pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 17, 2026
@astracat-bot

astracat-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 17, 2026, 10:43 PM UTC

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 9e307c8

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 5.38 MB packed (+251 B); no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot 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.

Changes requested: the cache change is sound and its tests prove it, but the release note and the description each claim something the change does not do.

  • The changeset says theme part data is now read again "when npm replaces it with a file of the same size and modification time", but npm never writes that cache file and the old key already caught a replacement through its inode; what changes for part data is a rewrite in place that keeps size, mtime and inode, so reword that clause or leave part data out of the note.
  • The description says each new test fails without the fix, but throws for an absent file in theme-discovery.test.mjs passes on the base because it guards an error the base already threw, so reword that sentence.

Non-blocking: moduleText, parseModule and partData can keep an entry under the absent stamp - when a file appears between the stamp and the read; keeping nothing for - closes that.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim (changeset): a long-running process reads a family doc again after npm replaces it with one of the same size and mtime: verified by the new family-doc test, which fails on the base and passes here.
  • Claim (changeset): the same for a theme or icon descriptor: verified by the new descriptor test; icon sets and icon definitions read through the same function.
  • Claim (changeset): the same for theme part data: false, since the old key held the inode and npm does not write that file.
  • Claim: every in-process file cache now keys on the shared fileStamp: verified in the four changed modules; no private copy of the rule remains among the in-process file caches.
  • Claim: the part-data key left out ctime: verified (the old key was inode, size and mtime).
  • Claim: fileStamp is a raw stat that read recording does not see, while the old copies used the recorded fs.statSync: verified in read-record.mjs.
  • Claim: each cache records its file with recordContentRead, as the TypeScript config reader does, so a kept catalog sees the dependency on a cache hit: verified by the four recording tests, which fail on the base and pass here.
  • Claim: an absent descriptor still throws the error a stat gives: verified (readStaticDescriptorValue calls fs.statSync on an absent stamp; the test passes on both).
  • Claim: each changed cache reads again a file rewritten with the same size and mtime, and a cache hit still records its file: verified.
  • Claim: each new test fails without the fix: false, one of the eight new tests passes on the base.
  • .changeset/cache-file-stamp.md: finding (part-data clause).
  • packages/cli/api/theme-edit/_parts.mjs: non-blocking note (absent stamp kept).
  • packages/cli/api/theme-edit/theme-census-key.test.mjs: clear.
  • packages/cli/foundation/discovery/component-discovery.mjs: clear.
  • packages/cli/foundation/discovery/component-discovery.test.mjs: clear.
  • packages/cli/foundation/discovery/module-exports.mjs: non-blocking note (absent stamp kept).
  • packages/cli/foundation/discovery/module-exports.test.mjs: clear.
  • packages/cli/foundation/discovery/theme-discovery.mjs: clear.
  • packages/cli/foundation/discovery/theme-discovery.test.mjs: finding (the description's claim about its absent-file test).

Automated review (maintainer link)

Comment thread .changeset/cache-file-stamp.md Resolved
… note

A file that appears between its stamp and its read was kept under the
absent stamp `-`, and served after it was removed again. The module text,
parsed module, doc value, descriptor and part data caches now keep
nothing for `-`.

The changeset now says what changes for the theme part data cache: a
rewrite in place that keeps its size and modification time. npm never
writes that file, and the old key already caught a replacement.

@astracat-bot astracat-bot 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.

Approved pending CI: CI has not finished on this head yet, so the required checks still need to pass before this merges.

The follow-up fixes both points from the last review: the release note now describes the in-place rewrite of the part data cache, and the description says the absent-descriptor test passes on the base too. No cache keeps anything read under the absent stamp any more. The seven new re-read and recording tests fail on the base and pass here.

Claims and files checked

Review mode: incremental; reason: none

  • Claim (changeset): a long-running process reads a family doc again after npm replaces it with one of the same size and mtime: verified by component-discovery.test.mjs:191, which fails on the base and passes here.
  • Claim (changeset): the same for a theme or icon descriptor: verified by theme-discovery.test.mjs:588; icon sets and icon definitions read through the same reader.
  • Claim (changeset): the theme part data cache is read again after an in-place rewrite with the same size and mtime: verified by theme-census-key.test.mjs:64.
  • Claim: a cache keyed on size and mtime alone kept serving old content after npm replaced a file: verified (the base's member and descriptor keys used only those two).
  • Claim: every in-process file cache now keys on the shared fileStamp: verified at each call site (component-discovery.mjs:281, :1119, module-exports.mjs:143, :158, theme-discovery.mjs:721, _parts.mjs:758); no private copy remains.
  • Claim: the part-data key left out ctime: verified (the base key was inode, size and mtime).
  • Claim: fileStamp is a raw stat that read recording does not see, while the old copies used the recorded stat: verified in read-record.mjs.
  • Claim: each cache records its file with recordContentRead, as the TypeScript config reader does, so a kept catalog sees the dependency on a cache hit: verified by the four recording tests and package-tsconfig.mjs:51.
  • Claim: an absent descriptor still throws the error a stat gives: verified (theme-discovery.mjs:723, theme-discovery.test.mjs:615).
  • Claim: each changed cache reads again a file rewritten with the same size and mtime, and a cache hit still records its file, and each of those tests fails without the fix: verified, seven tests fail on the base and pass here.
  • Claim: the absent-descriptor test guards kept behavior and passes on the base too: verified.
  • .changeset/cache-file-stamp.md: clear.
  • packages/cli/api/theme-edit/_parts.mjs: clear.
  • packages/cli/api/theme-edit/theme-census-key.test.mjs: clear.
  • packages/cli/foundation/discovery/component-discovery.mjs: clear.
  • packages/cli/foundation/discovery/component-discovery.test.mjs: clear.
  • packages/cli/foundation/discovery/module-exports.mjs: clear.
  • packages/cli/foundation/discovery/module-exports.test.mjs: clear.
  • packages/cli/foundation/discovery/theme-discovery.mjs: clear.
  • packages/cli/foundation/discovery/theme-discovery.test.mjs: clear.

Automated review (maintainer link)

@josephfarina
josephfarina merged commit 2f67389 into main Nov 18, 2026
155 of 157 checks passed
@github-actions
github-actions Bot deleted the josephfarina/file-identity-cache-rule branch November 18, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 9e307c88 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant