Skip to content

UPSTREAM candidate (executablebooks/MyST-NB): on a cache hit, myst-nb writes the notebook to jupyter_execute without the cached outputs #327

Open

Description

@mmcky

This is an UPSTREAM candidate, recorded here first. Nothing has been filed on executablebooks/MyST-NB. It is to be reviewed in detail before anything is raised there.

What myst-nb does

In execution_mode: cache, when a page's notebook matches a record in the jupyter-cache execution cache, myst-nb 1.4.0 renders the page from a merged copy: the cache client replaces its notebook with cache.merge_match_into_notebook(self.notebook) (myst_nb/core/execute/cache.py:37), and jupyter-cache merges into a deep copy. But the parser then writes the notebook it read from the source to _build/jupyter_execute (myst_nb/sphinx_.py:183-184), not the client's merged copy. For a MyST Markdown source that notebook has no outputs; an .ipynb source is written with whatever outputs it stores. The docutils entry point does the same when it writes processed.ipynb (myst_nb/docutils_.py:201-202).

On a cache miss the client executes its notebook in place (cache.py:73), so the written file has its outputs. The difference is only on a hit.

The same lines are on MyST-NB's main today (sphinx_.py:197-198, cache.py:37, at 06e4880 of 2026-10-19). v1.4.0 is MyST-NB's latest release.

It looks like a regression. In v0.13.2 the parser added the cache's outputs to the notebook before writing it (myst_nb/parser.py:65-68, then nb_output_to_disc), and the unmerged write arrived with the rewrite in executablebooks/MyST-NB#380 (merged 2022-04-20).

Why it matters here

_build/jupyter_execute looks like the executed notebooks, but after a build that takes MyST Markdown pages from the cache it holds outputs-free copies of each of them. build-lectures' error-outputs check (#247) reads those files, so it misses errors on cached pages: that is #322. #326, still open, has the check read the merged copy from the cache, with the same jupyter-cache calls myst-nb makes, and does not depend on any change in myst-nb.

The candidate change upstream

Write the client's notebook (nb_client.notebook) instead of the parsed one, at sphinx_.py:183 and docutils_.py:201, so that the file written is what the page shows, on a hit as on a miss. Searches of MyST-NB's issues and pull requests on 2026-11-15 found no report of this. The nearest is executablebooks/MyST-NB#617 (open), a different symptom: a jupytext source recorded in the cache with the wrong reader, so the page itself renders without outputs.

Before anything is filed upstream

  • A minimal reproduction outside QuantEcon's actions: a MyST Markdown page built with execution_mode: cache, then built again with jb build --all (or sphinx-build -E) keeping _build/.jupyter_cache, comparing jupyter_execute/*.ipynb after each build. A plain second build re-reads no unchanged page, so it rewrites nothing.
  • Whether anything downstream relies on the outputs-free file, such as a download button or a notebook-to-notebook build.
  • The maintainer's review and approval of the issue text.

Claude Code (on behalf of mmcky)

Activity

  1. added
    low-priority
    on Nov 15, 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

    low-priority

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions