fix(pre-commit-advisory): key hook-env cache on the resolved Python patch - #53
Merged
Merged
Conversation
…atch
The hook-env cache key interpolated the `python-version` input, which
callers give as a bare X.Y ("3.13"). The venvs go-pre-commit builds under
~/.cache/pre-commit/repo*/py_env-* bind the interpreter by full patch path
(/opt/hostedtoolcache/Python/X.Y.Z), so a runner-image patch bump left the
key matching exactly while restoring venvs whose interpreter was gone —
every `language: python` hook then failed with
[ERROR] hook execution error: fork/exec .../bin/<hook>: no such file or directory
Key on steps.setup-python.outputs.python-version (a full X.Y.Z) instead,
in both `key` and `restore-keys`. The patch must be in the prefix too: a
restore-keys ending at X.Y just falls through to the next stale sibling,
so purging one entry doesn't clear the wedge.
Observed on trading#3262 (3.13.14 -> 3.13.15): all four pre-commit-hooks
entries errored while the csharpier/gitleaks hooks passed, which reads as
a diff problem rather than a cache one. Three cache entries shared the key
and all three needed deleting before a re-run went green.
Costs one cold rebuild per branch scope on a patch bump; a
.pre-commit-config.yaml edit still reuses same-interpreter envs.
blairham
added a commit
that referenced
this pull request
Aug 15, 2026
…ss-env wipe fix (#60) v4.6.6 (blairham/go-pre-commit#40) wipes a leftover hook environment that has no install-state marker before installing over it. The advisory workflow restores hook envs from actions/cache (#50/#53), so a cache entry missing its install_state_v2 previously poisoned the run: golang envs failed with "go install ./...: directory go_env-default/ pkg/mod/... outside main module". With the wipe, a bad cache entry costs one reinstall instead of a red job.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
pre-commit / advisoryfails with everylanguage: pythonhook erroring, while the C#/gitleaks/local hooks pass:Because the advisory reports as a ❌ on the PR, this reads as a problem with the author's diff. It isn't — the diff is never at fault.
Cause
The hook-env cache key interpolated the
python-versioninput, which callers give as a bareX.Y("3.13"). The venvs go-pre-commit builds under~/.cache/pre-commit/repo*/py_env-*bind the interpreter by full patch path (/opt/hostedtoolcache/Python/X.Y.Z).So when a runner-image refresh bumps the patch, the key still matches exactly and restores venvs whose interpreter no longer exists.
fork/execis Go'sos/execerror — go-pre-commit is reporting the dangling interpreter, not causing it.Fix
Key on
steps.setup-python.outputs.python-version(the resolvedX.Y.Z) instead of the input, in bothkeyandrestore-keys.The patch has to be in the prefix too. A
restore-keysending atX.Yjust falls through to the next stale sibling, which is why partial cache purges don't clear it.Evidence
Observed on trading#3262,
3.13.14 → 3.13.15. Three cache entries shared keygo-pre-commit-Linux-py3.13-f7a835d9…, branch-scoped separately. All three had to be deleted before a re-run went green (passing job, 1m42s).Tradeoff
A Python patch bump now costs one cold rebuild per branch scope instead of a silently broken restore. A
.pre-commit-config.yamledit still reuses same-interpreter envs via the prefix.Verification
actionlintclean locally. Blast radius is every caller repo, and the first run on each branch scope after merge will be a cold rebuild by design.Not included, as a separate concern:
blairham/go-pre-commitis pinned atv4.6.1;v4.6.2shipped 2026-08-06.