Skip to content

Enrich code_mode NotebookCell with runtime status and error#9056

Merged
mscolnick merged 5 commits into
mainfrom
push-zwrmlvyyplzo
Apr 7, 2026
Merged

Enrich code_mode NotebookCell with runtime status and error#9056
mscolnick merged 5 commits into
mainfrom
push-zwrmlvyyplzo

Conversation

@manzt

@manzt manzt commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator

Agents inspecting cells via code_mode had no visibility into execution state. The new NotebookCell wrapper joins document data with runtime state from the kernel graph, exposing status (a synthesized CellStatusType) and error (the last exception, persisted across status changes). Staleness is detected from code mismatch, the runtime stale flag (lazy mode), or never-run cells.

@manzt manzt added the enhancement New feature or request label Apr 6, 2026
Copilot AI review requested due to automatic review settings April 6, 2026 02:22
@vercel

vercel Bot commented Apr 6, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 7, 2026 3:33am

Request Review

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.

Pull request overview

This PR extends the code_mode cell inspection surface so agents can see execution-related runtime information for each notebook cell, by wrapping document cells with kernel graph state and exposing a synthesized status plus a persisted error.

Changes:

  • Added an enriched code_mode NotebookCell wrapper that joins document cell data with runtime state (status, error).
  • Updated _CellsView to return enriched cells (including repr output showing status).
  • Expanded tests to snapshot the new CellsView/enriched cell representations and validate status mapping behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
marimo/_code_mode/_context.py Introduces enriched NotebookCell with synthesized status/error; updates _CellsView to yield enriched cells and include status in repr.
marimo/_code_mode/__init__.py Re-exports the enriched NotebookCell and the new CellStatusType.
tests/_code_mode/test_cells_view.py Updates repr expectations to snapshots and adds new tests for enriched cell status/error and repr.

Comment thread marimo/_code_mode/_context.py
Comment thread marimo/_code_mode/_context.py
Comment thread marimo/_code_mode/_context.py Outdated
Comment thread tests/_code_mode/test_cells_view.py
Comment thread marimo/_code_mode/_context.py
Comment thread marimo/_code_mode/_context.py Outdated
Comment thread marimo/_code_mode/_context.py
Comment thread marimo/_code_mode/_context.py Outdated
Agents inspecting cells via code_mode had no visibility into execution
state. The new `NotebookCell` wrapper joins document data with runtime
state from the kernel graph, exposing `status` (a synthesized
`CellStatusType`) and `error` (the last exception, persisted across
status changes). Staleness is detected from code mismatch, the runtime
stale flag (lazy mode), or never-run cells.
manzt added 4 commits April 6, 2026 22:53
Add docstrings to the delegated properties on `NotebookCell` so they
appear in `help()` output, and fix the `_CellsView` docstring which
referenced a nonexistent `CellView` type instead of `NotebookCell`.
The inline comments on the `Literal` type definition aren't surfaced by
`help()`, so agents calling `help(NotebookCell)` had no way to discover
what each status value means. Moving the descriptions into the `status`
property docstring puts them where interactive help actually displays
them.
`_CellsView` methods like `values()`, `items()`, `find()`, and `grep()`
returned `list`, exposing mutability on what should be a read-only view.
Narrowing the return type to `Sequence` signals the intended contract.

Also fixes an edge case where cells registered in the kernel graph but
never executed returned `status=None` instead of `"stale"`. This happens
when a cell has an impl with matching code but `run_result_status` is
still `None` — the staleness check missed it because the code matched
and the runtime `stale` flag wasn't set.
The protocol used `str | None` for `runtime_state` and
`run_result_status`, but the canonical types `RuntimeStateType` and
`RunResultStatusType` already exist in `marimo._ast.cell`. Since this
protocol is internal, there's no reason to keep the types loose.
@mscolnick mscolnick merged commit c95aee6 into main Apr 7, 2026
43 checks passed
@mscolnick mscolnick deleted the push-zwrmlvyyplzo branch April 7, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants