Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): coalesce tool output before it fills the live buffer #16317

Mergedsnarkyalyx(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/16317/headmerged by maria-rcks View on GitHub

Showing 3 changed files with 151 additions and 19 deletions.

x
0 of 3 viewed, 3 left
57 additions and 0 deletionsapps/server/src/orchestration-v2/LiveStreamBudget.test.tsModified
View file
@@ -87,6 +87,63 @@
});
​
describe("replayAndBufferProjectedLiveEvents", () => {
+ it.effect.each(["items", "bytes"] as const)(
+ "replays the undelivered tail after a %s overflow without losing or duplicating events",
+ (limit) =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const pubsub = yield* PubSub.unbounded<Event>();
+ const subscribed = yield* Deferred.make<PubSub.Subscription<Event>>();
+ const events = [
+ { sequence: 1, text: "one" },
+ { sequence: 2, text: "two" },
+ { sequence: 3, text: "three" },
+ ];
+ const limits = limit === "items" ? { maxItems: 1 } : { maxSerializedBytes: 40 };
+ const pull = yield* Stream.toPull(
+ replayAndBufferProjectedLiveEvents(
+ {
+ project: (event: Event) => event,
+ subscribe: PubSub.subscribe(pubsub).pipe(
+ Effect.tap((subscription) => Deferred.succeed(subscribed, subscription)),
+ ),
+ latestSequence: Effect.succeed(1),
+ replay: () => Stream.succeed(events[0]!),
+ },
+ limits,
+ ),
+ );