---
title: "A cache restore key brought back an old build's output | Proofline"
description: "When the exact key misses, actions/cache can restore a cache whose key matches a restore-keys prefix, searching the run's own branch before the default branch."
url: https://proofline.sh/learn/actions-cache-restore-keys-stale-output/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# A cache restore key brought back an old build's output

When the exact key misses, actions/cache can restore a cache whose key matches a restore-keys prefix, searching the run's own branch before the default branch. If the cached path holds build output, the next build starts on another commit's files, and a build that does not clean its output directory leaves the stale ones in place. Cache inputs such as downloaded packages, not the outputs you ship. When a cache is restored before the build, find which key it restored before you trust the artifact.

Code review The Proofline team December 2, 2026 3 min read

## How a partial match restores

The `restore-keys` input lists "prefix-matched keys, that are used for restoring stale cache if no cache hit occurred for key". [actions/cache](https://github.com/actions/cache#inputs) GitHub's reference adds that the action tries the exact key, then prefixes, on the run's branch first and then on the default branch, that when several caches match a prefix, "the action returns the most recently created cache", and that a run can restore caches from its own branch, the default branch and, for a pull request, the base branch. [Dependency caching reference](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching)

The `cache-hit` output is `true` only for an exact match. It is `false` when a restore key matched and empty when nothing was restored. [actions/cache outputs](https://github.com/actions/cache#outputs) The step log names the key it used, in a line that starts `Cache restored from key:` [in the action's source](https://github.com/actions/cache/blob/main/src/restoreImpl.ts). The separate `actions/cache/restore` action also returns it as the `cache-matched-key` output. [actions/cache/restore](https://github.com/actions/cache/tree/main/restore#outputs) A step guarded by `if: steps.cache.outputs.cache-hit != 'true'` therefore runs after a partial match, and it runs on top of the restored files.

## Fixture: a deleted module that stayed in dist/

This fixture simulates the restore with a tarball, because the restore is only a file extraction. TypeScript 5.9.3 on Node 24.22.3. Commit A has `src/price.ts` and `src/legacy-discount.ts`, and its `dist/` is saved under `build-linux-<hash A>`. Commit B deletes the legacy module. Its exact key misses, the prefix `build-linux-` matches A, and the build runs:

```
# key build-linux-<hash B> misses; restore-keys build-linux- matches A: cache-hit=false
$ npx tsc && ls dist
legacy-discount.js
price.js
$ rm -rf dist && npx tsc && ls dist
price.js
```

The compiler wrote `price.js` and did not remove `legacy-discount.js`, so an artifact made from `dist/` would contain code that no longer exists at commit B. The build exited 0 both times. Any packaging step that globs `dist/**`, and any server that loads every file in a directory, would pick it up.

## Decide what goes in the cache

| Path | Safe to restore from another commit? | Why |
| --- | --- | --- |
| Package manager download cache (`~/.npm`, `~/.cache/pip`, Go module cache) | Yes, when installs are pinned by a lockfile | The installer installs what the lockfile names; without pins, a cached package can be chosen over a newer download |
| Compiler caches keyed by their own inputs (`GOCACHE`, `sccache`) | Yes, with care | The tool looks each entry up by a hash of its inputs; see [go test's cached results](/learn/go-test-cached-result/) for what it cannot validate |
| `node_modules` | Only with an exact key | A partial restore holds another lockfile's tree. [`npm ci`](https://docs.npmjs.com/cli/v11/commands/npm-ci) removes it first; `npm install` builds on it |
| `dist/`, `build/`, `target/release` binaries you ship | No | Nothing checks that the files came from this commit |

Cache the download directory, where a partial match only saves time, and build into a clean output directory. If an output cache is worth its time, give it an exact key built from every input and no `restore-keys`.

```
- uses: actions/cache@v6
  with:
    path: ~/.npm
    key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
    restore-keys: npm-${{ runner.os }}-
- run: rm -rf dist && npm ci && npm run build
  shell: bash
```

## What else leaves the same trace

A file in the artifact with no source at the commit has other causes: a build step that copies a whole directory, a self-hosted runner whose checkout set `clean: false`, or a generator that is out of date. The restored key in the log, the checkout's inputs and a fresh run of the generator tell them apart. Compare the artifact's file list with a clean build of the same commit. A file only the artifact has came from somewhere else; a file both have can still differ in content, so compare checksums too.

To pass a build between jobs, use an artifact from the same run instead of a cache; see [an artifact from another run](/learn/artifact-from-another-run/). For build caching in Docker, see [a cached layer that kept an old download](/learn/docker-build-cache-stale-layer/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Your job downloaded an artifact from another run. Which commit built it?](/learn/artifact-from-another-run/)
    
    Deployment failures The Proofline team December 2, 2026 3 min read
    
-   ### [The Docker build said CACHED, and the image kept last week's download](/learn/docker-build-cache-stale-layer/)
    
    Code review The Proofline team December 2, 2026 3 min read
