Repository navigation
Overlay-base cache restore misses on cache backends that only prefix-match restoreKeys #4202
Description
Summary
downloadOverlayBaseDatabaseFromCache restores the overlay-base database by passing the key prefix as the primary key, with no restoreKeys:
codeql-action/src/overlay/caching.ts
Lines 290 to 302 in d208ec7
| actionsCache.restoreCache( | |
| [dbLocation], | |
| cacheRestoreKeyPrefix, | |
| undefined, | |
| { | |
| // Azure SDK download (which is the default) uses 128MB segments; see | |
| // https://github.com/actions/toolkit/blob/main/packages/cache/README.md. | |
| // Setting segmentTimeoutInMs to 3000 translates to segment download | |
| // speed of about 40 MB/s, which should be achievable unless the | |
| // download is unreliable (in which case we do want to abort). | |
| segmentTimeoutInMs: 3000, | |
| }, | |
| ), |
actionsCache.restoreCache(
[dbLocation],
cacheRestoreKeyPrefix,
undefined,
{ segmentTimeoutInMs: 3000 },
)This depends on the primary key matching by prefix. GitHub's cache service does that, but some Actions-cache-compatible backends only prefix-match restoreKeys. One example is the transparent cache on Blacksmith runners. On those backends, PR runs can never restore the overlay-base database, even though default-branch runs upload it successfully. Every PR run then falls back to a full analysis.
What we see
Default-branch run, on the same runner type:
Setting overlay database mode to overlay-base with caching because we are analyzing the default branch.
Uploading overlay-base database to Actions cache with key codeql-overlay-base-database-1-<hash>-python-2.27.1-<sha>-<run_id>-1
Successfully uploaded overlay-base database from /home/runner/_work/_temp/codeql_databases
Pull request run:
Setting overlay database mode to overlay with caching because we are analyzing a pull request.
Looking in Actions cache for overlay-base database with restore key codeql-overlay-base-database-1-<hash>-python-2.27.1-
No overlay-base database found in Actions cache
No overlay-base database found in cache, reverting overlay database mode to none.
Minimal reproduction of the backend difference
A cache entry saved as probe-<run_id>-full, then restored in a later job on the same branch with actions/cache/restore@v4:
| Restore | GitHub-hosted runner | Blacksmith runner |
|---|---|---|
key: probe-<run_id>- (prefix as the primary key, like this action) |
hit | miss |
key: probe-<run_id>-nomatch, restore-keys: probe-<run_id>- |
hit | hit |
Suggested fix
Also pass the prefix as a restore key:
actionsCache.restoreCache(
[dbLocation],
cacheRestoreKeyPrefix,
[cacheRestoreKeyPrefix],
{ segmentTimeoutInMs: 3000 },
)On GitHub's cache this matches exactly the same entries as today, since the prefix is tried first either way. On backends that only prefix-match restore keys, overlay analysis starts working.
Environment
github/codeql-action/initandanalyze@v4, CodeQL bundle 2.27.1build-mode: none, languagespythonandjavascript-typescript- Third-party hosted runners (Blacksmith) whose
actions/cachecalls go to their own cache backend
Activity
mbg commentedon Oct 7, 2026
Hi @Yuppyboy,
Thanks for the report about how this behaves on third-party runners. The requested change here seems straight-forward and reasonable to me, although note that in general we don't (and can't) guarantee compatibility with third-party-specific behaviours.