Repository navigation
Description
A traceback can reach a published page while every check stays green. When the exception happens while IPython displays a cell's result, rather than while the cell's code runs, the kernel reports the cell as successful. nbclient does not raise CellExecutionError, and myst-nb renders the traceback without a Sphinx warning. So -W never fires, the status page shows ✅, and build-lectures reports success. This issue proposes a check in build-lectures that fails the step when an executed notebook holds an error output.
Where it happened
On python-advanced.quantecon.org, the Black–Litterman lecture shows two tracebacks where its two decolletage(λ) figures should be: TypeError: only 0-dimensional arrays can be converted to Python scalars. The cells pass length-1 arrays to ax.text, which NumPy 2.4 no longer accepts. Matplotlib only converts those coordinates when the inline backend draws the figure, inside IPython's display formatter, so the error happens after the cell's own code has finished. QuantEcon/lecture-python-advanced.myst#403 repairs the lecture itself.
Release archives of that site:
| Release | NumPy | Tracebacks on the page | Status page |
|---|---|---|---|
| publish-2026jun25 | 2.3.5 | 0 | ✅ |
| publish-2026jul08 | 2.3.5 | 0 | ✅ |
| publish-2026aug02 | 2.4.6 | 2 | ✅ |
| publish-2026nov01 (live) | 2.4.6 | 2 | ✅ |
Everything that could have caught it was green:
- The weekly cache build (
jb build lectures -W --keep-going) has executed the notebook under NumPy 2.4 since late July. - Review and improve black_litterman, BCG_complete_mkts, BCG_incomplete… lecture-python-advanced.myst#384 (2026-09-20) edited
black_litterman.md, so its CI re-executed the notebook with-W, and the run passed. - The site's status page lists the lecture as ✅.
That repo calls jb build directly rather than through build-lectures, but build-lectures makes the same decision: its build step passes or fails on the jb build exit code alone, so it would have passed too. The extra-args description (build-lectures/action.yml lines 35-37) implies that with -W, a notebook that raises an exception fails the build. This notebook raised one and did not.
Why -W does not see it
- IPython's display formatters catch any exception a formatter raises, print it with
showtraceback, and carry on (IPython/core/formatters.pylines 279-294). The traceback becomes anerroroutput on the cell, but theexecute_replystatus staysok. - nbclient decides whether to raise
CellExecutionErrorfrom that status alone, and returns early unless it iserror(nbclient/client.pylines 899-913). Soallow_errors=Falselets the cell through, and execution continues. - myst-nb renders an
erroroutput as a code block and emits no warning (myst_nb/core/render.pylines 538-562). With no warning,-Whas nothing to promote, and noreports/<doc>.err.logis written.
Reproduction
This cell reproduces it without depending on NumPy or Matplotlib versions:
class DisplayFails:
def _repr_html_(self):
raise ValueError("harness: deliberate display-time error")
DisplayFails()Run locally with IPython 9.15.0, nbclient 0.11.0 and myst-nb 1.4.0, the versions in the live site's build:
- nbclient with
allow_errors=False: kernel reply statusok, outputserror(ValueError) andexecute_result, no exception, and the next cell runs. A plain1/0cell, for comparison, gets statuserrorand raisesCellExecutionError. - A one-page myst-nb book with the lecture's
ax.textpattern, built withsphinx-build -W --keep-going, exits 0, and the page contains the traceback.
Proposed change
Add a step to build-lectures, after "Build lectures", that reads the executed notebooks and fails when one holds an error output.
- Where to look. myst-nb writes every notebook it renders, outputs included, to
<outdir>/../jupyter_execute/<docname>.ipynb, whether it executed the notebook or took it from the cache (myst_nb/sphinx_ext.pylines 171-179). Forbuild-lecturesthat is<output-dir>/_build/jupyter_execute/. Reading the notebooks rather than the HTML covers thepdflatexbuilder too, and gives the exception name and message for the report. - What counts. Any output with
output_type: error, except in a cell taggedraises-exceptionor a notebook whosemetadata.execution.allow_errorsis true. These are the same exemptions nbclient honours for an exception the cell raises. - What it reports. One
::error file=<source>::annotation per hit, naming the document, the cell index andename: evalue, then the traceback in a log group behind::stop-commands::, as "Report build failure" does for eacherr.log(lines 282-297). - A new input,
error-outputs.fail(the default) fails the step,warnannotates and passes, andignoreskips the check. A book that setsexecute.allow_errors: truewould set this towarnorignore.build-jupyter-cachecallsbuild-lecturesfor each builder, so it would get the check as well, and should pass the input through. - Stale notebooks.
_build/jupyter_executetravels in a restored build cache, and a lecture removed from the book leaves its notebook behind. Scan only notebooks that still have a source document undersource-dir.
The script needs only the Python standard library, which the build environment already has.
Harness assertion
build-fail-guard (test-actions.yml lines 822-907) stages a cell that raises, which -W already catches. Alongside it:
- A
build-display-error-guardjob that derivesdisplay_error.mdfromlecture1.mdthe same way, appends theDisplayFailscell above, and asserts thatbuild-lecturesreportsfailureand that the log namesdisplay_errorandharness: deliberate display-time error. It should also assert that noreports/display_error.err.logexists, which pins this as the case-Wmisses. - A control in a job that is meant to pass, such as
env-hit-build: a fixture page with a cell taggedraises-exception, so the exemption is tested and the job stays green.
Today the first job goes red, because the build passes. Both jobs pass after the change.
Rollout
Consumers on @v0 get a new default with the next v0 release, and any site that is already publishing a hidden traceback goes red on its next build. Before releasing, grep each lecture site's HTML for class="output traceback" to see which sites that is. Alternatively, ship with warn as the default for one release.
Out of scope
Warnings printed to stderr, such as DeprecationWarnings, also show on the page, and pass for a different reason: myst-nb's nb_output_stderr defaults to show. Whether to flag those is a separate decision, because many of them are deliberate or harmless.
Priority
Medium. No build breaks, but this let a broken page ship for three months while every check passed. The next NumPy or Matplotlib deprecation that expires inside figure rendering will slip through the same way.
Claude Code (on behalf of mmcky)
Activity
docs(plan): catch up with wave 1 and the v0.13.0 and v0.14.0 releases (…
docs(plan): catch up with wave 1 and the v0.13.0 and v0.14.0 releases (…
test(harness): raise the display-time error through display(), as a f…
test(harness): build-display-error-guard, for the error outputs -W mi…
test(harness): raise the display-time error through display(), as a f…
feat(build-lectures): fail on error outputs in the executed notebooks…
mmcky commentedon Nov 5, 2026
A correction to "Why
-Wdoes not see it", found while building #256: since ipykernel 7.3.0 (released 2026-06-10), the gap is narrower than step 1 above describes, but it is still open for figures.What changed. ipykernel now marks the
execute_replyaserrorwhen a traceback is shown while the displayhook is formatting a cell's last value._showtracebacksets_last_traceback_during_displayhookwhen the displayhook has a message open (zmqshell.pylines 700-703 at v7.4.0), anddo_executereplieserrorwhen it is set (ipkernel.pylines 468-473). nbclient then raisesCellExecutionError, and-Wfails the build.So the reproducer above no longer reproduces. A cell whose last value has a
_repr_html_that raises (DisplayFails()) fails-Wunder ipykernel 7.4.0. Run 41975613328 shows myst-nb reportingExecuting notebook failed: CellExecutionErrorfor it, with IPython 9.18.1. This issue's local reproduction used IPython 9.15.0 and an earlier ipykernel.What still slips through. Output shown through
display()never opens a displayhook message, so a formatter error there still leaves the cellok. That is how a figure reaches the page:plt.show(), and the inline backend's flush after the cell, both calldisplay(fig). So the Black–Littermanax.textcase still passes-Wunder ipykernel 7.4.0. So do the 27 tracebacks on tools-techniques'five_preferences(RuntimeError: Failed to process string with tex because latex could not be found). The reproducer that still works on current versions is:Run 41976251440 shows it: myst-nb cached the notebook as executed successfully, and
jb build -Wprintedbuild succeeded.with the traceback on the page. #256'sbuild-display-error-guardjob uses this form. That job also asserts that noreports/display_error.err.logis written, so it will say so if a later ipykernel closes this path too.Claude Code (on behalf of mmcky)
test(harness): build-display-error-guard, for the error outputs -W mi…
test(harness): raise the display-time error through display(), as a f…
feat(build-lectures): fail on error outputs in the executed notebooks…
fix(build-lectures): escape an invalid error-outputs in its annotatio…
feat(build-lectures): fail on error outputs in the executed notebooks…
docs(manual): the cross-cutting chapters, and signposts for the templ…
fix(build-lectures): check a page taken from the execution cache for …