Skip to content

Commit 496856d

Browse files
fix(server): migration 64 skips thread payloads that are not valid JSON (pingdotgg#35884)
1 parent b23f94e commit 496856d

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎apps/server/src/persistence/Migrations/064_CanonicalizeThreadPullRequestLinks.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,36 @@ layer("064_CanonicalizeThreadPullRequestLinks", (it) => {
123123
'user', ${v1Payload}, '{}', 1)
124124
`;
125125

126+
yield* sql`
127+
INSERT INTO orchestration_v2_projection_threads (
128+
thread_id, project_id, title, default_provider, runtime_mode, interaction_mode,
129+
created_at, updated_at, payload_json
130+
) VALUES (
131+
'damaged', 'project-1', 'damaged', 'codex', 'full-access', 'default',
132+
${updatedAt}, ${updatedAt}, ''
133+
)
134+
`;
135+
yield* sql`
136+
INSERT INTO orchestration_events (
137+
event_id, aggregate_kind, stream_id, stream_version, event_type, occurred_at,
138+
actor_kind, payload_json, metadata_json, application_event_version
139+
) VALUES ('event:damaged', 'thread', 'damaged', 0, 'thread.created', ${updatedAt},
140+
'user', '', '{}', 2)
141+
`;
142+
126143
assert.deepEqual(yield* runMigrations({ toMigrationInclusive: 64 }), [
127144
[64, "CanonicalizeThreadPullRequestLinks"],
128145
]);
146+
const [damagedThread] = yield* sql<{ readonly payload_json: string }>`
147+
SELECT payload_json FROM orchestration_v2_projection_threads WHERE thread_id = 'damaged'
148+
`;
149+
const [damagedEvent] = yield* sql<{ readonly payload_json: string }>`
150+
SELECT payload_json FROM orchestration_events WHERE event_id = 'event:damaged'
151+
`;
152+
assert.equal(damagedThread?.payload_json, "");
153+
assert.equal(damagedEvent?.payload_json, "");
154+
yield* sql`DELETE FROM orchestration_v2_projection_threads WHERE thread_id = 'damaged'`;
155+
yield* sql`DELETE FROM orchestration_events WHERE event_id = 'event:damaged'`;
129156
assert.deepEqual(yield* runMigrations({ toMigrationInclusive: 64 }), []);
130157
const rows = yield* sql<{ readonly thread_id: string; readonly payload_json: string }>`
131158
SELECT thread_id, payload_json FROM orchestration_v2_projection_threads

‎apps/server/src/persistence/Migrations/064_CanonicalizeThreadPullRequestLinks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default Effect.gen(function* () {
3434
updated_at
3535
FROM orchestration_v2_projection_threads
3636
WHERE thread_id > ${afterThreadId}
37+
AND json_valid(payload_json)
3738
AND json_type(payload_json, '$.pullRequests') IS NULL
3839
AND json_type(payload_json, '$.linkedPullRequest') = 'object'
3940
ORDER BY thread_id
@@ -65,6 +66,7 @@ export default Effect.gen(function* () {
6566
WHERE sequence > ${afterSequence}
6667
AND application_event_version = 2 AND aggregate_kind = 'thread'
6768
AND event_type LIKE 'thread.%'
69+
AND json_valid(payload_json)
6870
AND json_type(payload_json, '$.pullRequests') IS NULL
6971
AND json_type(payload_json, '$.linkedPullRequest') = 'object'
7072
ORDER BY sequence

0 commit comments

Comments
 (0)