GeezerVison is showing github.com — perf(server): events stop maintaining two indexes no query needs by KiroshiAiviom · Pull Request #19623 · pingdotgg/t3code
Conversation
Problem
Every event commit updates all 9 indexes on orchestration_events. Two of them serve no query: nothing filters, joins or sorts on correlation_id, and every reader of idx_orch_events_stream_sequence has an equal or cheaper index available. Together they cost about 2.6 WAL pages per event (part of #19105).
Change
- Migration 063 drops
idx_orch_events_correlation_id and idx_orch_events_stream_sequence.
- Three per-thread agent reads are pinned with
INDEXED BY idx_orchestration_events_agent_stream_sequence, like the file's existing pins. Without planner statistics, SQLite otherwise picks application_sequence for them and ranges over every V2 event (160× slower). The pinned queries always include the partial index's application_event_version = 2 AND aggregate_kind = 'thread' terms, so the pin always prepares.
idx_orchestration_events_application_sequence stays: latestAgentSequence() and the shell MAX(sequence) need it.
Scope and approval
#19105 is open and triaged by maintainers as a performance bug, naming "fewer pages per commit" as the remaining lever. This PR only removes index maintenance; it does not change commit grouping or projections.
Verification
- Migration test: migrate to 62, then 63; both indexes are gone, the other six remain.
- Plan test (25k events, no statistics): the per-thread read, the read with
eventType and getAgentReplayStats return the right rows and plan SEARCH ... USING INDEX idx_orchestration_events_agent_stream_sequence. It fails with the migration alone, reproducing the regression the pins prevent.
- 79 persistence/migration tests and 435 tests in callers (
ShellStream, ClaudeAdapterV2, ThreadFind, recovery, ingestion) pass. Typecheck and lint clean.
Query plans before/after on a replica of the real schema (200k events), all 33 orchestration_events read shapes, in three stats modes (none / ANALYZE / the server's PRAGMA optimize). Times are ms in no-stats mode:
| Query |
Before |
After |
readAgentEvents(threadId) |
stream_sequence, 0.78 |
agent_stream_sequence, 0.67 |
readAgentEvents(threadId, eventType) |
stream_sequence, 0.67 |
agent_stream_sequence, 0.61 |
readAgentEvents(threadId, bounded) |
stream_sequence, 0.41 |
agent_stream_sequence, 0.41 |
getAgentReplayStats |
stream_sequence, 0.65 |
agent_stream_sequence, 0.67 |
| Drop only, no pins: the three reads above |
— |
application_sequence, 161–192 |
LegacyV1 existing-rows read, migrate-dev-db |
stream_sequence |
stream_version, same cost |
| The other 26 shapes |
— |
same plan |
WAL per event, one event per commit, 3,000 events:
|
Pages |
Bytes |
Time |
| Before |
23.27 |
95.9 KB |
0.286 ms |
| After |
20.68 (−11%) |
85.2 KB |
0.176 ms |
An older server opening a migrated database stays fast: the server runs PRAGMA optimize right after migrating, which gives it stats that steer those reads to the agent index (0.87 ms).
Collisions: #19451 also adds migration 063, and #19407 lists both indexes in plannerStatistics.ts. Whichever lands second renumbers or removes those two rows.
Not checked: plans against a production database with stale statistics.
Written by Claude Opus 5.5 in Claude Code.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Every orchestration event is its own SQLite commit, and each commit updates
all nine indexes on orchestration_events (#19105). Two of them do no read work:
no query filters, joins or orders on correlation_id, and the partial
(stream_id, sequence) agent index already serves every per-thread sequence read
that used idx_orch_events_stream_sequence.
Migration 063 drops idx_orch_events_correlation_id and
idx_orch_events_stream_sequence. Without planner statistics, SQLite would then
send per-thread readAgentEvents and getAgentReplayStats to the
(application_event_version, sequence) index, a range over every V2 event:
1 ms became 160-190 ms on a 200k-event replica. Both reads now name
idx_orchestration_events_agent_stream_sequence with INDEXED BY, as the command
and high-water reads already do. Thread reads that also filter by command keep
the command index.
EXPLAIN QUERY PLAN for 33 orchestration_events query shapes on the replica,
with no statistics, full ANALYZE and optimize-style limited ANALYZE: the pinned
reads use the agent index at equal or lower cost; the LegacyV1 import and
migrate-dev-db filters move from stream_sequence to stream_version, the same
(aggregate_kind, stream_id) prefix; every other plan is unchanged. WAL frames
per event in a replayed streaming workload fall from 23.27 to 20.68 (-11%).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
coderabbitai
Bot
commented
Oct 14, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Important
Review skipped
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3091d75f-5432-42ad-b713-fbb8d46d58d5
📥 Commits
-
Reviewing files that changed from the base of the PR and between a396768 and b48bfc0.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8f0f1284-d9e0-4b52-9d84-d28c9712a097
📥 Commits
-
Reviewing files that changed from the base of the PR and between 348f217 and 07ab2ce.
📒 Files selected for processing: 8
-
apps/server/src/orchestration-v2/FoundationPersistence.test.ts
apps/server/src/persistence/Migrations.ts
apps/server/src/persistence/Migrations/055_OrchestrationV2.test.ts
apps/server/src/persistence/Migrations/063_DropUnusedEventIndexes.test.ts
apps/server/src/persistence/Migrations/063_DropUnusedEventIndexes.ts
apps/server/src/persistence/OrchestrationEventStore.sequence.test.ts
apps/server/src/persistence/OrchestrationEventStore.ts
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
-
The event store now selects indexes for thread-scoped reads and replay statistics. Migration 63 drops two event indexes and is included in the migration registry and migration tests.
Changes: Orchestration event indexes
| Layer / File(s) |
Summary |
Thread-scoped event read indexes apps/server/src/persistence/OrchestrationEventStore.ts, apps/server/src/persistence/OrchestrationEventStore.sequence.test.ts |
Application-row reads and replay statistics use the agent stream/sequence index for thread-scoped queries. The test checks returned events, replay counts, and query plans. |
Register and verify index removal apps/server/src/persistence/Migrations/063_DropUnusedEventIndexes.ts, apps/server/src/persistence/Migrations.ts, apps/server/src/persistence/Migrations/063_DropUnusedEventIndexes.test.ts, apps/server/src/persistence/Migrations/055_OrchestrationV2.test.ts, apps/server/src/persistence/reconcileV2PreviewMigration.test.ts, apps/server/src/orchestration-v2/FoundationPersistence.test.ts |
Migration 63 drops the correlation-ID and stream-sequence indexes. Migration registration and expectations include migration 63. The migration test checks which indexes remain. |
Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers: juliusmarminge
Merge Risk: ⚪ Minimal · up to 07ab2
-
The change drops two unused event indexes and pins three thread-scoped reads to a retained index. It reduces per-event write cost, and no concrete merge-blocking risk was found.
Security architecture risk: 🔵 Low · up to 07ab2
-
The change preserves event-identity constraints and query filtering while removing two lookup indexes. No introduced security issue was established. Interrupted or concurrent migration execution and application-version rollback remain only partially validated.
Retained concerns
No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The directly affected asset is the server's orchestration-event database and its read workload. The inspected changes alter index maintenance and access plans, not row ownership, caller authority, or the set of rows selected by existing filters.
Trust Boundaries and Controls
- observed — Index names are selected from fixed SQL fragments. Thread IDs, command IDs, event types, and sequence bounds remain SQL value interpolations; caller input does not become an index identifier or raw SQL in the changed queries.
Resilience and Maintainability Implications
- inferred — If interruption leaves only one index dropped, the remaining integrity constraints are unaffected. Repeating the two DROP INDEX IF EXISTS statements can converge without restoring or rewriting event rows. This property does not independently establish migration-ledger atomicity or concurrent-migrator behavior.
Pre-merge checks: 4
-
Passed checks: 4 passed
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title clearly and concisely describes the main performance change: removing unnecessary event indexes. It follows the conventional commit format. |
| Description check |
 |
The description covers the problem, implementation, scope, migration effects, query-plan safeguards, verification results, performance measurements, known collision risks, and an unchecked production-… |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Note Written by claude-opus-5-5 on behalf of Maria
Thanks for this. I'm closing it as part of PR triage. Right now we're only taking focused bug fixes from outside contributors (see Read this first), and this PR is not one.
From the review: Dropping the correlation and stream-sequence indexes and forcing query indexes is performance work. Schema-replica timings and synthetic commits do not establish improvement through an actual provider turn; maintainer agreement is needed.
If you think this was a mistake, message me on Twitter at @maria_rcks and I'll take another look.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:M
30-99 changed lines (additions + deletions).
vouch:unvouched
Author is not yet trusted in the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|