Skip to content

[Bug] Memory leak in groupHistories Map - keys never evicted #2384

@robbyczgw-cla

Description

@robbyczgw-cla

Summary

The groupHistories Map grows unbounded as new groups/topics are encountered. Keys are never deleted, only values are cleared.

Affected Files

  • src/telegram/bot.tsdist/telegram/bot.js:152
  • src/signal/monitor.tsdist/signal/monitor.js
  • src/web/auto-reply/monitor.tsdist/web/auto-reply/monitor.js
  • src/imessage/monitor/monitor-provider.tsdist/imessage/monitor/monitor-provider.js

Problem

const groupHistories = new Map();  // Never cleaned up

As users interact with more groups/topics over time, the Map grows. Growth is O(unique groups), not O(messages), so it's slow but unbounded.

Impact

  • Long-running instances accumulate memory
  • Severity: LOW (slow growth, only affects long uptimes with many groups)

Suggested Fix

Option 1: Use a TTL-based Map with automatic eviction

import { createTTLMap } from '../infra/ttl-map.js';
const groupHistories = createTTLMap({ maxAge: 24 * 60 * 60 * 1000 }); // 24h TTL

Option 2: Add periodic LRU eviction for oldest entries

Verification

Confirmed by code analysis with Codex CLI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions