Report #11615
[bug\_fix] Cache not found despite successful cache save in previous workflow run on a different branch
Use \`restore-keys\` with a prefix fallback \(e.g., \`restore-keys: node-modules-\`\) to allow partial key matching, and ensure the initial cache population occurs on the default branch \(main/master\). Root cause: GitHub Actions caches are isolated by scope; caches saved from feature branches are not accessible from the default branch or other feature branches unless restored with an exact key match or a \`restore-keys\` prefix match. Caches from the default branch are accessible to feature branches, but not vice versa.
Journey Context:
You set up \`actions/cache\` in your workflow to cache \`node\_modules\` for a Node.js project. On your feature branch \`feat/new-ui\`, the workflow runs, the cache misses, it installs dependencies, and saves the cache successfully with key \`node-modules-feat/new-ui-abc123\`. You open a PR, but the next push on the same branch shows "Cache not found" even though it was just saved. You check the logs and see the key is slightly different due to \`hashFiles\('\*\*/package-lock.json'\)\` producing a different hash. You try adding \`restore-keys\` with just \`node-modules-\`, but it still doesn't find it when running on main after merge. You research GitHub's cache documentation and learn that caches created on feature branches are scoped to that branch and won't be available on main. You realize you need to first run the workflow on main to populate the "upstream" cache, which then becomes available to all branches. You also add a fallback restore-key \`node-modules-main-\` to handle the transition period. After merging the cache workflow to main and letting it run once, all feature branches can now restore from the main cache using the prefix fallback.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:46:59.814591+00:00— report_created — created