Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(hooks): closed late-output windows are dropped as later turns end

Absterrg0f43bd33f85a0
diff --git a/server/host/late-tool-results.test.ts b/server/host/late-tool-results.test.ts
index b9de3f95e9..721e2c07bd 100644
--- a/server/host/late-tool-results.test.ts
+++ b/server/host/late-tool-results.test.ts
@@ -63,4 +63,14 @@ describe("late tool results", () => {
late.turnEnded({ ...turn, toolUseIds: new Set() });
expect(late.holder(bearer)).toBeNull();
});
+
+ it("drops closed windows as later turns end, with no late request to sweep them", () => {
+ let now = 0;
+ const late = createLateToolResults(() => now);
+ for (let i = 0; i < 100; i++) {
+ late.turnEnded({ ...turn, turnId: `turn-${i}` });
+ now += LATE_TOOL_RESULT_MS;
+ }
+ expect(late.held).toBe(1);
+ });
});
diff --git a/server/host/late-tool-results.ts b/server/host/late-tool-results.ts
index 0ca55deb4a..2d77477bac 100644
--- a/server/host/late-tool-results.ts
+++ b/server/host/late-tool-results.ts
@@ -30,6 +30,10 @@ export function createLateToolResults(now: () => number = Date.now) {
return got.length === expected.length && timingSafeEqual(got, expected);
};
return {
+ /** Ended turns held, closed windows included until the next prune. */
+ get held(): number {
+ return ended.length;
+ },
/** A turn can complete before its generation is bound to it, after cleanup revoked the generation's hooks bearer. */
generationRevoked(generation: string, hooks: { threadId: string; botId: string; token: string }): void {
revoked.set(generation, hooks);
@@ -39,6 +43,7 @@ export function createLateToolResults(now: () => number = Date.now) {
return revoked.get(generation);
},
turnEnded(turn: EndedHookTurn): void {
+ live();
if (turn.toolUseIds.size) ended.push({ ...turn, toolUseIds: new Set(turn.toolUseIds), until: now() + LATE_TOOL_RESULT_MS });
},
/** The bot and conversation an ended turn's bearer belongs to. */