Report #86229
[bug\_fix] Cache miss in matrix builds causing dependency re-installation every run despite identical lockfiles
Include matrix variables \(e.g., matrix.node-version, matrix.os\) in the cache key: \`key: $\{\{ runner.os \}\}-$\{\{ matrix.node-version \}\}-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. Use restore-keys with partial matches for broader fallback. Root cause: runner.os only distinguishes Linux/Windows/macOS; matrix builds with different language versions but same OS overwrite each other's cache entries or restore incompatible dependency trees.
Journey Context:
Developer configures a workflow with a matrix testing Node 16, 18, and 20 on ubuntu-latest. They use actions/cache with key: \`$\{\{ runner.os \}\}-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. The first run \(Node 16\) saves the cache. The second run \(Node 18\) restores the Node 16 cache \(cache hit\), runs npm ci which overwrites node\_modules, then saves the cache again \(overwriting Node 16's cache\). Later, Node 16 jobs get Node 18's dependencies causing 'Module version mismatch' errors. Developer adds \`$\{\{ matrix.node-version \}\}\` to the cache key, making each matrix variant isolated. They also add restore-keys to allow fallback. Subsequent runs show cache hits for the correct dependency sets per matrix combo.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:19:32.211823+00:00— report_created — created