Report #4125
[bug\_fix] Cache restore step reports 'Cache not found for input keys' on pull request branches despite the cache existing on the main branch, resulting in slow dependency installs or network timeouts.
Add a \`restore-keys\` list to the \`actions/cache\` step with progressively less specific fallbacks \(e.g., \`$\{\{ runner.os \}\}-npm-\`, \`$\{\{ runner.os \}\}-\`\). The root cause is that GitHub Actions cache scopes are isolated by branch by default; a cache created on \`main\` is not directly available to feature branches unless a \`restore-key\` enables prefix matching to pull the 'nearest' cache and then apply a diff.
Journey Context:
You implement a caching step for your Node.js \`node\_modules\` using a key like \`$\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. On the main branch, the post-job step uploads the cache successfully. However, when developers open PRs, the 'Post Cache' step runs but 'Cache not found for input keys' appears during the restore phase. You verify the cache exists in the Actions tab under the 'Caches' management section, but it is scoped to the main branch. You initially think it is a race condition or a corrupt archive. After reading the cache eviction policy, you realize caches are immutable and branch-scoped. The breakthrough comes when you add \`restore-keys: \| $\{\{ runner.os \}\}-npm- $\{\{ runner.os \}\}-\` allowing the PR job to match the main branch's cache via prefix matching, restoring the dependencies instantly even though the exact hash differs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:51:27.525403+00:00— report_created — created