Fix console output routing for code_mode run_cell#8790
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes incorrect console output cell attribution when redirect_streams is entered recursively (e.g., code_mode executing a target cell while already inside the scratchpad’s redirect context), by swapping stream.cell_id for the nested scope and restoring it on exit.
Changes:
- Update
redirect_streamsto swapstream.cell_idin nested contexts and restore it in afinallyblock. - Add runtime tests covering nested/non-nested behavior and restoration on exceptions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
marimo/_runtime/redirect_streams.py |
Implements nested-context cell_id swapping/restoration so console routing targets the correct cell. |
tests/_runtime/test_redirect_streams.py |
Adds regression tests validating nested swap + restoration (including exception paths). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When code_mode runs cells via `ctx.run_cell()`, execution happens inside the scratchpad's `redirect_streams` context. The nested `redirect_streams` call for the target cell was a complete no-op, so all print output was tagged with `SCRATCH_CELL_ID` instead of the actual cell ID. The frontend never associated it with the correct cell. The fix is narrowly scoped: only when the outer context is the scratchpad do we swap `stream.cell_id` to the target cell. Regular nested contexts (e.g. post-execution hooks running within a cell's context) preserve the existing no-op behavior.
a59dc2a to
ab7425b
Compare
akshayka
approved these changes
Mar 20, 2026
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.21.2-dev20 |
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.
When code_mode runs cells via
ctx.run_cell(), execution happens insidethe scratchpad's
redirect_streamscontext. The nestedredirect_streamscall for the target cell was a complete no-op, so allprint output was tagged with
SCRATCH_CELL_IDinstead of the actualcell ID. The frontend never associated it with the correct cell.
The fix is narrowly scoped: only when the outer context is the
scratchpad do we swap
stream.cell_idto the target cell. Regularnested contexts (e.g. post-execution hooks running within a cell's
context) preserve the existing no-op behavior.