Skip to content

fix(runtimed-py): audit fixes — single-cell lookups, MCP accessors, stub types#927

Merged
rgbkrk merged 1 commit intomainfrom
audit/runtimed-py-mcp-coherence
Mar 18, 2026
Merged

fix(runtimed-py): audit fixes — single-cell lookups, MCP accessors, stub types#927
rgbkrk merged 1 commit intomainfrom
audit/runtimed-py-mcp-coherence

Conversation

@rgbkrk
Copy link
Copy Markdown
Member

@rgbkrk rgbkrk commented Mar 18, 2026

Audit of the merged #923 + #924 state found several issues. Net -6 lines.

Bugs fixed

collect_outputs — still used handle.get_cells() (materializes ALL cells) + linear find after #924 fixed get_cell. Every execute_cell completion paid this cost. Now uses handle.get_cell(cell_id).

get_cell_metadata — same bug, used get_cells() + find. Now uses handle.get_cell_metadata(cell_id) directly with clone-handle-drop-lock pattern.

MCP server

replace_match / replace_regex — used get_cell() (full cell with output resolution) when they only need the source string. Now use get_cell_source().

Type stubs

5 return type mismatches in .pyi for both Session and AsyncSession:

Method Was Should be
move_cell None str (new position)
get_cell Cell | None Cell (raises on missing)
set_cell_source_hidden None bool
set_cell_outputs_hidden None bool
set_cell_tags None bool

Not fixed (noted for future)

  • restart_kernel wait_for_ready holds mutex up to 30s during broadcast polling
  • sync_environment_impl holds mutex up to 300s
  • get_cell_outputs returns list[str] not list[Output] — type impedance with formatting helpers

PR submitted by @rgbkrk's agent Quill, via Zed

…tub types

Audit of merged #923 + #924 found several issues:

Rust (session_core.rs):
- collect_outputs: get_cells() + find → get_cell() (single-cell lookup)
- get_cell_metadata: get_cells() + find → handle.get_cell_metadata()
  with clone-handle-drop-lock pattern

MCP server:
- replace_match: get_cell() → get_cell_source() (only needs source)
- replace_regex: same fix

Type stubs (.pyi):
- move_cell: None → str (returns new position)
- get_cell: Cell | None → Cell (raises on missing, never None)
- set_cell_source_hidden: None → bool
- set_cell_outputs_hidden: None → bool
- set_cell_tags: None → bool
All fixed for both Session and AsyncSession.
@github-actions github-actions bot added mcp MCP server and agent integrations quill PR authored by Quill Agent 🦆 labels Mar 18, 2026
@rgbkrk rgbkrk requested a review from Copilot March 18, 2026 03:00
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

Audit follow-up to the merged per-cell accessor work (#923/#924), focused on eliminating remaining full-cell materialization hotspots in runtimed-py + MCP, and aligning Python type stubs with actual binding behavior.

Changes:

  • Replace get_cells()+find with single-cell accessors in runtimed-py (collect_outputs, get_cell_metadata) to avoid O(n_cells) cloning.
  • Update MCP server replace_match / replace_regex to use get_cell_source() instead of fetching full cells.
  • Fix multiple .pyi return-type mismatches for Session and AsyncSession (e.g., get_cell, move_cell, metadata helpers).

Reviewed changes

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

File Description
python/runtimed/src/runtimed/runtimed.pyi Adjusts stub return types to reflect binding behavior (notably get_cell, move_cell, and metadata-related helpers).
python/nteract/src/nteract/_mcp_server.py Uses per-field accessors (get_cell_source) for text replacement tools to avoid unnecessary cell materialization.
crates/runtimed-py/src/session_core.rs Removes remaining get_cells()-based lookups in hot paths in favor of per-cell getters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

def get_cell_position(self, cell_id: str) -> str | None: ...
def delete_cell(self, cell_id: str) -> None: ...
def move_cell(self, cell_id: str, after_cell_id: str | None = None) -> None: ...
def move_cell(self, cell_id: str, after_cell_id: str | None = None) -> str: ...
@rgbkrk rgbkrk merged commit 8148abb into main Mar 18, 2026
23 of 24 checks passed
@rgbkrk rgbkrk deleted the audit/runtimed-py-mcp-coherence branch March 18, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp MCP server and agent integrations quill PR authored by Quill Agent 🦆

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants