Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): bound ordinal recovery to selected messages #27495

MergedMotaghi(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/27495/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 72 additions and 0 deletions.

x
0 of 2 viewed, 2 left
63 additions and 0 deletionsapps/server/src/orchestration-v2/ProjectionStore.test.tsModified
View file
@@ -2097,6 +2097,69 @@
byteIds,
Array.from({ length: 70 }, (_, index) => `turn-item:bounded-sql-history:${index + 1}`),
+​
+ // Selected message reads recover ordinals for only the loaded messages, while 69
+ // unloaded assistant messages remain in the thread's history.
+ const firstMessageId = MessageId.make("message:bounded-sql-history:1");
+ const lastMessageId = MessageId.make("message:bounded-sql-history:1000");
+ const insertMessageItem = (
+ suffix: string,
+ itemThreadId: string,
+ ordinal: number,
+ messageId: string | null | undefined,
+ ) => sql`
+ INSERT INTO orchestration_v2_projection_turn_items (
+ turn_item_id, thread_id, run_id, node_id, provider_thread_id, provider_turn_id,
+ parent_item_id, ordinal, type, status, updated_at, payload_json
+ ) VALUES (
+ ${`turn-item:bounded-sql-history:ordinal-${suffix}`}, ${itemThreadId}, NULL, NULL, NULL,
+ NULL, NULL, ${ordinal}, 'assistant_message', 'completed', ${nowIso},
+ ${encodeUnknownJsonString({ messageId })}
+ )
+ `;
+ yield* insertMessageItem("duplicate", threadId, 0, lastMessageId);
+ yield* insertMessageItem(
+ "other-thread",
+ "thread:bounded-sql-history:other",
+ -1,
+ firstMessageId,