Skip to content

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

fix: preserve automation failure history during active runs

Afloat1872e9fa09e8
diff --git a/server/routine-run-window.test.ts b/server/routine-run-window.test.ts
index ba1373a72a..8947a8cd0f 100644
--- a/server/routine-run-window.test.ts
+++ b/server/routine-run-window.test.ts
@@ -38,6 +38,17 @@ describe("the app's run window", () => {
expect(ids(appRunWindow(runs, NOW - 14 * DAY))).toEqual(runs.slice(0, 11).map((candidate) => candidate.id));
});
+ it.each(["queued", "running", "waiting"] as const)("keeps the failure streak while a newer run is %s", (status) => {
+ const runs = [
+ run("active", "r", 20, status),
+ ...Array.from({ length: 8 }, (_, i) => run(`fail-${i}`, "r", 21 + i, "failed", { seenAt: NOW })),
+ run("ok", "r", 40, "completed"),
+ run("older", "r", 41, "completed"),
+ ];
+
+ expect(ids(appRunWindow(runs, NOW - 14 * DAY))).toEqual(ids(runs.slice(0, -1)));
+ });
+
it("answers a range, a thread, the window, or everything", () => {
const runs = [run("a", "r", 1, "completed", { threadId: "t1" }), run("b", "r", 30, "completed")];
const listRuns = (from?: number, to?: number) => runs.filter((candidate) => (from === undefined || candidate.scheduledFor >= from) && (to === undefined || candidate.scheduledFor <= to));
diff --git a/server/routine-run-window.ts b/server/routine-run-window.ts
index 34afaaaa97..2dcffa5934 100644
--- a/server/routine-run-window.ts
+++ b/server/routine-run-window.ts
@@ -17,7 +17,7 @@ export function appRunWindow(newestFirst: readonly RoutineRun[], since: number):
reach.set(run.routineId, own);
const reached = own.count < NEWEST_RUNS_PER_AUTOMATION || !own.settled;
own.count += 1;
- if (run.status !== "cancelled" && run.status !== "queued" && !isRoutineProblemRun(run)) own.settled = true;
+ if (run.status !== "cancelled" && !ACTIVE.has(run.status) && !isRoutineProblemRun(run)) own.settled = true;
return reached || run.scheduledFor >= since || ACTIVE.has(run.status) || (isRoutineProblemRun(run) && !run.seenAt);
});
}