Skip to content

refactor: enforce cell_ids parameter in session serialization and caching#8904

Merged
mscolnick merged 1 commit intomainfrom
ms/enforce-cell-id
Mar 27, 2026
Merged

refactor: enforce cell_ids parameter in session serialization and caching#8904
mscolnick merged 1 commit intomainfrom
ms/enforce-cell-id

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

  • Updated serialize_session_snapshot and persist_session_view_to_cache functions to require cell_ids as a mandatory parameter.
  • Enhanced CachingExtension to include the document parameter in SessionCacheManager.
  • Adjusted SessionCacheWriter to utilize cell_ids from the NotebookDocument for improved session management.
  • Updated tests to reflect changes in the serialization process, ensuring compatibility with the new mandatory cell_ids parameter.

…hing

- Updated `serialize_session_snapshot` and `persist_session_view_to_cache` functions to require `cell_ids` as a mandatory parameter.
- Enhanced `CachingExtension` to include the `document` parameter in `SessionCacheManager`.
- Adjusted `SessionCacheWriter` to utilize `cell_ids` from the `NotebookDocument` for improved session management.
- Updated tests to reflect changes in the serialization process, ensuring compatibility with the new mandatory `cell_ids` parameter.
Copilot AI review requested due to automatic review settings March 27, 2026 21:40
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 27, 2026 9:41pm

Request Review

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 makes session snapshot serialization deterministic by requiring callers to pass an explicit cell_ids ordering, and threads the canonical NotebookDocument into session caching so the cache writer can always serialize cells in document order.

Changes:

  • Make serialize_session_view, serialize_session_snapshot, and persist_session_view_to_cache require cell_ids (no implicit fallback ordering).
  • Update session caching to pass NotebookDocument into SessionCacheManager/SessionCacheWriter and serialize using document.cell_ids.
  • Update session serialization/caching tests to construct documents and pass cell_ids explicitly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/_session/state/test_serialize_session_missing_type.py Updates test to use CellId_t and pass required cell_ids into serialize_session_view.
tests/_session/state/test_serialize_session.py Refactors tests with helpers, adds NotebookDocument fixtures, and updates cache writer/manager construction and serialization calls.
marimo/_session/state/serialize.py Makes cell_ids required and uses document.cell_ids for cache writes; updates cache writer/manager APIs to accept NotebookDocument.
marimo/_session/extensions/extensions.py Passes session.document into SessionCacheManager during attach.
marimo/_server/export/_session_cache.py Makes cell_ids required for snapshot serialization and persistence helpers.

Comment on lines 87 to 91
When `cell_ids` is provided, it determines the order of the cells in
the NotebookSession schema (and only these cells will be saved to the
schema). When not provided, this method attempts to recover the notebook
order from the SessionView object, but this is not always possible.
"""
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The docstring still describes cell_ids as optional ("When not provided...") but cell_ids is now a required parameter. Please update/remove that portion of the docstring so it matches the new API contract (and avoids suggesting a fallback behavior that no longer exists).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
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.

I supposed there's never a case where cell_id != view.cell_id ? Looks good with passing tests

@mscolnick
Copy link
Copy Markdown
Contributor Author

I supposed there's never a case where cell_id != view.cell_id ? Looks good with passing tests

Unlikely. It's possible the view has a “leak” in edit mode and doesn't clean up notifications in some cases but that's ok - source of truth is now the document.

@mscolnick mscolnick merged commit 3d9d536 into main Mar 27, 2026
48 of 49 checks passed
@mscolnick mscolnick deleted the ms/enforce-cell-id branch March 27, 2026 22:07
@github-actions
Copy link
Copy Markdown

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

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.

3 participants