ai-devkit icon indicating copy to clipboard operation
ai-devkit copied to clipboard

perf(agent-manager): Grok summary builds the full message array on every refresh

Open codeaholicguy opened this issue 2 months ago • 0 comments

Problem

GrokSessionParser.readSession (packages/agent-manager/src/providers/grok/GrokSessionParser.ts) calls parseChatHistory(chatPath, false). On every refresh, for every live Grok agent, that:

  • reads the entire chat_history.jsonl;
  • builds the full ConversationMessage[] array, only to derive a summary (last role and last <user_query> prompt).

That is full-file I/O plus allocations proportional to the whole conversation, per agent, per refresh.

Proposed approach

  • Split summary scanning from conversation building: a summary reducer tracks only the last role, the last user query and timestamps, without accumulating messages.
  • Run the summary reducer through the incremental summary utility (#256).

Acceptance criteria

  • [ ] readSession doesn't build a message array; a test or benchmark shows allocation independent of message count.
  • [ ] A second refresh on an unchanged chat_history.jsonl reads 0 bytes; after appending K bytes it reads ≤ K + 64 KiB.
  • [ ] Summary output equals the current output for all existing Grok fixtures.

Depends on #256.

codeaholicguy avatar Sep 28 '26 08:09 codeaholicguy