Repository navigation
Update the docs cache as a whole - #1350
Merged
Merged
Conversation
2 tasks done
charlespwd
approved these changes
Oct 20, 2026
EvilGenius13
approved these changes
Oct 20, 2026
Updating the docs cache rewrote it one file at a time: - setup wrote the new latest.json first. If a later download failed, the cache had the new revision but a mix of old and new files, and no run fixed it until the next revision. - A file removed upstream stayed in the cache forever. - A run reading the cache while another wrote it could read a truncated file. - An HTTP error page was cached as if it were the file. setup now reads the remote revision without writing it. When it changed, replaceThemeLiquidDocs downloads every file into a new folder and swaps it in with two renames. So the cache is always one complete set, and a failed update leaves it as it was, to be retried on the next run. A download that isn't 2xx now fails. The manager's tests mock node:fs/promises, which leaked into the new downloader tests in the shared vitest project, so they now run isolated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clauderic
force-pushed
the
docs-cache-atomic-writes
branch
from
October 20, 2026 13:47
252bb9d to
fca4a62
Compare
charlespwd
approved these changes
Oct 20, 2026
1 task done
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.
Stacked on #1349. Review that one first; this PR's base moves down the stack as the PRs below it merge.
What are you adding in this PR?
The docs cache is now updated as a whole, as one folder swap, instead of one file at a time.
Updating it file by file had four problems:
setupwrote the newlatest.jsonbefore the other files. If a later download failed, the cache had the new revision but a mix of old and new files, and no run fixed it until the next revision.fs.writeFiletruncates first.downloaddidn't check the response status, so an HTTP error page was cached as if it were the file.Now:
setupreads the remote revision without writing it.replaceThemeLiquidDocsdownloads every file into a new folder next to the cache, then swaps it in with two renames: the old folder out, the new one in.The swap isn't atomic: between the two renames there's no cache folder. A reader in that moment falls back to the bundled docs, as it already does when the cache is missing. Two runs that update at once each stage a complete folder, and the cache ends up as one of them. A rename that loses the race fails, and that run keeps its old docs.
downloadThemeLiquidDocs(dir)is unchanged, since the CLI and the build use it to download into a folder of their choice.The manager's tests mock
node:fs/promises. In the shared vitest project that mock leaked into the new downloader tests, so the manager's tests now run isolated, like the other files inisolatedTests.What's next? Any followup issues?
None.
Tophatting
npx vitest run packages/theme-check-docs-updater. The downloader tests swap a real temporary folder: a complete download replaces it and drops a file that's gone upstream, and a failed one leaves it as it was. Both fail with the old file-by-file writes. The manager tests check thatsetupreplaces the docs only when the revision changed.HOMEso your own cache is untouched: build the package, then callnew ThemeLiquidDocsManager(console.error).tags()twice. The first run downloads into a staging folder and swaps it in, and the second reads the cache without downloading. Only the cache folder is left in$HOME/Library/Caches.Before you deploy
changeset🤖 Generated with Claude Code