Skip to content

restore-jupyter-cache: the templates restore only the execution cache, keyed on the environment too (#160, step 2) #270

Closed

Description

@mmcky

#160's step 1 makes a build-cache restore remove <path>/html, so a deleted page or static file is no longer published again. This is step 2, which the maintainer decided on 2026-11-07 would follow it: the templates stop restoring the full _build at all. Analysis: #160's comment of 2026-11-07, against main at 9644f17.

The problem step 1 leaves

  • Leftovers outside html. A restored build cache still holds _build/jupyter, _build/latex and _build/jupyter_execute from the last cache build, including the outputs of lectures deleted since. html-copy-notebooks copies every .ipynb under _build/jupyter into the site, and html-copy-pdf every .pdf under _build/latex. So a workflow that builds jupyter or pdflatex over a restored cache can still publish a deleted lecture's notebook, or a figure PDF, as the canary's ci.yml does, and templates/publish.yml does with its optional steps on. feat(build-lectures): fail on error outputs in the executed notebooks, which -W misses (#247) #256's error-output check already has to skip stale notebooks in _build/jupyter_execute (build-lectures/check-error-outputs.py:35-38).
  • Storage. Each cache build saves the full _build, which contains _build/.jupyter_cache, and then saves _build/.jupyter_cache again on its own (build-jupyter-cache/action.yml:426-438). So the execution cache is stored twice, against the repository's 10 GB cache budget, past which GitHub evicts the least recently used caches (review M3, .qe/dev/log/2026-10-06-codebase-review.md:220-245). After step 1, every restore also downloads the whole _build and deletes its html.
  • No speed in return. A fresh checkout gives every source file a newer mtime than the last build's, so Sphinx re-reads and rewrites every page whatever was restored. Only .jupyter_cache saves work, by sparing notebook execution.

Why not simply restore cache-type: execution today

The two caches are keyed differently. The build cache's key hashes the environment files and never falls back across an environment change. The execution cache's key hashes only the lectures, and falls back to any execution cache (restore-jupyter-cache/action.yml:164-182). So under execution, a pull request that changes the environment, an Anaconda baseline bump for one, would restore outputs made with the old packages, re-execute nothing and pass. The new packages would first run in the next weekly cache build, after the merge. The restore chapter documents this (docs/user/actions/restore-jupyter-cache.md:139). Under build, the same pull request misses the cache and re-executes everything, which is the signal it needs.

The change

  1. The execution cache's key hashes the environment too.
    • build-jupyter-cache saves it as jupyter-cache-<hash of environment>-<hash of environment-update>-<hash of the .md files>-<run id> (build-jupyter-cache/action.yml:433-438).
    • restore-jupyter-cache looks it up with the build cache's fallbacks: jupyter-cache-<env>-<update>-<md>-, then jupyter-cache-<env>-<update>-, then jupyter-cache-<env>-. It never falls back across an environment change.
    • The environment and environment-update inputs then apply to both cache types, and their descriptions lose "Ignored for the execution cache". Run scripts/generate-docs.py.
  2. The templates restore cache-type: 'execution': templates/ci.yml:157, and an explicit value at templates/publish.yml:89, each with a short comment on why.
  3. Review M3. Once no template restores the full _build, decide whether build-jupyter-cache keeps saving it: keep it, make it opt-in through a new input, or deprecate it for one release and then drop it. Whatever the choice, it goes in the CHANGELOG.
  4. The docs. ARCHITECTURE's "Two caches" section and the restore chapter describe the templates restoring the execution cache, and when the build cache is still the right choice.
  5. The harness.
    • bjc-restore-exec and the jobs that assert an execution key (.github/workflows/test-actions.yml:740, :772, :2515) take the new key.
    • The harness header's second constraint (:29-33), that a genuine execution-cache miss can't be constructed, stops being true, because the fallback now carries the per-run salted environment hash.
    • Add an execution-cache restore with a changed environment file, and assert that it misses. Against main today it restores the bare jupyter-cache- fallback, so it fails, which shows that it can.
  6. CHANGELOG. Under Changed: the execution cache's key includes the environment, so a repository that already restores execution misses once after the release, until its next cache build. None does in production today. Also under Changed: the templates restore the execution cache.

Out of scope

  • Changing restore-jupyter-cache's default from build to execution. Without that, a caller who omits cache-type keeps today's behaviour, with step 1's prune. It is a separate decision, best taken once lecture-dp and the canary have run on execution for a while. It would change what a caller with no inputs restores, so its CHANGELOG entry would need a ⚠️ mark.
  • Moving lecture-dp and the canary, a one-line edit each, made after the release.

The canary check, for the staged release

On a staging branch, switch the canary's ci.yml to cache-type: 'execution', and show:

  • the restore reports an execution-cache hit, and the build executes only the lectures the pull request changed;
  • a pull request that deletes a _static file or a lecture gets a preview that returns 404 for it, while a control page returns 200;
  • a pull request that changes environment.yml misses the execution cache and executes every lecture;
  • cache.yml saves the execution cache under the new key.

Depends on #160's step 1, which ships first. Related: QuantEcon/workspace-lectures#41, the lecture repositories' interim prune and their cutover to these actions, which waits on #160.

Claude Code (on behalf of mmcky), drafted by the mini:actions-proposals session and filed by the organiser

Activity

  1. added
    enhancement
    on Nov 6, 2026
  2. mmcky commented on Nov 7, 2026

    @mmcky
    ContributorAuthor

    Checked against main at e40924a (v0.16.0) on 2026-11-07, after step 1 merged as #275. The design holds. The execution cache's key still hashes only the lectures and falls back to any execution cache (restore-jupyter-cache/action.yml:167-185), while the build cache's never falls back across an environment change (:186-209). build-jupyter-cache still saves both caches (:426-438). Most cited lines have moved since 9644f17: the templates' restore steps are now at templates/ci.yml:157-162 and templates/publish.yml:91-92, and the harness's execution-key assertions at test-actions.yml:753, :786 and :2646.

    No QuantEcon repository restores cache-type: execution. lecture-dp restores the default (build) in ci.yml and publish.yml. The canary restores build in ci.yml. test-lecture-theme-sphinx saves the caches but restores neither. A GitHub-wide code search found no caller outside QuantEcon. Measured sizes: lecture-dp's build cache is 91.6 MiB, against 15.7 MiB for its execution cache. The canary's is 6.3 MiB against 0.7 MiB, and lecture-python.myst's zipped _build is about 300 MiB.

    Since step 1, the leftovers this issue removes are only in _build/jupyter and _build/latex. They reach a site only through a workflow that builds jupyter or pdflatex over a restored build cache and copies the output in, as the canary's ci.yml does. lecture-dp builds HTML only, so step 1 already fixed it.

    What the PR will do beyond the issue's list:

    • every execution-cache job in the harness passes a salted environment file, since without one the new fallback would not be salted;
    • the new test changes only the environment, with the lectures byte for byte the seed's, so today's code restores the seed's own cache and fails every time;
    • a control shows that a lecture edit still falls back inside one environment;
    • the restore's status report drops "After lecture content changes (execution cache)", which was never true;
    • the passages in five other files (templates/cache.yml and four manual pages) that say the templates restore the build cache are brought in line.

    The maintainer's decisions, 2026-11-07: M3: build-jupyter-cache keeps saving the full _build, unchanged, since restore-jupyter-cache's default still restores it. CHANGELOG: Changed, with no ⚠️ marker. Fallbacks: the execution cache's mirror the build cache's exactly, so they cross an environment-update change but never an environment change. restore-jupyter-cache's default stays build. Moving it, and with it retiring the full _build save or making it opt-in, is a later, separate decision, once lecture-dp and the canary have run on execution for a while.

    Claude Code (on behalf of mmcky), organiser session; the check by the mini:actions-cache session

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions