Skip to content

Model breakpoints as a server-owned record - #12225

Open
manzt wants to merge 2 commits into
notebook-extensions/scopefrom
notebook-extensions/breakpoints
Open

manzt wants to merge 2 commits into
notebook-extensions/scopefrom
notebook-extensions/breakpoints

Conversation

@manzt

@manzt manzt commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

This PR adds marimo.breakpoints, the first notebook extension. When a notebook has a runtime, the host owns one breakpoint set for that runtime. Edits to the set reach connected editors through the notebook stream. An editor that connects later gets the current set in its snapshot. A new runtime starts with an empty set.

Extension definition

breakpoints.ts defines replace as a PUT operation. The request maps cell IDs to one-based line numbers and replaces the full breakpoint set. The response contains the accepted set and its runtime ID. Extension definition

// packages/host-protocol/src/marimo/breakpoints.ts
const cells = Schema.Record(CellId, Schema.Array(BreakpointLine));
const ReplaceBreakpointsRequest = Schema.Struct({ cells });
const Breakpoints = Schema.Struct({ runtime_id: RuntimeId, cells });

const Replace = HttpApiEndpoint.put("replaceBreakpoints", "/", {
  // ...
  payload: ReplaceBreakpointsRequest,
  success: Breakpoints,
}).annotate(OpenApi.Identifier, "notebook.extensions.breakpoints.replace");

export default defineNotebookExtension({
  name: "marimo.breakpoints",
  record: Breakpoints,
  endpoints: [Replace],
});

Generated TypeScript client

The client generator uses the operation ID to expose notebook.extensions.breakpoints.replace. Generated client binding

// example.ts — in a client application
import { Client } from "@marimo-team/client";

const client = new Client(hostUrl, { token });
await client.notebook(notebookId).extensions.breakpoints.replace({
  body: { cells: { setup: [3, 8] } },
});

Generated Python bindings

The extension definition generates the Python call and handler signature. Generated Python bindings

# marimo/_server/extensions/breakpoints/_generated.py

# Calls
class Replace:
    class Call:
        params: Replace.Params                 # notebook_id
        headers: Replace.Headers               # idempotency_key
        body: ReplaceBreakpointsRequest        # cells

    Result: TypeAlias = result.Result[
        Breakpoints, MutationProblem | protocol.NoRuntimeProblem
    ]

# Handler
class Handlers(Protocol):
    async def replace(self, call: Replace.Call, /) -> Replace.Result: ...

Breakpoint handler

extension.py implements api.Handlers. The host opens one handler per notebook and binds it to each runtime as it attaches. Implementation

# marimo/_server/extensions/breakpoints/extension.py
from marimo._server.extensions.breakpoints import _generated as api

class Breakpoints(api.Handlers):
    def __init__(self, scope: NotebookScope[api.Breakpoints]) -> None:
        self._scope = scope

    async def replace(self, call: api.Replace.Call) -> api.Replace.Result:
        ...  # Normalize call.body.cells and skip an unchanged set.
        self._scope.runtime.send(SetBreakpointsCommand(...))
        record = api.Breakpoints(runtime_id=runtime.id, cells=cells)
        return Ok(self._scope.put(record, request_id=call.headers.idempotency_key))

@contextmanager
def open(scope: NotebookScope[api.Breakpoints]) -> Iterator[Breakpoints]:
    state = Breakpoints(scope)
    with scope.runtime.while_ready(state.bind_runtime):
        yield state

The existing editor route delegates to this handler. #12226 switches the debugger gutter to the generated client method and removes the legacy route and notification.

@manzt
manzt added this pull request to stack #12227 December 2, 2026 00:27
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 69.97% 29191 / 41718
🔵 Statements 69.92% 29766 / 42566
🔵 Functions 65.49% 7050 / 10765
🔵 Branches 65.42% 17135 / 26192
File CoverageNo changed files found.
Generated in workflow #26590 for commit 0603afe by the Vitest Coverage Report Action

@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from 74037f8 to 2fa5975 Compare December 3, 2026 01:10
@manzt
manzt removed this pull request from stack #12227 December 3, 2026 01:11
@manzt
manzt changed the base branch from notebook-extensions/foundation to notebook-extensions/scope December 3, 2026 01:11
@manzt
manzt added this pull request to stack #12252 December 3, 2026 01:11
@manzt manzt added enhancement New feature or request host-protocol Related to the marimo host protocol or it's implementation. labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

React Doctor skipped this pull request — it changed no React files.

Reviewed by React Doctor for commit 0603afe.

@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from 2fa5975 to 29fa141 Compare December 3, 2026 19:07
@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from 29fa141 to 0740a2a Compare December 3, 2026 19:11
@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from 0740a2a to c8fe665 Compare December 3, 2026 19:14
@manzt
manzt marked this pull request as ready for review December 3, 2026 19:16
Copilot AI balanced review requested due to automatic review settings December 3, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The legacy breakpoint route allows non-positive lines to corrupt retained state and returns HTTP 500 instead of the intended status codes for expected HostError refusals.

2 open issues
What changed in this PR

Adds marimo.breakpoints as the first notebook extension, making breakpoint state server-owned and shared across connected editors.

Changes:

  • Defines the extension contract and generated TypeScript/Python bindings.
  • Publishes breakpoint updates and snapshots, with empty state for new runtimes.
  • Delegates the legacy route to the extension and adds integration coverage.
File Description
tests/​_server/​host/​test_host_websocket.py Tests kernel dispatch and filtered stream replay.
tests/​_server/​host/​test_host_index.py Checks advertised breakpoint operation.
tests/​_server/​host/​test_host_bridge.py Updates expected runtime attachment events.
tests/​_server/​host/​test_host_breakpoints.py Tests sharing, permissions, reconnects, and clearing.
tests/​_server/​host/​test_host_api.py Tests rejection without a live runtime.
packages/​host-protocol/​src/​marimo/​breakpoints.ts Defines breakpoint records and replacement operation.
packages/​host-protocol/​src/​marimo.ts Registers the extension.
packages/​client/​src/​protocol.ts Adds generated breakpoint schemas and events.
packages/​client/​src/​operations.ts Adds generated operation metadata.
packages/​client/​src/​extensions.ts Exposes the client replacement method.
packages/​client/​src/​__tests__/​protocol.test.ts Tests breakpoint decoding and validation.
packages/​client/​src/​__tests__/​notebook-client.test.ts Tests request routing and serialization.
packages/​client/​README.md Documents breakpoint extension access.
marimo/​_server/​host/​stream_options.py Allows filtering breakpoint events.
marimo/​_server/​host/​notebook_api.py Routes and authorizes extension requests.
marimo/​_server/​host/​index.py Advertises extensions for untitled notebooks.
marimo/​_server/​host/​__init__.py Includes extension operations in host capabilities.
marimo/​_server/​extensions/​notebook.py Installs and dispatches the breakpoint handler.
marimo/​_server/​extensions/​breakpoints/​extension.py Manages runtime-scoped breakpoint state.
marimo/​_server/​extensions/​breakpoints/​_generated.py Adds generated Python extension bindings.
marimo/​_server/​extensions/​breakpoints/​__init__.py Introduces the breakpoint package.
marimo/​_server/​extensions/​api.py Collects extension operations and dispatch.
marimo/​_server/​api/​endpoints/​execution.py Delegates legacy breakpoint requests.
marimo/​_core/​handlers.py Extracts reusable mutation dispatch.

Review effort: Balanced

@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from c8fe665 to 61d17bd Compare December 3, 2026 19:56
@manzt manzt added internal A refactor or improvement that is not user facing and removed enhancement New feature or request labels Dec 3, 2026
@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from 61d17bd to 192e2fd Compare December 3, 2026 20:52
@manzt
manzt force-pushed the notebook-extensions/breakpoints branch from 192e2fd to 0603afe Compare December 3, 2026 20:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

host-protocol Related to the marimo host protocol or it's implementation. internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants