claude-code-templates icon indicating copy to clipboard operation
claude-code-templates copied to clipboard

fix: prevent unbounded Map growth in chats server

Open drewburchfield opened this issue 1 month ago • 1 comments

Summary

Three Maps in the chats server grow without bounds, causing memory exhaustion in long-running deployments:

  • conversationMessageCounts and conversationMessageSnapshots in chats-mobile.js retain entries for deleted conversations
  • fileActivity and typingTimeout in FileWatcher.js accumulate stale entries
  • DataCache.js cache 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.size in 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 avatar Dec 07 '25 18:12 drewburchfield

@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.

vercel[bot] avatar Dec 07 '25 18:12 vercel[bot]