Skip to content

Cache Not Matching: One or more cache(s) with similar key but they have different version or scope #1376

Closed

Description

@rplankenhorn

Describe the bug
When using the @actions/cache package, I am unable to restore caches created using the exact same running on subsequent runs.

##[debug]No matching cache found for cache key 'javascript-Linux-X64-asdf-cache-v3-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb', version '8f2c4c9871d15fb24bd9c7ff48a327b81a4ae937f38daeb3e64228538586e821 and scope refs/heads/main. 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://github.com/proxy/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: javascript-Linux-X64-asdf-cache-v3-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb, Cache Version: 70108c5493886eef63e4ea83249a420f4e651fe696[22](https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4451018370/jobs/7817280641#step:3:23)5cdb3e6597dca83b6a5d, Cache Scope: refs/heads/main, Cache Created: 20[23](https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4451018370/jobs/7817280641#step:3:24)-03-17T19:47:06.9966667Z
##[debug]Failed to delete archive: Error: ENOENT: no such file or directory, unlink ''

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://github.com/rplankenhorn/github-actions-cache-issue
  2. Click on Actions, Javascript, Added JS Action
  3. Click Rerun All Jobs
  4. Observe error for both ubuntu-latest and macos-latest runners.

Expected behavior
Cache should be matched and restored.

Screenshots
Screenshot 2023-03-17 at 3 52 19 PM

Additional context
Note: Caching works as expected when using the published @action/save and @action/restore.

Activity

  1. added
    bug
    on Mar 17, 2023
  2. rplankenhorn commented on Mar 20, 2023

    @rplankenhorn
    Author

    When running:

    gh api \
      -H "Accept: application/vnd.github+json" \
      -H "X-GitHub-Api-Version: 2022-11-28" \
      /repos/rplankenhorn/github-actions-cache-issue/actions/caches
    

    Result:

    {
      "total_count": 2,
      "actions_caches": [
        {
          "id": 76,
          "ref": "refs/heads/main",
          "key": "javascript-macOS-X64-asdf-cache-v3-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb",
          "version": "1fbd10634ef18b69f961b73f6ee5ba707df92396ac0348130e3e6d2c4b4620b5",
          "last_accessed_at": "2023-03-17T19:47:25.433333300Z",
          "created_at": "2023-03-17T19:47:25.433333300Z",
          "size_in_bytes": 53634712
        },
        {
          "id": 75,
          "ref": "refs/heads/main",
          "key": "javascript-Linux-X64-asdf-cache-v3-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb",
          "version": "70108c5493886eef63e4ea83249a420f4e651fe696225cdb3e6597dca83b6a5d",
          "last_accessed_at": "2023-03-17T19:47:06.996666700Z",
          "created_at": "2023-03-17T19:47:06.996666700Z",
          "size_in_bytes": 55913760
        }
      ]
    }
    

    There seems to be some issue with the getCacheVersion function. From what I can tell, it seems to be giving different results when creating and restoring cache.

    Creating getCacheVersion: 70108c5493886eef63e4ea83249a420f4e651fe696225cdb3e6597dca83b6a5d
    Restoring getCacheVersion: 8f2c4c9871d15fb24bd9c7ff48a327b81a4ae937f38daeb3e64228538586e821

  3. MSP-Greg commented on Mar 21, 2023

    @MSP-Greg
    Contributor

    @rplankenhorn I think 'paths' need to match for a cache to be restored from a saved cache. The version is based on 'paths'.

    Quick look thru your code showed one is asdfCacheOptions.inputPaths, and the other is asdfCacheOptions.cachedPaths

  4. rplankenhorn commented on Mar 21, 2023

    @rplankenhorn
    Author

    @MSP-Greg Thanks for getting back to me and good catch. I made the changes here but the cache is still not matching. I completely deleted all the cache, recreated them, and then ran the job a third time to try and restore them: https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4480149929/jobs/7875080489

    ##[debug]Resource Url: https://github.com/proxy/artifactcache.actions.githubusercontent.com/MceA4re36QTIzQw93oLEwLlynmegnm6Wy6zMkqz54Pugm4WIPJ/_apis/artifactcache/cache?keys=javascript-Linux-X64-asdf-cache-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb&version=70108c5493886eef63e4ea83249a420f4e651fe696225cdb3e6597dca83b6a5d
    Cloning into '/home/runner/.asdf'...
    ##[debug]Resource Url: https://github.com/proxy/artifactcache.actions.githubusercontent.com/MceA4re36QTIzQw93oLEwLlynmegnm6Wy6zMkqz54Pugm4WIPJ/_apis/artifactcache/caches?key=javascript-Linux-X64-asdf-cache-ad0714eded685c1468e724c55d2e35a406f[19](https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4480149929/jobs/7875080489#step:3:20)927fb887e51f50439fb6ce03afb
    ##[debug]No matching cache found for cache key 'javascript-Linux-X64-asdf-cache-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb', version '70108c5493886eef63e4ea83249a4[20](https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4480149929/jobs/7875080489#step:3:21)f4e651fe696225cdb3e6597dca83b6a5d and scope refs/heads/main. 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://github.com/proxy/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: javascript-Linux-X64-asdf-cache-ad0714eded685c1468e724c55d2e35a406f19927fb887e51f50439fb6ce03afb, Cache Version: 2e300497d0ee7c7058a03dff2243903148a762c27b17b76a2d7d5c1782ee4e98, Cache Scope: refs/heads/main, Cache Created: 2023-03-[21](https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4480149929/jobs/7875080489#step:3:22)T14:21:29.39Z
    ##[debug]Failed to delete archive: Error: ENOENT: no such file or directory, unlink ''
    

    As you can see, still getting the same error. Here is the link to the full job: https://github.com/rplankenhorn/github-actions-cache-issue/actions/runs/4480149929/jobs/7875080489

  5. MSP-Greg commented on Mar 21, 2023

    @MSP-Greg
    Contributor

    Can you try changing:

    const cacheId = restoreCache(cachedPaths, primaryKey);

    to

    const cacheId = restoreCache(cachedPaths.slice(), primaryKey);
  6. rplankenhorn commented on Mar 21, 2023

    @rplankenhorn
    Author

    @MSP-Greg

    Edit: Actually, this might have more to do with Git and ASDF but will continue to investigate.

    Can you try changing:

    const cacheId = restoreCache(cachedPaths, primaryKey);

    to

    const cacheId = restoreCache(cachedPaths.slice(), primaryKey);

    Interesting. Now the cache is matching but I am getting a different error when trying to restore:

    2023-03-21T15:33:52.7419868Z Cache Size: ~52 MB (54141223 B)
    2023-03-21T15:33:52.7420558Z [command]/usr/bin/tar -xf /home/runner/work/_temp/1da62ce5-9f74-401b-b44c-425fcc0364e7/cache.tzst -P -C /home/runner/work/github-actions-cache-issue/github-actions-cache-issue --use-compress-program unzstd
    2023-03-21T15:33:53.2453299Z Cache restored successfully
    2023-03-21T15:33:53.4713288Z BUG: refs/files-backend.c:3040: initial ref transaction called with existing refs
    2023-03-21T15:33:53.8493218Z /home/runner/.asdf/lib/functions/plugins.bash: line 51:  1723 Aborted                 (core dumped) git clone -q "$source_url" "$plugin_path"
    2023-03-21T15:33:53.8550624Z webpack://asdf-action/./node_modules/@actions/exec/lib/toolrunner.js?:592
    2023-03-21T15:33:53.8551669Z                 error = new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`);
    2023-03-21T15:33:53.8552639Z                         ^
    2023-03-21T15:33:53.8553035Z 
    2023-03-21T15:33:53.8553560Z Error: The process '/home/runner/.asdf/bin/asdf' failed with exit code 1
    2023-03-21T15:33:53.8554367Z     at ExecState._setResult (webpack://asdf-action/./node_modules/@actions/exec/lib/toolrunner.js?:592:25)
    2023-03-21T15:33:53.8555408Z     at ExecState.CheckComplete (webpack://asdf-action/./node_modules/@actions/exec/lib/toolrunner.js?:575:18)
    2023-03-21T15:33:53.8556254Z     at ChildProcess.eval (webpack://asdf-action/./node_modules/@actions/exec/lib/toolrunner.js?:469:27)
    2023-03-21T15:33:53.8556813Z     at ChildProcess.emit (node:events:527:28)
    2023-03-21T15:33:53.8557224Z     at maybeClose (node:internal/child_process:1092:16)
    2023-03-21T15:33:53.8557743Z     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
    2023-03-21T15:33:53.8633196Z ##[debug]Node Action run completed with exit code 1
    2023-03-21T15:33:53.8648154Z ##[debug]ASDF_DIR='/home/runner/.asdf'
    2023-03-21T15:33:53.8648722Z ##[debug]ASDF_DATA_DIR='/home/runner/.asdf'
    2023-03-21T15:33:53.8653869Z ##[debug]Finishing: Run /./.github/actions/asdf-action
    
  7. rplankenhorn commented on Mar 21, 2023

    @rplankenhorn
    Author

    @MSP-Greg I was able to resolve the above error and now cache is restoring properly. So passing in a shallow copy of the array rather than the array itself is what fixed the issue? Should the restore/save functions be updated to automatically handle this for the user?

  8. MSP-Greg commented on Mar 21, 2023

    @MSP-Greg
    Contributor

    So passing in a shallow copy of the array rather than the array itself is what fixed the issue?

    Yes. It should be an array of strings, so I think slice() works for all cases.

    Should the restore/save functions be updated to automatically handle this for the user?

    See PR #1378

  9. rplankenhorn commented on Mar 21, 2023

    @rplankenhorn
    Author

    Duplicate of #1377

  10. added a commit that references this issue on Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions