Report #45416
[bug\_fix] Cache not found or cache key mismatch across branches or workflow runs
Add a \`restore-keys\` fallback list to the cache action, using increasingly broad keys \(e.g., \`npm-$\{\{ runner.os \}\}-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` then \`npm-$\{\{ runner.os \}\}-\`\). Ensure the cache is saved on the default branch \(e.g., \`main\`\) so that PRs can inherit it via the fallback keys, as caches are scoped by branch with read-only access to the base branch cache.
Journey Context:
A developer configures caching for \`npm\` using \`actions/cache\` with a key like \`npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. They notice that while the cache saves successfully on the \`main\` branch, pull requests consistently show 'Cache not found'. They suspect a hash mismatch and add debug logging to print the hash, confirming it's identical. After checking the cache action documentation, they realize that caches are branch-scoped; a PR cannot access a cache saved on its own head branch \(which is ephemeral\), and while it can read from the base branch \(\`main\`\), the key must match exactly OR they must use \`restore-keys\`. They add \`restore-keys: \| npm-$\{\{ runner.os \}\}-\` allowing the PR to restore the \`main\` branch cache even if the lockfile changed slightly. The next PR build restores the cache instantly, only updating the delta.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:42:12.761761+00:00— report_created — created