Skip to content

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

fix(steer-queue): keep a restored row without a timestamp in place

erywimee822b57efd0
diff --git a/server/steer-queue.test.ts b/server/steer-queue.test.ts
index 6e148a408c..88dedcbfb1 100644
--- a/server/steer-queue.test.ts
+++ b/server/steer-queue.test.ts
@@ -341,6 +341,29 @@ describe("steer-queue module", () => {
expect(run.mock.calls.map((call) => call[2])).toEqual(["my own request", "older report", "older note"]);
});
+ it("keeps a row without a timestamp behind a first message queued after it, across restarts", () => {
+ const bot = fakeBot("bot-legacy-clock", "thread-legacy-clock", true);
+ const store = fakeStore([bot]);
+ const run = vi.fn();
+ let clock = 1_000;
+ const now = vi.spyOn(Date, "now").mockImplementation(() => clock);
+ try {
+ saveChatFollowup({ id: "legacy-plain-line", kind: "bot", ownerId: bot.id, threadId: bot.threadId,
+ payload: { text: "older person line", prompt: "older person line" } });
+ restoreSteeredMessages();
+ clock = 200_000;
+ queueSteeredMessage(bot.id, bot.threadId, "my own request", { first: true });
+ clock = 300_000;
+ restoreSteeredMessages();
+ } finally {
+ now.mockRestore();
+ }
+ bot.busy = false;
+ drainSteeredMessages(store, run);
+ drainSteeredMessages(store, run);
+ expect(run.mock.calls.map((call) => call[2])).toEqual(["older person line", "my own request"]);
+ });
+
it("drains one call's spoken lines as one turn, and the next call's as its own", () => {
const bot = fakeBot("bot-call-groups", "thread-call-groups", true);
const store = fakeStore([bot]);
diff --git a/server/steer-queue.ts b/server/steer-queue.ts
index d32ccf5533..ae497edcea 100644
--- a/server/steer-queue.ts
+++ b/server/steer-queue.ts
@@ -85,7 +85,9 @@ export function restoreSteeredMessages(): void {
...(origin.success ? { origin: origin.data } : {}),
messageId: row.id,
prompt: row.payload.prompt ?? row.payload.text,
- queuedAt: row.payload.queuedAt ?? Date.now(),
+ // A row from a build before queuedAt has no time of its own: it was written before anything this build queues,
+ // and a fixed time keeps a later first insert behind it on every restart.
+ queuedAt: row.payload.queuedAt ?? 0,
}, first, aheadOfOthers);
queues.set(row.threadId, entry);
}