fix: prevent unbounded Map growth in chats server
Summary
Three Maps in the chats server grow without bounds, causing memory exhaustion in long-running deployments:
-
conversationMessageCountsandconversationMessageSnapshotsinchats-mobile.jsretain entries for deleted conversations -
fileActivityandtypingTimeoutinFileWatcher.jsaccumulate stale entries -
DataCache.jscache size (50) causes thrashing with 800+ conversations
Changes
chats-mobile.js: Remove Map entries for conversations that no longer exist during loadInitialData().
DataCache.js: Increase maxCacheSize from 50 to 500. Extend TTLs to reduce cache misses.
FileWatcher.js: Add periodic cleanup (every 5 minutes) of file activity entries older than 10 minutes.
Test Plan
- [ ] Start server with 500+ conversations
- [ ] Monitor memory usage over 30+ minutes
- [ ] Delete several conversations while server runs
- [ ] Verify Map sizes stabilize (check via
conversationMessageCounts.sizein logs)
Summary by cubic
Prevents unbounded Map growth in the chats server to stop memory leaks and stabilize long-running deployments. Adds cleanup for stale entries and tunes cache settings to reduce eviction thrash.
-
Bug Fixes
- Remove conversationMessageCounts and conversationMessageSnapshots entries for deleted conversations during loadInitialData().
- Add a 5-minute cleanup to purge stale fileActivity (>10 min) and clear orphaned typingTimeouts.
-
Performance
- Increase DataCache maxCacheSize to 500 and extend TTLs to reduce cache evictions with large (800+ ) conversation sets.
Written for commit debc6452fc3f3ee0ed31d9939a3083cf50a5f86b. Summary will update automatically on new commits.
@drewburchfield is attempting to deploy a commit to the Claude Code Templates Team on Vercel.
A member of the Team first needs to authorize it.