Repository navigation
perf(server): index thread messages so shell builds stop sorting full history - #198
Merged
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
…est visible text The thread shell's latest_visible_text subquery ordered every message of a thread by updated_at with no matching index (only user messages had one), so each shell build sorted the thread's full history and parsed each user message's JSON. Measured on the live database: 6.6s across all 486 threads before, 31ms after. Migration 100. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nullStack65
force-pushed
the
perf/thread-shell-responsive
branch
from
November 24, 2026 04:33
b24e309 to
f1cf01b
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.
Root cause
The thread shell's
latest_visible_textsubquery (ProjectionStore.ts, selectShellThreadRows) orders all of a thread's messages byupdated_at DESCand filters out idle-compaction messages. Only user messages had a matching partial index, so every shell build used a temp B-tree over the thread's whole history and parsed each user message's JSON. This is the 84ms p50 / 1.3s max statement behindgetThreadShell,projectShellItemsandsql.transactionon the reader connection (603 calls, 67s total in the trace window).Fix
Migration 100 adds
orchestration_v2_projection_messages_thread_updated_idx (thread_id, updated_at DESC, message_id DESC), and the subquery uses it, so the scan walks in order and stops at the first visible message.Measured (live DB, read-only, all 486 threads)
Tests
statement.stat, a Node API missing on the R720's system Node).Not fixed, noted
🤖 Generated with Claude Code
Deploy: fleet