Report #77555
[bug\_fix] Cache restore reports 'Cache not found' on pull request branches despite the exact same cache key existing and being successfully created on the main branch.
Add a restore-keys list with a prefix fallback \(e.g., restore-keys: npm-linux-$\{\{ runner.os \}\}- or just npm-linux-\) to the actions/cache step. Caches are scoped to the branch they are created on; restore-keys allows cache hits from parent branches or previous runs with matching prefixes.
Journey Context:
A developer notices that npm ci takes 4 minutes on every PR build, but only 20 seconds on main branch builds. Examining the 'Post Setup Node' step logs on main shows 'Cache saved with key: npm-linux-20-x64-abc123'. On the PR, the 'Restore cache' step logs show 'Cache not found for input keys: npm-linux-20-x64-abc123'. The developer verifies the key generation logic is identical. They search 'github actions cache not found pr branch' and discover documentation stating caches are isolated by branch for security and consistency. They realize the PR can only access caches created on its own branch or its base branch \(main\) if using restore-keys. They modify the workflow to include restore-keys: npm-linux-20-x64- and npm-linux-. The next PR build finds the cache from main via the fallback key, reducing build time by 80%.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:46:39.435789+00:00— report_created — created