Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Don't count a run started before the routine was last changed toward turning it off
AdityaUmale741d7746adda
diff --git a/server/routine-outcomes.ts b/server/routine-outcomes.tsindex 9ff3ebf7e5..a747005241 100644--- a/server/routine-outcomes.ts+++ b/server/routine-outcomes.ts@@ -23,7 +23,7 @@ const NO_START = new RegExp(`^${beforeBot}.+${afterBot}`);* run in a row turns the routine off and says so. Turning it on again, or any change, starts the count afresh. A busy* or unavailable Cloud service is not counted: that passes by itself, and nothing would turn the routine back on. */export function offAfterNoStarts<R extends { enabled: boolean; nextRunAt: number | null; updatedAt: number }, T extends Outcome>(routine: R | undefined, runs: readonly T[], run: T, now: number): { routine: R; alert: { detail: string } } | undefined {- if (!routine?.enabled || run.status !== "failed" || !run.error || !NO_START.test(run.error)) return undefined;+ if (!routine?.enabled || run.status !== "failed" || !run.error || run.createdAt < routine.updatedAt || !NO_START.test(run.error)) return undefined;const earlier = outcomesNewestFirst(runs, run.routineId, run.id).slice(0, NO_START_RUNS_BEFORE_OFF - 1);if (earlier.length < NO_START_RUNS_BEFORE_OFF - 1 || earlier.some((other) => other.status !== "failed" || other.error !== run.error || other.createdAt < routine.updatedAt)) return undefined;Object.assign(routine, { enabled: false, nextRunAt: null, updatedAt: Math.max(now, routine.updatedAt + 1) });diff --git a/server/routines.test.ts b/server/routines.test.tsindex 601bb19135..65e17fb57f 100644--- a/server/routines.test.ts+++ b/server/routines.test.ts@@ -6,6 +6,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";import type { GroupGoalRunStatus } from "../shared/group-goal-run.ts";import { isRoutineProblemRun } from "../shared/routines.ts";import { ROUTINE_SKIPPED_WHILE_WAITING, ROUTINE_SUPERSEDED } from "./routine-execution.ts";+import { offAfterNoStarts } from "./routine-outcomes.ts";import { RUN_PROGRESS_WINDOW_MS } from "./routine-progress-save.ts";import {nextOccurrence,@@ -353,6 +354,17 @@ describe("bounded scheduled overlap and run health", () => {expect(alerts.at(-1)).toBeNull();});+ it("does not count a run that started before the routine was last changed toward turning it off", () => {+ const error = "Maus's cloud desktop didn't start. Change where this routine runs.";+ const run = (id: string, createdAt: number) => ({ id, routineId: "r", status: "failed", error, createdAt, finishedAt: createdAt + 50 });+ const afterEdit = [run("a", 150), run("b", 160)];+ const routine = () => ({ enabled: true, nextRunAt: 1, updatedAt: 100 });+ const queuedBeforeEdit = run("old", 50);+ expect(offAfterNoStarts(routine(), [...afterEdit, queuedBeforeEdit], queuedBeforeEdit, 300)).toBeUndefined();+ const third = run("c", 170);+ expect(offAfterNoStarts(routine(), [...afterEdit, third], third, 300)?.routine).toMatchObject({ enabled: false, nextRunAt: null });+ });+it("counts restart recovery only once and sanitizes obsolete or invalid health metadata", async () => {const h = harness(start);const routine = h.manager.create({ ...input(), enabled: false });