21. Session Memory
What the Session Memory Code Is Doing
The services/SessionMemory/ files reveal a background note-maintenance system. It initializes a dedicated markdown memory file,
watches thresholds, and periodically uses a forked subagent to summarize useful information from the active session without interrupting the main loop.
Important Mechanisms
- Threshold-based initialization and update cadence
- Shared state for “last summarized message” and token counts
- Timeout and stale-extraction protection
- Read/write integration with the same tool and permission framework as the rest of the app
Main Lesson
Long-session products need a separate memory-maintenance loop. The user conversation cannot be the only place where durable state lives.
Source Navigation
Recommended Source Files
source/services/SessionMemory/sessionMemory.tssource/services/SessionMemory/sessionMemoryUtils.tssource/services/SessionMemory/prompts.tssource/history.tssource/assistant/sessionHistory.ts
Next Files to Read
source/services/compact/sessionMemoryCompact.tssource/services/compact/compact.tssource/services/extractMemories/extractMemories.ts