fix: increased cache robustness for wire level cell resolution#10109
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
6450f9d to
32b44cb
Compare
Bundle a session's per-cell and per-function caches into the output of marimo export html-wasm --execute, so a dependency-free browser (Pyodide) can skip recomputation. Stacked on the cache-robustness PR (#10109), which provides the graceful-degrade / hashing-parity restore machinery this relies on to consume the bundled caches without the original deps. This pull request was authored by a coding agent.
There was a problem hiding this comment.
Pull request overview
This PR bumps the persistent cache schema to v5 and hardens cell-level caching in environments where optional dependencies (e.g. torch in WASM) are unavailable, while also ensuring background cache writes are flushed during kernel teardown for export/durability consistency.
Changes:
- Improve stub/restore behavior so unmaterializable defs (missing optional deps) still allow downstream cache-key reproduction via persisted content digests, and cached wrappers (
@mo.cache/@mo.persistent_cache) can be reconstituted as working wrappers on restore. - Avoid fetching blobs that can’t be deserialized in the current environment (root module absent), substituting an
UnhashableStubthat carries the persisted digest. - Add teardown-time flushing for lazy loader background writes and adjust invalidation semantics to mark manifests stale (without destroying recoverable cache entries).
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/_save/stubs/test_module_stub.py | Adds coverage for ModuleStub version fallback to root package version and empty-version behavior. |
| tests/_save/loaders/test_loader.py | Adds coverage ensuring absent-module blobs are not fetched and content digests propagate into stubs. |
| tests/_runtime/test_cached_stage.py | Updates invalidation expectations (stale-only) and adds scenario coverage for serializable siblings not forcing live reruns. |
| marimo/_session/managers/kernel.py | Attempts cleaner shutdown and gives the kernel time to flush pending work before termination. |
| marimo/_save/stubs/module_stub.py | Captures root package __version__ for submodule aliases to preserve version-pinned hashes on restore. |
| marimo/_save/stubs/lazy_stub.py | Extends schema (function tuples) and enriches UnhashableStub with content_hash for downstream hashing. |
| marimo/_save/stubs/function_stub.py | Adds cached-wrapper support (is_cached) and dump/restore helpers for schema persistence. |
| marimo/_save/loaders/loader.py | Introduces a flush() hook for loaders to drain async writes. |
| marimo/_save/loaders/lazy.py | Adds module-availability gating for blob fetch, persists content digests, and wires in global flush for active loaders. |
| marimo/_save/loaders/init.py | Exposes flush_active_caches from loaders package. |
| marimo/_save/hash.py | Teaches the hasher to replay persisted content digests from restored stubs and to handle marimo-owned stubs without flipping cache mode. |
| marimo/_save/cache.py | Bumps cache version to 5; improves restore degradation behavior and adds cached-wrapper stub capture/restore logic. |
| marimo/_runtime/runtime.py | Adds callback teardown phase while runtime context is still alive. |
| marimo/_runtime/kernel_lifecycle.py | Invokes callback teardown before tearing down runtime context. |
| marimo/_runtime/executor/lifecycles/cached.py | Improves logging/UI def detection and changes invalidation to stale-only (no clear). |
| marimo/_runtime/callbacks/protocol.py | Adds SupportsTeardown runtime-checkable protocol. |
| marimo/_runtime/callbacks/cache.py | Implements teardown flush of active caches for durability on kernel teardown. |
| marimo/_runtime/callbacks/init.py | Re-exports SupportsTeardown. |
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
32b44cb to
72f09a2
Compare
Bundle a session's per-cell and per-function caches into the output of marimo export html-wasm --execute, so a dependency-free browser (Pyodide) can skip recomputation. Stacked on the cache-robustness PR (#10109), which provides the graceful-degrade / hashing-parity restore machinery this relies on to consume the bundled caches without the original deps. This pull request was authored by a coding agent.
| def __init__(self, function: Any, is_cached: bool = False) -> None: | ||
| self.is_cached = is_cached | ||
| if is_cached: | ||
| # Capture the wrapped body's source (incl. the decorator line). | ||
| function = function.__wrapped__ |
There was a problem hiding this comment.
I don't think anyone has FunctionStub pickles yet, so this is fine. Technically breaking but I expect 0 impact
| if var not in variable_hashes: | ||
| # NB. persist a digest for data primitives so a consumer | ||
| # reproduces its key without the value. | ||
| digest = _maybe_content_digest(obj) |
There was a problem hiding this comment.
should this happen in a thread? is this expensive to do on the main thread and in a for loop
There was a problem hiding this comment.
Good point. will be care for when this runs through WASM. Doing this as a follow up to unblock my other branch in the meantime
mscolnick
left a comment
There was a problem hiding this comment.
looks great! one small comment on perf for the lazy store
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.14-dev37 |
Bundle a session's per-cell and per-function caches into the output of marimo export html-wasm --execute, so a dependency-free browser (Pyodide) can skip recomputation. Stacked on the cache-robustness PR (#10109), which provides the graceful-degrade / hashing-parity restore machinery this relies on to consume the bundled caches without the original deps. This pull request was authored by a coding agent.
Bundle a session's per-cell and per-function caches into the output of marimo export html-wasm --execute, so a dependency-free browser (Pyodide) can skip recomputation. Stacked on the cache-robustness PR (#10109), which provides the graceful-degrade / hashing-parity restore machinery this relies on to consume the bundled caches without the original deps. This pull request was authored by a coding agent.
📝 Summary
This PR resolves 3 issues with the cell level caching introduced.
@mo.persistent_cachefunctions were not correctly resolved and their subsequent calling would break if dependent on a unhashable stub