actions / actions/cache

restore-keys not being tried when another other exact key has different scope

Open
#1,446 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.6k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

In the workflow below, I try to look up the exact key, and if it fails, I want it to look up the partial key as described in restore-keys.

However, it seems like if there are similar EXACT key matches, but with different version and/or scope, it doesn't even try restore-keys.

Actual result

Here below the lines that show that the partial key venv-Linux-avatar-python- wasn't being tried at all.

##[debug]No matching cache found for cache key 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0', version 'a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da and scope refs/heads/tc/api/retry-email-sending. There exist one or more cache(s) with similar key but they have different version or scope. See more info on cache matching here: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key 
##[debug]Other caches with similar key:
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2923/merge, Cache Created: 2024-08-08T09:18:03.8933333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2924/merge, Cache Created: 2024-08-08T09:01:03.0433333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2917/merge, Cache Created: 2024-08-07T15:42:32.2633333Z

Expected result

I expected the cache to try the following caches on the default-branch (main) due to the venv-Linux-avatar-python- restore-keys :

  • venv-Linux-avatar-python-b3cc8e9136fb1220e68d1e090bec21ef1ff5e989b1dd8ce4a4ad419ab0472643
  • venv-Linux-avatar-python-16ef110bc5029f7410029d94501801d0b277cbb6e2d6122d5fe9a4df54c53cd9

See images below.

Workflow

- name: Load cached avatar-python dependencies
  id: cached-avatar-python-dependencies
  uses: actions/cache@v4
  with:
    path: ${{ github.workspace }}/client/build/avatar-python/.venv
    key: venv-${{ runner.os }}-avatar-python-${{ hashFiles('**/client/build/avatar-python/**/poetry.lock') }}
    restore-keys: |
      venv-${{ runner.os }}-avatar-python-
Full debug logs
##[debug]Evaluating condition for step: 'Load cached avatar-python dependencies'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Load cached avatar-python dependencies
##[debug]Register post job cleanup for action: actions/cache@v4
##[debug]Loading inputs
##[debug]Evaluating: format('{0}/client/build/avatar-python/.venv', github.workspace)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> '{0}/client/build/avatar-python/.venv'
##[debug]..Evaluating Index:
##[debug]....Evaluating github:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'workspace'
##[debug]..=> '/home/runner/work/avatar/avatar'
##[debug]=> '/home/runner/work/avatar/avatar/client/build/avatar-python/.venv'
##[debug]Result: '/home/runner/work/avatar/avatar/client/build/avatar-python/.venv'
##[debug]Evaluating: format('venv-{0}-avatar-python-{1}', runner.os, hashFiles('**/client/build/avatar-python/**/poetry.lock'))
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'venv-{0}-avatar-python-{1}'
##[debug]..Evaluating Index:
##[debug]....Evaluating runner:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'os'
##[debug]..=> 'Linux'
##[debug]..Evaluating hashFiles:
##[debug]....Evaluating String:
##[debug]....=> '**/client/build/avatar-python/**/poetry.lock'
##[debug]Search root directory: '/home/runner/work/avatar/avatar'
##[debug]Search pattern: '**/client/build/avatar-python/**/poetry.lock'
##[debug]Starting process:
##[debug]  File name: '/home/runner/runners/2.317.0/externals/node16/bin/node'
##[debug]  Arguments: '"/home/runner/runners/2.317.0/bin/hashFiles"'
##[debug]  Working directory: '/home/runner/work/avatar/avatar'
##[debug]  Require exit code zero: 'False'
##[debug]  Encoding web name:  ; code page: ''
##[debug]  Force kill process on cancellation: 'False'
##[debug]  Redirected STDIN: 'False'
##[debug]  Persist current code page: 'False'
##[debug]  Keep redirected STDIN open: 'False'
##[debug]  High priority process: 'False'
##[debug]Updated oom_score_adj to 500 for PID: 7751.
##[debug]Process started with process id 7751, waiting for process exit.
##[debug]Match Pattern: **/client/build/avatar-python/**/poetry.lock
##[debug]::debug::followSymbolicLinks 'false'
##[debug]::debug::followSymbolicLinks 'false'
##[debug]::debug::implicitDescendants 'true'
##[debug]::debug::matchDirectories 'true'
##[debug]::debug::omitBrokenSymbolicLinks 'true'
##[debug]::debug::Search path '/home/runner/work/avatar/avatar'
##[debug]/home/runner/work/avatar/avatar/client/build/avatar-python/poetry.lock
##[debug]Found 1 files to hash.
##[debug]undefined
##[debug]Hash result: '4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]STDOUT/STDERR stream read finished.
##[debug]STDOUT/STDERR stream read finished.
##[debug]Finished process 7751 with exit code 0, and elapsed time 00:00:05.2137956.
##[debug]..=> '4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]=> 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]Result: 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]Evaluating: format('venv-{0}-avatar-python-
##[debug]', runner.os)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'venv-{0}-avatar-python-
##[debug]'
##[debug]..Evaluating Index:
##[debug]....Evaluating runner:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'os'
##[debug]..=> 'Linux'
##[debug]=> 'venv-Linux-avatar-python-
##[debug]'
##[debug]Result: 'venv-Linux-avatar-python-
##[debug]'
##[debug]Loading env
Run actions/cache@v4
##[debug]Resolved Keys:
##[debug]["venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0","venv-Linux-avatar-python-"]
##[debug]Checking zstd --quiet --version
##[debug]1.5.6
##[debug]zstd version: 1.5.6
##[debug]Resource Url: https://acghubeus1.actions.githubusercontent.com/bUitQ9Jf0UgHNT3iYVD4ZwKmf3J9DOVKcZ3NeM7CroU4VrM2tP/_apis/artifactcache/cache?keys=venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0%2Cvenv-Linux-avatar-python-&version=a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da
##[debug]Resource Url: https://acghubeus1.actions.githubusercontent.com/bUitQ9Jf0UgHNT3iYVD4ZwKmf3J9DOVKcZ3NeM7CroU4VrM2tP/_apis/artifactcache/caches?key=venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0
##[debug]No matching cache found for cache key 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0', version 'a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da and scope refs/heads/tc/api/retry-email-sending. There exist one or more cache(s) with similar key but they have different version or scope. See more info on cache matching here: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key 
##[debug]Other caches with similar key:
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2923/merge, Cache Created: 2024-08-08T09:18:03.8933333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2924/merge, Cache Created: 2024-08-08T09:01:03.0433333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2917/merge, Cache Created: 2024-08-07T15:42:32.2633333Z
##[debug]Failed to delete archive: Error: ENOENT: no such file or directory, unlink ''
Cache not found for input keys: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, venv-Linux-avatar-python-
##[debug]Node Action run completed with exit code 0
##[debug]Save intra-action state CACHE_KEY = venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0
##[debug]Finishing: Load cached avatar-python dependencies

Caches

image
image
image
image
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the actions/cache@v4 implementation that resolves the exact key and restore-keys, then trace the cache request and scope information shown in the debug logs. Compare the documented cache-matching behavior with the reported request sequence; done means a matching restore-key cache is attempted after an exact-key miss, with tests covering differing scopes or versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, typescript
Domain
ci-cd
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.