Skip to content

fix: set file in compilation for app mode linecache and better stack traces#8800

Merged
dmadisetti merged 4 commits intomainfrom
dm/app-mode-cache
Mar 24, 2026
Merged

fix: set file in compilation for app mode linecache and better stack traces#8800
dmadisetti merged 4 commits intomainfrom
dm/app-mode-cache

Conversation

@dmadisetti
Copy link
Copy Markdown
Collaborator

📝 Summary

Previously app/run mode utilized the default edit mode style line caches. By passing in the filename during app mode compilation, we ensure the line cache is set for file level tracebacks. Example:
image

Closes #8764

Copilot AI review requested due to automatic review settings March 20, 2026 20:18
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 24, 2026 3:52am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 improves traceback/stack trace fidelity when running notebooks in app/run mode by ensuring compiled cells are associated with the real notebook filename, allowing tracebacks to reference the source file instead of synthetic __marimo__cell_*.py paths (addressing #8764).

Changes:

  • Pass the notebook filename into compile_cell(...) when get_mode() == "run" to enable file-based source positions/linecache usage.
  • Add a run-mode regression test asserting tracebacks reference the real notebook file and not __marimo__cell_*.py.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
marimo/_runtime/runtime.py In run mode, forwards app_metadata.filename into cell compilation to improve traceback file references.
tests/_runtime/test_trace.py Adds a test that verifies run-mode tracebacks include the notebook filename and exclude synthetic cell filenames.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dmadisetti dmadisetti requested a review from mscolnick March 23, 2026 17:29
code: str, filename: str
) -> Optional[SourcePosition]:
@functools.lru_cache(maxsize=1)
def _build_source_position_map(
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.

is there a concern the change over time and this is stale?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yep, with run --watch, good catch

@dmadisetti dmadisetti merged commit 27d5e87 into main Mar 24, 2026
46 of 61 checks passed
@dmadisetti dmadisetti deleted the dm/app-mode-cache branch March 24, 2026 17:24
@github-actions
Copy link
Copy Markdown

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

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.

Ability to map notebook cell exceptions back to the source file

3 participants