Repository navigation
Description
build-lectures' check for error outputs (#247) reads the notebooks myst-nb writes to jupyter_execute. Its comment (build-lectures/action.yml:392-398) gives the premise: "myst-nb writes every notebook it renders, outputs included, to /../jupyter_execute whether it executed it or took it from the cache". For a notebook taken from the cache, that isn't so. Found during the repro for #98.
What myst-nb 1.4.0 does. On a cache hit, its client renders the page from jupyter-cache's merged copy (myst_nb/core/execute/cache.py: self._notebook = cache.merge_match_into_notebook(self.notebook)). Then myst_nb/sphinx_.py writes the notebook it was given, which has no outputs, to jupyter_execute (nbformat.writes(notebook), :180–:184). So a build that reads a page from the cache leaves an outputs-free notebook behind, and the check finds no error outputs on that page.
Shown. In the repro's run 43683024646 (the quantecon image: myst-nb 1.4.0, jupyter-cache 1.0.1, Sphinx 7.4.7), the check counted 11 error outputs on inequality at three points:
- 11 after the
jupyterbuild, which executed it; - 11 after
pdflatex, which re-read nothing; - 0 after
html, which re-read every page from the cache.
What it misses
- A later build in the same job that re-reads a page from the cache. In
build-jupyter-cache's order (jupyter,pdflatex,html), thehtmlbuild re-reads every page of a book with parts, so its check sees nothing. - A pull-request build whose restored execution cache serves every unchanged page, as
templates/ci.ymlsets up withcache-type: 'execution'. The check covers only the pages that build executes.
The build that executes a notebook still catches its error outputs. So where the cache build runs the check with error-outputs: fail, it fails, and build-jupyter-cache saves no cache. What doesn't hold is a later build relying on the check for pages it took from the cache, and the docs that say it can:
- the comment above;
docs/user/actions/build-jupyter-cache.md:121, which says an error output "fails every builder when the check fails at all, because each one checks the same notebooks in_build/jupyter_execute".
The harness doesn't cover it. build-display-error-guard (.github/workflows/test-actions.yml:1516) runs no build that takes a page from the cache.
Possible directions, none decided:
- read a cached page's outputs through jupyter-cache;
- check what the build rendered, rather than what it wrote to
jupyter_execute.
Writing the unmerged notebook on a cache hit may also be worth raising with myst-nb.
Claude Code (on behalf of mmcky), organiser session
Activity
docs: a native pipeline's doctrees clear needs no counterpart (#98) (#…
mmcky commentedon Nov 15, 2026
Checked against
main(f7e98be): the facts hold. On a cache hit myst-nb 1.4.0 renders from jupyter-cache's merged copy (myst_nb/core/execute/cache.py:37; jupyter-cache 1.0.1 merges into a deep copy) but writes the notebook it read, without outputs (myst_nb/sphinx_.py:181-184). Run 43683024646's log shows the 11 error outputs (allowed there byexecute.allow_errors) falling to 0 afterhtml. It also shows a first build given a copied cache counting 0, which is the pull-request case. Locally, the harness fixture built over nothing but its execution cache shows the traceback ondisplay_error.html, while the check passes underfail.The fix: check a cached page as the cache holds it. Where myst-nb looks in the execution cache for a page (cache mode, no exclude pattern, after the notebook's own
mystnboverrides), the check matches the notebook in_build/jupyter_executeagainst the cache with the same two jupyter-cache calls myst-nb makes, and checks the merged copy, which is what the page shows. A notebook with no match was executed by the build that wrote it, and is checked as written. A cache that can't be read leaves the page unchecked, and is reported, failing the step underfail, as an unreadable notebook does today. The inputs, the outputs and the messages stay as they are, apart from a count in the log's summary line.Rejected: reading the doctrees (it ties the check to myst-nb's internal AST, and would lose the structured error and execution counts the messages use), grepping the HTML (one builder, no cell or line), scanning the whole cache (stale versions and removed pages), and patching myst-nb at build time. Writing the merged notebook upstream in myst-nb would be the cleaner fix there. Ours doesn't depend on it.
Tests and docs. A new harness job,
build-cache-error-guard, executes the fixture's display-time error into the cache witherror-outputs: warn. It then builds again withfail, once with--allover the same_buildand once over the execution cache alone, and each must fail with one error output. On today's code both pass. The comment inbuild-lectures/action.yml, thebuild-lectureschapter (Behaviour 4, and the note that a later build reads no page, which isn't so afterpdflatexin a book with parts), andbuild-jupyter-cache's Behaviour 3 are corrected to match.Claude Code (on behalf of mmcky)
ci(scratch): run the restored-cache case after the --all case fails (#…
Merge origin/main into fix/322-cached-error-outputs
fix(build-lectures): check a page taken from the execution cache for …
release: v0.21.0 (#334)