Skip to content
Latchkey

actions/cache not saved when the job is cancelled or fails early in CI

actions/cache saves in its post-job step, which runs only if the job completes its main steps. If the build step fails or the job is cancelled before then, the post step is skipped and no cache is stored, so the next run is a cold miss and the cycle repeats.

What this error means

Every run logs "Cache not found for input keys" and no run logs "Cache saved with key", because the job consistently fails (or is cancelled) before the cache post step executes.

actions/cache
Cache not found for input keys: deps-Linux-abc123
# ...build step fails...
# post step for actions/cache is skipped, nothing saved
# next run: Cache not found for input keys: deps-Linux-abc123 (again)

Common causes

The job fails before the cache post step

A failing test or build after the dependencies are installed stops the job, so the post-save never runs and the populated cache is discarded.

Concurrency cancels the run mid-flight

A concurrency group that cancels in-progress runs can stop a job before its cache is saved.

How to fix it

Save the cache as soon as dependencies are ready

Split restore and save: use actions/cache/restore early, then actions/cache/save right after install so the cache persists even if later steps fail.

.github/workflows/ci.yml
- uses: actions/cache/restore@v4
  id: restore
  with: { path: ~/.npm, key: npm-${{ hashFiles('**/package-lock.json') }} }
- run: npm ci
- uses: actions/cache/save@v4
  if: always() && steps.restore.outputs.cache-hit != 'true'
  with: { path: ~/.npm, key: npm-${{ hashFiles('**/package-lock.json') }} }

Make sure the install step succeeds first

  1. Confirm at least one run completes installation so a cache can be saved.
  2. Move the save before the steps that tend to fail.
  3. Verify a run logs "Cache saved with key" before relying on hits.

How to prevent it

  • Split restore/save so the cache stores before fragile steps.
  • Ensure one green run saves the cache initially.
  • Watch for concurrency cancellations that skip the save.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →