Skip to content

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

Count only open waits toward handed-on work's one-wait limit

Rutvij974bd077a5c52e
diff --git a/server/waits.test.ts b/server/waits.test.ts
index c9300bedc2..beb34c6307 100644
--- a/server/waits.test.ts
+++ b/server/waits.test.ts
@@ -108,6 +108,17 @@ describe("WaitManager", () => {
expect(await handed("a1")).toMatchObject({ state: "created" });
});
+ it("lets handed-on work set a new wait once its wait has ended, even before the ending is posted", async () => {
+ const h = harness();
+ const handed = () => h.manager.create({ botId: "bot-1", threadId: "t-1", label: "the report", condition: { kind: "file_exists", path: "/r.txt" }, assignmentId: "a1" });
+ const first = await handed();
+ const id = (first as { wait: WaitRecord }).wait.id;
+ h.stamp = { size: 1, mtimeMs: 1 }; h.postOk = false; h.advance(5_000); await h.manager.tick();
+ expect(h.waitOf(id).ending).toMatchObject({ status: "fired" });
+ h.stamp = null;
+ expect(await handed()).toMatchObject({ state: "created", wait: { assignmentId: "a1" } });
+ });
+
it("creates a wait with a 24-hour default and its first check due, and keeps it across a restart", async () => {
const h = harness();
const created = await h.manager.create({ botId: "bot-1", threadId: "t-1", label: "the report", condition: { kind: "file_exists", path: "/r.txt" } });
diff --git a/server/waits.ts b/server/waits.ts
index 9d2a641a1d..a8a8c44ebd 100644
--- a/server/waits.ts
+++ b/server/waits.ts
@@ -216,7 +216,7 @@ export class WaitManager {
}
private limitRefusal({ botId, threadId, assignmentId }: Pick<NewWait, "botId" | "threadId" | "assignmentId">): CreateWaitResult | null {
- const handed = assignmentId ? this.waits.filter((w) => w.assignmentId === assignmentId) : [];
+ const handed = assignmentId ? this.waits.filter((w) => w.assignmentId === assignmentId && !w.ending) : [];
if (handed.length >= WAIT_LIMITS.perAssignment) {
return { state: "refused", status: 409, error: `Work handed to you keeps one wait at a time, and this work already has one:\n${waitList(handed)}\nFinish this turn; it tells you here when it happens.` };
}