Skip to content

improvement: enable reading session cache in App Mode (configurable)#7895

Merged
mscolnick merged 2 commits intomarimo-team:mainfrom
aqora-io:feat-read-only-cache
Feb 9, 2026
Merged

improvement: enable reading session cache in App Mode (configurable)#7895
mscolnick merged 2 commits intomarimo-team:mainfrom
aqora-io:feat-read-only-cache

Conversation

@jpopesculian
Copy link
Contributor

@jpopesculian jpopesculian commented Jan 19, 2026

Implements #7849

Changes

  1. Bug fix: cell_ids was not initialized on the SessionView so cache exports would sometimes be exported out of order. The fix was to emit an UpdateCellIdsNotification on notebook creation
  2. Add a new serve_cached_sessions_in_apps runtime configuration item to use the cache in a read-only manner when running as an application

@github-actions github-actions bot added the bash-focus Area to focus on during release bug bash label Jan 19, 2026
@vercel
Copy link

vercel bot commented Jan 19, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 9, 2026 10:24am

Request Review

Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

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

The added cache flags makes sense in the context, but it seems like you'd always wanted cached outputs when auto instantiation is on?

Agreed that the behavior might be somewhat broken now

</FormItem>

<FormDescription>
Whether to cache cell outputs to disk and restore them on
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is true by default when auto instantiation is off I'm not sure we need the additional distinction

LOGGER.info("App is already instantiated, skipping instantiation.")
return

cell_ids = [er.cell_id for er in request.execution_requests]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this right? Not certain the cellida must be in order. If it is correct can you leave a comment why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated this to take an explicit cell_ids for clarity. I think because dict keys are ordered in python as far as my knowledge goes, this would be essentially the same, but it seems somewhat fragile, so better to be explicit

@mscolnick
Copy link
Contributor

We don't want the config for edit-mode and app-mode to be the same (there are cases you want one without the other).

How about runtime.serve_cached_sessions_in_apps

class RuntimeConfig:
   ...
   serve_cached_sessions_in_apps: NotRequired[bool]

this way we 1) don't need to set a default and 2) we can fallback to False. this will also result in less of a diff footprint.

also we don't need to show this in the UI if this is just deployment configuration (which I assume is your use-case)

@jpopesculian jpopesculian force-pushed the feat-read-only-cache branch 2 times, most recently from 9f36e24 to e597d8e Compare February 4, 2026 11:39
@mscolnick mscolnick added the enhancement New feature or request label Feb 5, 2026
@mscolnick mscolnick changed the title Improvements to session caching improvement: enable reading session cache in App Mode (configurable) Feb 5, 2026
Copy link
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

Enables app-mode (RUN) sessions to initialize from the on-disk session cache in a read-only manner, and fixes initial cell ordering initialization so cached exports/replays are ordered deterministically.

Changes:

  • Add cell_ids to CreateNotebookCommand and emit an UpdateCellIdsNotification at notebook instantiation to initialize SessionView.cell_ids.
  • Introduce CacheMode and run CachingExtension in read-only mode for RUN sessions (configurable via runtime.serve_cached_sessions_in_apps).
  • Update OpenAPI schema and tests to account for the new cellIds field and caching mode behavior.

Reviewed changes

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

Show a summary per file
File Description
tests/_session/state/test_session_view.py Update CreateNotebookCommand test fixtures to include cell_ids.
tests/_session/extensions/test_extensions.py Add coverage for read-only caching mode (no writer start; rename ignored).
tests/_server/test_sessions.py Validate caching enablement + cache mode across EDIT/RUN and config override.
tests/_server/api/endpoints/test_ws.py Adjust snapshot expectation: first notification is now update-cell-ids.
tests/_runtime/test_runtime.py Update runtime instantiation tests to pass cell_ids.
tests/_runtime/test_dotenv.py Update CreateNotebookCommand fixture with cell_ids.
tests/_pyodide/test_pyodide_session.py Update JSON parsing fixture to include cellIds.
packages/openapi/src/api.ts Regenerate TS types for cellIds on CreateNotebookCommand and new runtime config key.
packages/openapi/api.yaml Update OpenAPI schema: cellIds required on CreateNotebookCommand; add serve_cached_sessions_in_apps.
marimo/_session/session.py Configure caching extension by session mode; enable RUN cache read via config.
marimo/_session/extensions/extensions.py Add CacheMode and skip writer start + rename handling in read-only mode.
marimo/_runtime/runtime.py Broadcast UpdateCellIdsNotification at instantiate using request.cell_ids.
marimo/_runtime/commands.py Extend CreateNotebookCommand with cell_ids.
marimo/_pyodide/bootstrap.py Populate cell_ids when creating notebook in Pyodide.
marimo/_config/config.py Add runtime.serve_cached_sessions_in_apps to config schema/docs.

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

Comment on lines +145 to +152
if mode == SessionMode.EDIT:
cache_enabled = not auto_instantiate
cache_mode = CacheMode.READ_WRITE
else:
cache_enabled = config_manager.get_config()["runtime"].get(
"serve_cached_sessions_in_apps", False
)
cache_mode = CacheMode.READ
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

PR description says a new cache_outputs setting was added to control caching, but the implementation here is keyed off runtime.serve_cached_sessions_in_apps and there are no cache_outputs references in the repo. Please either update the PR description to match the actual config knob (and naming), or implement/rename the setting so the behavior is controlled by cache_outputs as described.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated PR description

(
'{"type": "create-notebook", "executionRequests": [{"cellId": "cell-1", "code": "print(1)", "type": "execute-cell"}], '
'"setUiElementValueRequest": {"objectIds": [], "values": [], "type": "update-ui-element"}, '
'"cellIds": [], "setUiElementValueRequest": {"objectIds": [], "values": [], "type": "update-ui-element"}, '
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

This create-notebook JSON fixture sets cellIds to an empty list even though executionRequests contains cell-1. Using an empty cellIds list makes the test less representative and could allow regressions in cell ordering (the new behavior depends on cell_ids). Update the payload so cellIds matches the execution request IDs.

Suggested change
'"cellIds": [], "setUiElementValueRequest": {"objectIds": [], "values": [], "type": "update-ui-element"}, '
'"cellIds": ["cell-1"], "setUiElementValueRequest": {"objectIds": [], "values": [], "type": "update-ui-element"}, '

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@mscolnick mscolnick merged commit d85e9b7 into marimo-team:main Feb 9, 2026
5 of 6 checks passed
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.19.10-dev11

manzt added a commit to marimo-team/marimo-lsp that referenced this pull request Feb 12, 2026
Fixes #398. Notebooks failed to execute with a `TypeError: Missing
required argument 'cell_ids'` when constructing `CreateNotebookCommand`
in the LSP session.

marimo-team/marimo#7895 introduced a required `cell_ids` field on
`CreateNotebookCommand` to fix out-of-order cache exports — the
`SessionView` wasn't being initialized with cell IDs, so the caching
system didn't know the canonical cell ordering. The marimo-lsp session
subclasses the marimo session and constructs `CreateNotebookCommand`
directly, so it wasn't updated when the upstream signature changed. This
surfaces as a crash on any cell execution attempt since `instantiate()`
is called on the first run.

The fix passes `cell_ids=tuple(codes.keys())` to match the upstream
pattern, and bumps the marimo dependency to >=0.19.10 where this field
is required.
manzt added a commit to marimo-team/marimo-lsp that referenced this pull request Feb 12, 2026
Fixes #398. Notebooks failed to execute with a `TypeError: Missing
required argument 'cell_ids'` when constructing `CreateNotebookCommand`
in the LSP session.

marimo-team/marimo#7895 introduced a required `cell_ids` field on
`CreateNotebookCommand` to fix out-of-order cache exports — the
`SessionView` wasn't being initialized with cell IDs, so the caching
system didn't know the canonical cell ordering. The marimo-lsp session
subclasses the marimo session and constructs `CreateNotebookCommand`
directly, so it wasn't updated when the upstream signature changed. This
surfaces as a crash on any cell execution attempt since `instantiate()`
is called on the first run.

The fix passes `cell_ids=tuple(codes.keys())` to match the upstream
pattern, and bumps the marimo dependency to >=0.19.10 where this field
is required.
mscolnick added a commit that referenced this pull request Feb 12, 2026
mscolnick added a commit that referenced this pull request Feb 12, 2026
@jpopesculian jpopesculian deleted the feat-read-only-cache branch February 12, 2026 20:45
@jpopesculian jpopesculian restored the feat-read-only-cache branch February 13, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants