[GH-ISSUE #1823] Cache restore-keys not matched in creation reverse order #886

Closed
opened 2026-03-01 21:47:10 +03:00 by kerem · 1 comment
Owner

Originally created by @vladum on GitHub (May 25, 2023).
Original GitHub issue: https://github.com/nektos/act/issues/1823

Bug report info

act version:            0.2.45
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 8
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	/var/run/docker.sock
Config files:           
	/home/vladum/.actrc:
		-P ubuntu-latest=catthehacker/ubuntu:act-latest
		-P ubuntu-22.04=catthehacker/ubuntu:act-22.04
		-P ubuntu-20.04=catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.19.3
	Module path:           github.com/nektos/act
	Main version:          v0.2.45
	Main path:             github.com/nektos/act
	Main checksum:         h1:I1yFTwBa5f2XOhsZFicj7W4cY40joNNrgah8mh0l7lg=
	Build settings:
		-compiler:            gc
		CGO_ENABLED:          1
		CGO_CFLAGS:           
		CGO_CPPFLAGS:         
		CGO_CXXFLAGS:         
		CGO_LDFLAGS:          
		GOARCH:               amd64
		GOOS:                 linux
		GOAMD64:              v1
Docker Engine:
	Engine version:        23.0.5
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         systemd
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    Ubuntu 22.04.2 LTS
	OS type:               linux
	OS version:            22.04
	OS arch:               x86_64
	OS kernel:             5.19.0-41-generic
	OS CPU:                8
	OS memory:             31763 MB
	Security options:
		name=apparmor
		name=seccomp,profile=builtin
		name=cgroupns

Command used with act

act push

Describe issue

First, thanks a lot for adding cache support! CC @wolfogre

Now, on the bug...

GitHub Actions cache docs says the following:

When a key doesn't match directly, the action searches for keys prefixed with the restore key. If there are multiple partial matches for a restore key, the action returns the most recently created cache.

I don't think this happens in act.

This behavior is important when implementing the cache update trick documented here. In summary, we want to restore the latest cache entry and write to a new one.

Side note: In the repro I posted, github.run_id is replaced by seconds since the epoch because run_id would be always 1 in act. This is not important for this bug, but it would be nice to get a unique run_id - maybe there's a way and I don't know it.

In the workflow I posted, the expectation is that file will keep getting dates appended to it every time the workflow is triggered. This happens on GitHub, but not on act.

Anyway, I think the fix is trivial: change findCache to SortBy("CreatedAt").Reverse() instead of the current SortBy("Key").

Happy to contribute if someone more familiar with the code confirms this is the right approach.

Thanks!

No response

Workflow content

on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: generate incrementing counter
        id: counter
        run: echo "value=$(date +%s)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v3
        with:
          key: test-${{ steps.counter.outputs.value }}
          path: file
          restore-keys: test-

      - name: read file loaded from cache
        run: cat file || true
  
      - name: append to file to be cached
        run: echo $(date) >> file

Relevant log output

n/a

Additional information

No response

Originally created by @vladum on GitHub (May 25, 2023). Original GitHub issue: https://github.com/nektos/act/issues/1823 ### Bug report info ```plain text act version: 0.2.45 GOOS: linux GOARCH: amd64 NumCPU: 8 Docker host: DOCKER_HOST environment variable is not set Sockets found: /var/run/docker.sock Config files: /home/vladum/.actrc: -P ubuntu-latest=catthehacker/ubuntu:act-latest -P ubuntu-22.04=catthehacker/ubuntu:act-22.04 -P ubuntu-20.04=catthehacker/ubuntu:act-20.04 -P ubuntu-18.04=catthehacker/ubuntu:act-18.04 Build info: Go version: go1.19.3 Module path: github.com/nektos/act Main version: v0.2.45 Main path: github.com/nektos/act Main checksum: h1:I1yFTwBa5f2XOhsZFicj7W4cY40joNNrgah8mh0l7lg= Build settings: -compiler: gc CGO_ENABLED: 1 CGO_CFLAGS: CGO_CPPFLAGS: CGO_CXXFLAGS: CGO_LDFLAGS: GOARCH: amd64 GOOS: linux GOAMD64: v1 Docker Engine: Engine version: 23.0.5 Engine runtime: runc Cgroup version: 2 Cgroup driver: systemd Storage driver: overlay2 Registry URI: https://index.docker.io/v1/ OS: Ubuntu 22.04.2 LTS OS type: linux OS version: 22.04 OS arch: x86_64 OS kernel: 5.19.0-41-generic OS CPU: 8 OS memory: 31763 MB Security options: name=apparmor name=seccomp,profile=builtin name=cgroupns ``` ### Command used with act ```sh act push ``` ### Describe issue First, thanks a lot for adding cache support! CC @wolfogre Now, on the bug... GitHub Actions cache [docs](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) says the following: > When a key doesn't match directly, the action searches for keys prefixed with the restore key. If there are multiple partial matches for a restore key, the action returns the most recently created cache. I don't think this happens in `act`. This behavior is important when implementing the cache update trick documented [here](https://github.com/actions/cache/blob/6a1a45d/tips-and-workarounds.md#update-a-cache). In summary, we want to restore the **latest** cache entry and write to a new one. Side note: In the repro I posted, `github.run_id` is replaced by seconds since the epoch because `run_id` would be always 1 in `act`. This is not important for this bug, but it would be nice to get a unique `run_id` - maybe there's a way and I don't know it. In the workflow I posted, the expectation is that `file` will keep getting dates appended to it every time the workflow is triggered. This happens on GitHub, but not on `act`. Anyway, I think the fix is trivial: change `findCache` to `SortBy("CreatedAt").Reverse()` instead of the current `SortBy("Key")`. Happy to contribute if someone more familiar with the code confirms this is the right approach. Thanks! ### Link to GitHub repository _No response_ ### Workflow content ```yml on: push jobs: test: runs-on: ubuntu-latest steps: - name: generate incrementing counter id: counter run: echo "value=$(date +%s)" >> $GITHUB_OUTPUT - uses: actions/cache@v3 with: key: test-${{ steps.counter.outputs.value }} path: file restore-keys: test- - name: read file loaded from cache run: cat file || true - name: append to file to be cached run: echo $(date) >> file ``` ### Relevant log output ```sh n/a ``` ### Additional information _No response_
kerem 2026-03-01 21:47:10 +03:00
Author
Owner

@github-actions[bot] commented on GitHub (Nov 22, 2023):

Issue is stale and will be closed in 14 days unless there is new activity

<!-- gh-comment-id:1821889533 --> @github-actions[bot] commented on GitHub (Nov 22, 2023): Issue is stale and will be closed in 14 days unless there is new activity
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#886
No description provided.