You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
path.join produces \-separated paths on Windows, so key.startsWith(prefix) never matches there — deleted files are never pruned and the cache leaks indefinitely. Use path.sep or root + path.sep to be portable. Fix this →
[should-fix] mapWithConcurrency propagates worker rejections unchecked (src/core/cost-tracker.ts:409-414). If the fn callback throws rather than returning null, the for(;;) loop re-throws out of the async worker, causing Promise.all(workers) to reject. scanCodexSessionCached currently catches everything so this is safe today, but the helper's contract is fragile — a future caller that lets an error escape would silently drop all in-flight results. A .catch(() => null) guard on the inner await fn(...) would seal this. Fix this →
[nit] Stale entries leak when mixing codexSessionsDir values (src/core/cost-tracker.ts:221-224). pruneCodexScanCache only evicts entries under the directories scanned in the current call. If buildCostReport() (default dir) and buildCostReport({ codexSessionsDir: "/custom" }) are interleaved in the same process, cache entries from each call's dir are never pruned by the other. In practice the cache is bounded by the number of real session files, so this won't cause a memory blowup, but it's worth a comment.
[nit] Unnecessary module cast in tests (src/core/__tests__/cost-tracker.test.ts:74-77, 103-106, 133-136). clearCostTrackerCache and getCostTrackerCacheStats are regular named exports — they're already in typeof costTracker. The as typeof costTracker & { ... } intersection cast (and the optional-? variant in the first test) is dead code. Import them directly alongside the other named imports to remove the ambiguity.
Verdict: APPROVE
The caching logic is correct for the common case: mtime+size key is sufficient, the pruning correctly ignores files that disappeared between listing and stat (they don't get added to seenFiles so they're evicted), and concurrent workers are safe under JS's single-threaded event loop. The three new tests cover the meaningful branches (hit, miss-on-change, prune-on-delete). The two should-fix items are low-risk edge cases that don't affect typical macOS/Linux usage but are worth addressing before this pattern is copied elsewhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #49
Verification