Report #22790
[bug\_fix] Cache key returns 0 matches \(cache miss\) on feature branches despite identical cache existing on main branch
Use the \`restore-keys\` input in \`actions/cache\` to provide a prefix fallback \(e.g., \`restore-keys: $\{\{ runner.os \}\}-npm-\`\), or use \`actions/setup-node\` \(or similar setup actions\) which handle the fallback logic automatically via their \`cache\` input.
Journey Context:
Your team has a Node.js project. On the \`main\` branch, your workflow installs dependencies and saves them to a cache with the key \`$\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('package-lock.json'\) \}\}\`. The save succeeds. You create a feature branch \`feat/new-ui\`, push it, and the workflow runs. The 'Restore cache' step reports 'Cache not found for input keys: linux-npm-abc123...'. You check the Actions tab for the main branch—the cache is definitely there with the same hash. You search the error and find GitHub documentation explaining cache isolation. You realize that while caches from the default branch are accessible to feature branches, the 'exact key' lookup in \`actions/cache\` is scoped such that a feature branch cannot see the main branch's cache key directly unless using \`restore-keys\`. You add \`restore-keys: $\{\{ runner.os \}\}-npm-\` to your cache action configuration. The next run on the feature branch finds the main branch's cache via the prefix match, restores the node\_modules, and skips the npm install, cutting the build time from 4 minutes to 30 seconds. The fix works because \`restore-keys\` performs a prefix search across the repository's accessible cache scopes, whereas the primary key requires an exact match that is isolated per-branch for writes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:39:59.151077+00:00— report_created — created