fix(runtimed-py): audit fixes — single-cell lookups, MCP accessors, stub types#927
Merged
fix(runtimed-py): audit fixes — single-cell lookups, MCP accessors, stub types#927
Conversation
…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.
Contributor
There was a problem hiding this comment.
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()+findwith single-cell accessors in runtimed-py (collect_outputs,get_cell_metadata) to avoid O(n_cells) cloning. - Update MCP server
replace_match/replace_regexto useget_cell_source()instead of fetching full cells. - Fix multiple
.pyireturn-type mismatches forSessionandAsyncSession(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: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Audit of the merged #923 + #924 state found several issues. Net -6 lines.
Bugs fixed
collect_outputs— still usedhandle.get_cells()(materializes ALL cells) + linear find after #924 fixedget_cell. Everyexecute_cellcompletion paid this cost. Now useshandle.get_cell(cell_id).get_cell_metadata— same bug, usedget_cells()+ find. Now useshandle.get_cell_metadata(cell_id)directly with clone-handle-drop-lock pattern.MCP server
replace_match/replace_regex— usedget_cell()(full cell with output resolution) when they only need the source string. Now useget_cell_source().Type stubs
5 return type mismatches in
.pyifor both Session and AsyncSession:move_cellNonestr(new position)get_cellCell | NoneCell(raises on missing)set_cell_source_hiddenNoneboolset_cell_outputs_hiddenNoneboolset_cell_tagsNoneboolNot fixed (noted for future)
restart_kernelwait_for_ready holds mutex up to 30s during broadcast pollingsync_environment_implholds mutex up to 300sget_cell_outputsreturnslist[str]notlist[Output]— type impedance with formatting helpersPR submitted by @rgbkrk's agent Quill, via Zed