Report #8332
[bug\_fix] Cache restored but dependencies missing \(poisoned or stale cache\)
Include a hash of the lockfile \(e.g., \`hashFiles\('\*\*/package-lock.json'\)\`\) in the primary cache key. Use \`restore-keys\` with a prefix \(e.g., \`npm-$\{\{ runner.os \}\}-\`\) for partial fallback that allows cache updates, ensuring dependency changes invalidate stale caches.
Journey Context:
A Node.js workflow uses \`actions/cache\` with a static key \`key: node-modules-$\{\{ runner.os \}\}\` to cache \`node\_modules\`. Initially, builds are fast. After merging a feature branch that adds the \`axios\` package, the main branch builds start failing with "Cannot find module 'axios'" despite \`npm ci\` running successfully. Examining the cache step shows "Cache restored successfully" from key \`node\_modules-Linux\`. The developer realizes that the cache key did not change when \`package-lock.json\` changed, so it restored the old \`node\_modules\` without \`axios\`. Because \`npm ci\` sees \`node\_modules\` exists and is complete \(due to the restored cache\), it skips installation. The fix requires adding \`$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` to the cache key so any dependency change invalidates the old cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:14:27.372102+00:00— report_created — created