fix: reduce session.messages() calls with event-based caching to prevent memory leaks
- Replace session.messages() fetch in context-window-monitor with message.updated event cache - Replace session.messages() fetch in preemptive-compaction with message.updated event cache - Add per-session transcript cache (5min TTL) to avoid full rebuild per tool call - Remove session.messages() from background-agent polling (use event-based progress) - Add TTL pruning to todo-continuation-enforcer session state Map - Add setInterval.unref() to tool-input-cache cleanup timer Fixes #1222
This commit is contained in:
@@ -37,7 +37,7 @@ export function getToolInput(
|
||||
}
|
||||
|
||||
// Periodic cleanup (every minute)
|
||||
setInterval(() => {
|
||||
const cleanupInterval = setInterval(() => {
|
||||
const now = Date.now()
|
||||
for (const [key, entry] of cache.entries()) {
|
||||
if (now - entry.timestamp > CACHE_TTL) {
|
||||
@@ -45,3 +45,7 @@ setInterval(() => {
|
||||
}
|
||||
}
|
||||
}, CACHE_TTL)
|
||||
// Allow process to exit naturally even if interval is running
|
||||
if (typeof cleanupInterval === "object" && "unref" in cleanupInterval) {
|
||||
cleanupInterval.unref()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user