fix(usage-bar): evict oldest template cache entry when size exceeds limit#99358
fix(usage-bar): evict oldest template cache entry when size exceeds limit#99358zhangqueping wants to merge 1 commit into
Conversation
…imit The module-level fileCache Map grows without bound and holds a live fs.watch watcher for each cached template file. Evict the oldest entry (closing its watcher) when the cache reaches MAX_FILE_CACHE_SIZE (64) so long-running gateways do not accumulate unused watchers. Fixes openclaw#98960
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this one-file branch targets the right bug but repeats the known after-allocation eviction flaw and lacks real behavior proof, while #98990 is the stronger open canonical fix path with pre-allocation eviction, tests, and sufficient live-output proof. Canonical path: Land the corrected bounded-cache fix through #98990 after its review findings are resolved, then close the canonical issue from the merged implementation. So I’m closing this here and keeping the remaining discussion on #98990. Review detailsBest possible solution: Land the corrected bounded-cache fix through #98990 after its review findings are resolved, then close the canonical issue from the merged implementation. Do we have a high-confidence way to reproduce the issue? Yes, by source inspection: current main and the latest release store every valid distinct usage-template file path in fileCache and can attach an fs.watch watcher without any production eviction path. I did not run a live many-template watcher 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 this branch evicts only after trying to allocate the replacement watcher and is superseded by an open candidate that uses the safer pre-allocation ordering plus focused proof. Security review: Security review cleared: The diff only changes an internal TypeScript cache path and does not add dependencies, scripts, workflows, downloads, package-resolution changes, or secrets handling. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against e7384d5f0205. |
|
Closing as superseded by #98990, which uses the safer pre-allocation eviction ordering (evict before creating the new watcher, not after) and includes real-behavior proof with watcher create/close measurement. Ref. ClawSweeper review: |
Summary
The module-level
fileCacheMap in template.ts grows without bound. Each entry holds a livefs.watchwatcher. Watchers are never closed and entries are never evicted — onlyclearUsageBarTemplateCacheForTest()closes them.Root Cause
src/auto-reply/usage-bar/template.ts:146—cacheTemplateFile()inserts without checking cache size.What changed
Add
MAX_FILE_CACHE_SIZE = 64and evict the oldest entry (closing its watcher) before inserting new entries when the cache is full.Evidence
Source inspection:
fileCache.set(path, entry)at line 146 never evicts. Each new template file path creates a persistent watcher that lives for the gateway lifetime.Risk checklist
Risk level: Low — cache eviction is LRU by insertion order (Map iteration order). A re-fetched cache-miss just reloads the file. 64 unique template paths is far above any real usage.
Fixes #98960