Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Remove execution policy from host document state (#11292)

Trevor Manz082ee870c11c
diff --git a/marimo/_core/document.py b/marimo/_core/document.py
index e9952da3fb..ffe97693ed 100644
--- a/marimo/_core/document.py
+++ b/marimo/_core/document.py
@@ -7,7 +7,7 @@ import hashlib
import json
from copy import deepcopy
from dataclasses import dataclass, field
-from typing import TYPE_CHECKING, Any, Literal
+from typing import TYPE_CHECKING, Any
from msgspec import UNSET
@@ -17,8 +17,6 @@ from marimo._core.errors import EditConflict, Invalid
if TYPE_CHECKING:
from collections.abc import Iterator, Mapping, Sequence
-Policy = Literal["autorun", "lazy"]
-
def etag(text: str) -> protocol.Etag:
"""The first 16 hex characters of SHA-256 over the UTF-8 text."""
@@ -150,11 +148,9 @@ class Document:
cells: Sequence[CellSource],
app_config: Mapping[str, Any],
*,
- policy: Policy = "autorun",
saved: bool = True,
) -> None:
self._id = notebook_id
- self._policy: Policy = policy
self._cells: dict[str, protocol.Cell] = {}
self._order: list[str] = []
self._app_config: dict[str, Any] = {}
@@ -193,7 +189,6 @@ class Document:
for cell in (by_id[cell_id] for cell_id in document.order)
],
document.app_config,
- policy=document.policy,
saved=False,
)
for cell in restored:
@@ -354,10 +349,6 @@ class Document:
self._saved_etag = self._record.etag if etag is None else etag
return self._refresh()
- def set_policy(self, policy: Policy) -> protocol.Document | None:
- self._policy = policy
- return self._refresh()
-
def _build(self, source: CellSource) -> protocol.Cell:
code = normalize_code(source.code)
hashed = code_hash(code)
@@ -379,7 +370,6 @@ class Document:
notebook_id=self._id,
order=tuple(protocol.CellId(c) for c in self._order),
app_config=dict(self._app_config),
- policy=self._policy,
etag=document_etag(
order,
app_config,
diff --git a/marimo/_core/protocol.py b/marimo/_core/protocol.py
index 7545f7c945..91e428a8fb 100644
--- a/marimo/_core/protocol.py
+++ b/marimo/_core/protocol.py
@@ -884,12 +884,6 @@ class Document(Struct, frozen=True):
description="Identifies the order alone. Its text is the cell IDs in order as a JSON array, with no whitespace and strings carrying only the escapes JSON requires. Editing a cell does not change it."
),
]
- policy: Annotated[
- Literal["autorun", "lazy"],
- Meta(
- description="When dependents of an evaluated cell run. `autorun` runs them on every change; `lazy` leaves them for a later run. Set by the host."
- ),
- ]
saved_etag: (
Annotated[
Etag,
diff --git a/marimo/_server/host/bridge.py b/marimo/_server/host/bridge.py
index 324002e6d5..fb24ac2043 100644
--- a/marimo/_server/host/bridge.py
+++ b/marimo/_server/host/bridge.py
@@ -9,7 +9,6 @@ from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from marimo import _loggers
-from marimo._config.manager import ScriptConfigReader
from marimo._core import protocol
from marimo._core.document import CellSource, Document, revision
from marimo._core.errors import (
@@ -39,7 +38,7 @@ if TYPE_CHECKING:
from marimo._config.manager import MarimoConfigManager
from marimo._core.backend import Message
- from marimo._core.document import Changed, Policy
+ from marimo._core.document import Changed
from marimo._core.stream import Event, Sink
from marimo._messaging.notebook import NotebookCell
from marimo._server.session_manager import SessionManager
@@ -174,7 +173,6 @@ class SessionBridge(SessionEventListener):
record.id,
cells,
app_config,
- policy=self._policy(file, session),
saved=session is None,
)
if session is not None and loaded is not None:
@@ -519,21 +517,6 @@ class SessionBridge(SessionEventListener):
cells, app_config = documents.from_session(session)
notebook.replace(cells, app_config)
- def _policy(self, file: Path | None, session: Session | None) -> Policy:
- config_manager = (
- session.config_manager
- if session is not None
- else self._config_manager
- )
- if config_manager is None:
- return "autorun"
- if session is None:
- config_manager = config_manager.with_partial(
- ScriptConfigReader(None if file is None else str(file))
- )
- policy = config_manager.get_config()["runtime"]["on_cell_change"]
- return "lazy" if policy == "lazy" else "autorun"
-
def _project_path(self, path: Path) -> Path:
root = self.index.root
if root is None:
diff --git a/protocols/host/fixtures/edit-response.json b/protocols/host/fixtures/edit-response.json
index 6a35fcb5b9..5a673c88fa 100644
--- a/protocols/host/fixtures/edit-response.json
+++ b/protocols/host/fixtures/edit-response.json
@@ -9,7 +9,6 @@
"app_config": {
"width": "full"
},
- "policy": "autorun",
"etag": "f01a47d5aa0cad55",
"saved_etag": "e59d9c2af02f5814",
"order_etag": "162e15055422ed71",
diff --git a/protocols/host/fixtures/edits.sse b/protocols/host/fixtures/edits.sse
index cdf28ea1e8..d0243adde4 100644
--- a/protocols/host/fixtures/edits.sse
+++ b/protocols/host/fixtures/edits.sse
@@ -12,9 +12,9 @@ data: {"id":"k7f2","request_id":"9b1c6d2e-0f3a-4b5c-8d7e-1f2a3b4c5d6e","time":"2
id: 113
event: document
-data: {"document":{"notebook_id":"n1","order":["c1","c2","c3"],"app_config":{"width":"full"},"policy":"autorun","etag":"f01a47d5aa0cad55","saved_etag":"e59d9c2af02f5814","order_etag":"162e15055422ed71","app_config_etag":"283513048dfeb45b"},"request_id":"9b1c6d2e-0f3a-4b5c-8d7e-1f2a3b4c5d6e","time":"2026-10-01T09:21:00Z"}
+data: {"document":{"notebook_id":"n1","order":["c1","c2","c3"],"app_config":{"width":"full"},"etag":"f01a47d5aa0cad55","saved_etag":"e59d9c2af02f5814","order_etag":"162e15055422ed71","app_config_etag":"283513048dfeb45b"},"request_id":"9b1c6d2e-0f3a-4b5c-8d7e-1f2a3b4c5d6e","time":"2026-10-01T09:21:00Z"}
id: 114
event: document
-data: {"document":{"notebook_id":"n1","order":["c1","c2","c3"],"app_config":{"width":"full"},"policy":"autorun","etag":"f01a47d5aa0cad55","saved_etag":"f01a47d5aa0cad55","order_etag":"162e15055422ed71","app_config_etag":"283513048dfeb45b"},"request_id":"save-9b1c6d2e","time":"2026-10-01T09:21:02Z"}
+data: {"document":{"notebook_id":"n1","order":["c1","c2","c3"],"app_config":{"width":"full"},"etag":"f01a47d5aa0cad55","saved_etag":"f01a47d5aa0cad55","order_etag":"162e15055422ed71","app_config_etag":"283513048dfeb45b"},"request_id":"save-9b1c6d2e","time":"2026-10-01T09:21:02Z"}
diff --git a/protocols/host/fixtures/notebook-events.sse b/protocols/host/fixtures/notebook-events.sse
index a1a72aa39a..c1144e6382 100644
--- a/protocols/host/fixtures/notebook-events.sse
+++ b/protocols/host/fixtures/notebook-events.sse
@@ -11,7 +11,7 @@ event: cell
data: {"cell":{"id":"k7f2","notebook_id":"n1","code":"y = x * 2","name":"_","config":{"column":null,"disabled":false,"hide_code":true,"expand_output":false},"etag":"f199b5f48ae0aabb","code_hash":"db2b9ee97e1ecf4c"}}
event: document
-data: {"document":{"notebook_id":"n1","order":["c1","c3","k7f2"],"app_config":{"width":"full"},"policy":"autorun","etag":"e59d9c2af02f5814","saved_etag":"e59d9c2af02f5814","order_etag":"b9c412c2d7d63161","app_config_etag":"283513048dfeb45b"}}
+data: {"document":{"notebook_id":"n1","order":["c1","c3","k7f2"],"app_config":{"width":"full"},"etag":"e59d9c2af02f5814","saved_etag":"e59d9c2af02f5814","order_etag":"b9c412c2d7d63161","app_config_etag":"283513048dfeb45b"}}
event: analysis
data: {"analysis":{"notebook_id":"n1","document_etag":"e59d9c2af02f5814","cells":{"c1":{"defs":["mo"],"refs":[],"errors":[]},"c3":{"defs":["x"],"refs":[],"errors":[]},"k7f2":{"defs":["y"],"refs":["x"],"errors":[]}}}}
diff --git a/protocols/host/fixtures/problems/edit-conflict.json b/protocols/host/fixtures/problems/edit-conflict.json
index 411fbcabc9..885a9592bb 100644
--- a/protocols/host/fixtures/problems/edit-conflict.json
+++ b/protocols/host/fixtures/problems/edit-conflict.json
@@ -29,7 +29,6 @@
"app_config": {
"width": "full"
},
- "policy": "autorun",
"etag": "f01a47d5aa0cad55",
"saved_etag": "e59d9c2af02f5814",
"order_etag": "162e15055422ed71",
diff --git a/protocols/host/openapi.yaml b/protocols/host/openapi.yaml
index 7ebb316d2f..cf0ae004c9 100644
--- a/protocols/host/openapi.yaml
+++ b/protocols/host/openapi.yaml
@@ -1385,13 +1385,11 @@ components:
type: object
description: |
The document as a whole, without its cells, which are their own
- objects: the cell order, app config, and host execution policy.
- The policy is retained for v1 compatibility and comes from the
- runtime configuration, not the notebook's app config. One per notebook,
+ objects: the cell order and app config. One per notebook,
and removed with it. The order and the app
config carry their own etags, so an edit to one does not conflict
with an edit to the other, or with edits to cells.
- required: [notebook_id, order, app_config, policy, etag, saved_etag, order_etag, app_config_etag]
+ required: [notebook_id, order, app_config, etag, saved_etag, order_etag, app_config_etag]
properties:
notebook_id:
$ref: '#/components/schemas/NotebookId'
@@ -1404,10 +1402,6 @@ components:
type: object
additionalProperties: true
description: Notebook-level settings, the keyword arguments to `marimo.App` such as `width` and `app_title`. Informational for now; no change sets it over this protocol.
- policy:
- type: string
- enum: [autorun, lazy]
- description: When dependents of an evaluated cell run. `autorun` runs them on every change; `lazy` leaves them for a later run. Set by the host.
etag:
$ref: '#/components/schemas/Etag'
description: Identifies the document as currently applied. Its text is `order_etag`, `app_config_etag`, and every cell's `etag` in order, so it changes when any of them does.
diff --git a/tests/_core/test_notebook.py b/tests/_core/test_notebook.py
index 5e4498acaf..eec5161658 100644
--- a/tests/_core/test_notebook.py
+++ b/tests/_core/test_notebook.py
@@ -1205,7 +1205,6 @@ def test_restoration_preserves_revisions_and_outputs(
record().id,
[CellSource(CellId("c2"), "pass"), CellSource(CellId("c1"), "42")],
{"width": "full"},
- policy="lazy",
saved=saved,
)
# The output belongs to the previous source, and the saved revision can
diff --git a/tests/_core/test_notebook_document.py b/tests/_core/test_notebook_document.py
index 4766685f28..9981fe1c30 100644
--- a/tests/_core/test_notebook_document.py
+++ b/tests/_core/test_notebook_document.py
@@ -333,9 +333,7 @@ class TestApply:
class TestFromRecords:
def test_preserves_the_saved_revision(self) -> None:
- source = Document(
- NOTEBOOK, fixture_cells(), {"width": "full"}, policy="lazy"
- )
+ source = Document(NOTEBOOK, fixture_cells(), {"width": "full"})
# The saved revision precedes the current one; both survive.
source.replace([CellSource("c1", "import marimo")], {"width": "full"})
restored = Document.from_records(source._record, list(source))
diff --git a/tests/_server/host/test_host_api.py b/tests/_server/host/test_host_api.py
index d1ab2dd5e5..72edbdc281 100644
--- a/tests/_server/host/test_host_api.py
+++ b/tests/_server/host/test_host_api.py
@@ -1484,7 +1484,7 @@ async def test_the_notebook_stream_carries_cells_then_the_document(
assert second["config"]["hide_code"] is True
assert document["order"] == [first["id"], second["id"]]
assert document["app_config"] == {"width": "full"}
- assert document["policy"] == "autorun"
+ assert "policy" not in document
assert document["saved_etag"] == document["etag"]
assert all(
c["notebook_id"] == harness.notebook_id for c in (first, second)
diff --git a/tests/_server/host/test_host_bridge.py b/tests/_server/host/test_host_bridge.py
index 8d1a6f383a..84eafe940b 100644
--- a/tests/_server/host/test_host_bridge.py
+++ b/tests/_server/host/test_host_bridge.py
@@ -9,7 +9,6 @@ from typing import TYPE_CHECKING
import pytest
-from marimo._config.manager import MarimoConfigManager
from marimo._core import protocol
from marimo._core.errors import Conflict, DecisionRequired, EditConflict
from marimo._core.stream import Event
@@ -29,8 +28,7 @@ if TYPE_CHECKING:
from pathlib import Path
from typing import Any
- from marimo._config.manager import UserConfigStore
- from marimo._core.document import CellSource, Policy
+ from marimo._core.document import CellSource
from marimo._session.consumer import SessionConsumer
@@ -54,78 +52,6 @@ def _():
"""
- ("server_policy", "script_policy", "expected"),
- [
- ("autorun", None, "autorun"),
- ("lazy", None, "lazy"),
- ("autorun", "lazy", "lazy"),
- ("lazy", "autorun", "autorun"),
- ],
-)
-async def test_initial_policy_inherits_server_config_with_script_overrides(
- manager: FakeManager,
- tmp_path: Path,
- user_config_manager: UserConfigStore,
- server_policy: Policy,
- script_policy: Policy | None,
- expected: Policy,
-) -> None:
- prepare(manager, tmp_path, "a.py")
- path = tmp_path / "a.py"
- header = (
- "# /// script\n"
- "# [tool.marimo.runtime]\n"
- f'# on_cell_change = "{script_policy}"\n'
- "# ///\n"
- if script_policy is not None
- else ""
- )
- path.write_text(header + NOTEBOOK)
- config = MarimoConfigManager(user_config_manager).with_overrides(
- {"runtime": {"on_cell_change": server_policy}}
- )
- bridge = SessionBridge(manager, config) # type: ignore[arg-type]
- await bridge.open()
- record = bridge.index.notebook_for(str(path))
- assert record is not None
-
- notebook = await bridge.host.notebook(record.id)
-
- assert notebook.document._record.policy == expected
- assert notebook.runtime is None
- assert manager.starts == []
- bridge.close()
-
-
-async def test_initial_policy_uses_the_adopted_sessions_effective_config(
- manager: FakeManager,
- tmp_path: Path,
- user_config_manager: UserConfigStore,
-) -> None:
- prepare(manager, tmp_path, "a.py")
- path = tmp_path / "a.py"
- path.write_text(NOTEBOOK)
- config = MarimoConfigManager(user_config_manager).with_overrides(
- {"runtime": {"on_cell_change": "autorun"}}
- )
- session = FakeSession(str(path))
- session.config_manager = config.with_overrides(
- {"runtime": {"on_cell_change": "lazy"}}
- )
- manager.sessions["browser"] = session
- bridge = SessionBridge(manager, config) # type: ignore[arg-type]
-
- await bridge.open()
-
- record = bridge.index.notebook_for(str(path))
- assert record is not None
- notebook = await bridge.host.notebook(record.id)
- assert notebook.document._record.policy == "lazy"
- assert notebook.runtime is not None
- bridge.close()
-
-
async def test_an_adopted_document_is_saved_as_far_as_the_file_goes(
manager: FakeManager, tmp_path: Path
) -> None: