Skip to content

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

Closed

Description

@quantecon-services

Found by the canary experiment for #205 (QuantEcon/test-actions-lecture-intro#70, run). That experiment runs setup-environment in standard mode on the canary's own environment.yml, which pins anaconda=2025.12.

What happens

In standard mode the action runs these steps in order:

  1. setup-miniconda, with activate-environment: <environment-name> and python-version, creates the environment: conda create --name quantecon python=3.13.
  2. actions/cache restores $CONDA/envs/<environment-name> on top of it.
  3. On anything but an exact hit, conda env update --prune runs.

The restore's tar overwrites the files both environments share, and leaves the files only the fresh environment has. When the cached environment's packages differ from what conda create python=<version> installs that day, the restored environment is a mix of both.

On the canary:

  • The two environments differ. The fresh environment gets pip 26.2.1 and Python 3.13.15. The cached one has pip 25.3 and Python 3.13.9, Anaconda 2025.12's pins.
  • An exact hit leaves pip broken (hit job). pip list fails with ImportError: cannot import name 'BuildDependencyInstallError' from 'pip._internal.exceptions': pip 26.2.1's build_env/ package sits beside pip 25.3's exceptions.py. conda list then reports pip 26.2.1 from PyPI beside python 3.13.9. The lectures still built, because nothing in a build runs pip.
  • A fallback restore fails the job (edit job). conda env update runs pip for the file's pip: section and dies with the same ImportError.

So a repository that pins its stack, as every one pinning anaconda does, gets a broken pip on every restore. Its first run after an edit to environment.yml fails outright. This predates #206: a restore has always landed on the freshly created environment. No production consumer is affected yet: those that use setup-environment run it in a container, which has no Conda cache.

Why the harness doesn't see it

Its fixture pins nothing: python=3.13 and an unpinned pip. So the fresh and cached environments hold the same versions, and every file is overwritten.

Proposed fix

Delete the environment setup-miniconda created before the restore, so that a restore is an exact copy of the cache. On a miss, create the environment again the same way, conda create -n <environment-name> python=<python-version>, before conda env update, so python-version keeps its meaning.

Restoring before setup-miniconda runs would also avoid the mix. It depends on what setup-miniconda does with an environment that already exists, which would need checking.

Test

Pin an older pip in the harness fixture, so the fresh and cached environments differ. Then:

  • assert that python -m pip --version works after env-hit-build's exact hit;
  • env-file-edit's fallback update must succeed.

Both would fail today. The canary experiment, re-run at the fix's commit, would confirm it on a full Anaconda stack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions