Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): skip the run history scan when finding a scheduled turn #48256

OpenUtkarshUsername(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48256/headopened View on GitHub

Showing 7 changed files with 76 additions and 0 deletions (loading 4).

x
0 of 7 viewed, 7 left
53 additions and 0 deletionsapps/server/src/orchestration-v2/ProjectionStore.test.tsModified
View file
@@ -575,6 +575,59 @@
}).pipe(Effect.provide(layerTest)),
​
+it.effect("looks up the first scheduled run for a prompt without reading run history", () =>
+ Effect.gen(function* () {
+ const store = yield* ProjectionStore.ProjectionStoreV2;
+ const sql = yield* SqlClient.SqlClient;
+ const threadId = yield* addRolledBackRecoveryCandidate("scheduled-outcome");
+ const scheduledMessageId = MessageId.make("scheduled-task-message:task:test:1:manual");
+ const runCount = 5_000;
+ yield* sql`
+ WITH RECURSIVE history(position) AS (
+ SELECT 2 UNION ALL SELECT position + 1 FROM history WHERE position < ${runCount}
+ )
+ INSERT INTO orchestration_v2_projection_runs (
+ run_id, thread_id, ordinal, provider, provider_instance_id, provider_thread_id,
+ status, requested_at, completed_at, payload_json
+ )
+ SELECT 'run:scheduled-outcome:' || position, thread_id, position, provider,
+ provider_instance_id, provider_thread_id, status, requested_at, completed_at,
+ json_set(payload_json, '$.id', 'run:scheduled-outcome:' || position, '$.ordinal', position,
+ '$.userMessageId', CASE WHEN position >= ${runCount - 1} THEN ${scheduledMessageId}
+ ELSE 'message:scheduled-outcome:' || position END)
+ FROM history CROSS JOIN orchestration_v2_projection_runs
+ WHERE thread_id = ${threadId} AND ordinal = 1
+ `;
+ const history = (yield* store.getThreadRecords(threadId, ["runs"])).runs;
+ const original = history.find((run) => run.userMessageId === scheduledMessageId);
+ assert.lengthOf(history, runCount);