From 06b1fa1216739f752b4f8f5514fc33be111a5145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20B=C3=B6ckerman?= Date: Mon, 8 Jun 2026 23:04:54 +0300 Subject: [PATCH] Skip already-deleted caches in PR cleanup loop GitHub's Actions Cache list endpoint is eventually consistent: a cache just deleted in one outer iteration can reappear in the next list call, causing the second `gh cache delete` to 404 and fail the job (as seen in PR #553's Cleanup caches run). Track every ID the script has already removed and filter subsequent list responses against it so each cache is only deleted once. --- mise-tasks/github/cache/remove-for-pr.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mise-tasks/github/cache/remove-for-pr.py b/mise-tasks/github/cache/remove-for-pr.py index 92e7402c..5a6580bb 100755 --- a/mise-tasks/github/cache/remove-for-pr.py +++ b/mise-tasks/github/cache/remove-for-pr.py @@ -55,22 +55,23 @@ def remove_cache(entry: CacheEntry) -> None: def main() -> None: pr = int(os.environ["usage_pr"]) # noqa: SIM112 print(f"Removing caches for PR {pr}") + seen: set[int] = set() counter = 0 total_count = 0 while True: - caches = list_caches(pr) + raw = list_caches(pr) + caches = [c for c in raw if c.id not in seen] if not caches: print(f"Removed {counter} caches for PR {pr}") break total_count += len(caches) - total_str = str(total_count) - if len(caches) == LIMIT: - total_str += "+" + total_str = f"{total_count}+" if len(raw) == LIMIT else str(total_count) for cache in caches: counter += 1 print(f"Removing cache: {counter}/{total_str}: {cache.key}") remove_cache(cache) + seen.add(cache.id) if __name__ == "__main__":