From 8f942ff0712b9638f7393f18ab0f47d7d2cbba5e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 11 Nov 2026 09:44:40 +0000 Subject: [PATCH] fix(kvb-org-organize): skip a missing cache root in the cache trim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cache_files walked every cache_dirs entry with os.fwalk, which raises FileNotFoundError for a folder that does not exist (~/.cache/ms-playwright on this host), so cleanup --caches crashed and trim_caches never ran at disk stage warn. A root that cannot be walked is now skipped and the other roots are still trimmed. 🎯 Fix: 95 % 💥 Break: 2 % 💸 Cost: 100 % ⏱️ Time: 100 % 🛡️ Security: 100 % 🏆 Score: 93 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 --- skills/kvb-org-organize/scripts/watch.py | 23 +++++++++++++---------- tests/test_watch.py | 10 ++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/skills/kvb-org-organize/scripts/watch.py b/skills/kvb-org-organize/scripts/watch.py index b308673..caee087 100755 --- a/skills/kvb-org-organize/scripts/watch.py +++ b/skills/kvb-org-organize/scripts/watch.py @@ -1047,16 +1047,19 @@ def cache_files(dirs: list[str]) -> list[tuple[float, int, str, str]]: files = [] seen: set[tuple[int, int]] = set() for root in map(os.path.expanduser, dirs): - for base, _, names, fd in os.fwalk(root, follow_symlinks=False): - for name in names: - try: - st = os.stat(name, dir_fd=fd, follow_symlinks=False) - except OSError: - continue - if (st.st_dev, st.st_ino) in seen: - continue - seen.add((st.st_dev, st.st_ino)) - files.append((st.st_atime, st.st_blocks * 512, os.path.join(base, name), root)) + try: + for base, _, names, fd in os.fwalk(root, follow_symlinks=False): + for name in names: + try: + st = os.stat(name, dir_fd=fd, follow_symlinks=False) + except OSError: + continue + if (st.st_dev, st.st_ino) in seen: + continue + seen.add((st.st_dev, st.st_ino)) + files.append((st.st_atime, st.st_blocks * 512, os.path.join(base, name), root)) + except OSError: + continue return files diff --git a/tests/test_watch.py b/tests/test_watch.py index d75f636..136a58d 100644 --- a/tests/test_watch.py +++ b/tests/test_watch.py @@ -637,6 +637,16 @@ class TestWatchCommands(unittest.TestCase): kept = self.base / ".local" / "state" / "agents-council" / "queue-history.jsonl" self.assertNotIn("outside", kept.read_text(encoding="utf-8") if kept.exists() else "") + def test_cache_trim_skips_a_missing_cache_root_and_trims_the_others(self): + watch = _load() + old = self.cache / "old" + old.write_bytes(b"x" * 4096) + os.utime(old, (0, 0)) + self.cfg["cache_dirs"] = [str(self.base / "missing"), str(old), str(self.cache)] + self.cfg["cache_budget_percent"] = 0 + watch.trim_caches(self.cfg) + self.assertFalse(old.exists()) + def test_cache_trim_counts_the_blocks_a_sparse_file_holds(self): watch = _load() with (self.cache / "sparse").open("wb") as handle: