improvement: enable reading session cache in App Mode (configurable)#7895
improvement: enable reading session cache in App Mode (configurable)#7895mscolnick merged 2 commits intomarimo-team:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
84b2312 to
51f70b0
Compare
dmadisetti
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This is true by default when auto instantiation is off I'm not sure we need the additional distinction
marimo/_runtime/runtime.py
Outdated
| LOGGER.info("App is already instantiated, skipping instantiation.") | ||
| return | ||
|
|
||
| cell_ids = [er.cell_id for er in request.execution_requests] |
There was a problem hiding this comment.
Is this right? Not certain the cellida must be in order. If it is correct can you leave a comment why?
There was a problem hiding this comment.
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
|
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 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 also we don't need to show this in the UI if this is just deployment configuration (which I assume is your use-case) |
51f70b0 to
2b524ce
Compare
2b524ce to
20316e4
Compare
20316e4 to
1974e4d
Compare
9f36e24 to
e597d8e
Compare
e597d8e to
79f5d49
Compare
79f5d49 to
8eeed59
Compare
8eeed59 to
5df004b
Compare
5df004b to
029e2e8
Compare
029e2e8 to
703c07d
Compare
There was a problem hiding this comment.
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_idstoCreateNotebookCommandand emit anUpdateCellIdsNotificationat notebook instantiation to initializeSessionView.cell_ids. - Introduce
CacheModeand runCachingExtensionin read-only mode for RUN sessions (configurable viaruntime.serve_cached_sessions_in_apps). - Update OpenAPI schema and tests to account for the new
cellIdsfield 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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"}, ' |
There was a problem hiding this comment.
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.
| '"cellIds": [], "setUiElementValueRequest": {"objectIds": [], "values": [], "type": "update-ui-element"}, ' | |
| '"cellIds": ["cell-1"], "setUiElementValueRequest": {"objectIds": [], "values": [], "type": "update-ui-element"}, ' |
and use a read-only cache for run mode
703c07d to
b2bbde1
Compare
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.19.10-dev11 |
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.
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.
Implements #7849
Changes
cell_idswas not initialized on theSessionViewso cache exports would sometimes be exported out of order. The fix was to emit anUpdateCellIdsNotificationon notebook creationserve_cached_sessions_in_appsruntime configuration item to use the cache in a read-only manner when running as an application