Skip to content
TypeScript

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

Julius Marminge93a3e8fbd332
diff --git a/apps/server/src/persistence/Migrations.test.ts b/apps/server/src/persistence/Migrations.test.ts
index 54e4a711aa8..bf4b9676e2a 100644
--- a/apps/server/src/persistence/Migrations.test.ts
+++ b/apps/server/src/persistence/Migrations.test.ts
@@ -78,6 +78,44 @@ describe("runMigrations", () => {
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
);
+ it.effect("drops the unused correlation index and keeps correlation values", () =>
+ Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+ yield* runMigrations({ toMigrationInclusive: 54 });
+ yield* sql`
+ INSERT INTO orchestration_events (
+ event_id, aggregate_kind, stream_id, stream_version, event_type, occurred_at,
+ command_id, causation_event_id, correlation_id, actor_kind, payload_json, metadata_json
+ )
+ VALUES (
+ 'event-1', 'thread', 'thread-1', 0, 'thread.created', '2026-01-01T00:00:00.000Z',
+ 'command-1', NULL, 'correlation-1', 'client', '{}', '{}'
+ )
+ `;
+
+ yield* runMigrations();
+
+ const indexes = yield* sql<{ readonly name: string }>`
+ SELECT name FROM sqlite_master
+ WHERE type = 'index' AND tbl_name = 'orchestration_events' AND sql IS NOT NULL
+ `;
+ const indexNames = indexes.map((row) => row.name);
+ assert.notInclude(indexNames, "idx_orch_events_correlation_id");
+ for (const kept of [
+ "idx_orch_events_stream_version",
+ "idx_orch_events_stream_sequence",
+ "idx_orch_events_command_id",
+ "idx_orchestration_events_agent_stream_sequence",
+ ]) {
+ assert.include(indexNames, kept);
+ }
+ const events = yield* sql<{ readonly correlation_id: string | null }>`
+ SELECT correlation_id FROM orchestration_events WHERE event_id = 'event-1'
+ `;
+ assert.deepStrictEqual(events, [{ correlation_id: "correlation-1" }]);
+ }).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
+ );
+
it.effect.each([30, 54])("still starts with a site-local migration at id %s", (id) =>
Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
diff --git a/apps/server/src/persistence/Migrations.ts b/apps/server/src/persistence/Migrations.ts
index feab4ef823f..3ee83e5fe01 100644
--- a/apps/server/src/persistence/Migrations.ts
+++ b/apps/server/src/persistence/Migrations.ts
@@ -80,6 +80,7 @@ import Migration0074 from "./Migrations/074_ExcludeAttachmentPlaceholdersFromSea
import Migration0075 from "./Migrations/075_SubagentDeliveryState.ts";
import Migration0076 from "./Migrations/076_ProjectionProjectsPinArchive.ts";
import Migration0077 from "./Migrations/077_RepairBooleanSettledOverride.ts";
+import Migration0078 from "./Migrations/078_DropOrchestrationEventCorrelationIndex.ts";
const migrationEntries = [
[1, "OrchestrationEvents", Migration0001],
@@ -160,6 +161,7 @@ const migrationEntries = [
[75, "SubagentDeliveryState", Migration0075],
[76, "ProjectionProjectsPinArchive", Migration0076],
[77, "RepairBooleanSettledOverride", Migration0077],
+ [78, "DropOrchestrationEventCorrelationIndex", Migration0078],
] as const;
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
diff --git a/apps/server/src/persistence/Migrations/078_DropOrchestrationEventCorrelationIndex.ts b/apps/server/src/persistence/Migrations/078_DropOrchestrationEventCorrelationIndex.ts
new file mode 100644
index 00000000000..bf00778eff5
--- /dev/null
+++ b/apps/server/src/persistence/Migrations/078_DropOrchestrationEventCorrelationIndex.ts
@@ -0,0 +1,10 @@
+import * as Effect from "effect/Effect";
+import * as SqlClient from "effect/sql/SqlClient";
+
+export default Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+
+ // No query filters events by correlation_id, so this index only adds write
+ // and storage cost. The column and its values stay.
+ yield* sql`DROP INDEX IF EXISTS idx_orch_events_correlation_id`;
+});
diff --git a/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts b/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
index 4083978758c..d062961b3af 100644
--- a/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
+++ b/apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
@@ -57,6 +57,7 @@ describe("V2 preview upgrade", () => {
[75, "SubagentDeliveryState"],
[76, "ProjectionProjectsPinArchive"],
[77, "RepairBooleanSettledOverride"],
+ [78, "DropOrchestrationEventCorrelationIndex"],
]);
assert.deepStrictEqual(yield* runMigrations(), []);
assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -157,6 +158,7 @@ describe("V2 preview upgrade", () => {
[75, "SubagentDeliveryState"],
[76, "ProjectionProjectsPinArchive"],
[77, "RepairBooleanSettledOverride"],
+ [78, "DropOrchestrationEventCorrelationIndex"],
]);
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
);