Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Main green: keep a capture that began before upkeep started, and three test fixes (#4808)
Milind Sonid9d7c100be53
diff --git a/server/memory-upkeep-lifecycle.test.ts b/server/memory-upkeep-lifecycle.test.tsindex cd84466f6c..8ba24fafc4 100644--- a/server/memory-upkeep-lifecycle.test.ts+++ b/server/memory-upkeep-lifecycle.test.ts@@ -201,4 +201,24 @@ describe("scheduled memory upkeep", () => {expect(loop.status(BOT.id).lastCapture).toBeUndefined();expect(addToAboutMe).not.toHaveBeenCalled();});++ it("keeps a capture that began before the first start", async () => {+ let release!: (answer: string) => void;+ const held = new Promise<string>((resolve) => { release = resolve; });+ const generateText = vi.fn((prompt: string) => prompt.startsWith(ORGANIZE_MARKER) ? Promise.resolve("{}") : held);+ loop = createMemoryUpkeep({+ bots: () => [BOT], bot: () => BOT, engine: () => ({ generateText }), busy: () => false,+ addToAboutMe: () => 0, sourceLabel: () => "chat", quietMs: () => 60_000, tidyHour: () => 3,+ });+ // A chat answered at boot, while the engines are still being read: upkeep starts during its capture call.+ const capture = loop.capture({ botId: BOT.id, threadId: "chat", turns: [{ person: "Acme launches Friday.", bot: "Noted" }] });+ await vi.advanceTimersByTimeAsync(0);+ expect(generateText).toHaveBeenCalledTimes(1);+ loop.start();+ release('[{"text":"Acme launches Friday","kind":"fact","evidence":"Acme launches Friday"}]');+ await capture;+ await loop.idle();+ expect(memory()).toContain("Acme launches Friday");+ expect(loop.status(BOT.id).lastCapture).toMatchObject({ added: 1 });+ });});diff --git a/server/memory-upkeep.ts b/server/memory-upkeep.tsindex 22c6f1b1a2..210edbccdd 100644--- a/server/memory-upkeep.ts+++ b/server/memory-upkeep.ts@@ -901,7 +901,9 @@ export function createMemoryUpkeep(deps: UpkeepDeps): MemoryUpkeep {log(`memory upkeep: could not queue turns saved at the last shutdown: ${(error as Error).message}`);}}- const started = ++generation;+ // stop() already ended the last generation; a capture that began before the first start (a chat answered while+ // the engines are still being read at boot) is kept.+ const started = generation;const scheduledTick = () => { if (started === generation) void tick(); };timer = setInterval(scheduledTick, TIDY_CHECK_MS);timer.unref?.();