Report #48736
[bug\_fix] Cache restore misses or restores wrong cache due to restore-keys prefix ordering
Structure restore-keys with most specific fallback first, ending with the broadest prefix. The primary key should be exact; restore-keys should list prefixes from specific to generic without the full exact key.
Journey Context:
Developer configures caching for npm dependencies using \`actions/cache\`. They set the key to \`$\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`. They add restore-keys as \`$\{\{ runner.os \}\}-node-\` expecting a partial match if the lockfile changes. The first run populates the cache. A dependency is updated, changing package-lock.json. The next run generates a new primary key, finds no exact match, but fails to hit the restore-keys fallback despite the \`$\{\{ runner.os \}\}-node-\` prefix existing. The developer enables step debugging and sees the restore-keys are evaluated but no hit occurs. They search the cache documentation and discover that restore-keys matches prefixes, but the cache action searches for keys that START WITH the restore-key value. However, if they accidentally included the full hash in the restore-key \(making it too specific\), or if the restore-keys list is ordered with the most generic first, it might match an old generic cache instead of a recent semi-specific one. The actual fix is ensuring the restore-keys list is ordered from most specific fallback to least specific, and ensuring the primary key changes when dependencies change. They reorder restore-keys to be \`$\{\{ runner.os \}\}-node-\` and ensure no more specific partial keys are missing, and the cache hit works correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T12:17:11.541553+00:00— report_created — created