@devries-cameron20 / t3code Mirror · read-only / commits / 93a3e8fbd3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 05:45 UTC

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 2, 2026 at 18:32 UTC 93a3e8fbd3323e40c8d1fc8e60f9e5b40d5f2279
4 files changed +52
apps/server/src/persistence/Migrations.test.ts
+38
@@ -78,6 +78,44 @@ describe("runMigrations", () => {
78 }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
79 );
80
81 + it.effect("drops the unused correlation index and keeps correlation values", () =>
82 + Effect.gen(function* () {
83 + const sql = yield* SqlClient.SqlClient;
84 + yield* runMigrations({ toMigrationInclusive: 54 });
85 + yield* sql`
86 + INSERT INTO orchestration_events (
87 + event_id, aggregate_kind, stream_id, stream_version, event_type, occurred_at,
88 + command_id, causation_event_id, correlation_id, actor_kind, payload_json, metadata_json
89 + )
90 + VALUES (
91 + 'event-1', 'thread', 'thread-1', 0, 'thread.created', '2026-01-01T00:00:00.000Z',
92 + 'command-1', NULL, 'correlation-1', 'client', '{}', '{}'
93 + )
94 + `;
95 +
96 + yield* runMigrations();
97 +
98 + const indexes = yield* sql<{ readonly name: string }>`
99 + SELECT name FROM sqlite_master
100 + WHERE type = 'index' AND tbl_name = 'orchestration_events' AND sql IS NOT NULL
101 + `;
102 + const indexNames = indexes.map((row) => row.name);
103 + assert.notInclude(indexNames, "idx_orch_events_correlation_id");
104 + for (const kept of [
105 + "idx_orch_events_stream_version",
106 + "idx_orch_events_stream_sequence",
107 + "idx_orch_events_command_id",
108 + "idx_orchestration_events_agent_stream_sequence",
109 + ]) {
110 + assert.include(indexNames, kept);
111 + }
112 + const events = yield* sql<{ readonly correlation_id: string | null }>`
113 + SELECT correlation_id FROM orchestration_events WHERE event_id = 'event-1'
114 + `;
115 + assert.deepStrictEqual(events, [{ correlation_id: "correlation-1" }]);
116 + }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
117 + );
118 +
119 it.effect.each([30, 54])("still starts with a site-local migration at id %s", (id) =>
120 Effect.gen(function* () {
121 const sql = yield* SqlClient.SqlClient;
apps/server/src/persistence/Migrations.ts
+2
@@ -80,6 +80,7 @@ import Migration0074 from "./Migrations/074_ExcludeAttachmentPlaceholdersFromSea
80 import Migration0075 from "./Migrations/075_SubagentDeliveryState.ts";
81 import Migration0076 from "./Migrations/076_ProjectionProjectsPinArchive.ts";
82 import Migration0077 from "./Migrations/077_RepairBooleanSettledOverride.ts";
83 +import Migration0078 from "./Migrations/078_DropOrchestrationEventCorrelationIndex.ts";
84
85 const migrationEntries = [
86 [1, "OrchestrationEvents", Migration0001],
@@ -160,6 +161,7 @@ const migrationEntries = [
161 [75, "SubagentDeliveryState", Migration0075],
162 [76, "ProjectionProjectsPinArchive", Migration0076],
163 [77, "RepairBooleanSettledOverride", Migration0077],
164 + [78, "DropOrchestrationEventCorrelationIndex", Migration0078],
165 ] as const;
166
167 export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
apps/server/src/persistence/Migrations/078_DropOrchestrationEventCorrelationIndex.ts new
+10
@@ -0,0 +1,10 @@
1 +import * as Effect from "effect/Effect";
2 +import * as SqlClient from "effect/sql/SqlClient";
3 +
4 +export default Effect.gen(function* () {
5 + const sql = yield* SqlClient.SqlClient;
6 +
7 + // No query filters events by correlation_id, so this index only adds write
8 + // and storage cost. The column and its values stay.
9 + yield* sql`DROP INDEX IF EXISTS idx_orch_events_correlation_id`;
10 +});
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
+2
@@ -57,6 +57,7 @@ describe("V2 preview upgrade", () => {
57 [75, "SubagentDeliveryState"],
58 [76, "ProjectionProjectsPinArchive"],
59 [77, "RepairBooleanSettledOverride"],
60 + [78, "DropOrchestrationEventCorrelationIndex"],
61 ]);
62 assert.deepStrictEqual(yield* runMigrations(), []);
63 assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -157,6 +158,7 @@ describe("V2 preview upgrade", () => {
158 [75, "SubagentDeliveryState"],
159 [76, "ProjectionProjectsPinArchive"],
160 [77, "RepairBooleanSettledOverride"],
161 + [78, "DropOrchestrationEventCorrelationIndex"],
162 ]);
163 }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
164 );