Repository navigation
gh cache delete <cache-key> misreports count when multiple match #11595
Description
Activity
Thanks for reporting this, @luxass! 🙏
I can confirm the issue. Here's what I tried:
gh cache list --json ref,key,id | cat # [{"id":1257026745,"key":"some-key","ref":"refs/heads/main-copy-2"},{"id":1256992430,"key":"some-key","ref":"refs/heads/main"}] gh cache delete some-key # ✓ Deleted 1 cache from gh-babakks/foo gh cache list --json ref,key,id | cat # []
Although two cache entries were deleted, the message says "1". However, when I tried with
--allI got "2":gh cache delete --all # ✓ Deleted 2 caches from gh-babakks/fooIn whatever way we look at this (i.e. should/shouldn't count distinct keys), the outputs are obviously inconsistent. So, this needs to be fixed.
Triage notes on potential fix
The reason behind this is that we use two different API endpoints to delete cache entries:
-
delete by ID, where an ID is equivalent to a unique combination of key/ref values. This endpoint just responds with
HTTP 204(no content). -
delete by key and an optional ref, which responds with a detailed list of deleted entries (like a list request) accompanied by a top-level
total_countfield:{ "total_count": 2, "actions_caches": [/*...*/] }In this case
ghignores the count reported in the response body and assumes it has successfully deleted one entry, which is not necessarily accurate.
So the fix is to update
ghso that when it's deleting cache entries by key, the count should be taken from the response body.Note
Although this bug affects lots of users, the impact is merely a confusion for the user and nothing unusual/unexpected will happen. So, I marked this as a https://github.com/cli/cli/labels/p3 to avoid unnecessary prioritisation.
Reacted by Lucas Nørgård-
- addedgh-cacherelating to the gh cache commandrelating to the gh cache commandpriority-3Affects a small number of users or is largely cosmeticAffects a small number of users or is largely cosmetic
on Sep 30, 2025 As this seems to be a straightforward change, I'm going to put down the A/C and label it as help wanted
Contributions welcome .@luxass, if you're up for it, feel free to submit a fix.
Reacted by Lucas NørgårdAcceptance Criteria
Keep current behaviour
Given I have a repo with non-zero number of cache entries
When I rungh cache delete --all
Then I see a success message with the same number of cache entries (distinct count by key/ref combination)Delete by key
Given I have a repo with multiple cache entries with the same key
When I rungh cache delete <KEY>
Then I see a success message with the number of entries of the same keyDelete by key and ref
Given I have a repo with non-zero number of cache entries
When I rungh cache delete <KEY> --ref <REF>
Then I see a success message with the number of deleted entries- addedhelp wantedContributions welcomeContributions welcomeand removedneeds-triageneeds to be reviewedneeds to be reviewed
on Oct 1, 2025
Describe the bug
When using
gh cache deletewith a cache-key that has multiple matches like so:When i run the
gh cache delete test-cache-this-is-always-the-sameit outputs that one cache was successfully deleted. Even though that all three of these was deleted.Affected version
gh version 2.78.0 (2025-08-21)
https://github.com/cli/cli/releases/tag/v2.78.0
Steps to reproduce the behavior
@actions/cachewith the same key across multiple branches. (I have created a testing repository, which can be used as a starting point https://github.com/luxass/gh-cache-test)gh cache listgh cache deletewhich prints that one cache was successfully deleted.Expected vs actual behavior
I would expect that it prints the correct number of caches that was deleted.
Additional Context
The REST Api supports returning the list of deleted caches when using a cache-key.
https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-github-actions-caches-for-a-repository-using-a-cache-key
So there should probably be some conditional output, since the delete by cache-id returns a 204 status code.
Logs
Paste the activity from your command line. Redact if needed.