Report #96275
[bug\_fix] Cache not found for input keys across branches
The actions/cache action restricts cache hits to the current branch and the default branch \(usually main or master\). If you include $\{\{ github.ref \}\}, $\{\{ github.sha \}\}, or branch names in the cache key, you create keys that only exist for that specific branch/commit. Remove branch-specific components from the primary key; use a stable key like os-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}. To enable cross-branch hits, use restore-keys with a prefix like os- that can match caches from other branches. Root cause: Cache isolation by branch for security and consistency.
Journey Context:
Your CI workflow installs Node dependencies and caches node\_modules using actions/cache. On the main branch, it restores from cache in 10 seconds. You create a feature branch, push, and the same step takes 3 minutes because it says Cache not found for input keys: Linux-node-refs/heads/feature-branch-xyz. You check the cache key in the main branch logs: Linux-node-refs/heads/main. You realize you used key: $\{\{ runner.os \}\}-node-$\{\{ github.ref \}\} thinking it would help separate caches per branch. You check the GitHub Actions cache documentation and see the note about cache isolation: caches are already scoped to branches, meaning a cache created on a feature branch is not accessible from main unless explicitly configured via restore-keys. You understand that including the branch name in the key creates redundant isolation and prevents cross-branch hits. You remove $\{\{ github.ref \}\} from the key, using only $\{\{ runner.os \}\}-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}, and add restore-keys: $\{\{ runner.os \}\}- to allow falling back to any OS-matching cache from other branches. Now your feature branch immediately hits the cache created by main.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:10:48.579498+00:00— report_created — created