ISSUE DESCRIPTION Marimo's print routing breaks Numba compilation In notebooks that do…
- User
ISSUE DESCRIPTION
Marimo's print routing breaks Numba compilation
In notebooks that do not use
mo.Thread,printmust retain builtin identity so Numba can compile functions that call it.mo.Threadmust continue routing output to the spawning cell, with output isolation between concurrent threads.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /marimo, current file: none) bash-$
- Assistant
I’ll first locate the print-routing and thread implementations, then inspect their tests and reproduce the builtin-identity problem before making a minimal change.
- Assistant
ripgrepis unavailable, so I’ll use recursivegrepto find the relevant implementation and test coverage. - Assistant
The likely interaction is between
Thread, thread-local stream proxies, and runtime stream setup. I’ll read those modules and search all assignments involvingprintorsys.stdout. - Assistant
A dedicated
print_overridemodule exists; I’ll inspect it and every call site to understand why the override is process-wide and how thread routing is currently activated. - Assistant
The override is injected as the notebook main module’s global
print, which shadows the builtin and causes Numba’s identity/type checks to fail even when nomo.Threadexists. I’ll inspect module creation, kernel lifecycle, and thread tests to determine where a lazy activation/deactivation can be safely implemented. - Assistant
A minimal compatible design is to stop injecting the override at kernel creation and install it lazily into the notebook globals when an
mo.Threadis constructed. That preserves exact builtin identity for notebooks that never usemo.Thread, while existing thread-ID/context routing continues to isolate concurrent threads. I’ll verify how the runtime context exposes the kernel’s globals and whether lifecycle cleanup is needed. - Assistant
The context provides the per-kernel globals dictionary, so lazy installation can be session-specific and won’t cross-contaminate concurrent notebook sessions. Before editing, I’ll reproduce Numba’s failure directly with the current module creation path and confirm Numba is available.
- Assistant
The repository environment lacks required dependencies (
msgspec), so the direct reproduction cannot import Marimo. I’ll check the project’s prescribed test tooling and use its locked environment (likelyuv) rather than modifying dependencies ad hoc. - Assistant
I’ll use
uv run, which resolves the locked project environment. First I’ll reproduce identity and, if Numba is not in the dev environment, use a small Numba-style identity check while retaining the reported failure as the behavioral target. - Assistant
The reproduction confirms the notebook global shadows
builtins.print; Numba itself is not installed in the locked dev set. To ensure all kernel construction paths—including test/session helpers—are fixed, I’ll changecreate_main_moduleto preserve builtin lookup rather than only changing one caller, and lazily set the override inThread.__init__for kernel contexts. I’ll also inspect direct tests ofcreate_main_modulebefore editing. - Assistant
There are no direct tests constraining module creation. I’ll preserve the existing
printkey but initialize it to the actual builtin whenever print routing is enabled; this makes identity explicit and minimizes namespace changes.mo.Threadwill replace it with the routing function only when it is still the builtin, avoiding clobbering a user-definedprint. I’ll also make thread registration cleanup exception-safe to prevent stale thread IDs from misrouting output after a target raises. - Assistant
The core change is in place. I’ll now rerun the identity reproduction, exercise a kernel through its normal test fixture path to verify lazy replacement, and run the focused print/thread test suites.
- Assistant
All 35 focused tests pass, including existing thread print routing. I’ll inspect those assertions to ensure they cover spawning-cell routing and concurrency isolation, then run formatting/type lint on changed files and broader runtime tests if practical.
- Assistant
The existing tests verify correct cell routing for a thread but do not explicitly run multiple threads concurrently. The implementation remains isolated because each
Threadgets a cloned context/stream andget_context()is thread-local; the shared wrapper only dispatches based on that per-thread context. I’ll run the broader runtime and server print tests, then inspect the final diff/status for accidental changes. - Assistant
The broader suite passes (302 passed, 1 expected xfail, 9 environment/platform skips), and lint/format/diff checks are clean. To fully satisfy the reported error checklist, I’ll use
uv’s ephemeral--with numbaenvironment to reproduce actual compilation before and after the fix without changing project files. - Assistant
Actual Numba compilation now succeeds and emits a compiled signature. For completeness, I’ll run the same function with the former wrapper explicitly restored to confirm the exact reported compilation failure, then do one final diff check and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.