TypeScript
fix(server): keep events during thread subscription startup (#9521)
Theo Browne9c9ae3dc0e94
diff --git a/apps/server/src/server.test.ts b/apps/server/src/server.test.tsindex d972e2e0080..0c6f8b11127 100644--- a/apps/server/src/server.test.ts+++ b/apps/server/src/server.test.ts@@ -7304,7 +7304,6 @@ it.layer(NodeServices.layer)("server router seam", (it) => {projectionSnapshotQuery: {getThreadDetailSnapshot: () =>Effect.gen(function* () {- yield* Effect.sleep("25 millis");yield* PubSub.publish(liveEvents, messageEvent);return Option.some({ snapshotSequence: 1, thread });}),@@ -7317,14 +7316,19 @@ it.layer(NodeServices.layer)("server router seam", (it) => {withWsRpcClient(wsUrl, (client) =>client[ORCHESTRATION_WS_METHODS.subscribeThread]({threadId: defaultThreadId,- }).pipe(Stream.take(2), Stream.runCollect),+ requestCompletionMarker: true,+ }).pipe(+ Stream.takeUntil((item) => item.kind === "synchronized"),+ Stream.runCollect,+ ),),- ).pipe(Effect.timeout("2 seconds"));+ );assert.equal(items[0]?.kind, "snapshot");assert.equal(items[1]?.kind, "event");assert.equal(items[1]?.kind === "event" ? items[1].event.sequence : null, 2);- }).pipe(Effect.provide(NodeHttpServer.layerTest), TestClock.withLive),+ assert.equal(items[2]?.kind, "synchronized");+ }).pipe(Effect.provide(NodeHttpServer.layerTest)),);it.effect("coalesces buffered live tool updates to the latest state", () =>diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.tsindex 839937cf2ea..cb38a684b9b 100644--- a/apps/server/src/ws.ts+++ b/apps/server/src/ws.ts@@ -1549,7 +1549,9 @@ const makeWsRpcLayer = (// Attach live delivery before reading either replay or snapshot state.// Otherwise an event published while the snapshot is loading is lost.const liveBuffer = yield* makeThreadLiveEventCoalescer();- yield* Effect.forkScoped(liveStream.pipe(Stream.runForEach(liveBuffer.offer)));+ yield* Effect.forkScoped(liveStream.pipe(Stream.runForEach(liveBuffer.offer)), {+ startImmediately: true,+ });const bufferedLiveStream = liveBuffer.stream;// When the client already loaded the snapshot over HTTP it passes