Skip to content

fix: ChatManager.get_escalations iterates the entire escalations list on every call — replace with per-conversation index #193

@BigBen-7

Description

@BigBen-7

Description

src/chat.py stores all escalation events in a single flat list:

self.escalations: List[EscalationEvent] = []

get_escalations(conversation_id) filters this list on every call:

def get_escalations(self, conversation_id=None) -> List[EscalationEvent]:
    if conversation_id:
        return [e for e in self.escalations if e.conversation_id == conversation_id]
    return self.escalations.copy()

In a high-volume support environment with thousands of escalations, every call to GET /chat/{id}/escalations scans the entire list. With 10,000 escalations and 100 concurrent requests, this is 1,000,000 comparisons per second.

Requirements & context

  • Replace the flat self.escalations: List[EscalationEvent] with a per-conversation dict:
    self.escalations: Dict[str, List[EscalationEvent]] = {}
  • Update escalate_conversation to append to self.escalations.setdefault(conversation_id, [])
  • Update get_escalations(conversation_id):
    • With conversation_id: return self.escalations.get(conversation_id, [])
    • Without: return a flat list from all values (only used for admin queries)
  • The change must be backward-compatible — existing callers of get_escalations must work without modification
  • Write a performance test confirming lookup time is O(1) per conversation, not O(n) global

Suggested execution

git checkout -b fix/chat-escalations-dict-index
  • Update src/chat.py
  • Write tests confirming O(1) lookup

Guidelines

  • PR must include: Closes #[issue_id]
  • Timeframe: 24 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programbugSomething isn't workingchatChat system and real-time messagingperformancePerformance and optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions