Repository navigation
fix(setup-environment): a restored Conda environment is an exact copy of the cache (#209) - #210
Conversation
…ter every restore The first run confirmed the cache-version fix but found QuantEcon/actions#209: a restore mixed the cache with the environment setup-miniconda had just created, which broke pip. This pins setup-environment and build-lectures to the fix's commit in QuantEcon/actions#210, and makes hit and edit also require a single pip record in conda-meta and a pip that runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FeKTxWtkzVMyPbqeSgM2Tb
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes a widely-used core action's standard-mode behavior and performs rm -rf on Conda environment paths, so final human review is warranted despite the strong test evidence.
Review effort: Balanced
Findings: None
What changed in this PR
This PR fixes issue #209 in the setup-environment action: in standard mode, setup-miniconda created the Conda environment (with python-version) before the cache restore, so the restore's tar extracted the cache on top of a fresh environment, leaving a mix of both (e.g. two pip versions' files coexisting, breaking pip import). The fix deletes the freshly-created environment before the restore so a restore is an exact copy of the cache, and recreates it only when nothing was restored. It fits into the ongoing hardening of the Conda caching path (following #205/#206/#208).
Changes:
- Add a step to remove the
setup-miniconda-created environment before the cache restore, and a guarded step to recreate it withpython-versionon a cache miss. - Add three harness jobs (
env-pinned-seed/hit/edit) that pinpip=25.3below a fresh install so exact-hit and fallback restores are asserted to hold a single working pip. - Update user docs, TESTING coverage row, and CHANGELOG.
| File | Description |
|---|---|
setup-environment/action.yml |
Removes the fresh env before restore and recreates it on a miss so a restore is an exact cache copy; core fix for #209. |
.github/workflows/test-actions.yml |
Adds env-pinned-seed/hit/edit jobs (pinned pip) proving a restore is exact, and wires them into harness-summary. |
docs/user/actions/setup-environment.md |
Rewrites the standard-mode step list to describe env removal/recreation and renumbers subsequent steps. |
docs/dev/TESTING.md |
Extends the setup-environment coverage row to note the new #209 pinned-pip jobs. |
CHANGELOG.md |
Adds a Fixed entry describing the exact-copy restore fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…#209) setup-miniconda creates the environment before the cache restore, and tar extracts over it without deleting what only the fresh environment has. The harness fixture pins nothing, so its fresh and cached environments hold the same versions and the mix never showed; the canary's pinned Anaconda stack found it (#209). Three new jobs pin pip to 25.3, below what a fresh `conda create` installs, under their own salted cache-version: - env-pinned-seed: a true miss builds the environment with pip 25.3. - env-pinned-hit: the exact hit must hold one pip record in conda-meta and a working pip 25.3. - env-pinned-edit: a fallback restore must update cleanly, which runs pip, and hold the same single pip. On the current action the hit and edit jobs fail by design. The fix follows in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FeKTxWtkzVMyPbqeSgM2Tb
… of the cache (#209) setup-miniconda creates the environment, with python-version, before the cache restore, and the restore's tar extracted the cache on top of it, keeping every file only the fresh environment had. A cache whose packages differ from a fresh `conda create`, as any pinned stack's do, came back as a mix of both. The previous commit's jobs show it: after an exact hit conda-meta held pip-25.3 and pip-26.2.1 records, and a fallback restore's `conda env update` died importing pip (BuildDependencyInstallError). - A step after setup-miniconda removes the environment it created, so a restore is an exact copy of the cache. It refuses an empty or dotted environment-name, or one with a slash, and an unset CONDA, rather than point rm -rf at or above envs/. - When nothing was restored, a step creates the environment the way setup-miniconda did, `conda create -n <name> python=<version>`, so python-version keeps its meaning. After a fallback restore the environment exists and the update step runs as before. - The chapter's standard-mode steps, CHANGELOG and TESTING follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FeKTxWtkzVMyPbqeSgM2Tb
c64c532 to
586a95c
Compare
Move [Unreleased] into a dated 0.13.0 section (decision 11, 2026-11-04), and record the deploy-CLI moves since v0.12.0 (#207, #219), which Dependabot made without a CHANGELOG entry. The release carries #198, #206 and #210 to @v0 consumers, so it is staged on the canary before v0 moves. This commit changes only CHANGELOG.md, and the harness has no @v0 workaround for this release to drop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WT8bMbMmeUUEj8EjiweB6S
Fixes #209. Rebased onto
mainnow that #208 has merged. The two commits are nowb375952(the jobs) and586a95c(the fix), and their diff is unchanged. The runs below are from before the rebase.The bug
In standard mode,
setup-minicondacreates the environment withpython-versionbefore the cache restore. The restore'starthen extracted the cache on top of it: it overwrote the files both environments hold, and kept the ones only the fresh environment had.A cache whose packages differ from what a fresh
conda createinstalls, as any pinned stack's do, came back as a mix of both. On the canary's Anaconda 2025.12 stack, pip 26.2.1's files sat beside pip 25.3's, and pip failed to import. An exact hit left pip broken. A fallback restore failed the job, becauseconda env updateruns pip.The fix
setup-minicondadeletes the environment it created, so a restore is an exact copy of the cache. The step refuses an empty or dottedenvironment-name, one containing a slash, and an unsetCONDA, rather than pointrm -rfat or aboveenvs/.setup-minicondadid,conda create -n <name> python=<version>, sopython-versionkeeps its meaning. After a fallback restore the environment already exists, and the update step runs as before.setup-minicondastill runs withactivate-environment, for the login-shell activation thatbuild-lectures'bash -lrelies on.Evidence: red, then green
The in-repo fixture pins nothing, so its fresh and cached environments always matched and the harness never saw the mix. The three new jobs pin
pip=25.3, below what a fresh create installs, under their own saltedcache-version.194cc3f(nowb375952) adds only the jobs. They failed on the current action, and every other job passed:env-pinned-hit:conda-meta holds 2 pip records … pip-25.3-pyhc872135_0.json, pip-26.2.1-pyhc872135_0.jsonenv-pinned-edit:ImportError: cannot import name 'BuildDependencyInstallError', thenCondaEnvException: Pip failedc64c532(now586a95c) is the fix. The whole harness is green. For example,env-pinned-hitnow reportsthe exact hit restored the cached environment and nothing else: pip 25.3.c64c532, on its full Anaconda 2025.12environment.yml. All four jobs passed, and each restore now also requires a single pip record and a working pip. Itseditjob had failed at fix(setup-environment): bumping cache-version builds a fresh Conda environment (#205) #206's commit; its fallback restore now updates cleanly.Also in this PR
Rollout
setup-environmentdoes in standard mode, so it ships in the next release.setup-environmentrun it in a container.🤖 Generated with Claude Code
https://claude.ai/code/session_01FeKTxWtkzVMyPbqeSgM2Tb