Severity: Medium
Location: src/memory/search.ts:85-89 and src/memory/knowledge.ts:41-45
Description:
ensureIndex() and loadKnowledge() both use module-level caches (dirty flag, cache variable) that persist for the lifetime of the Node.js process. These caches are never invalidated if the JSON files are modified externally (e.g., by another process, a backup restore, or manual editing).
For a long-running agent that may run for weeks, stale cached data can accumulate without the agent realizing it.
Suggested Fix:
Add file-watcher based cache invalidation using fs.watch or fs.watchFile, or at minimum check file mtime against cached mtime when loading:
let cacheMtime: number | null = null;
export function loadKnowledge(): KnowledgeEntry[] {
const p = getKnowledgePath();
if (!fs.existsSync(p)) return [];
const stat = fs.statSync(p);
if (cacheMtime !== stat.mtimeMs) {
cache = null;
cacheMtime = stat.mtimeMs;
}
if (cache) return cache;
// ...
}
Apply the same pattern to feedback.ts and chat.ts.
Severity: Medium
Location:
src/memory/search.ts:85-89andsrc/memory/knowledge.ts:41-45Description:
ensureIndex()andloadKnowledge()both use module-level caches (dirtyflag,cachevariable) that persist for the lifetime of the Node.js process. These caches are never invalidated if the JSON files are modified externally (e.g., by another process, a backup restore, or manual editing).For a long-running agent that may run for weeks, stale cached data can accumulate without the agent realizing it.
Suggested Fix:
Add file-watcher based cache invalidation using
fs.watchorfs.watchFile, or at minimum check file mtime against cached mtime when loading:Apply the same pattern to
feedback.tsandchat.ts.