Report #17926
[bug\_fix] Cache restore fails in pull request builds despite successful cache save on the default branch \(cache scope isolation\)
Ensure the cache key saved on the default branch matches the key expected in the PR, and add a \`restore-keys\` fallback list that includes a prefix key \(e.g., \`os-$\{\{ runner.os \}\}-\`\) to match caches from the default branch when an exact match isn't found. The root cause is that GitHub Actions caches are isolated by branch scope; a cache created on a feature branch is not accessible to other feature branches, and while pull requests can access the base branch's cache, they cannot access caches from other PRs or the head branch unless an exact key matches or a restore-key prefix matches a base branch cache.
Journey Context:
A developer sets up \`actions/cache\` for Node.js \`node\_modules\`, using a key like \`npm-$\{\{ hashFiles\('package-lock.json'\) \}\}\`. They push to \`main\`, the job runs, and the post-step saves the cache successfully. They create a feature branch, modify \`package.json\`, and open a PR. The workflow runs but reports "Cache not found". The developer inspects the key and sees \`npm-\` in the PR and \`npm-\` on main. They assume the cache should fall back to the main branch's cache, but it doesn't. They read the GitHub docs on "Cache scope" and learn that without \`restore-keys\`, only exact matches are sought. They add \`restore-keys: \| npm-$\{\{ runner.os \}\}- npm-\` which allows the PR job to restore the \`node\_modules\` from the main branch cache \(saving time\) and then save a new cache specific to its own lockfile hash for future runs on that branch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:47:47.131673+00:00— report_created — created