The best way to control Claude Code, Codex and more from any computer or phone
fix(server): migrate-dev-db no longer trips over webhook tables (#24404)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 24, 2026 at 11:49 UTC
79014e6c41e99344c59470c3b315da4ce3ba162d
2 files changed
+31
-3
apps/server/scripts/migrate-dev-db.test.ts
+15
-2
@@ -87,6 +87,12 @@ const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(functio
87
created_at, updated_at, last_run_status, run_count)
88
VALUES ('task-1', 'Nightly', 'Run it', 1, '{}', 'project-kept', '{}', '{}',
89
'full-access', 'default', 'user', 'user', '2026-08-01', '2026-08-01', 'never', 0)`;
90
+ yield* sql`INSERT INTO scheduled_task_webhook_replay_keys
91
+ (task_id, replay_key, delivery_id, expires_at)
92
+ VALUES ('task-1', 'replay-1', 'delivery-1', 1900000000000)`;
93
+ yield* sql`INSERT INTO scheduled_task_webhook_pending
94
+ (delivery_id, task_id, coalesce_key, due_at, task_json, request_json, delivery_ids_json)
95
+ VALUES ('delivery-1', 'task-1', 'key-1', 1900000000000, '{}', '{}', '[]')`;
96
yield* sql`INSERT INTO auth_sessions (session_id, subject, scopes, method, issued_at, expires_at)
97
VALUES ('session-1', 'user', '[]', 'pairing', '2026-08-01', '2027-08-01')`;
98
}),
@@ -119,10 +125,17 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
125
SELECT stream_id FROM orchestration_events ORDER BY stream_id`;
126
const sessions = yield* sql<{ provider_session_id: string }>`
127
SELECT provider_session_id FROM orchestration_v2_projection_provider_sessions`;
122
- const [leftovers] = yield* sql<{ auth: number; tasks: number; transfers: number }>`
128
+ const [leftovers] = yield* sql<{
129
+ auth: number;
130
+ tasks: number;
131
+ webhooks: number;
132
+ transfers: number;
133
+ }>`
134
SELECT
135
(SELECT COUNT(*) FROM auth_sessions) AS auth,
136
(SELECT COUNT(*) FROM scheduled_tasks) AS tasks,
137
+ (SELECT COUNT(*) FROM scheduled_task_webhook_replay_keys) +
138
+ (SELECT COUNT(*) FROM scheduled_task_webhook_pending) AS webhooks,
139
(SELECT COUNT(*) FROM orchestration_v2_projection_context_transfers) AS transfers`;
140
return { threads, events, sessions, leftovers };
141
}),
@@ -139,7 +152,7 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
152
kept.sessions.map((row) => row.provider_session_id),
153
["session-shared"],
154
);
142
- assert.deepStrictEqual(kept.leftovers, { auth: 0, tasks: 0, transfers: 0 });
155
+ assert.deepStrictEqual(kept.leftovers, { auth: 0, tasks: 0, webhooks: 0, transfers: 0 });
156
}),
157
);
158
apps/server/scripts/migrate-dev-db.ts
+16
-1
@@ -250,6 +250,21 @@ const copySourceSlice = Effect.fn("copyDevDbSourceSlice")(function* (sourcePath:
250
);
251
const tables = schema.filter((entry) => entry.type === "table" && !isShadowTable(entry.name));
252
const filtered = tables.some((table) => table.name === "orchestration_v2_projection_threads");
253
+ // A row that points into a cleared table cannot be copied, so whatever references one is
254
+ // cleared with it, however far down the chain a newer migration added it.
255
+ const references = yield* sql<{ name: string; parent: string }>`
256
+ SELECT m.name, f."table" AS parent FROM src.sqlite_master m, pragma_foreign_key_list(m.name, 'src') f
257
+ WHERE m.type = 'table'`;
258
+ const cleared = new Set(CLEARED_TABLES);
259
+ for (let grew = true; grew;) {
260
+ grew = false;
261
+ for (const { name, parent } of references) {
262
+ if (cleared.has(parent) && !cleared.has(name)) {
263
+ cleared.add(name);
264
+ grew = true;
265
+ }
266
+ }
267
+ }
268
269
yield* sql.withTransaction(
270
Effect.gen(function* () {
@@ -263,7 +278,7 @@ const copySourceSlice = Effect.fn("copyDevDbSourceSlice")(function* (sourcePath:
278
WHERE ${rootIsVisible(sql)}`;
279
}
280
for (const { name } of tables) {
266
- if (CLEARED_TABLES.includes(name) || virtualTables.includes(name)) continue;
281
+ if (cleared.has(name) || virtualTables.includes(name)) continue;
282
const nullable = threadIdNullable.get(name);
283
const filter = !filtered
284
? ""