Skip to content

fix: restore the trimmed execution trace#9618

Merged
dmadisetti merged 1 commit into
dm/runner-cleanupfrom
dm/traceback-cleanup
May 20, 2026
Merged

fix: restore the trimmed execution trace#9618
dmadisetti merged 1 commit into
dm/runner-cleanupfrom
dm/traceback-cleanup

Conversation

@dmadisetti
Copy link
Copy Markdown
Collaborator

@dmadisetti dmadisetti commented May 19, 2026

📝 Summary

This fix is a followup to #9617 and #9616 and restores the truncated stacktrace to the user's notebook.


Before fix:

image

After fix:

image

@vercel
Copy link
Copy Markdown

vercel Bot commented May 19, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 20, 2026 6:27pm

Request Review

@dmadisetti dmadisetti force-pushed the dm/traceback-cleanup branch from 77e2f46 to 8aadc48 Compare May 19, 2026 23:36
@dmadisetti dmadisetti added the internal A refactor or improvement that is not user facing label May 19, 2026
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 5 files

Architecture diagram
sequenceDiagram
    participant UserCell as "User Cell Code"
    participant Executor as "DefaultExecutor"
    participant CauseChain as "Exception Chain"
    participant MarimoRuntime as "MarimoRuntimeException"
    participant Hooks as "Post-Execution Hooks"
    participant Traceback as "write_traceback()"
    participant Frontend as "User Notebook UI"

    Note over UserCell,Frontend: Runtime Exception Flow

    UserCell->>Executor: execute_cell() or execute_cell_async()
    Executor->>Executor: exec(cell.body, glbls)
    alt Exception raised in user code
        UserCell-->>Executor: BaseException (e.g., ValueError)
        Executor->>CauseChain: Strip executor.py frame from e.__traceback__
        Note over Executor,CauseChain: Sets e.__traceback__ = e.__traceback__.tb_next
        Executor->>MarimoRuntime: raise MarimoRuntimeException from e
        Note over Executor,MarimoRuntime: User's traceback starts at user code, not executor.py
    end

    MarimoRuntime-->>Hooks: run_result.exception (MarimoRuntimeException)
    Hooks->>Hooks: traceback.format_exception(run_result.exception)
    Hooks->>CauseChain: Access __cause__.__traceback__ (user-code frames only)
    CauseChain-->>Hooks: Formatted traceback string
    Hooks->>Traceback: write_traceback(formatted_traceback)
    
    alt Code mode
        Traceback->>Frontend: broadcast_notification with raw traceback data
    else Run mode
        alt show_tracebacks enabled
            Traceback->>Frontend: sys.stderr._write_with_mimetype (highlighted)
        else show_tracebacks disabled
            Traceback->>Frontend: No traceback sent
        end
    end

    Note over UserCell,Frontend: Traceback now includes full execution path from user code
Loading

Re-trigger cubic

Comment thread tests/_runtime/test_executor_evaluator.py Outdated
@dmadisetti dmadisetti force-pushed the dm/traceback-cleanup branch from 772f9e3 to 2415611 Compare May 20, 2026 18:26
@dmadisetti dmadisetti force-pushed the dm/runner-cleanup branch from 6d9c8c1 to 0500e7d Compare May 20, 2026 18:27
@dmadisetti dmadisetti marked this pull request as ready for review May 20, 2026 20:47
@mscolnick mscolnick requested a review from Copilot May 20, 2026 21:08
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

Restores user-facing (trimmed) execution tracebacks after the executor refactor by stripping the internal DefaultExecutor frame at the exception source, and removing downstream string-based traceback trimming in messaging/hooks.

Changes:

  • Strip the executor’s own frame from caught exceptions in DefaultExecutor (sync + async) before wrapping in MarimoRuntimeException.
  • Remove _trim_traceback usage and implementation so traceback formatting relies on the already-trimmed exception.
  • Update/add tests to assert the executor frame is absent and adjust snapshots accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
marimo/_runtime/executor/executor.py Strips the executor frame from exception tracebacks before wrapping.
marimo/_messaging/tracebacks.py Removes string-based traceback trimming; highlights/broadcasts the passed traceback as-is.
marimo/_runtime/runner/hooks_post_execution.py Stops trimming formatted tracebacks before highlighting.
tests/_runtime/test_executor_evaluator.py Adds assertions that executor frames are removed from cause tracebacks (sync/async).
tests/_server/test_scratchpad_integration.py Updates snapshot expectations to match trimmed tracebacks.
tests/_messaging/test_tracebacks.py Removes unit test coverage for deleted _trim_traceback.

Comment thread marimo/_runtime/executor/executor.py
Comment thread marimo/_runtime/executor/executor.py
Comment thread tests/_runtime/test_executor_evaluator.py
Comment thread tests/_runtime/test_executor_evaluator.py
@dmadisetti dmadisetti merged commit d469e1a into dm/runner-cleanup May 20, 2026
7 checks passed
@dmadisetti dmadisetti deleted the dm/traceback-cleanup branch May 20, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants