fix(usage-bar): evict oldest template cache entry when full#98853
fix(usage-bar): evict oldest template cache entry when full#98853zhangLei99586 wants to merge 3 commits into
Conversation
Each cached template file holds a live fs.watch watcher. The module-level Map grew without bound, accumulating watchers and memory for every distinct file path ever loaded during the process lifetime. Add a MAX_CACHED_TEMPLATES limit (32) and evict the oldest entry, closing its watcher, before inserting.
|
Codex review: needs real behavior proof before merge. Reviewed July 3, 2026, 2:38 AM ET / 06:38 UTC. Summary PR surface: Source +11. Total +11 across 1 file. Reproducibility: yes. Source inspection shows each distinct valid template path can allocate an fs.watch watcher and current main stores it in fileCache with no production eviction path; I did not run a live many-template exhaustion repro in this read-only review. Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Land a bounded-cache implementation that evicts and closes the oldest watcher before allocating the next watcher, with focused eviction and same-key retry coverage. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows each distinct valid template path can allocate an fs.watch watcher and current main stores it in fileCache with no production eviction path; I did not run a live many-template exhaustion repro in this read-only review. Is this the best way to solve the issue? No. The cache module is the right boundary, but the fix should evict before watcher allocation and include focused overflow/watcher-close regression coverage. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7cfc66ad0746. Label changesLabel justifications:
Evidence reviewedPR surface: Source +11. Total +11 across 1 file. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
Superseded by #98990, merged as The landed implementation is the stronger version of this fix: current Closing this candidate because the underlying issue is fixed on |
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
Related: #98960
What Problem This Solves
Module-level
fileCachegrew unbounded with livefs.watchwatchers.Why This Change Was Made
Add
MAX_CACHED_TEMPLATES=32, evict oldest + close watcher before insert.User Impact
Prevents unbounded watcher/memory growth.
Evidence
MAX_CACHED_TEMPLATES=32(line 13), eviction atfileCache.set(line 149)translator.test.ts: 13/13 passed ✅