Skip to content

fix: use shared memory for virtual files when running with app isolation #9181

Merged
akshayka merged 5 commits intomainfrom
aka/isolate-apps-bug-fixes
Apr 14, 2026
Merged

fix: use shared memory for virtual files when running with app isolation #9181
akshayka merged 5 commits intomainfrom
aka/isolate-apps-bug-fixes

Conversation

@akshayka
Copy link
Copy Markdown
Contributor

@akshayka akshayka commented Apr 14, 2026

This change updates isolated apps to use shared memory for virtual
file storage.

Isolated apps run in different processes from the main server. This
means they need to place virtual file data in shared memory, but
historically run-mode has run in-process and used in-memory
storage.

The change looks large because we're lifting the choice of storage
out of the kernel context, letting the caller decide what storage
backend to use. This required touching many files. In practice the change is small.

This fixes the issue identified in the following comment: #9127 (comment)

This change updates isolated apps to use shared memory for virtual
file storage.

Isolated apps run in different processes from the main server. This
means they need to place virtual file data in shared memory, but
historically run-mode has used run in-process and used in-memory
storage.

The change looks large because we're lifting the choice of storage
out of the kernel context, letting the caller decide what storage
backend to use. This required touching many files.
Copilot AI review requested due to automatic review settings April 14, 2026 00:50
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 14, 2026 9:30pm

Request Review

Comment on lines -161 to 170
# Use shared memory in edit mode,
# in-memory storage in run mode (same process)
storage = (
# Storage is chosen explicitly by the caller. None means virtual files
# are not supported; we still construct an (inert) InMemoryStorage so
# the registry has a backend, but ctx.virtual_files_supported is False.
storage: VirtualFileStorage = (
SharedMemoryStorage()
if mode == SessionMode.EDIT
if virtual_file_storage == "shared_memory"
else InMemoryStorage()
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the main change in this PR.

@akshayka akshayka added the bug Something isn't working label Apr 14, 2026
@akshayka akshayka requested a review from dmadisetti April 14, 2026 00:52
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

This PR updates marimo’s virtual file subsystem to work correctly when apps are run in isolated subprocesses by making the virtual-file storage backend an explicit choice (shared memory vs in-process memory vs disabled).

Changes:

  • Replace the boolean virtual_files_supported flag with virtual_file_storage: "in_memory" | "shared_memory" | None and thread it through session/kernel/app-host/runtime creation paths.
  • Configure AppHost (isolated run-mode) kernels to use shared-memory virtual-file storage so the parent server can serve /@file/... requests.
  • Add a process-isolation smoke test for virtual files and update docs/tests to use the new parameter.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tests/conftest.py Updates kernel/test config to pass virtual_file_storage based on session mode.
tests/_session/app_host/test_main.py Switches app-host tests to pass virtual_file_storage="shared_memory".
tests/_session/app_host/test_app_host.py Switches app-host tests to pass virtual_file_storage="shared_memory".
tests/_server/test_sessions.py Updates session/kernel-manager tests to new virtual_file_storage arg.
tests/_runtime/test_runtime.py Updates runtime tests to use virtual_file_storage.
marimo/_smoke_tests/process_isolation/virtual_files.py Adds a smoke-test notebook for virtual files under process isolation.
marimo/_smoke_tests/process_isolation/README.md Documents how to run the process-isolation virtual-file smoke test.
marimo/_session/session.py Threads virtual_file_storage into the “original kernel” session creation path.
marimo/_session/managers/kernel.py KernelManager now stores and passes virtual_file_storage into runtime.launch_kernel.
marimo/_session/managers/ipc.py Removes virtual_files_supported from IPC manager args (IPC kernels always disable virtual files).
marimo/_session/managers/app_host.py Forces AppHost kernels to use virtual_file_storage="shared_memory".
marimo/_session/app_host/main.py App-host kernel launch now forwards virtual_file_storage.
marimo/_session/app_host/host.py AppHost create_kernel now accepts virtual_file_storage.
marimo/_session/app_host/commands.py Updates CreateKernelCmd to include virtual_file_storage.
marimo/_server/session_manager.py Chooses default virtual_file_storage based on session mode (edit vs run).
marimo/_server/export/init.py Export path disables virtual files via virtual_file_storage=None.
marimo/_runtime/virtual_file/storage.py Introduces VirtualFileStorageType and keeps storage backends.
marimo/_runtime/virtual_file/init.py Re-exports VirtualFileStorageType.
marimo/_runtime/runtime.py Updates launch_kernel signature to accept virtual_file_storage.
marimo/_runtime/context/kernel_context.py Selects virtual-file backend based on virtual_file_storage and sets virtual_files_supported.
marimo/_runtime/app/kernel_runner.py Uses shared-memory storage for embedded/edit-like runner context.
marimo/_pyodide/pyodide_session.py Disables virtual files via virtual_file_storage=None.
marimo/_ipc/types.py Removes virtual_files_supported from KernelArgs.
marimo/_ipc/launch_kernel.py IPC kernel launch disables virtual files via virtual_file_storage=None.

Comment thread tests/_server/test_sessions.py
Comment thread marimo/_runtime/context/kernel_context.py
Comment thread tests/_server/test_sessions.py Outdated
Comment thread tests/_server/test_sessions.py Outdated
Comment thread tests/_server/test_sessions.py Outdated
Comment thread marimo/_smoke_tests/process_isolation/virtual_files.py
Comment thread tests/_server/test_sessions.py Outdated
Comment thread marimo/_smoke_tests/process_isolation/virtual_files.py
Comment thread marimo/_smoke_tests/process_isolation/README.md
Comment thread tests/_server/test_sessions.py Outdated
Thanks copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread marimo/_ipc/types.py
# Whether to use run-mode config (autorun) vs edit-mode config (lazy)
is_run_mode: bool = False
# Runtime behavior flags
virtual_files_supported: bool = True
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@manzt I can keep this argument and just ignore it to prevent a breaking change, lmk. It looks like it was ignored before

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We extend the KernelManager impl in the VS Code extension, so we probably just need to bump the minimum marimo version in the next release.

https://github.com/marimo-team/marimo/actions/runs/24527579413

dmadisetti
dmadisetti previously approved these changes Apr 14, 2026
@akshayka akshayka merged commit 4572872 into main Apr 14, 2026
43 checks passed
@akshayka akshayka deleted the aka/isolate-apps-bug-fixes branch April 14, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants