The best way to control Claude Code, Codex and more from any computer or phone
fix(server): drop V1 projections nothing reads after the V2 upgrade (#20947)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 17, 2026 at 10:24 UTC
7e0418a641e3009be070cd4506d6b8aa68d6d486
6 files changed
+76
-91
apps/server/src/persistence/Migrations.ts
+2
@@ -65,6 +65,7 @@ import Migration0059 from "./Migrations/059_McpAppModelContext.ts";
65
import Migration0060 from "./Migrations/060_ThreadSnapshotWindowIndexes.ts";
66
import Migration0061 from "./Migrations/061_PullRequestReviewGuides.ts";
67
import Migration0062 from "./Migrations/062_ThreadFailureLookupIndex.ts";
68
+import Migration0063 from "./Migrations/063_DropUnusedV1Projections.ts";
69
70
export const migrationEntries = [
71
[1, "OrchestrationEvents", Migration0001],
@@ -130,6 +131,7 @@ export const migrationEntries = [
131
[60, "ThreadSnapshotWindowIndexes", Migration0060],
132
[61, "PullRequestReviewGuides", Migration0061],
133
[62, "ThreadFailureLookupIndex", Migration0062],
134
+ [63, "DropUnusedV1Projections", Migration0063],
135
] as const;
136
137
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
apps/server/src/persistence/Migrations/055_OrchestrationV2.test.ts
+3
-1
@@ -13,7 +13,7 @@ layer("055_OrchestrationV2", (it) => {
13
Effect.sync(() => {
14
assert.deepStrictEqual(
15
migrationEntries.map(([id]) => id),
16
- Array.from({ length: 62 }, (_, index) => index + 1),
16
+ Array.from({ length: 63 }, (_, index) => index + 1),
17
);
18
}),
19
);
@@ -34,6 +34,7 @@ layer("055_OrchestrationV2", (it) => {
34
[60, "ThreadSnapshotWindowIndexes"],
35
[61, "PullRequestReviewGuides"],
36
[62, "ThreadFailureLookupIndex"],
37
+ [63, "DropUnusedV1Projections"],
38
]);
39
assert.deepStrictEqual(yield* runMigrations(), []);
40
@@ -62,6 +63,7 @@ layer("055_OrchestrationV2", (it) => {
63
{ migration_id: 60, name: "ThreadSnapshotWindowIndexes" },
64
{ migration_id: 61, name: "PullRequestReviewGuides" },
65
{ migration_id: 62, name: "ThreadFailureLookupIndex" },
66
+ { migration_id: 63, name: "DropUnusedV1Projections" },
67
]);
68
69
const tables = yield* sql<{ readonly name: string }>`
apps/server/src/persistence/Migrations/063_DropUnusedV1Projections.test.ts
new
+49
@@ -0,0 +1,49 @@
1
+import { assert, it } from "@effect/vitest";
2
+import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
3
+import * as Effect from "effect/Effect";
4
+import * as SqlClient from "effect/sql/SqlClient";
5
+
6
+import { runMigrations } from "../Migrations.ts";
7
+
8
+const layer = it.layer(NodeSqliteClient.layer({ filename: ":memory:" }));
9
+
10
+layer("063_DropUnusedV1Projections", (it) => {
11
+ it.effect("drops V1 projections nothing reads and keeps the transcript import sources", () =>
12
+ Effect.gen(function* () {
13
+ const sql = yield* SqlClient.SqlClient;
14
+ yield* runMigrations({ toMigrationInclusive: 62 });
15
+ yield* sql`
16
+ INSERT INTO projection_thread_messages
17
+ (message_id, thread_id, role, text, is_streaming, created_at, updated_at)
18
+ VALUES ('message-1', 'thread-1', 'user', 'hello', 0, '2026-01-01', '2026-01-01')
19
+ `;
20
+
21
+ yield* runMigrations({ toMigrationInclusive: 63 });
22
+
23
+ const rows = yield* sql<{ readonly name: string }>`
24
+ SELECT name FROM sqlite_master WHERE type = 'table'
25
+ `;
26
+ const tables = new Set(rows.map((row) => row.name));
27
+ for (const dropped of [
28
+ "projection_thread_activities",
29
+ "projection_turns",
30
+ "projection_thread_proposed_plans",
31
+ "projection_pending_approvals",
32
+ "projection_state",
33
+ "checkpoint_diff_blobs",
34
+ ]) {
35
+ assert.isFalse(tables.has(dropped), dropped);
36
+ }
37
+ for (const kept of [
38
+ "projection_threads",
39
+ "projection_thread_messages",
40
+ "projection_thread_pull_requests",
41
+ ]) {
42
+ assert.isTrue(tables.has(kept), kept);
43
+ }
44
+ assert.deepEqual(yield* sql`SELECT message_id FROM projection_thread_messages`, [
45
+ { message_id: "message-1" },
46
+ ]);
47
+ }),
48
+ );
49
+});
apps/server/src/persistence/Migrations/063_DropUnusedV1Projections.ts
new
+20
@@ -0,0 +1,20 @@
1
+import * as Effect from "effect/Effect";
2
+import * as SqlClient from "effect/sql/SqlClient";
3
+
4
+/**
5
+ * V2 databases start as a copy of the V1 database, and nothing reads these V1
6
+ * projections after the copy. The V1 transcript import still reads threads,
7
+ * messages and pull request links, so those stay. Builds before 0.1.0 read
8
+ * `state.sqlite`, never this file, so dropping them does not affect a rollback.
9
+ * The freed pages are reported as reclaimable space for `t3 doctor`.
10
+ */
11
+export default Effect.gen(function* () {
12
+ const sql = yield* SqlClient.SqlClient;
13
+
14
+ yield* sql`DROP TABLE IF EXISTS projection_thread_activities`;
15
+ yield* sql`DROP TABLE IF EXISTS projection_turns`;
16
+ yield* sql`DROP TABLE IF EXISTS projection_thread_proposed_plans`;
17
+ yield* sql`DROP TABLE IF EXISTS projection_pending_approvals`;
18
+ yield* sql`DROP TABLE IF EXISTS projection_state`;
19
+ yield* sql`DROP TABLE IF EXISTS checkpoint_diff_blobs`;
20
+});
apps/server/src/persistence/reconcileV2PreviewMigration.test.ts
+2
@@ -42,6 +42,7 @@ describe("V2 preview upgrade", () => {
42
[60, "ThreadSnapshotWindowIndexes"],
43
[61, "PullRequestReviewGuides"],
44
[62, "ThreadFailureLookupIndex"],
45
+ [63, "DropUnusedV1Projections"],
46
]);
47
assert.deepStrictEqual(yield* runMigrations(), []);
48
assert.deepStrictEqual(yield* sql`SELECT * FROM orchestration_v2_legacy_imports`, imports);
@@ -127,6 +128,7 @@ describe("V2 preview upgrade", () => {
128
[60, "ThreadSnapshotWindowIndexes"],
129
[61, "PullRequestReviewGuides"],
130
[62, "ThreadFailureLookupIndex"],
131
+ [63, "DropUnusedV1Projections"],
132
]);
133
}).pipe(Effect.provide(NodeSqliteClient.layer({ filename: ":memory:" }))),
134
);
scripts/mobile-showcase-environment.ts
-90
@@ -21,18 +21,6 @@ export const SHOWCASE_SCENES = [
21
] as const;
22
export type ShowcaseScene = (typeof SHOWCASE_SCENES)[number];
23
24
-const PROJECTOR_NAMES = [
25
- "projection.projects",
26
- "projection.threads",
27
- "projection.thread-messages",
28
- "projection.thread-proposed-plans",
29
- "projection.thread-activities",
30
- "projection.thread-sessions",
31
- "projection.thread-turns",
32
- "projection.checkpoints",
33
- "projection.pending-approvals",
34
-] as const;
35
-
24
const MODEL_SELECTION = JSON.stringify({ instanceId: "codex", model: "gpt-5.4" });
25
const PROJECT_SCRIPTS = JSON.stringify([
26
{
@@ -392,23 +380,6 @@ function insertThread(
380
snoozedUntil,
381
snoozedAt,
382
);
395
- database
396
- .prepare(
397
- `INSERT INTO projection_turns (
398
- thread_id, turn_id, pending_message_id, assistant_message_id, state, requested_at,
399
- started_at, completed_at, checkpoint_turn_count, checkpoint_ref, checkpoint_status,
400
- checkpoint_files_json, source_proposed_plan_thread_id, source_proposed_plan_id
401
- ) VALUES (?, ?, NULL, ?, ?, ?, ?, ?, NULL, NULL, NULL, '[]', NULL, NULL)`,
402
- )
403
- .run(
404
- input.id,
405
- turnId,
406
- isWorking ? null : `${input.id}-answer`,
407
- isWorking ? "running" : "completed",
408
- minutesBefore(now, input.minutesAgo + 2),
409
- minutesBefore(now, input.minutesAgo + 2),
410
- isWorking ? null : updatedAt,
411
- );
383
database
384
.prepare(
385
`INSERT INTO projection_thread_sessions (
@@ -424,14 +395,9 @@ function insertThread(
395
// do not read the V1 thread rows; moving the seed to V2 is tracked in
396
// https://github.com/pingdotgg/t3code/issues/15013.
397
const SEEDED_V1_TABLES = [
427
- "projection_pending_approvals",
428
- "projection_thread_proposed_plans",
429
- "projection_thread_activities",
398
"projection_thread_messages",
399
"projection_thread_sessions",
432
- "projection_turns",
400
"projection_threads",
434
- "projection_state",
401
] as const;
402
403
const SEEDED_PROJECTION_TABLES = [...SEEDED_V1_TABLES, "projection_projects"] as const;
@@ -558,62 +524,6 @@ function seedDatabase(
524
}
525
}
526
561
- const turnId = `${SHOWCASE_THREAD_ID}-turn`;
562
- const insertActivity = database.prepare(
563
- `INSERT INTO projection_thread_activities (
564
- activity_id, thread_id, turn_id, tone, kind, summary, payload_json, sequence, created_at
565
- ) VALUES (?, ?, ?, 'tool', 'tool.completed', ?, ?, ?, ?)`,
566
- );
567
- insertActivity.run(
568
- "trace-remote-handoff",
569
- SHOWCASE_THREAD_ID,
570
- turnId,
571
- "Traced the remote handoff path",
572
- JSON.stringify({
573
- itemType: "command_execution",
574
- title: "Traced the remote handoff path",
575
- detail: "Three environments, one continuous workspace",
576
- status: "completed",
577
- }),
578
- 1,
579
- minutesBefore(now, 8),
580
- );
581
- insertActivity.run(
582
- "sync-command-center",
583
- SHOWCASE_THREAD_ID,
584
- turnId,
585
- "Synced the command center",
586
- JSON.stringify({
587
- itemType: "file_change",
588
- title: "Synced the command center",
589
- detail: "2 files changed · instant handoffs · calm reconnects",
590
- status: "completed",
591
- }),
592
- 2,
593
- minutesBefore(now, 6),
594
- );
595
- insertActivity.run(
596
- "run-changed-suite",
597
- SHOWCASE_THREAD_ID,
598
- turnId,
599
- "Ran the changed workspace",
600
- JSON.stringify({
601
- itemType: "command_execution",
602
- title: "Ran the changed workspace",
603
- detail: "612 tests passed · 3 environments online",
604
- status: "completed",
605
- }),
606
- 3,
607
- minutesBefore(now, 4),
608
- );
609
-
610
- for (const [index, projector] of PROJECTOR_NAMES.entries()) {
611
- database
612
- .prepare(
613
- "INSERT INTO projection_state (projector, last_applied_sequence, updated_at) VALUES (?, ?, ?)",
614
- )
615
- .run(projector, index + 1, minutesBefore(now, 1));
616
- }
527
database.exec("COMMIT");
528
} catch (error) {
529
// A failed BEGIN (or an error SQLite already auto-rolled back) leaves no