fix(save): keep lazy cache restore robust when a cached dep is absent#10065
Closed
dmadisetti wants to merge 2 commits into
Closed
fix(save): keep lazy cache restore robust when a cached dep is absent#10065dmadisetti wants to merge 2 commits into
dmadisetti wants to merge 2 commits into
Conversation
Three related fixes to the lazy-store restore path, extracted from the cache-e2e WASM validation work: - Restore tripwire: `_deserialize_blob` catches `ModuleNotFoundError` and binds the def as an `UnhashableStub` instead of aborting the whole restore — a torch tensor restored where torch is absent stays inert until touched, then raises a clear unhydratable error naming the def. The return value is excluded (a stubbed return fails the restore as a clean miss). Each def sharing a blob gets its own re-labeled stub. - Module-version pin survives restore: the pinned `__version__` captured at cache time is now persisted (`Item.module_version`) and replayed onto the `MissingModule` placeholder, so a version-pinned content hash reproduces on restore instead of collapsing to an empty version and missing. `hash.py` falls back to the in-scope placeholder when the module is not in `sys.modules`. `str()`-coerce the version because torch's `TorchVersion` is not encodable by the manifest codec. - Stale-key invalidation: `CacheState.stale_keys` + `Loader.mark_stale()` let a manifest be forced to miss for the session without being served or re-fetched (the WASM HTTP store would otherwise just re-fetch a cleared key). `save_cache` clears the mark so a recomputed value self-heals to a hit. No-op for loaders without a session-scoped store. Also resolves nested stubs on restore (an `ImmediateReferenceStub` whose blob is itself a `CustomStub`).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
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.
This pull request was authored by a coding agent.
Follow-up to #9898 (merged). Three related fixes to the lazy-store restore path, extracted and hardened from WASM cache-restore validation (torch → KANNs demo). All three are independent robustness improvements to the save layer.
1. Restore tripwire
LazyLoader._deserialize_blobnow catchesModuleNotFoundErrorand binds the def as anUnhashableStubinstead of aborting the entire restore. A cached value whose codec needs an absent package (e.g. atorchtensor restored where torch isn't installed) stays inert until touched, then raises a clear unhydratable error naming the def. The return value is excluded — a stubbed return fails the restore as a clean miss. Each def sharing a blob (all UI vars shareui.pickle) gets its own re-labeled stub.2. Module-version pin survives restore
pin_modules=Truecaptured a module's__version__at cache time but discarded it on restore, so a version-pinned content hash recomputed tomodule:<ref>:and missed. The version is now persisted (Item.module_version) and replayed onto theMissingModuleplaceholder;hash.pyfalls back to the in-scope placeholder when the module isn't insys.modules. Version isstr()-coerced because torch'sTorchVersionisn't encodable by the manifest codec.3. Stale-key invalidation mechanism
Adds
CacheState.stale_keys+Loader.mark_stale()(no-op default): a manifest can be forced to miss for the session without being served or re-fetched. This is the primitive the cell-cache preflight (stacked PR #9895) needs — the WASM HTTP store would otherwise re-fetch a cleared key and re-hit the same unusable value in a loop.save_cacheclears the mark so a recomputed value self-heals to a hit.Also resolves nested stubs on restore (an
ImmediateReferenceStubwhose blob is itself aCustomStub).Test plan
tests/_save/loaders/test_lazy_wasm.py: newTestRestoreTripwire,TestModuleVersionPin,TestStaleKeys(42 pass)tests/_save/full suite: 327 pass🤖 Generated with Claude Code