Skip to content

Apply MAX_MESSAGE_CONTEXT when loading chat history #6

Description

@cubrift

Problem

Config.js defines MAX_MESSAGE_CONTEXT, but messageAI calls getRecentHistory(jid) without a limit. MessageDatabase.getRecentHistory defaults to 999999999, so every message in a chat can be loaded and sent through the response flow as the conversation grows.

This can increase memory use, model input size, and API cost over time. It also makes the configured context limit misleading.

Expected behavior

The AI response path should load only a bounded number of recent messages, while preserving chronological order for the messages that are retained.

Suggested direction

Pass MAX_MESSAGE_CONTEXT into getRecentHistory (or make the database helper use the configured default), then verify that the selected rows remain ordered from oldest to newest.

Acceptance criteria

  • The response path no longer loads unbounded history.
  • MAX_MESSAGE_CONTEXT is the single visible limit used for normal AI context.
  • The retained messages are still returned in chronological order.
  • A focused test or reproducible verification demonstrates that older messages are excluded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    codexUse for codex-generated issues only.enhancementPerformance update or requestgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions