GeezerVison is showing github.com — perf(client-runtime): skip history scans when no runs are queued (#25… · pingdotgg/t3code@ff4197c
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/client-runtime/src/state
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadWorkflows.test.ts +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts"; |
4 | 4 | import { |
5 | 5 | canForkProjectedAssistantItem, |
6 | 6 | deriveThreadQueueWorkflowState, |
| 7 | + getUserQueuedThreadRuns, |
7 | 8 | resolveLatestMergeBackRun, |
8 | 9 | threadSupportsProviderHandoff, |
9 | 10 | } from "./threadWorkflows.ts"; |
@@ -30,6 +31,24 @@ const capabilities = (input?: { |
30 | 31 | }) as never; |
31 | 32 |
|
32 | 33 | describe("thread workflows", () => { |
| 34 | + it("skips message history classification when no runs are queued", () => { |
| 35 | + let metadataReads = 0; |
| 36 | + const message = { |
| 37 | + id: "message", |
| 38 | + get delegatedCompletion() { |
| 39 | + metadataReads++; |
| 40 | + return undefined; |
| 41 | + }, |
| 42 | + }; |
| 43 | + const projection = { |
| 44 | + runs: [{ id: "active", status: "running", userMessageId: "message", ordinal: 1 }], |
| 45 | + messages: [message], |
| 46 | + } as never; |
| 47 | + |
| 48 | + expect(getUserQueuedThreadRuns(projection)).toEqual([]); |
| 49 | + expect(metadataReads).toBe(0); |
| 50 | + }); |
| 51 | + |
33 | 52 | it("allows a completed thread to switch providers after its session detaches", () => { |
34 | 53 | const projection = { |
35 | 54 | thread: { |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadWorkflows.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,6 +125,8 @@ export function threadSupportsProviderHandoff(projection: Projection | null | un |
125 | 125 | export function getUserQueuedThreadRuns( |
126 | 126 | projection: Pick<Projection, "runs" | "messages">, |
127 | 127 | ): ReadonlyArray<Run> { |
| 128 | + if (!projection.runs.some((run) => run.status === "queued")) return []; |
| 129 | + |
128 | 130 | const automaticCompletionMessageIds = new Set( |
129 | 131 | projection.messages |
130 | 132 | .filter( |
|