fix(mpl): contain comm callback errors in mpl_interactive#9532
Merged
Conversation
A raising callback in _handle_comm_msg or _handle_download was killing the kernel subprocess via asyncio.run. Catch and log instead.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
No issues found across 1 file
Architecture diagram
sequenceDiagram
participant UI as Browser UI
participant UV as Uvicorn Server
participant KRN as Kernel Subprocess
participant CM as WIDGET_COMM_MANAGER
participant MC as MarimoComm
participant MPI as mpl_interactive
participant FM as Figure Manager
participant LOG as Logger
Note over UI,LOG: Matplotlib Pan/Zoom Event Flow
UI->>UV: Comm message (pan/zoom event)
UV->>KRN: receive_comm_message()
KRN->>CM: handle message
CM->>MC: handle_msg()
MC->>MPI: _handle_comm_msg()
alt Event type is "download"
MPI->>MPI: _handle_download(fmt)
alt Download succeeds
MPI->>FM: savefig()
MPI->>UI: Send blob via comm
else Exception in download
MPI->>LOG: LOGGER.exception()
MPI->>MPI: Return cleanly
end
else Event type is JSON (mouse/toolbar)
MPI->>FM: handle_json(event)
alt Callback succeeds
FM-->>MPI: void
MPI->>UI: Updated figure state
else Exception propagates
FM-->>MPI: raise Exception
Note over MPI,LOG: CHANGED: Exception caught here
MPI->>LOG: LOGGER.exception()
MPI->>MPI: Continue processing
end
end
alt Exception not caught (before fix)
MPI->>KRN: Unhandled exception propagates
KRN->>KRN: asyncio.run terminates
KRN-->>UV: Subprocess dies
UV->>UI: "stopped responding"
else Exception caught (after fix)
KRN->>KRN: Remains alive
KRN-->>UI: Normal response continues
end
Note over UI,LOG: Error handling boundary: all exceptions from FM callbacks<br/>are contained within mpl_interactive layer
Light2Dark
approved these changes
May 13, 2026
Collaborator
Light2Dark
left a comment
There was a problem hiding this comment.
should we add tests?
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents exceptions raised inside matplotlib interactive comm callbacks from propagating through the comm manager and crashing the kernel subprocess, while still emitting tracebacks for debugging.
Changes:
- Wrap
self._figure_manager.handle_json(event)intry/except Exceptionand log failures withLOGGER.exception. - Wrap figure download rendering/sending logic in
try/except Exceptionand log failures withLOGGER.exception.
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.7-dev12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A raising callback inside
mpl_interactive._handle_comm_msg(e.g. matplotlib'sAttributeError: 'Axes' object has no attribute '_pan_start'fromend_panwithout a priorstart_pan) was propagating up throughMarimoComm.handle_msg→WIDGET_COMM_MANAGER.receive_comm_message→ the kernel's request handler, terminatingasyncio.runand killing the kernel subprocess. The uvicorn parent kept serving so the UI just reported "stopped responding".This wraps the
handle_jsonand_handle_downloadcalls intry/except Exceptionand logs viaLOGGER.exceptionso a buggy callback is contained while the traceback still surfaces for diagnosis.BaseExceptionis intentionally not caught.Fixes the kernel-crash half of the matplotlib pan/zoom issue (see linked Linear issue). The underlying matplotlib
_pan_startbug is tracked separately.Test plan
_handle_comm_msgwith a raisinghandle_jsonreturns cleanly and a follow-up message is processed.