Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): opening a long thread reads from its latest segments, not its whole history #33305

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/33305/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 3 changed files with 188 additions and 4 deletions.

x
0 of 3 viewed, 3 left
140 additions and 0 deletionsapps/server/src/orchestration-v2/ProjectionStore.test.tsModified
View file
@@ -1,3 +1,5 @@
+import * as NodeSqlite from "node:sqlite";
+​
import { assert, it, vi } from "@effect/vitest";
import {
EnvironmentId,
@@ -57,6 +59,13 @@
​
import { layerReaderDatabase, traceSqlRouting } from "../persistence/testkit/SqliteRouting.ts";
​
+declare module "node:sqlite" {
+ interface StatementSync {
+ // Node 26 has this; @types/node 24 does not declare it yet.
+ stat(counter: "vmStep"): number;
+ }
+}
+​
const layerTest = Layer.mergeAll(
ProjectionStore.layer.pipe(Layer.provideMerge(SqlitePersistence.layerMemory)),
SqlitePersistence.layerMemory,
@@ -3356,6 +3365,137 @@
yield* sql`UPDATE orchestration_v2_projection_turn_items SET ordinal = 999,
payload_json = json_set(payload_json, '$.ordinal', 999)
WHERE turn_item_id = 'turn-item:bounded-sql-history:999'`;
+ // Work folded below the newest 502 visible rows still counts its whole group, so the
+ // 100 commands after the messages stay hidden in the 398-item group.
+ yield* sql`UPDATE orchestration_v2_projection_turn_items SET type = 'assistant_message',
+ payload_json = json_set(payload_json, '$.type', 'assistant_message', '$.text', 'Working',
+ '$.messageId', turn_item_id, '$.streaming', json('false'))