Skip to content

ci: keep the venv cache valid across runners - #36

Merged
notdodo merged 1 commit into
mainfrom
ci/fix-venv-cache
Nov 15, 2026
Merged

notdodo merged 1 commit into
mainfrom
ci/fix-venv-cache

Conversation

@notdodo

@notdodo notdodo commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Problem

The .venv cache added in #35 breaks CI on any PR whose uv.lock already has a cache entry (#31 is failing because of it):

  1. setup-uv's python-version only selects the interpreter. The actual Python download happens during uv sync, into uv-python-dir, and that directory wasn't cached.
  2. On a cache hit, .venv was restored but its interpreter wasn't. uv run logged Ignoring existing virtual environment linked to non-existent Python interpreter, deleted the venv, and recreated it with only the default groups, dropping the redaction extra.
  3. "Install dependencies" was skipped because of the hit, so mypy failed with 11 import-not-found errors for presidio.

Fix

  • cache-python: true on setup-uv: the uv-managed interpreter is cached and restored, so the restored .venv links to a Python that exists.
  • .venv and .mypy_cache are still cached, keyed per Python version and uv.lock, as upstream did. The ~/.local/.cache/uv path is dropped because it isn't the uv cache directory under setup-uv, which caches wheels itself.
  • task install always runs. On a valid restored venv it's a no-op of about a second. If a restore is ever partial, it repairs the venv, so CI never runs silently without the redaction extra.
  • Unchanged: uv build and all action versions.

Validation

  • actionlint and zizmor 1.32.0 pass.
  • On GitHub, the first run saves the cache. I'll rerun to confirm the cache hit: the venv should be reused, there should be no "non-existent Python interpreter" warning, and the install step should be near-instant.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

kics-logo

KICS version: v2.2.1

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 2
Files parsed placeholder 2
Files failed to scan placeholder 0
Total executed queries placeholder 4
Queries failed to execute placeholder 0
Execution time placeholder 0

Queries Results

|
|

@notdodo notdodo changed the title ci: cache only mypy state, not the virtualenv ci: keep the venv cache valid across runners Nov 15, 2026
The cached .venv linked to a uv-managed interpreter that setup-uv did not
restore, so on a cache hit uv deleted and recreated the venv with only the
default groups, and the skipped install step left mypy without the
redaction extra.

Enable setup-uv cache-python so the interpreter is restored with the venv,
cache .venv and .mypy_cache per Python version and uv.lock, and always run
task install so any partial restore self-heals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@notdodo
notdodo merged commit 9ad1359 into main Nov 15, 2026
@notdodo
notdodo deleted the ci/fix-venv-cache branch November 15, 2026 10:08
notdodo added a commit that referenced this pull request Nov 15, 2026
## Problem
Python 3.15 CI takes about 14 minutes whenever `uv.lock` changes, which
includes every Dependabot PR and #37:

- The venv cache key and setup-uv's own cache key both include the
lockfile hash, and neither has a fallback. A changed lockfile misses
both.
- There are no 3.15 wheels yet for numpy, pydantic-core, thinc and
others, so a miss means compiling all of them from source.
- setup-uv's Python cache misses too. A restored venv whose interpreter
is missing gets deleted and rebuilt, which is the same failure #36 fixed
for exact hits.

## Fix
- `restore-keys: python-<ver>-venv-` on the venv cache. A lockfile
change now restores the latest venv for that Python version, `task
install` applies only the changed packages, and the result is saved
under the new key.
- `uv python install <ver>` runs before `task install`, so the restored
venv always has its interpreter.

## Validation
- actionlint and zizmor are clean.
- This PR doesn't change `uv.lock`, so its run is an exact cache hit.
The fallback path gets its real test when #37, which does change the
lockfile, is updated from `main` after this merges. Its 3.15 job should
drop from about 14 minutes to roughly 1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

1 participant