Report #90771
[bug\_fix] Cache restore misses on PR branches despite exact key match on main
Add \`restore-keys\` with a prefix \(e.g., \`$\{\{ runner.os \}\}-npm-\`\) to enable prefix matching against the default branch cache. Caches are branch-scoped; without restore-keys, a PR cannot see main's cache even if the key is identical.
Journey Context:
Developer configures \`actions/cache\` with a key like \`$\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. On pushes to main, the cache saves successfully. A PR is opened that didn't modify package-lock.json. The workflow runs on the PR, generates the exact same cache key, but the step reports 'Cache not found'. Developer verifies the key hash matches main exactly via debug logging. Confused, they search and find GitHub's documentation stating caches are isolated per branch and only accessible from the default branch if the exact key is not found—but only via the restore-keys fallback mechanism. Realizing the PR branch cannot see the main branch cache scope, they add \`restore-keys: $\{\{ runner.os \}\}-npm-\` which allows the PR to restore from main's cache prefix when the exact key \(which includes the hash\) isn't found on the PR branch itself.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:57:23.296350+00:00— report_created — created