Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedjuliusmarmingemerged 6 commits intomain fromrefs/pull/23211/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

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.

    1. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 63325c7

      Macroscope's review found this PR approvable — The migration removes an unused, non-unique event correlation index while preserving the column and all event data. Its impact is limited to internal database storage and index maintenance.

      No code changes detected at a0ca3f3. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB+16 B (+0.3%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB+16 B (+1.3%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.6 KiB+41 B (+0.2%)24.4 KiB✅
      CodexLive turn messages12+1 (+100.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 07a1e79 · PR result: a0ca3f3 · 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.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 63325c7f9902c5a20c5e426d16cab0418c0f77fc and a0ca3f3305c1789ee634cf7017d6264957d47e40.

      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:

      • Trigger review

      No actionable comments were generated in the recent review.

      Walkthrough

      Migration 78 removes idx_orch_events_correlation_id while leaving the correlation_id column and its values intact. The migration registry and preview expectations include migration 78. Tests verify index removal, retained indexes, and value preservation.

      Changes: Correlation index migration

      Layer / File(s)Summary
      Implement and register migration
      apps/server/src/persistence/Migrations/078_DropOrchestrationEventCorrelationIndex.ts, apps/server/src/persistence/Migrations.ts
      Migration 78 drops idx_orch_events_correlation_id if it exists and adds the migration to the registry.
      Verify migration behavior and upgrade lists
      apps/server/src/persistence/Migrations.test.ts, apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
      The migration test checks that the index is removed, specified indexes remain, and the event retains its correlation value. Preview-upgrade and retry expectations include migration 78.

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

      Change: Bug fix · Severity of issue fixed: Medium

      Possibly related issues

      • pingdotgg/t3code#20534 — The migration removes the index identified in the issue while preserving the correlation column and values.

      Suggested reviewers: yash-singh1

      Merge Risk: Minimal · previous review 63325

      No actionable merge-blocking risk was identified in the migration or upgrade-path changes.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title "fix(server): stop maintaining the unused event correlation index" matches the main change: migration 078 drops idx_orch_events_correlation_id, which no server query uses. It uses a conventi…
      Description checkPassedThe description follows the template's Problem, Change, Scope and approval, and Verification sections. It explains the unused index and its insert cost, and it names the migration, the preserved colum…
      Linked Issues checkPassedIssue [#20534] requires removal of only idx_orch_events_correlation_id, preservation of correlation_id values, and retention of the other event indexes, including `idx_orchestration_events_agent_s…
      Out of Scope Changes checkPassedThe whole-PR diff contains the migration, its registry entry, migration-preview expectation updates, and the regression test. These changes directly implement and validate issue [#20534]. No unrelated…
      Full details: Title check

      Explanation

      The title "fix(server): stop maintaining the unused event correlation index" matches the main change: migration 078 drops idx_orch_events_correlation_id, which no server query uses. It uses a conventional commit prefix and is specific, and it does not mention the preserved column or other indexes, which is acceptable.

      Full details: Description check

      Explanation

      The description follows the template's Problem, Change, Scope and approval, and Verification sections. It explains the unused index and its insert cost, and it names the migration, the preserved column and indexes, and the regression test. It links issue #20534 and reports focused tests, targeted lint, typecheck, and a runtime upgrade check. The template's wording says the verification must not be "tests pass" alone, and this description gives observed results. Minor gaps: the Change section says "migration 68" while the file is 078, and the agent/model attribution line is present. These are non-critical, so the check passes.

      Full details: Linked Issues check

      Explanation

      Issue [#20534] requires removal of only idx_orch_events_correlation_id, preservation of correlation_id values, and retention of the other event indexes, including idx_orchestration_events_agent_stream_sequence. Migration 078 executes only DROP INDEX IF EXISTS idx_orch_events_correlation_id. The new migration test verifies the target index is absent, the correlation value remains, and the required indexes remain. The migration is registered in Migrations.ts, and both migration-preview expectations include it. The implementation uses migration 78 rather than the description's stated migration 68; the issue does not require a specific migration number.

      Full details: Out of Scope Changes check

      Explanation

      The whole-PR diff contains the migration, its registry entry, migration-preview expectation updates, and the regression test. These changes directly implement and validate issue [#20534]. No unrelated client, contract, or product-behavior changes are present in the diff.

      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

      CodeRabbit Verify

      • Run CodeRabbit Verify to test the changes in this pull request.
      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 059313e6e999294ab8d71cc9c95e4108738594d7 and 63325c7f9902c5a20c5e426d16cab0418c0f77fc.

      Files selected for processing: 3
      • apps/server/src/persistence/Migrations.ts
      • apps/server/src/persistence/Migrations/078_DropOrchestrationEventCorrelationIndex.ts
      • apps/server/src/persistence/reconcileV2PreviewMigration.test.ts

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

    4. juliusmarminge added labelsvia-triage:gates-failing

    5. juliusmarminge added labelsbugfix

    6. juliusmarminge removed labelsvia-triage:gates-failing

    7. juliusmarminge added labelspr:gate-failed

    8. juliusmarminge removed labelspr:gate-failed

    9. juliusmarminge added labelspr:ready

    10. juliusmarminge merged this93a3e8f

    11. juliusmarminge closed this

    12. The automated pipeline stopped on this pull request and will not merge it:

      the proof has no capture anyone can open:

      • Base reproduction: the specified merge-base lacks the affected Swift client; an unfixed Swift commit is needed for a valid comparison.
      • Head behavior: folder browsing, clone destination defaults, environment reseeding, blank-setting fallback, and preservation of manual edits were not exercised.
      • No captures were produced, so there are no public evidence URLs. No upload was attempted.

      It stays open for a person to finish or close.

Sign in to join this conversation.