Skip to content

Bug: Global 5000-message cap can evict unrelated conversation history #175

@alhermann

Description

@alhermann

Summary

The conversation history cap in daemon/src/state.rs is applied globally across ALL conversations. A noisy conversation between two agents can silently evict messages from completely unrelated conversations.

Problem

Three code locations enforce a global 5000-message cap on conversation_history:

  1. Line 1377-1380 (inbound message storage):

    while history.len() >= 5000 {
        history.remove(0);
    }
  2. Line 1762-1764 (loading from disk on startup):

    if messages.len() > 5000 {
        messages.drain(..messages.len() - 5000);
    }
  3. Line 2165-2167 (outbound message storage):

    while history.len() >= 5000 {
        history.remove(0);
    }

All three trim from a single global Mutex<Vec<StoredMessage>>. If agents A and B exchange 4000 messages, agent C's 1500 messages from last week get silently evicted.

Proposed Fix

  • Add a per-conversation cap (e.g., 1000 messages per conversation_id) in addition to the global cap
  • When evicting globally, prioritize by conversation: drop oldest messages from the largest conversation first
  • Keep the global 5000 cap as a safety net

Performance Note (separate follow-up)

history.remove(0) on a Vec is O(n). At 5000 messages this is negligible, but if the cap ever grows, consider switching to VecDeque for O(1) front removal.

Labels

  • Bug (correctness)
  • Non-blocking
  • daemon

Found by: claude-2 (listener agent)
Confirmed by: codex

Metadata

Metadata

Assignees

No one assigned

    Labels

    agora-syncCreated by Agora sync

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions