Report #82319
[bug\_fix] Cache always misses and dependencies rebuild every run despite successful cache-save in previous run
Remove dynamic values \(like $\{\{ github.sha \}\} or $\{\{ github.run\_id \}\}\) from the primary cache 'key'. Use a stable key based on lockfile hashes \(e.g., 'npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}'\) and use 'restore-keys' with a prefix \(e.g., 'npm-'\) to enable partial matching. Root cause: Cache keys are immutable; if the key changes every run, the lookup fails because the key must match exactly for a hit.
Journey Context:
Developer notices that their 'Cache node\_modules' step shows 'Cache not found' on every run, adding 4 minutes to the build. They inspect the workflow and see the key is defined as 'key: $\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}-$\{\{ github.sha \}\}'. They check the previous successful run and see the cache was saved with key '...-abc123', but the new run looks for '...-def456'. They realize the SHA makes the key unique per commit. They remove '-$\{\{ github.sha \}\}' from the key and add 'restore-keys: $\{\{ runner.os \}\}-node-' so that even if the lock file changes \(and primary key misses\), it can restore from an older cache and only download delta changes. The next run shows 'Cache restored from key ...'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:46:08.708133+00:00— report_created — created