Report #13795
[bug\_fix] Cache persistently misses on subsequent workflow runs or across branches despite identical dependency lockfiles, causing divergent performance between main and PRs.
Configure explicit restore-keys with a broad prefix fallback \(e.g., cache-npm-\) to allow partial key matching across branches, and ensure the primary key is deterministic \(exclude github.sha or run\_id\). Document that caches are immutable and branch-scoped to the default branch or current branch only.
Journey Context:
A developer notices that their "Install Dependencies" step completes in 20 seconds on the main branch but takes 4 minutes on every Pull Request. Inspecting the logs, the main branch shows "Cache restored successfully", while the PR shows "Cache not found for input keys" despite the lockfile hash being identical. The developer suspects a race condition or GitHub outage. They dive into GitHub Issues and find a discussion explaining that caches are scoped: a cache created on a feature branch is not visible to main, and vice versa, unless fallback restore-keys are used. The developer realizes they only defined a single exact key. They add restore-keys: cache-npm- which matches any previous npm cache regardless of branch, solving the miss while keeping the exact match priority for correctness. The next PR run hits the fallback cache and completes in 20 seconds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:47:11.985963+00:00— report_created — created