Repository navigation
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Coverage Report for ./frontend
File CoverageNo changed files found. |
There was a problem hiding this comment.
🟡 Changes recommended
Extension endpoint identifiers can collide with core or other extension endpoints, causing contract generation to throw.
4 open issues
What changed in this PR
Introduces infrastructure for marimo-specific notebook extensions outside the core host protocol, using the existing HTTP operations and notebook event stream.
Changes:
- Adds extension definitions and Python/TypeScript binding generation.
- Adds notebook-scoped extension lifecycles and snapshot delivery.
- Updates documentation, tests, and generation checks.
| File | Description |
|---|---|
| tests/_server/host/test_notebook_extensions.py | Tests extension lifetime across sessions. |
| protocols/host/README.md | Documents marimo OpenAPI output. |
| packages/host-protocol/src/model/Events.ts | Names dotted extension events. |
| packages/host-protocol/src/marimo/defineNotebookExtension.ts | Defines notebook extension contracts. |
| packages/host-protocol/src/marimo.ts | Adds the marimo contract entrypoint. |
| packages/host-protocol/src/__tests__/python.test.ts | Tests extension binding generation. |
| packages/host-protocol/src/__tests__/openapi.test.ts | Tests extension contract isolation. |
| packages/host-protocol/src/__tests__/notebook-tags.ts | Adds a synthetic extension fixture. |
| packages/host-protocol/scripts/python/models.ts | Supports dotted fields and reusable definitions. |
| packages/host-protocol/scripts/python/extension.ts | Generates Python extension modules. |
| packages/host-protocol/scripts/python/calls.ts | Shares operation generation with extensions. |
| packages/host-protocol/scripts/python.ts | Writes generated extension bindings. |
| packages/host-protocol/scripts/openapi.ts | Adds the marimo OpenAPI option. |
| packages/host-protocol/README.md | Explains extension versus protocol scope. |
| packages/host-protocol/package.json | Exports the marimo entrypoint. |
| packages/client/src/request.ts | Binds notebook extension requests. |
| packages/client/src/notebook/client.ts | Exposes notebook extensions. |
| packages/client/src/extensions.ts | Adds the generated extension accessor. |
| packages/client/src/__tests__/operations.test.ts | Separates portable operation assertions. |
| packages/client/src/__tests__/generation.test.ts | Excludes tests from generated fixtures. |
| packages/client/scripts/generate-protocol.ts | Generates extension methods and typed dictionary keys. |
| packages/client/package.json | Generates from the marimo contract. |
| marimo/_server/host/session.py | Includes extensions in initial streams. |
| marimo/_server/host/bridge.py | Manages extension lifetimes and snapshots. |
| marimo/_server/host/backend.py | Connects session attachment to extensions. |
| marimo/_server/host/api.py | Delegates initial events to the bridge. |
| marimo/_server/extensions/scope.py | Provides session bindings and event publishing. |
| marimo/_server/extensions/notebook.py | Manages installed extensions and cleanup. |
| marimo/_server/extensions/__init__.py | Introduces the extensions package. |
| marimo/_core/stream.py | Accepts extension classes for event names. |
| .github/workflows/test_host_protocol.yaml | Watches generated extension bindings. |
Review effort: Balanced
a02a7ef to
16afe3a
Compare
090f793 to
73721c7
Compare
73721c7 to
a63ed9d
Compare
|
YAY this is looking so good. One question I have is what is your definition of "editor extensions" versus "notebook extensions". The function Also, when you say "editor" above is that synonymous with "client" in the host protocol? |


This description is longer than usual because I want to give anyone working on networking in marimo a practical way to think about the host model.
The goal of this PR is to let marimo build new and/or migrate existing editor features to the host architecture without making each feature part of the core protocol.
Why use the host architecture for editor-specific features?
Today, marimo splits ownership of some shared notebook state between the server and an "editing" client. That creates two problems.
The host architecture gives us one source of truth and is designed to support multiple clients. A host (server) is the sole owner of shared state, and each client requests changes through operations and observes through an event stream.
Why keep some features outside the core protocol?
The host protocol is intentionally narrow. It defines the core objects and operations that clients should agree on when working with the same reactive program. marimo’s editor can build on that shared core while keeping features specific to the editor when they make sense there.
Most importantly, each feature we add to the core becomes a public API that other hosts and clients can rely on and that we commit to maintaining (and not breaking).
The host model
The host protocol uses a client-server architecture with HTTP operations and a publish-subscribe event stream. The host owns notebook state as a collection of immutable records. Clients connect to the stream, receive a snapshot, and stay subscribed to changes.
Event stream and operations
To illustrate, here is an example of a "host" with one immutable record, a cell. When the client connects, it opens an event stream
GET /notebook/{id}/eventsand receives the sole record as an event on the stream:The client is now in sync with the host.
While the client is connected, a cell can change on the host. When this happens, the host does not describe what changed (i.e., a diff) but instead sends a replacement for the record (with the same ID) over the event stream.
The client replaces its record, and again is in sync.
Since the host is the sole owner of state, a client cannot alter the cell directly. Instead, it makes a request to change the record (i.e., make an edit).
An important nuance here is that the request says what the client wants done, but the host decides the result. If the host accepts, it applies the change to its own records (the source of truth) and sends the new record(s) on the event stream to every connected client, including the one that asked.
If the host denies the request, the client that dispatched the request is informed but no clients receive an update.
Notice how the clients observe changes the same way whether they come from their own requests, another client, or the host itself. Each client just subscribes to the event stream and updates its local state as the host publishes new or replacement records.
The cell illustrates the general pattern for defining a feature on the host. You define a record that represents its state and the operations that can change it. Connected clients observe the resulting records on the event stream.
Opening the event stream
In the one-cell example above, I said the client was in sync, but I left out one detail. How does the client know it’s up to date?
The host protocol has two special events for this, ready and reset. When a client first opens the stream, the host sends the current records, followed by
ready. In our example, there’s just one cell.At
ready, the client knows it’s up to date. In a real notebook, the host sends all the records that match the subscription beforeready, and the stream stays open for changes:I said all records, but the protocol also lets clients filter what they receive and resume where they left off after a disconnect. Following state
This PR
This PR gives marimo a way to define editor-specific records and operations outside the core protocol. A definition names the record and declares the operations that can change it. The
marimo.*namespace marks it as an editor extension.Here’s what a definition looks like, using
marimo.breakpointsfrom #12225.Each operation gets a route under the extension’s name, and the client gets a typed method for it.
Clients read the record from the existing notebook stream, so snapshots, live updates, and resume work as they do for core records. The list of extensions is empty in this PR.