ai-devkit
ai-devkit copied to clipboard
perf(agent-manager): Grok summary builds the full message array on every refresh
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
- [ ]
readSessiondoesn't build a message array; a test or benchmark shows allocation independent of message count. - [ ] A second refresh on an unchanged
chat_history.jsonlreads 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.