Skip to content

fix(setup-environment): a restored Conda environment is an exact copy of the cache (#209) - #210

Merged
mmcky merged 2 commits into
mainfrom
claude/stoic-newton-u867m9-restore-env
Sep 28, 2026
Merged

mmcky merged 2 commits into
mainfrom
claude/stoic-newton-u867m9-restore-env

Conversation

@quantecon-services

@quantecon-services quantecon-services commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #209. Rebased onto main now that #208 has merged. The two commits are now b375952 (the jobs) and 586a95c (the fix), and their diff is unchanged. The runs below are from before the rebase.

The bug

In standard mode, setup-miniconda creates the environment with python-version before the cache restore. The restore's tar then 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 create installs, 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, because conda env update runs pip.

The fix

  • Remove the fresh environment before the restore. A new step after setup-miniconda deletes the environment it created, so a restore is an exact copy of the cache. The step refuses an empty or dotted environment-name, one containing a slash, and an unset CONDA, rather than point rm -rf at or above envs/.
  • Recreate it when nothing was restored. A new 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 already exists, and the update step runs as before.

setup-miniconda still runs with activate-environment, for the login-shell activation that build-lectures' bash -l relies 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 salted cache-version.

Also in this PR

  • The chapter's standard-mode steps: the fresh environment is removed before the restore, and created when nothing is restored.
  • CHANGELOG: a Fixed entry.
  • TESTING's coverage row.

Rollout

  • Behaviour. It changes what setup-environment does in standard mode, so it ships in the next release.
  • Consumers. No current consumer is affected: those that use setup-environment run it in a container.
  • Caches. Existing caches stay valid, because the key is unchanged. Restoring them into an empty directory is what makes them usable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FeKTxWtkzVMyPbqeSgM2Tb

quantecon-services pushed a commit to QuantEcon/test-actions-lecture-intro that referenced this pull request Sep 28, 2026
…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
@quantecon-services
quantecon-services marked this pull request as ready for review September 28, 2026 05:59
@mmcky
mmcky requested a balanced review from Copilot September 28, 2026 06:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with python-version on a cache miss.
  • Add three harness jobs (env-pinned-seed/hit/edit) that pin pip=25.3 below 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.

Base automatically changed from claude/stoic-newton-u867m9 to main September 28, 2026 09:54
…#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
@quantecon-services
quantecon-services force-pushed the claude/stoic-newton-u867m9-restore-env branch from c64c532 to 586a95c Compare September 28, 2026 09:56
@mmcky
mmcky merged commit 610fbbd into main Sep 28, 2026
29 checks passed
@mmcky
mmcky deleted the claude/stoic-newton-u867m9-restore-env branch September 28, 2026 10:00
mmcky added a commit that referenced this pull request Nov 5, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setup-environment: a restored Conda environment mixes the cached one with the one setup-miniconda just created

4 participants