fix(server): stop maintaining the unused event correlation index#23171

open3
main
fix/issue-20534
opened4d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 3d ago

Problem

Every event insert maintains an unused correlation-ID index. On main, starting the real dev server and inspecting its isolated database with dbstat confirms the index remains; a larger read-only database has 2,211,840 bytes in it for 73,876 events. No server query filters or orders by that column. See #20534.

Change

Add migration 68 to drop only idx_orch_events_correlation_id. Preserve the correlation column, its values, and all other event indexes, including the agent-stream index required by legacy import. Add one upgrade regression test and update the existing migration-list expectations.

Scope and approval

Fixes #20534 GitCafe: https://git.cafe/pingdotgg/t3code/issues/20534 Triaged bug via the automated issue flow. This focused server performance fix removes an unused index without changing product behavior, contracts, or client code.

Verification

  • Red: on main plus the regression test, vp test run src/persistence/Migrations.test.ts failed on the assertion that the unused index must be absent (1 failed, 7 passed).
  • Green: 33 focused tests passed across Migrations.test.ts, reconcileV2PreviewMigration.test.ts, OrchestrationEventStore.test.ts, OrchestrationEventStore.sequence.test.ts, initializeV2Database.test.ts, orchestration-v2/legacy/LegacyV1ThreadImporter.test.ts, and orchestration-v2/legacy/LegacyV1Cutover.integration.test.ts. The upgrade test checks that correlation values and required indexes survive.
  • After merging current main with a merge commit, reran the same seven files: 33 passed at 4faeac5142.
  • Targeted lint and the server package typecheck passed. No repo-wide checks.
  • Runtime: vp run dev --home-dir /tmp/issue20534-canonical upgraded a canonical database from migration 67 to 68. The paired real web client loaded and created a thread. The index went from present (4,096 bytes on the empty fixture) to absent; four real events retained correlation values and all other event indexes remained. Runtime transcript.
  • Audited evidence index. Visual matrix: empty; no render paths changed. Server-only proof is the regression test plus runtime transcript. No native-client behavior was changed.
  • The populated reproduction snapshot has local-fork migration records, so the upstream runtime upgrade used a separate canonical fixture. A large populated canonical database was not timed. Schema-copy insert timings were noisy; no percentage speedup is claimed. Dropping the index frees database pages for reuse, rather than shrinking the file automatically.

Implemented with Claude Opus 5.5 through the Claude Code harness; triaged and reviewed with GPT-6.1-Sol through the Codex harness and Claude Opus 5.5 through Claude Code.

Checks

All checks passed

Added 3 commits

  • Merge origin/main into fix/issue-205344faeac5
  • test(server): reproduce unused correlation index (issue #20534)5dedf45
  • fix(server): drop the unused orchestration event correlation indexa623c6b
Synced from GitHub

Approvability

Verdict: Approved at 4faeac5

Macroscope's review found this PR approvable — This focused server migration removes an unused SQLite index while preserving the correlation column, stored values, and other indexes. The accompanying tests verify the migration history and schema invariants, with no product-default or user-facing behavior changes.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
CodexLive turn messages220 (0.0%)8✅
ClaudeTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
ClaudeLive turn messages220 (0.0%)8✅

Baseline: 89fe509 · PR result: 4faeac5 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 3ffe79b2-cc8f-4f62-9f7c-88edd361c164
📥 Commits

Reviewing files that changed from the base of the PR and between 89fe509232e787b51d0cf695861afe73316ce85b and 4faeac514204f78c537380ba5a8b7ae2401ce83c.

📒 Files selected for processing: 4
  • apps/server/src/persistence/Migrations.test.ts
  • apps/server/src/persistence/Migrations.ts
  • apps/server/src/persistence/Migrations/068_DropOrchestrationEventCorrelationIndex.ts
  • apps/server/src/persistence/reconcileV2PreviewMigration.test.ts

Limit details: You’ve used all 10 included reviews currently available.

📝 Walkthrough

Migration 68 drops idx_orch_events_correlation_id without changing the correlation_id column or its values. The migration is registered, and migration tests verify index removal, retained indexes, correlation ID preservation, and upgrade migration lists.

Changes: Correlation index migration

Layer / File(s)Summary
Implement and register migration
apps/server/src/persistence/Migrations/068_DropOrchestrationEventCorrelationIndex.ts, apps/server/src/persistence/Migrations.ts
Migration 68 drops idx_orch_events_correlation_id if it exists and is added to the migration entries.
Verify migration behavior and upgrade lists
apps/server/src/persistence/Migrations.test.ts, apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
Tests verify that the correlation ID and specified indexes remain, the correlation index is removed, and preview-upgrade expectations include migration 68.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: shivamhwp

Merge Risk: ⚪ Minimal · up to 4faea

The index can be removed without a supported impact on event data or the inspected query paths. No actionable issue remains before merge.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the main change: stopping maintenance of the unused event correlation index.
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Description checkPassedThe pull request description includes all required sections. It clearly states the problem, change, scope and approval, verification results, limitations, runtime validation, and the agent and harness…
Full details: Description check

Explanation

The pull request description includes all required sections. It clearly states the problem, change, scope and approval, verification results, limitations, runtime validation, and the agent and harness used.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.