Report #9854
[bug\_fix] Cache not found on feature branches despite existing cache on main branch
Add a \`restore-keys\` fallback list to the cache action. Use \`key: $\{\{ runner.os \}\}-npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` and \`restore-keys: $\{\{ runner.os \}\}-npm-\`. This allows feature branches to restore the cache from the base branch using prefix matching when an exact match doesn't exist.
Journey Context:
A team notices that CI on the \`main\` branch completes in 90 seconds due to \`actions/cache\` hitting on \`node\_modules\`. However, every PR branch takes 6\+ minutes running \`npm ci\` from scratch. The developer inspects the cache step logs on a PR and sees "Cache not found for input keys: linux-npm-a1b2c3d...". They check the main branch and see the cache key is \`linux-npm-x9y8z7w...\`. They realize the hash differs because the package-lock.json changed on the PR. They initially think they need to push the lock file to main to populate the cache, but that defeats the purpose. Searching the documentation, they discover the \`restore-keys\` parameter. By adding \`restore-keys: $\{\{ runner.os \}\}-npm-\`, the cache action performs a prefix search. The feature branch fails to find the exact hash match, but successfully restores the \`linux-npm-\` prefix cache from main, falling back to the closest match. The subsequent \`npm ci\` only needs to fetch delta changes, reducing the build time to 2 minutes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:15:34.601725+00:00— report_created — created