fix(code_mode): skip missing-package nudge for marimo.* imports#10167
Conversation
A failed `import marimo.<x>` surfaces as a missing `marimo` package, prompting code_mode to install marimo. But marimo is always installed and a bad submodule import can't be fixed by installing it, so filter marimo-owned modules/packages out of the missing-packages computation.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts marimo’s runtime missing-package detection so that failed imports under the marimo.* namespace do not trigger “missing package” nudges (which can’t fix missing marimo-owned submodules), and adds a regression test to ensure no alert is emitted.
Changes:
- Add
_is_marimo_module()and use it to excludemarimo/marimo.*from missing-package alert computations. - Ensure
missing_packages_hookfilters out marimo-owned modules/packages before deciding to alert or auto-install. - Add a runtime test asserting that
import marimo.<nonexistent>does not emitmissing-package-alert.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
marimo/_runtime/callbacks/packages.py |
Filters marimo/marimo.* out of missing-package detection paths to avoid incorrect install nudges. |
tests/_runtime/test_runtime.py |
Adds regression coverage for the “no missing-package alert on bad marimo submodule import” behavior. |
| """True for marimo itself or any of its submodules. | ||
|
|
||
| A failed `import marimo.<submodule>` surfaces as a missing "marimo" | ||
| package, but marimo is always installed and the error can never be | ||
| fixed by installing it. Treating it as missing would nudge callers | ||
| (e.g. code_mode) to install marimo, so we always skip these. | ||
| """ |
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant Cell as Cell Runner
participant Hook as missing_packages_hook
participant Filter as _is_marimo_module()
participant Mgr as Package Manager
participant CB as PackagesCallbacks
participant Alert as send_missing_packages_alert
participant Client as Frontend
Note over Cell,Client: Module import failure detection
Cell->>Hook: ImportError (missing modules)
Hook->>Mgr: module_to_package(mod)
Mgr-->>Hook: Package name
Note over Hook: For each missing module
Hook->>Filter: Check if module is marimo.*
alt Module is marimo.*
Filter-->>Hook: True (skip)
Hook->>Hook: continue (no package added)
else Module is not marimo.*
Filter-->>Hook: False
Hook->>Mgr: attempted_to_install(pkg)
Mgr-->>Hook: boolean
opt Not previously attempted
Hook->>Hook: Add to missing_packages set
end
end
Note over Hook: Post-loop cleanup
Hook->>Hook: Filter out marimo package names from set
alt missing_packages is non-empty
Hook->>CB: send_missing_packages_alert(packages)
CB->>Alert: Format alert with package names
Alert-->>Client: "Missing package" nudge
else missing_packages is empty
Hook->>Hook: return (no alert sent)
end
Note over Cell,Client: Result: marimo.* failures never trigger install nudges
The `@mo.cache` functions in `transitive_imports` bind their caching context the first time the module is imported. When that first import happened inside the kernel setup cell, they bound to the kernel's globals (my_module = module_0) instead of their own module scope (my_module = module_1), so the pinned hash collided with the kernel-defined function and the test failed. The test previously relied on a sibling test importing the module outside kernel execution first; under pytest-xdist that ordering isn't guaranteed, so the test flaked in CI. Import the module explicitly before running the kernel, matching the sibling tests' pattern.
| LOGGER = _loggers.marimo_logger() | ||
|
|
||
|
|
||
| def _is_marimo_module(module_name: str) -> bool: |
There was a problem hiding this comment.
I'm trying to think... would we want to help the agent understand that module doesn't exist? Or will it get that feedback?
There was a problem hiding this comment.
Thinking about it, probably not. The missing_packages_hook is supplementary and only governs the install nudge. The agent will still see an import error.
There was a problem hiding this comment.
yea they will get the error. this told them to install it
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.15-dev20 |
A failed
import marimo.<x>surfaces as a missingmarimopackage,prompting code_mode to install marimo. But marimo is always installed
and a bad submodule import can't be fixed by installing it, so filter
marimo-owned modules/packages out of the missing-packages computation.
Closes MO-6161