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, 12:00 UTC
perf(server): thread recovery reads are 10x faster (#27099)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 29, 2026 at 13:17 UTC
624e70ecdd48c388c324e18eaa170dd62319cb28
4 files changed
+37
-1
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+14
-1
@@ -6640,10 +6640,23 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
6640
completedAt: releasedAt,
6641
},
6642
});
6643
+ const { statements, tracer } = traceSqlStatements();
6644
assert.deepEqual(
6644
- (yield* store.getRuntimeRecoveryProjection(threadId)).runs.map((run) => run.id),
6645
+ (yield* store
6646
+ .getRuntimeRecoveryProjection(threadId)
6647
+ .pipe(Effect.withTracer(tracer))).runs.map((run) => run.id),
6648
[runId, newerRunId],
6649
);
6650
+ // Live-item filters must hit the active partial indexes, not walk the thread's history.
6651
+ const sql = yield* SqlClient.SqlClient;
6652
+ for (const statement of statements.filter((query) => query.includes("turn_items"))) {
6653
+ const plan = (yield* sql.unsafe<{ readonly detail: string }>(
6654
+ `EXPLAIN QUERY PLAN ${statement}`,
6655
+ )).map((row) => row.detail);
6656
+ for (const detail of plan) {
6657
+ assert.notMatch(detail, /turn_items_(thread_ordinal|thread_run)_idx \(thread_id=\?\)$/);
6658
+ }
6659
+ }
6660
}),
6661
);
6662
});
apps/server/src/persistence/Migrations.ts
+2
@@ -75,6 +75,7 @@ import Migration0069 from "./Migrations/069_ThreadMessageSearch.ts";
75
import Migration0070 from "./Migrations/070_PeerLinks.ts";
76
import Migration0071 from "./Migrations/071_PeerLinkFence.ts";
77
import Migration0072 from "./Migrations/072_WaitingLinkRequestIndex.ts";
78
+import Migration0073 from "./Migrations/073_ActiveTurnItemIndexes.ts";
79
80
const migrationEntries = [
81
[1, "OrchestrationEvents", Migration0001],
@@ -150,6 +151,7 @@ const migrationEntries = [
151
[70, "PeerLinks", Migration0070],
152
[71, "PeerLinkFence", Migration0071],
153
[72, "WaitingLinkRequestIndex", Migration0072],
154
+ [73, "ActiveTurnItemIndexes", Migration0073],
155
] as const;
156
157
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
apps/server/src/persistence/Migrations/073_ActiveTurnItemIndexes.ts
new
+19
@@ -0,0 +1,19 @@
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
+ // Recovery and provider-thread reads filter live items by this exact predicate; without
8
+ // these, each read walked every historical item in the thread.
9
+ yield* sql`
10
+ CREATE INDEX orchestration_v2_projection_turn_items_active_ordinal_idx
11
+ ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)
12
+ WHERE status IN ('pending', 'running', 'waiting')
13
+ `;
14
+ yield* sql`
15
+ CREATE INDEX orchestration_v2_projection_turn_items_active_run_idx
16
+ ON orchestration_v2_projection_turn_items(thread_id, run_id)
17
+ WHERE status IN ('pending', 'running', 'waiting')
18
+ `;
19
+});
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
+2
@@ -52,6 +52,7 @@ describe("V2 preview upgrade", () => {
52
[70, "PeerLinks"],
53
[71, "PeerLinkFence"],
54
[72, "WaitingLinkRequestIndex"],
55
+ [73, "ActiveTurnItemIndexes"],
56
]);
57
assert.deepStrictEqual(yield* runMigrations(), []);
58
assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -147,6 +148,7 @@ describe("V2 preview upgrade", () => {
148
[70, "PeerLinks"],
149
[71, "PeerLinkFence"],
150
[72, "WaitingLinkRequestIndex"],
151
+ [73, "ActiveTurnItemIndexes"],
152
]);
153
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
154
);