Skip to content

Commit 0a9abdd

Browse files
fix(server): dev database seed drops active pull request watches (#32744)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6b96956 commit 0a9abdd

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎apps/server/scripts/migrate-dev-db.test.ts‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,33 @@ const createFixtureSource = Effect.fn("createMigrateDevDbFixtureSource")(functio
3838
'{"lineage":{"parentThreadId":"stopped-thread","relationshipToParent":"fork","rootThreadId":"stopped-thread"}}';
3939
const subagentPayload =
4040
'{"lineage":{"parentThreadId":"subagent-parent","relationshipToParent":"subagent","rootThreadId":"subagent-parent"},"forkedFrom":{"type":"node","nodeId":"node-1"}}';
41+
const watchedPayload = JSON.stringify({
42+
pullRequests: [
43+
{
44+
host: "github.com",
45+
repository: "owner/repo",
46+
number: 7,
47+
url: "https://github.com/owner/repo/pull/7",
48+
source: "agent",
49+
linkedAt: "2026-08-01T00:00:00.000Z",
50+
snapshot: null,
51+
stack: null,
52+
watch: {
53+
startedAt: "2026-08-01T00:00:00.000Z",
54+
headSha: null,
55+
failedChecks: [],
56+
passed: false,
57+
passedChecks: [],
58+
remarksThrough: "2026-08-01T00:00:00.000Z",
59+
remarkIds: [],
60+
conflicting: false,
61+
wakes: 0,
62+
},
63+
},
64+
],
65+
});
4166
const threads = [
42-
["stopped-thread", "project-kept", "completed", "{}", "2026-08-01"],
67+
["stopped-thread", "project-kept", "completed", watchedPayload, "2026-08-01"],
4368
["fork-thread", "project-kept", "completed", forkPayload, "2026-08-02"],
4469
["running-thread", "project-kept", "running", "{}", "2026-08-05"],
4570
["settled-thread", "project-kept", "completed", '{"settledAt":"2026-08-01"}', "2026-08-05"],
@@ -129,6 +154,11 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
129154
SELECT stream_id FROM orchestration_events ORDER BY stream_id`;
130155
const sessions = yield* sql<{ provider_session_id: string }>`
131156
SELECT provider_session_id FROM orchestration_v2_projection_provider_sessions`;
157+
const [pullRequest] = yield* sql<{ url: string | null; watch: string | null }>`
158+
SELECT
159+
json_extract(payload_json, '$.pullRequests[0].url') AS url,
160+
json_extract(payload_json, '$.pullRequests[0].watch') AS watch
161+
FROM orchestration_v2_projection_threads WHERE thread_id = 'stopped-thread'`;
132162
const [leftovers] = yield* sql<{
133163
auth: number;
134164
tasks: number;
@@ -143,7 +173,7 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
143173
(SELECT COUNT(*) FROM scheduled_task_webhook_pending) AS webhooks,
144174
(SELECT COUNT(*) FROM orchestration_v2_projection_context_transfers) AS transfers,
145175
(SELECT COUNT(*) FROM peer_environment_links) AS links`;
146-
return { threads, events, sessions, leftovers };
176+
return { threads, events, sessions, pullRequest, leftovers };
147177
}),
148178
);
149179
assert.deepStrictEqual(
@@ -158,6 +188,11 @@ it.layer(NodeServices.layer)("migrate-dev-db", (it) => {
158188
kept.sessions.map((row) => row.provider_session_id),
159189
["session-shared"],
160190
);
191+
assert.deepStrictEqual(
192+
kept.pullRequest,
193+
{ url: "https://github.com/owner/repo/pull/7", watch: null },
194+
"copied pull request links keep their history but stop being watched",
195+
);
161196
assert.deepStrictEqual(kept.leftovers, {
162197
auth: 0,
163198
tasks: 0,

‎apps/server/scripts/migrate-dev-db.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ const pruneSnapshot = Effect.fn("pruneDevDbSnapshot")(function* (input: RunMigra
381381
AND stream_id NOT IN (SELECT thread_id FROM kept_threads))
382382
OR (aggregate_kind = 'project'
383383
AND stream_id NOT IN (SELECT project_id FROM kept_projects))`;
384+
yield* sql`UPDATE orchestration_v2_projection_threads
385+
SET payload_json = json_set(payload_json, '$.pullRequests', (
386+
SELECT json_group_array(json_remove(link.value, '$.watch') ORDER BY link.key)
387+
FROM json_each(payload_json, '$.pullRequests') AS link))
388+
WHERE EXISTS (
389+
SELECT 1 FROM json_each(payload_json, '$.pullRequests') AS link
390+
WHERE json_extract(link.value, '$.watch') IS NOT NULL)`;
384391
for (const table of CLEARED_TABLES) {
385392
yield* sql`DELETE FROM ${sql(table)}`;
386393
}

0 commit comments

Comments
 (0)