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 map the repository and locate print-routing and thread implementation code/tests. Then I’ll reproduce the identity problem, make the smallest architecture-compatible change, and run focused plus broader relevant tests.
- Assistant
rgis unavailable, so I’ll use recursivegrepand narrow by likely runtime/output modules. - Assistant
The likely interaction is between
_messaging/print_override.py, thread-local stream proxies, runtime stream installation, andThread. I’ll inspect those files and the existing thread tests to understand lifecycle and concurrency guarantees before changing anything. - Assistant
The root cause is confirmed structurally: every notebook main module receives a global
print_override, soprint is builtins.printis false even whenmo.Threadis never used. The clean direction is to stop injecting a print function and routemo.Threadvia per-thread stdout state instead; I’ll inspect kernel startup/redirection and tests to verify whether the existing stream proxy can carry that routing or whetherThreadneeds a dedicated scoped stream. - Assistant
Two implementation options remain: (1) lazy-inject the override only when
mo.Threadis constructed, preserving the current direct notification path and its thread isolation; or (2) use stdout. Option (2) is unreliable in edit mode because the parent cell restores globalsys.stdoutbefore a long-lived child prints—the reason the override exists. I’ll inspect runtime context/module ownership and full thread tests to design robust lazy injection without relying only on the target function shape. - Assistant
KernelRuntimeContext.globalsgivesThreada reliable notebook namespace, so lazy installation can be context-based rather than callable introspection. I’ll check kernel construction defaults and graph/name cleanup behavior, then reproduceprint is builtins.printthrough the same test session used by runtime tests. - Assistant
The test harness currently forces the override too, meaning changing only production wiring would leave behavior inconsistent and under-tested. A more coherent fix is for kernel creation to never eagerly inject
print; when a context-backedmo.Threadis constructed, it lazily installs the existing router into that kernel’s globals. I’ll implement that and also make thread registration cleanup exception-safe so stale thread IDs cannot misroute later output after an error. - Assistant
The core change is in place. I’ll run the focused runtime thread suite and print-router unit suite; the former now starts with builtin
printdespite the harness passing an override, and exercises lazy routing through real kernel contexts. - Assistant
Focused tests pass, including
mo.Threadprint routing. Next I’ll explicitly reproduce the reported identity/Numba scenario in a real kernel session using a temporary script outside the repository. I’ll also inspect how to construct execution requests, then verify concurrent threads route to their spawning cells rather than cross-contaminate. - Assistant
Numba is not installed in the project environment. Since package installation is allowed and the issue is specifically a compiler failure, I’ll check available interpreters/caches before deciding whether installation is needed, and inspect the request helper for an actual kernel-level identity check.
- Assistant
No local Numba installation/cache exists. I’ll install it into the existing virtual environment solely to run the reported reproduction, then execute a temporary kernel script checking both builtin identity and JIT compilation. This will not modify repository dependency files.
- Assistant
Numba is available now. I’ll first demonstrate that the former eager global override causes Numba’s compilation error, then run the same function in a kernel created with the fix and assert builtin identity plus successful execution. The script lives under
/tmp, not in the repository. - Assistant
The exact failure is reproduced (
TypingError) under old eager injection and resolved in the fixed kernel, withprint is builtins.printremaining true before and after compilation. I’ll now inspect/run the concurrency portions of the thread suite and add a temporary two-cell overlap scenario if existing tests only cover threads from one cell. - Assistant
Existing tests cover multiple threads sharing one cell but not overlapping threads spawned by distinct cells. I’ll run a temporary real-kernel scenario where cell A’s thread waits while cell B starts its own thread, releases both, and each emits unique output; then I’ll group notifications by
cell_idto verify isolation. - Assistant
The kernel scenario itself completed without errors; my temporary result parser assumed every recorded operation was a dictionary, but the stream also records typed variable notifications. I’ll correct only the
/tmpparser to filter dictionary operations and rerun. - Assistant
No routing assertion yet: the parser found no matching raw dictionaries because
MockStream.operationsstores protocol objects as well as notifications. I’ll inspect the mock’s normalization API and dump operation types/representations from the temporary scenario, then assert through the supportedMockStreamwrapper. - Assistant
The dump explains the mismatch: thread notifications are written through each copied
ThreadSafeStream, while the root mock records only main-cell notifications; this is also why existing tests inspect the stream captured inside each target. I’ll update the temporary scenario to capture each thread context stream and verify its operation’scell_idand payload independently. - Assistant
Concurrent threads from two distinct spawning cells are correctly isolated. I’ll now examine script-context behavior and run static checks. The lazy assignment is essential for kernel notebooks, but it should not introduce a meaningless mutation or circular import in script mode, where standard streams already work and no override was previously supplied.
- Assistant
Static lint passes; mypy is not installed. Script contexts intentionally rely on ordinary standard streams, and their
globalsproperty returns a transient merged dictionary, so the lazy router should be installed only forKernelRuntimeContext. I’ll narrow the assignment accordingly, avoiding an unnecessary import/mutation for scripts while preserving existing script behavior. - Assistant
The narrowed change is lint-clean. I’ll rerun both explicit reproductions and the affected messaging/runtime suites, including stream redirection and thread-local proxy tests, because eager print injection and stdout routing interact at that boundary.
- Assistant
All 55 related tests pass, and both explicit regressions pass. I’ll review the final diff for unintended changes/dead imports, inspect the use of
print_override_fnafter kernel creation, and run the full runtime and messaging test directories if the review is clean. - Assistant
The diff is limited to kernel print installation and thread lifecycle; no whitespace or accidental files.
print_override_fnremains inKernelArgsfor compatibility with existing callers but is deliberately no longer eagerly applied—the router itself is now consumed lazily byThread. I’ll run the complete_runtimeand_messagingsuites to catch broader regressions. - Assistant
The broad run reached 1,004 passing tests before one unrelated sandbox failure:
os.setsid()is denied by this container in a launch-kernel event-loop test. The failure occurs before kernel creation and is unrelated to the changed paths. Because--maxfail=1stopped before all messaging tests, I’ll run the complete messaging suite separately and then do a final status/diff check.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.