Minimal CPython REPL runtime (rlm.repl) - #1685
Open
snimu wants to merge 6 commits into
Open
Conversation
This was referenced Aug 23, 2026
- revalidate targeted interrupts through SIGINT delivery so a stale signal cannot cancel a later request - preserve a parked untargeted interrupt while another request is inflight - reject non-string interrupt ids and validate snapshot options (prune_oversized bool, max_bytes/max_variable_bytes present => int) - guard str(exc) in error/skip/fail reasons so a broken __str__ cannot kill the runtime - fail the snapshot when the manifest write fails (before any pruning) - report 'snapshot not found' reason on restore of a missing path - wait unbounded for the output-pump drain marker so done never precedes captured output and marker bytes never leak - document that aggregate-cap skips are not pruned
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e017cad. Configure here.
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.

Adds
rlm.repl: a minimal CPython REPL runtime (one 635-line file + a 127-line protocol doc) that speaks newline-delimited JSON over stdio — execute / interrupt / snapshot / restore / shutdown in, streamed stdout / stderr / result / display / error / done events out.Design points:
await(PyCF_ALLOW_TOP_LEVEL_AWAIT) on one persistent event loop; background tasks keep running between cells; last-expression repr echo like a REPL.bash()from the previous PR works unchanged on the persistent loop.Standalone in this PR: the runtime is fully tested (25 new tests incl. both interrupt paths, direct-fd capture, framing under noise) but the host still runs ipykernel — the host swap is the next PR. Measured: ~30 ms start-to-ready (ipykernel: ~1.2 s), ~0.13 ms per-cell round-trip.
Ticket: Linear ticket to be linked shortly (Linear API auth is being restored).
Stack
This is PR 2 of 4; each PR merges into its predecessor (merge bottom-up):
Note
Medium Risk
New arbitrary-code execution runtime with SIGINT dispatch, fd remapping, and dill pickle restore. Not yet the production kernel path, but bugs here will become session-critical once the host swaps over.
Overview
Adds a standalone
python -m rlm.replruntime that speaks newline-delimited JSON over stdio, as a future replacement for ipykernel (host still uses Jupyter in this PR).Cells run in one persistent
__main__namespace on a single asyncio loop with top-levelawait, trailing-expressionrepr, captured stdout/stderr (including direct fd writes),emit()display events, and KeyboardInterrupt for both sync-blocked and await-suspended work. Snapshot/restore pickles the user namespace withdill(lazy import; size caps and optional prune). Shutdown kills livebash()children.Also delays
ipykernel/IPythonimports so the package can load outside a Jupyter kernel, documents the protocol inrepl.md, and covers the runtime with subprocess tests.Reviewed by Cursor Bugbot for commit e017cad. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add
rlm.replCPython REPL runtime with JSON-lines protocolrlm.replmodule implements a subprocess-based REPL runtime speaking a newline-delimited JSON protocol over stdin/stdout, supporting cell execution with trailing-expression result echo, top-level await, and output capture via pipe pumps.KeyboardInterruptinto the active task or cancels and re-targets as needed.dillto serialize namespace variables with per-variable and aggregate byte caps, manifest generation, and prune-oversized reporting.rlm.__init__.pyto deferipykernel.comm.CommandIPython.get_ipythonimports to call time, so importingrlmno longer fails in environments withoutipykernel.rlm.host_requestnow raisesRuntimeErrorat call time (not import time) whenipykernel.comm.Commis unavailable; callers that previously relied on import-time failure will see the error later.Macroscope summarized e017cad.