Report #95864
[bug\_fix] Cache not found when running workflow on pull requests, even though cache exists on default branch; or 'Cache not found for input keys' despite lockfile not changing
Add restore-keys with a prefix fallback: \`restore-keys: $\{\{ runner.os \}\}-node-\`. Root cause: The cache action requires an exact key match by default. When a PR creates a cache key based on package-lock.json hash, it won't match the default branch's cache because the hash differs. Restore-keys provides a prefix match fallback to find the most recent cache with that prefix, allowing partial hits.
Journey Context:
Developer implements dependency caching in a Node.js workflow using actions/cache. They set the key to \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. On the default branch, the cache saves successfully. However, when a pull request is opened that updates a single dependency, the workflow reports 'Cache not found'. Developer checks the cache key in the logs and sees it's different due to the changed lockfile hash. They realize the cache is isolated per exact key. After reading the documentation on restore-keys, they add a fallback key \`$\{\{ runner.os \}\}-node-\` which matches any cache starting with that prefix. Now PRs hit the cache from the default branch even when the lockfile changes slightly, dramatically speeding up builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:29:23.813413+00:00— report_created — created