From d5f70ad230f7e37b683079f3976eecece20a4200 Mon Sep 17 00:00:00 2001 From: Sasa Junuzovic <44276455+microsasa@users.noreply.github.com> Date: Sun, 3 May 2026 07:44:20 -0700 Subject: [PATCH] fix: remove dead `child_ids` field from `_VSCodeDiscoveryCache` The `child_ids` field was stored on every cache miss but never read on cache hits, causing dead memory overhead proportional to the number of session directories. This removes the field from the dataclass while keeping `child_ids` as a local variable in `_cached_discover_vscode_logs` where it is actually used. - Remove `child_ids: _ChildIds` from `_VSCodeDiscoveryCache` dataclass - Update docstring to remove mention of stored child_ids - Update tests to remove `child_ids` kwarg from constructor calls - Replace `cached.child_ids` assertion with checks on remaining fields Closes #1174 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/copilot_usage/vscode_parser.py | 5 +---- tests/copilot_usage/test_vscode_parser.py | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/copilot_usage/vscode_parser.py b/src/copilot_usage/vscode_parser.py index 153319a3..778a98f6 100644 --- a/src/copilot_usage/vscode_parser.py +++ b/src/copilot_usage/vscode_parser.py @@ -131,8 +131,7 @@ class _VSCodeDiscoveryCache: *newest_child_path* / *newest_child_id* store the most recently modified immediate child at population time; re-stat'ing this single sentinel on a hit detects new window directories added inside an - existing session. *child_ids* is recorded at population time and - retained for diagnostics but is not fully rescanned on cache hits. + existing session. **Limitation:** only changes under the cached newest session directory are detected by the sentinel. If a different (older) session directory @@ -144,7 +143,6 @@ class _VSCodeDiscoveryCache: """ root_id: tuple[int, int] # (st_mtime_ns, st_size) of the logs root - child_ids: _ChildIds newest_child_path: Path | None # most-recently-modified session dir newest_child_id: tuple[int, int] | None # its identity at population log_paths: tuple[Path, ...] @@ -298,7 +296,6 @@ def _cached_discover_vscode_logs(base_path: Path | None) -> list[Path]: found = sorted(candidate.glob(_GLOB_PATTERN)) _VSCODE_DISCOVERY_CACHE[candidate] = _VSCodeDiscoveryCache( root_id=root_id, - child_ids=child_ids, newest_child_path=newest_path, newest_child_id=newest_id, log_paths=tuple(found), diff --git a/tests/copilot_usage/test_vscode_parser.py b/tests/copilot_usage/test_vscode_parser.py index b27cfe09..dbdb1fda 100644 --- a/tests/copilot_usage/test_vscode_parser.py +++ b/tests/copilot_usage/test_vscode_parser.py @@ -2716,7 +2716,6 @@ def test_cache_invalidated_on_root_mtime_change(self, tmp_path: Path) -> None: cached = _VSCODE_DISCOVERY_CACHE[tmp_path] _VSCODE_DISCOVERY_CACHE[tmp_path] = _VSCodeDiscoveryCache( root_id=(cached.root_id[0] + 1_000_000_000, cached.root_id[1]), - child_ids=cached.child_ids, newest_child_path=cached.newest_child_path, newest_child_id=cached.newest_child_id, log_paths=cached.log_paths, @@ -2753,7 +2752,8 @@ def test_discovery_cache_populated(self, tmp_path: Path) -> None: cached = _VSCODE_DISCOVERY_CACHE[tmp_path] assert len(cached.log_paths) == 1 assert cached.root_id == safe_file_identity(tmp_path) - assert cached.child_ids == _scan_child_ids(tmp_path) + assert cached.newest_child_path is not None + assert cached.newest_child_id is not None def test_new_window_under_existing_session_triggers_rediscovery( self, tmp_path: Path @@ -3267,7 +3267,6 @@ def test_field_reassignment_raises(self) -> None: """Assigning to a field after construction raises FrozenInstanceError.""" cache = _VSCodeDiscoveryCache( root_id=(0, 0), - child_ids=frozenset(), newest_child_path=None, newest_child_id=None, log_paths=(),