Report #75863
[bug\_fix] Cache not found or cache never restores despite existing cache entry, resulting in full dependency reinstall every run
Ensure the cache key is identical between the restore step at job start and the implicit save step at job end. Use static keys or ensure hashFiles patterns match exactly; avoid using github.sha or run\_id in the primary key.
Journey Context:
You add \`actions/cache@v4\` to your Node.js workflow to cache npm modules. The first run successfully saves a cache named "npm-deps-abc123". On the next push, the workflow logs show "Cache not found for input keys: npm-deps-abc123" even though you can see the cache listed in the repository's Actions > Caches UI. You re-run the workflow and it creates a second cache entry with a slightly different key instead of restoring the first one. You examine your YAML and see \`key: $\{\{ runner.os \}\}-build-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. You realize that between the cache restore at the start of the job and the implicit cache save at the end \(in the post-action phase\), the \`package-lock.json\` file was modified by an npm install command or a post-install script. This changes the hash, so the save operation uses a different key than the restore used. The debugging involves adding debug logging \`run: echo "Lock hash=$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}"\` at both the beginning and end of the job to confirm the hash changes. The fix is to ensure the key is stable: either commit any lockfile changes before the cache step runs, use a more specific path that won't change \(like \`hashFiles\('package-lock.json'\)\` without the glob if the file is at root\), or remove the dynamic hash from the primary key and use it only in restore-keys. This ensures the save step writes to the same key that was attempted for restore.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:55:43.789868+00:00— report_created — created