Skip to content

fix(code_mode): skip missing-package nudge for marimo.* imports#10167

Merged
mscolnick merged 2 commits into
mainfrom
ms/fix/skip-marimo-install-hint
Jul 15, 2026
Merged

fix(code_mode): skip missing-package nudge for marimo.* imports#10167
mscolnick merged 2 commits into
mainfrom
ms/fix/skip-marimo-install-hint

Conversation

@mscolnick

@mscolnick mscolnick commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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.

Closes MO-6161

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.
Copilot AI review requested due to automatic review settings July 13, 2026 19:05
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 13, 2026 9:28pm

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 exclude marimo / marimo.* from missing-package alert computations.
  • Ensure missing_packages_hook filters out marimo-owned modules/packages before deciding to alert or auto-install.
  • Add a runtime test asserting that import marimo.<nonexistent> does not emit missing-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.

Comment on lines +41 to +47
"""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.
"""

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Re-trigger cubic

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to think... would we want to help the agent understand that module doesn't exist? Or will it get that feedback?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea they will get the error. this told them to install it

@mscolnick
mscolnick merged commit eea39d2 into main Jul 15, 2026
43 checks passed
@mscolnick
mscolnick deleted the ms/fix/skip-marimo-install-hint branch July 15, 2026 21:21
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.15-dev20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants