Drop dangling @file URLs from the session cache#9278
Merged
Conversation
The session cache round-trips anywidget HTML verbatim, so cached `./@file/...` URLs replay into the new kernel pointing at buffers that no longer exist and the asset endpoint 404s. The assertion just checks the URL doesn't survive the round-trip — strip it, inline as a data URL, or persist and re-register the buffer; any of those satisfies it. Refs #9273.
Fixes #9273 The `./@file/...` URLs are backed by per-process buffers, so a cached snapshot replayed after kernel restart points at storage that no longer exists and the asset endpoint 404s (anywidget initialization for the restored cell then fails). `serialize_session_view` now takes a required `drop_virtual_file_outputs` keyword so each consumer picks deliberately based on whether the snapshot will be replayed in the same process as the producer. The on-disk cache passes `True` (cell appears un-run on restore, kernel re-emits a fresh output); HTML export and the static preview pass `False` and inline the buffers themselves while they're still live.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses stale ./@file/... virtual-file URLs being restored from the on-disk session cache after kernel restart, which can break anywidget initialization when the backing per-process buffers no longer exist.
Changes:
- Add a required
drop_virtual_file_outputskeyword toserialize_session_viewto force each consumer to choose whether to keep or drop virtual-file-backed outputs. - Drop outputs referencing virtual-file URLs for the on-disk session cache writer (and export session-cache path), while keeping them for HTML export and CLI preview (which inline/resolve them while still live).
- Add a regression test ensuring virtual-file URLs do not survive a cache round-trip when dropping is enabled.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
marimo/_session/state/serialize.py |
Adds virtual-file detection and a required flag to drop such outputs during session serialization; session cache writer now drops them. |
marimo/_server/export/_session_cache.py |
Session snapshot serialization for the on-disk cache now opts into dropping virtual-file outputs. |
marimo/_server/export/exporter.py |
HTML export serialization explicitly keeps virtual-file outputs so they can be inlined. |
marimo/_cli/development/commands.py |
Static preview serialization explicitly keeps virtual-file outputs. |
tests/_session/state/test_serialize_session.py |
Updates call sites and adds regression coverage for dropping dangling virtual-file URLs. |
tests/_session/state/test_serialize_session_missing_type.py |
Updates serialization call to include the new required keyword argument. |
The session-cache drop (#9273) matched the substring `./@file/`, which would also strip any plain-text output that merely mentioned the path. Anchoring to `./@file/<digits>-` restricts the match to the runtime's actual URL shape, and new tests cover the nested-dict recursion, the literal-prefix-in-text case, and the targeted-filter behavior.
manzt
commented
Apr 20, 2026
| # (see `marimo/_runtime/virtual_file/virtual_file.py`). Anchored to the | ||
| # byte-length digits so a literal "./@file/" mention in user content | ||
| # doesn't trip the check. | ||
| _VIRTUAL_FILE_URL_RE = re.compile(r"\./@file/\d+-") |
Collaborator
Author
There was a problem hiding this comment.
I think in a follow up we could actually "tag" a cell output with virtual files, so we don't need to parse it out here.
mscolnick
approved these changes
Apr 20, 2026
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.
Fixes #9273
The
./@file/...URLs are backed by per-process buffers, so a cached snapshot replayed after kernel restart points at storage that no longer exists and the asset endpoint 404s (anywidget initialization for the restored cell then fails).serialize_session_viewnow takes a requireddrop_virtual_file_outputskeyword so each consumer picks deliberately based on whether the snapshot will be replayed in the same process as the producer. The on-disk cache passesTrue(cell appears un-run on restore, kernel re-emits a fresh output); HTML export and the static preview passFalseand inline the buffers themselves while they're still live.