Report #99185
[bug\_fix] actions/cache reports 'Cache not found for input keys' on feature branches even though the lockfile has not changed, causing dependency installation to run from scratch on every pull request
Keep a precise \`key\` based on the lockfile hash, but add \`restore-keys\` with progressively less specific prefixes so a new branch can fall back to a cache created on the default branch. For example: \`key: npm-$\{\{ runner.os \}\}-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` with \`restore-keys: \| npm-$\{\{ runner.os \}\}- npm-\`.
Journey Context:
Your Node build installs dependencies on every push even though \`package-lock.json\` rarely changes. You add \`actions/cache@v4\` with \`key: npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` but no \`restore-keys\`. On \`main\` the first run saves the cache. On a feature branch the next run logs 'Cache not found for input keys' and reinstalls everything. You read the cache docs and learn that caches are scoped: a workflow run can restore caches created in the current branch or the default branch, but a brand new branch has no cache of its own, and an exact-key miss produces no restore without fallback keys. You add \`restore-keys\` with prefixes like \`npm-$\{\{ runner.os \}\}-\` and \`npm-\`. Now when the exact key misses, the action returns the most recent cache whose key starts with one of those prefixes, often created on \`main\`, and only newly changed dependencies are fetched. The fix works because \`restore-keys\` performs prefix matching against both current-branch and default-branch caches, bridging the cold-start gap without requiring an exact key hit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:42:57.759700+00:00— report_created — created