Skip to content

Commit 331ddd6

Browse files
Handle missing status field in execute_reply from XEUS-based kernels
XEUS-based Jupyter kernels (such as the Maple 2025 kernel) omit the 'status' field from execute_reply messages when execution produces an error. This violates the Jupyter messaging protocol, which requires every execute_reply to include status. The missing field causes a KeyError that crashes notebook execution. This is a workaround for a kernel-side protocol violation — the right fix is in the kernel. But the workaround is low-risk: we catch a specific KeyError("'status'") around client.execute_cell() and record it as a cell error output rather than crashing. Kernels that conform to the protocol are unaffected. Tested against Maple 2025 (XEUS 2.3.1) with 18 Quarto documents containing executable Maple code blocks.
1 parent 10946d2 commit 331ddd6

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/resources/jupyter/notebook.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,26 @@ def cell_execute(client, cell, index, execution_count, eval_default, store_histo
563563
# execute (w/o yaml options so that cell magics work)
564564
source = cell.source
565565
cell.source = nb_strip_yaml_options(client, cell.source)
566-
cell = client.execute_cell(
567-
cell=cell,
568-
cell_index=index,
569-
execution_count=execution_count,
570-
store_history=store_history,
571-
)
566+
try:
567+
cell = client.execute_cell(
568+
cell=cell,
569+
cell_index=index,
570+
execution_count=execution_count,
571+
store_history=store_history,
572+
)
573+
except KeyError as e:
574+
# Some kernels (e.g. XEUS-based Maple) omit 'status' from
575+
# execute_reply on error, violating the Jupyter protocol.
576+
# Record the error in the cell outputs rather than crashing.
577+
if str(e) == "'status'":
578+
cell.outputs.append(nbformat.v4.new_output(
579+
output_type="error",
580+
ename="KernelProtocolError",
581+
evalue="Kernel returned execute_reply without status field",
582+
traceback=["Cell source:", source],
583+
))
584+
else:
585+
raise
572586
cell.source = source
573587

574588
# if lines_to_next_cell is 0 then fix it to be 1

0 commit comments

Comments
 (0)