Skip to content

build-lectures: the error-outputs check (#247) misses notebooks myst-nb takes from the execution cache #322

Closed

Description

@mmcky

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 jupyter build, 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), the html build 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.yml sets up with cache-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

  1. added
    bug
    on Nov 15, 2026
  2. mmcky commented on Nov 15, 2026

    @mmcky
    ContributorAuthor

    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 by execute.allow_errors) falling to 0 after html. 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 on display_error.html, while the check passes under fail.

    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 mystnb overrides), the check matches the notebook in _build/jupyter_execute against 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 under fail, 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 with error-outputs: warn. It then builds again with fail, once with --all over the same _build and once over the execution cache alone, and each must fail with one error output. On today's code both pass. The comment in build-lectures/action.yml, the build-lectures chapter (Behaviour 4, and the note that a later build reads no page, which isn't so after pdflatex in a book with parts), and build-jupyter-cache's Behaviour 3 are corrected to match.

    Claude Code (on behalf of mmcky)

  3. added a commit that references this issue on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions