perf(inbox): index the 1.5s poll hot paths + bound the inbox feed (v0.265.3)#465
Merged
Conversation
….265.3)
The console polls /api/messages (listMessages) and /api/sessions (listSessions)
every 1.5s per open tab. node:sqlite is synchronous, so a slow query on either
blocks the whole server event loop — surfacing as laggy approval/inbox
notifications and contributing to the server feeling unresponsive on tenants
with a large history.
- Add hot-path indexes matching each poll's WHERE + ORDER BY:
messages(dismissed_at, created_at)
term_sessions(archived_at, created_at)
audit_events(run_id, type, ts) -- stampInsights per-live-session tallies
EXPLAIN QUERY PLAN confirms all now use the index with no temp b-tree sort.
- Bound listMessages to the newest 500 non-dismissed cards so a pathological
undismissed backlog can't grow the per-poll cost without limit (owner/admin
see all; the `mine` scope narrows further downstream).
Indexes apply to existing DBs on next boot.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WPLeBNcNJiURPKiUZ6iMmF
vikasprogrammer
force-pushed
the
feat/inbox-perf
branch
from
July 24, 2026 16:46
59f4f5b to
b8a2805
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The console polls
/api/messages(listMessages) and/api/sessions(listSessions) every 1.5s per open tab, andnode:sqliteis synchronous — a slow query on either blocks the entire server event loop. On data-heavy tenants (e.g. instawp) this surfaced as laggy approval/inbox notifications and contributed to the server feeling unresponsive. Both queries were full-table scans + sorts, growing with all-time history.What
WHERE+ORDER BY:messages(dismissed_at, created_at)— the inbox feedterm_sessions(archived_at, created_at)— the session listaudit_events(run_id, type, ts)— the per-live-session insight tallies (stampInsights, run every poll)listMessagesto the newest 500 non-dismissed cards, so a pathological undismissed backlog can't grow per-poll cost without limit (owner/admin see all;minenarrows further downstream; mark-all-read/dismiss iterate the same capped list).message_state's(message_id, member_id)join is already served by its composite PRIMARY KEY — no new index needed there.Verification
npm run typecheck+npm run buildclean.EXPLAIN QUERY PLANon all four hot queries: each nowSEARCH ... USING INDEXwith noUSE TEMP B-TREE FOR ORDER BY(the index satisfies the sort).Indexes apply to existing DBs on next boot (engine-level, not JSON policy).
🤖 Generated with Claude Code