Repository navigation
Conversation
The React Compiler cache at <git-common-dir>/bb-cache/react-compiler never removed anything. Builds alone grew it to 4.1 GB (702k index files) since Sep 10, and #8227 added test and dev-server entries. When the cache wrapper resolves its config and the cache's pruned-at marker is more than a day old, it touches the marker and starts a detached prune process. The prune deletes index buckets whose newest entry is older than 30 days, then deletes content that no remaining entry references and that is itself older than 30 days, so content a concurrent writer has just stored is never removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A missing bucket or content file, removed by a concurrent prune or by cacache.rm.content on a corrupt entry, made readFile or stat throw and the detached prune exit with the rest of the cache unpruned until the next day. The prune now skips files that are gone. The prune test also stores content with no index entry, as a writer does before it appends the entry, and checks that it survives. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/8227-cache-react-compiler-output-in-app-tests-an-thr_224svhsmxn
branch
November 30, 2026 21:42
scowalt
pushed a commit
to scowalt/bb
that referenced
this pull request
Dec 1, 2026
## Human comments ## What was wrong The React Compiler transform cache at `<git-common-dir>/bb-cache/react-compiler` never removes anything. Builds alone had grown it to 4.1 GB (702k index files, 2.7 GB of which is index) since Sep 10. get-bb#8227 now also caches app tests and the app dev server. A full app test run adds about 38 MB whenever the lockfile, a `package.json` or a Vite/Vitest config changes (38 commits on main touched one in the last 30 days), and the dev server adds a similar set of entries. Deleting the directory once only resets the clock for that one clone. ## What changed - `apps/app/react-compiler-cache-prune.ts` (new): - `pruneCompilerCache` deletes index buckets whose newest entry is older than 30 days. - It then deletes stored content that no remaining entry references and that is itself older than 30 days, so content a concurrent writer has just stored, before it appends the index entry, is kept. One race remains: cacache does not rewrite content that already exists, so a new entry whose output is byte-identical to old unreferenced content can lose that content to a prune that already scanned the index. That read, like any read racing a deletion, fails and falls back to a fresh compile that stores the content again, the same path a corrupt entry takes today. - Files that disappear mid-run (a second prune, or `cacache.rm.content` on a corrupt entry) are skipped instead of aborting the run. - Run as a script (Node ≥22.19 strips the types), it prunes the directory given as its argument. - `schedulePrune` checks a `pruned-at` marker in the cache directory. When the marker is more than a day old, it touches the marker and starts the script as a detached, unref'd process, so no build, test run or dev server waits on it. - `apps/app/vite-react-compiler.ts` calls `schedulePrune` once the cache is set up in `configResolved`. Failures only log a warning. - `docs/configuration.md` and `docs/debugging-and-qa.md` describe the pruning. Entries are dated by when they were written, so a cache hit does not refresh an entry. A module unchanged for more than 30 days recompiles once after a prune. `cacache.verify` was not used: it loads the whole index into memory, re-checksums all content and clears `tmp/` while other worktrees may be writing. CI is effectively unaffected. Its cache key includes the lockfile and `apps/app/vite*.ts` hashes, so it starts over whenever those change, and the prune finds little to delete there. ## How you verified - New `apps/app/src/test/react-compiler-cache-prune.test.ts`: - The first test runs the real script in a child process over expired, shared and recent entries. It checks that expired entries and their unreferenced content are removed, and that content a recent entry still uses survives. Breaking the liveness check makes it fail with `ENOENT` on the shared content. It also stores content with no index entry and checks that it survives; dropping the 30-day content age check makes that fail. - The second test checks that pruning is scheduled at most once a day. - On a real shared cache, the first prune took it from 4.1 GB to 1.4 GB: index files from 702k to 234k, content files from 22k to 9.7k. It took about 15 minutes, with a large copy competing for the disk. A steady-state run with nothing to delete took 3 min 54 s of wall time and 59 s of CPU. - A backdated marker made `pnpm exec turbo run build --filter=@bb/app --force` update the marker and leave a detached prune running after the build exited. The build itself reported `React Compiler cache: 1476 hits, 0 misses`. The Vitest config path also schedules it. - `pnpm exec turbo run typecheck lint lint:type-aware --filter=@bb/app` passes; the 8 React Compiler cache tests pass. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Human comments
What was wrong
The React Compiler transform cache at
<git-common-dir>/bb-cache/react-compilernever removes anything. Builds alone had grown it to 4.1 GB (702k index files, 2.7 GB of which is index) since Sep 10. #8227 now also caches app tests and the app dev server. A full app test run adds about 38 MB whenever the lockfile, apackage.jsonor a Vite/Vitest config changes (38 commits on main touched one in the last 30 days), and the dev server adds a similar set of entries. Deleting the directory once only resets the clock for that one clone.What changed
apps/app/react-compiler-cache-prune.ts(new):pruneCompilerCachedeletes index buckets whose newest entry is older than 30 days.cacache.rm.contenton a corrupt entry) are skipped instead of aborting the run.schedulePrunechecks apruned-atmarker in the cache directory. When the marker is more than a day old, it touches the marker and starts the script as a detached, unref'd process, so no build, test run or dev server waits on it.apps/app/vite-react-compiler.tscallsschedulePruneonce the cache is set up inconfigResolved. Failures only log a warning.docs/configuration.mdanddocs/debugging-and-qa.mddescribe the pruning.Entries are dated by when they were written, so a cache hit does not refresh an entry. A module unchanged for more than 30 days recompiles once after a prune.
cacache.verifywas not used: it loads the whole index into memory, re-checksums all content and clearstmp/while other worktrees may be writing.CI is effectively unaffected. Its cache key includes the lockfile and
apps/app/vite*.tshashes, so it starts over whenever those change, and the prune finds little to delete there.How you verified
apps/app/src/test/react-compiler-cache-prune.test.ts:ENOENTon the shared content. It also stores content with no index entry and checks that it survives; dropping the 30-day content age check makes that fail.pnpm exec turbo run build --filter=@bb/app --forceupdate the marker and leave a detached prune running after the build exited. The build itself reportedReact Compiler cache: 1476 hits, 0 misses. The Vitest config path also schedules it.pnpm exec turbo run typecheck lint lint:type-aware --filter=@bb/apppasses; the 8 React Compiler cache tests pass.🤖 Generated with Claude Code