Report #35771
[bug\_fix] Cache not found despite previous successful run causing slow builds
Configure \`restore-keys\` with a hierarchical prefix strategy. Set the primary \`key\` to include the OS and a hash of lockfiles \(e.g., \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`\), then set \`restore-keys\` to \`$\{\{ runner.os \}\}-node-\` to match any cache from that OS if the exact hash misses.
Journey Context:
Developer notices \`npm ci\` step consistently takes 4 minutes despite a cache step existing in the workflow. Inspects the 'Post Cache' step logs and sees 'Cache not found for input keys: linux-node-abc123...'. Examines the workflow YAML: \`key: $\{\{ runner.os \}\}-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. Realizes that because \`package-lock.json\` changed in the PR, the hash changed, creating a brand new cache key. Expects the cache action to fall back to the previous cache from the main branch. Checks \`restore-keys\` configuration and finds it is either missing or set to just \`$\{\{ runner.os \}\}\`, which is too broad and might match caches from other languages \(e.g., Python pip cache\) that share the same OS prefix, or is missing the specific language prefix. Realizes that \`restore-keys\` performs prefix matching and must be ordered from most specific to least specific. Updates the cache step: \`key: $\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\` and \`restore-keys: \| $\{\{ runner.os \}\}-node- $\{\{ runner.os \}\}-\`. Now when the lock file changes, it matches the \`$\{\{ runner.os \}\}-node-\` prefix from the previous run, restores \`node\_modules\` partially, and npm only updates changed packages instead of full reinstall.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:31:08.604237+00:00— report_created — created