Skip to content

refactor: improve persistent cache load error handling#13608

Merged
jerrykingxyz merged 3 commits intomainfrom
jerry/cache
Apr 7, 2026
Merged

refactor: improve persistent cache load error handling#13608
jerrykingxyz merged 3 commits intomainfrom
jerry/cache

Conversation

@jerrykingxyz
Copy link
Copy Markdown
Contributor

@jerrykingxyz jerrykingxyz commented Apr 3, 2026

Summary

Persistent cache loads data for the corresponding Occasion at each runtime stage. This PR improves the error handling process. When an error occurs during loading

  1. Persistent Cache should reset the cache of the current scope, because rspack will perform a full build of the current stage if the cache becomes unavailable, and therefore all data will be written after this build is complete.
  2. If the cache is unavailable at the current stage, it will directly cause the incremental build downstream to be unavailable. Therefore, the cache at the downstream stage can also be reset.

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings April 3, 2026 12:54
@github-actions github-actions Bot added release: refactor team The issue/pr is created by the member of Rspack. labels Apr 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the persistent cache subsystem to make cache load failures safer and more localized by introducing per-scope reset behavior and a shared cache lifecycle context, while removing legacy “artifact state” tracking.

Changes:

  • Introduce CacheContext to centralize persistent cache validity/readonly logic, warning collection, and scoped reset/load/save flows.
  • Update storage APIs to use synchronous save() and scoped reset(scope) that enqueue background work, with flush() as the async synchronization point.
  • Remove BuildModuleGraphArtifactState and rely on compilation.is_rebuild to control persistent-cache recovery behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rspack_tools/src/compare/occasion/make.rs Updates imports to use the new Occasion abstraction when recovering make artifacts.
crates/rspack_storage/src/memory/mod.rs Aligns MemoryStorage with new Storage trait (save() and reset(scope)).
crates/rspack_storage/src/lib.rs Changes Storage trait API: save() and scoped reset(scope) become sync enqueue operations.
crates/rspack_storage/src/filesystem/mod.rs Updates filesystem storage implementation to new Storage trait and scoped reset.
crates/rspack_storage/src/filesystem/db/mod.rs Adds scoped DB reset task and readonly fail-safe behavior for background operations.
crates/rspack_core/src/compilation/build_module_graph/mod.rs Stops re-exporting the removed BuildModuleGraphArtifactState.
crates/rspack_core/src/compilation/build_module_graph/graph_updater/mod.rs Removes initialization of the deleted artifact state.
crates/rspack_core/src/cache/persistent/snapshot/mod.rs Adds Snapshot::reset() to clear all snapshot-related scopes.
crates/rspack_core/src/cache/persistent/occasion/mod.rs Introduces the Occasion trait to standardize reset/save/recovery responsibilities.
crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs Converts MetaOccasion to implement the new Occasion trait.
crates/rspack_core/src/cache/persistent/occasion/make/mod.rs Converts MakeOccasion to implement Occasion and removes dependence on artifact state.
crates/rspack_core/src/cache/persistent/mod.rs Reworks PersistentCache to use CacheContext and scoped resets instead of global validity/reset.
crates/rspack_core/src/cache/persistent/context.rs Adds new CacheContext orchestration layer for load/save/reset flows and warning aggregation.
crates/rspack_core/src/cache/persistent/build_dependencies/mod.rs Adds scoped reset for build dependency storage.
crates/rspack_core/src/artifacts/build_module_graph_artifact.rs Removes BuildModuleGraphArtifactState and the state field from the artifact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rspack_storage/src/filesystem/db/mod.rs
Comment thread crates/rspack_storage/src/filesystem/db/mod.rs
Comment thread crates/rspack_core/src/cache/persistent/context.rs
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a3c7d789a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/rspack_core/src/cache/persistent/context.rs Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 3, 2026

Merging this PR will degrade performance by 2.7%

❌ 1 regressed benchmark
✅ 17 untouched benchmarks
⏩ 19 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@create_chunk_ids 10.6 ms 10.9 ms -2.7%

Comparing jerry/cache (4a4fce1) with main (7165b23)

Open in CodSpeed

Footnotes

  1. 19 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

Rsdoctor Bundle Diff Analysis

⚠️ Note: The latest commit (4847e205a0) does not have baseline artifacts. Using commit 7165b2395e for baseline comparison instead. If this seems incorrect, please wait a few minutes and try rerunning the workflow.

Found 6 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB 0
react-10k 5.7 MB 0
react-1k 826.9 KB 0
react-5k 2.7 MB 0
rome 984.1 KB 0
ui-components 5.0 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

📦 Binary Size-limit

Comparing 4a4fce1 to fix(core): move connection states to ModuleGraphConnection (#13624) by Fy

❌ Size increased by 7.91KB from 49.33MB to 49.34MB (⬆️0.02%)

@jerrykingxyz jerrykingxyz force-pushed the jerry/cache branch 2 times, most recently from f58cf34 to aefba61 Compare April 7, 2026 05:37
LingyuCoder
LingyuCoder previously approved these changes Apr 7, 2026
@jerrykingxyz jerrykingxyz merged commit c8abe3c into main Apr 7, 2026
57 of 59 checks passed
@jerrykingxyz jerrykingxyz deleted the jerry/cache branch April 7, 2026 06:47
hardfist pushed a commit that referenced this pull request Apr 9, 2026
* refactor: remove useless BuildModuleGraphArtifact state

* refactor: improve persistent cache load error handling

* feat: add trace log in cache context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants