Skip to content

Cache-host probe logs a failed cache reservation on every run once the entry is seeded #681

Closed

Description

@arcaven

Every Harden-Runner run with egress-policy: block logs a cache reservation failure that is not a failure, so users of the action learn to skim past its output. The cause looks small: the pre-step seeds a cache entry that, by design, can only be seeded once.

Expected: after the first seed, the cache-host probe finds an existing entry, so the steady state should not surface as a failure.

Actual: every run logs

Failed to save: Unable to reserve cache with key harden-runner-cacheKey, another job may be creating this cache.
-1

then continues correctly:

cache version: v2
Adding cacheHost: productionresultssa19.blob.core.windows.net:443 to allowed-endpoints

No second job is involved. I sampled five runs of a single-job workflow over three days, including a scheduled run that was the only job in flight in the repository. All five show both lines, and none degraded to audit.

Measurement. On one run the reservation failed at 17:35:36.4472726Z, and the cache API recorded lastAccessedAt = 17:35:36.470978Z on a harden-runner-cacheKey entry created a month earlier on refs/heads/main. The hostname was added at 17:35:36.4777572Z. The write was rejected and the read was served from that same pre-existing entry, 116 ms apart.

Mechanism. The pre-step calls saveCache unconditionally, then reads the blob hostname back from GetCacheEntryDownloadURL. The key is a constant and the cache version hashes the paths, which include the pinned action SHA, so one entry exists per ref scope per action version. Once seeded, CreateCacheEntry returns not-ok for that pair on every later run, and @actions/cache reports any not-ok reservation with its concurrency-flavored string plus a -1 return. The missing More details: suffix places the throw at the saveCacheV2 site rather than the policy-denial arm, so this reads as an ordinary "entry already exists".

Relevant paths: src/cache.ts (cacheKey), src/setup.ts (the saveCache call and the v2 branch), and packages/cache/src/cache.ts in actions/toolkit for the message text.

Could the pre-step resolve the download URL first and seed only when that lookup comes back empty? That would leave a real cache problem visible instead of buried.

Distinct from #675, which covers the fail-open when the lookup itself throws. Happy to follow up with a PR.

Pre-step log and cache metadata

Pre-step log, with the repository name and runner identifiers redacted:

[harden-runner] pre-step
[command]/usr/bin/tar --posix -cf cache.tgz --exclude cache.tgz -P -C /__w/<repo>/<repo> --files-from manifest.txt -z
Failed to save: Unable to reserve cache with key harden-runner-cacheKey, another job may be creating this cache.
-1
cache version: v2
cacheFilePath /__w/_actions/step-security/harden-runner/6c3c2f2c1c457b00c10c4848d6f5491db3b629df/dist/pre/cache.txt
Adding cacheHost: productionresultssa19.blob.core.windows.net:443 to allowed-endpoints
This job is running on a self-hosted runner.
[harden-runner] sendAllowedEndpoints completed in 54ms (sent 23 endpoints)

The matching cache entry, from gh cache list:

harden-runner-cacheKey  refs/heads/main  created=2026-07-10T10:52:45.579049Z  accessed=2026-08-08T17:35:36.470978Z  bytes=286

Version: harden-runner v2.18.0, pinned at 6c3c2f2c1c457b00c10c4848d6f5491db3b629df. Self-hosted ARC runners, container job, egress-policy: block with an explicit allowed-endpoints list.

Activity

  1. varunsh-coder commented on Aug 15, 2026

    @varunsh-coder
    Member

    This is fixed in v2.21.0.

    The pre-step now resolves the cache host read-first: it looks up the existing harden-runner-cacheKey entry before attempting any save, exactly as you suggested. In the steady state there is no save attempt at all, so the "Unable to reserve cache" line is gone from every run after the first. saveCache runs only when the lookup finds no entry (first run in a cache scope, or after eviction), followed by a second lookup that also covers losing the seeding race to a concurrent job.

    This same restructure closes the fail-open window you flagged in your follow-up comment on #675: a failed resolution no longer changes the egress policy under any circumstances.

    Thanks for the careful measurement, the 116 ms write-reject/read-hit trace made the mechanism unambiguous.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions