Skip to content

gh cache delete <cache-key> misreports count when multiple match #11595

Description

@luxass

Describe the bug

When using gh cache delete with a cache-key that has multiple matches like so:

Image

When i run the gh cache delete test-cache-this-is-always-the-same it outputs that one cache was successfully deleted. Even though that all three of these was deleted.

Image

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

  1. Create a new repository that includes an action that uses @actions/cache with 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)
  2. Verify with gh cache list
  3. Run gh cache delete which 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.

Activity

  1. babakks commented on Sep 30, 2025

    @babakks
    Member

    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 --all I got "2":

    gh cache delete --all                
    # ✓ Deleted 2 caches from gh-babakks/foo

    In 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:

    1. 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).

    2. 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_count field:

      {
        "total_count": 2,
        "actions_caches": [/*...*/]
      }

      In this case gh ignores 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 gh so 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.

  2. added
    gh-cacherelating to the gh cache command
    priority-3Affects a small number of users or is largely cosmetic
    on Sep 30, 2025
  3. babakks commented on Oct 1, 2025

    @babakks
    Member

    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.

  4. babakks commented on Oct 1, 2025

    @babakks
    Member

    Acceptance Criteria

    Keep current behaviour

    Given I have a repo with non-zero number of cache entries
    When I run gh 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 run gh cache delete <KEY>
    Then I see a success message with the number of entries of the same key

    Delete by key and ref

    Given I have a repo with non-zero number of cache entries
    When I run gh cache delete <KEY> --ref <REF>
    Then I see a success message with the number of deleted entries

  5. added and removed on Oct 1, 2025
  6. self-assigned this
    on Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggh-cacherelating to the gh cache commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions