You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: session loop re-reads all messages from DB every iteration #22208
filterCompactedEffect reads every message from the DB (via paginated SQL) at the start of each runLoop iteration, then discards pre-compaction messages. For compacted sessions with hundreds of messages, this means re-reading and discarding the same pre-compaction messages on every tool call round-trip.
Details
In prompt.ts:1314, filterCompactedEffect(sessionID) is called every loop step. This calls stream(sessionID) which does ceil(N/50) paginated SQL queries for all N messages in the session. Then filterCompacted() scans forward to find the last compaction boundary and discards everything before it.
For a session with 500 messages (300 pre-compaction, 200 post-compaction), each iteration does ~10 SQL queries but only uses ~200 messages. The pre-compaction messages are read and discarded every time.
Suggested Fix
Cache the compaction boundary (first post-compaction message ID/timestamp) per session and pass it as a since parameter to stream() so it adds a WHERE clause to skip older rows. The cache invalidates when a new compaction is created.
This would reduce DB reads by ~60% per iteration for compacted sessions.
Activity
github-actions commentedon Apr 12, 2026
This issue might be a duplicate of existing issues. Please check:
filterCompacted(stream(sessionID))loads entire conversation history from DB on every prompt loop iteration, with the same suggested fix of optimizing the compaction boundary to skip pre-compaction messagesPlease review the linked issues and consider whether this adds new information before continuing separately.
github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.