|
5 | 5 | NodeId, |
6 | 6 | ORCHESTRATION_V2_WS_METHODS, |
7 | 7 | RuntimeRequestId, |
| 8 | + RunId, |
8 | 9 | ThreadId, |
9 | 10 | TurnItemId, |
10 | 11 | type OrchestrationV2ThreadDetailSnapshot, |
@@ -2150,6 +2151,51 @@ describe("EnvironmentThreads", () => { |
2150 | 2151 | }), |
2151 | 2152 | ); |
2152 | 2153 |
|
| 2154 | + it.effect("caches a running thread once when its view closes, not on each update", () => |
| 2155 | + Effect.gen(function* () { |
| 2156 | + const scope = yield* Scope.make(); |
| 2157 | + const harness = yield* makeHarness().pipe(Effect.provideService(Scope.Scope, scope)); |
| 2158 | + const running: OrchestrationV2ThreadProjection = { |
| 2159 | + ...BASE_PROJECTION, |
| 2160 | + runs: [ |
| 2161 | + { |
| 2162 | + id: RunId.make("run-running"), |
| 2163 | + threadId: THREAD_ID, |
| 2164 | + ordinal: 1, |
| 2165 | + providerInstanceId: BASE_PROJECTION.thread.providerInstanceId, |
| 2166 | + modelSelection: BASE_PROJECTION.thread.modelSelection, |
| 2167 | + providerThreadId: null, |
| 2168 | + userMessageId: MessageId.make("message-running"), |
| 2169 | + rootNodeId: null, |
| 2170 | + activeAttemptId: null, |
| 2171 | + status: "running", |
| 2172 | + requestedAt: v2Now, |
| 2173 | + startedAt: v2Now, |
| 2174 | + completedAt: null, |
| 2175 | + checkpointId: null, |
| 2176 | + contextHandoffId: null, |
| 2177 | + }, |
| 2178 | + ], |
| 2179 | + }; |
| 2180 | + yield* Queue.offer(harness.inputs, snapshot(running, 4)); |
| 2181 | + yield* Queue.offer(harness.inputs, titleUpdated("Streaming update", 5)); |
| 2182 | + yield* awaitThreadState( |
| 2183 | + harness.observed, |
| 2184 | + (value) => |
| 2185 | + Option.isSome(value.data) && value.data.value.thread.title === "Streaming update", |
| 2186 | + ); |
| 2187 | + yield* TestClock.adjust("10 seconds"); |
| 2188 | + expect(yield* Ref.get(harness.savedThreads)).toHaveLength(0); |
| 2189 | + |
| 2190 | + yield* Scope.close(scope, Exit.void); |
| 2191 | + const saved = yield* Ref.get(harness.savedThreads); |
| 2192 | + expect(saved).toHaveLength(1); |
| 2193 | + expect(saved[0]?.snapshotSequence).toBe(5); |
| 2194 | + expect(saved[0]?.projection.thread.title).toBe("Streaming update"); |
| 2195 | + expect(saved[0]?.projection.runs[0]?.status).toBe("running"); |
| 2196 | + }), |
| 2197 | + ); |
| 2198 | + |
2153 | 2199 | it.effect("preserves data after a domain failure and resumes on a replacement session", () => |
2154 | 2200 | Effect.gen(function* () { |
2155 | 2201 | const harness = yield* makeHarness({ cached: BASE_PROJECTION }); |
|
0 commit comments