Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Routines: hold a scheduled occurrence while a finished run's thread works a follow-up
skygunner681bc6f50f08
diff --git a/server/routines.test.ts b/server/routines.test.tsindex 9269aee539..df508c546f 100644--- a/server/routines.test.ts+++ b/server/routines.test.ts@@ -172,6 +172,25 @@ describe("bounded scheduled overlap and run health", () => {expect(h.manager.listRuns().filter(run => run.status === "queued")).toHaveLength(0);});+ it("holds the next scheduled occurrence while a finished run's thread works a follow-up", async () => {+ const h = harness(start);+ const live = new Set<string>();+ h.options.turnLive = (run) => live.has(run.threadId ?? "");+ h.manager.create(input());+ h.setNow(start + 5 * 60_000); await h.manager.tick();+ finish(h, "thread-1", true);+ expect(h.manager.listRuns()[0].status).toBe("completed");+ // The person's follow-up keeps the finished run's conversation busy.+ live.add("thread-1");+ h.setNow(start + 10 * 60_000); await h.manager.tick();+ h.setNow(start + 15 * 60_000); await h.manager.tick();+ expect(h.started).toHaveLength(1);+ expect(realRuns(h.manager.listRuns()).map(run => run.status).sort()).toEqual(["completed", "queued"]);+ live.delete("thread-1");+ await h.manager.tick();+ expect(h.started.map(turn => turn.threadId)).toEqual(["thread-1", "thread-2"]);+ });+it("does not let queue mode accumulate work when the bot is busy before its first run", async () => {const h = harness(start); h.setBot("busy");const routine = h.manager.create({ ...input(), overlap: "queue" });diff --git a/server/routines.ts b/server/routines.tsindex ff79ddc7f2..87d09b8038 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -1117,9 +1117,9 @@ export class RoutineManager {this.runChecks(checked.id, checkHold(this.runs, checked.id, now, run.id), run.id).catch((error) => console.error(`routines: the checks of ${checked.id} failed`, error));continue;}- const sameRoutineWorking = (triggerSource === "schedule" || run.sameConversation) && this.runs.some(other =>- other.id !== run.id && other.routineId === run.routineId && ["running", "waiting"].includes(other.status));- const held = sameRoutineWorking || this.runs.some((other) => other.routineId === run.routineId && this.slowStops.holds(other.threadId));+ const held = (triggerSource === "schedule" || run.sameConversation) && this.runs.some(other =>+ other.id !== run.id && other.routineId === run.routineId && (["running", "waiting"].includes(other.status) || this.options.turnLive?.(other) === true)) ||+ this.runs.some((other) => other.routineId === run.routineId && this.slowStops.holds(other.threadId));const state = held ? "busy" : this.targetState(run);if (state === "busy") {if (run.deferredAt == null) {