Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Routines: keep the limit-replay option inside the file-size ratchet
Doğukaan Kılıçarslane734f00082da
diff --git a/server/index.ts b/server/index.tsindex 7bec4c915d..fb9958af72 100644--- a/server/index.ts+++ b/server/index.ts@@ -8914,11 +8914,9 @@ const limitFailovers = new LimitFailovers({ file: join(DATA_DIR, "limit-failoverconst automationDestinations = createAutomationDestinations({ store, mainThread: botMainThread, runs: () => routines?.listRuns() ?? [],cloud: CLOUD_HOME ? { owner: CLOUD_OWNER_KEY!, opener: routineOpener, reportFromOthers: cloudReportFromOthers, opened: (threadId, person) => threadStarters.set(threadId, person) } : null });routines = new RoutineManager({- emit: broadcast, limitResetAt: (engine) => limitClock.resetAt(engine), checks: proactive.checks,- skipLimitReplay: () => cfg.features?.recurringRoutinesSkipLimitReplay === true,+ emit: broadcast, limitResetAt: (engine) => limitClock.resetAt(engine), checks: proactive.checks, skipLimitReplay: () => cfg.features?.recurringRoutinesSkipLimitReplay === true,limitBackup: (botId, scope) => { const bot = store.bot(botId); return quotaSwitchEnabled() ? Boolean(bot && limitTakeover.backups(botId, bot.modelSelection, scope, approvalModeFor(bot)).length) : Boolean(bot && startupBackups(bot, cfg.automaticRecovery).length); },- launchId: DESKTOP_MANAGED && /^[\w-]{1,100}$/.test(process.env.OMB_DESKTOP_LAUNCH_ID ?? "")- ? process.env.OMB_DESKTOP_LAUNCH_ID : undefined,+ launchId: DESKTOP_MANAGED && /^[\w-]{1,100}$/.test(process.env.OMB_DESKTOP_LAUNCH_ID ?? "") ? process.env.OMB_DESKTOP_LAUNCH_ID : undefined,skipStartupRuns: Boolean(CLOUD_HOME) && wokeFromSleep(DATA_DIR), // a Cloud home waking from a sleep it was stopped forhasPendingDelegations: runtimeWorkPending, handedOffWorkLive: (threadId) => coordinator.outstandingFor(threadId).length > 0,routineTurn: (threadId) => directRequestOwners.get(threadId)?.automation !== undefined,diff --git a/server/routine-recovery.ts b/server/routine-recovery.tsindex 94bb41d1a7..7e4c9546d8 100644--- a/server/routine-recovery.ts+++ b/server/routine-recovery.ts@@ -7,7 +7,7 @@ import type { RuntimeEvent } from "../shared/runtime-events.ts";import type { RoutineRetryCause } from "../shared/routines.ts";import { engineFailureKind } from "./drivers/engine-errors.ts";import { classifyError } from "./drivers/retry.ts";-import type { RoutineRun } from "./routines.ts";+import type { Routine, RoutineRun } from "./routines.ts";import { hostTimeZone } from "./turn-clock.ts";import { classifyContinuable } from "./turn-continuation.ts";@@ -205,3 +205,10 @@ export function weekRuns(runs: readonly RoutineRun[], routineId: string, now: nu}return total ? { ok, total } : undefined;}++/** A run its repeating schedule started: not one started by hand or by an event, and not a one-off or limit-reset routine. */+export function scheduledRecurringRun(run: RoutineRun, routines: readonly Routine[]): boolean {+ if ((run.triggerSource ?? (run.manual ? "manual" : "schedule")) !== "schedule") return false;+ const type = routines.find((routine) => routine.id === run.routineId)?.schedule.type;+ return type !== undefined && type !== "once" && type !== "limit_reset";+}diff --git a/server/routines.ts b/server/routines.tsindex ea6610eb31..5358538d7c 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -23,7 +23,7 @@ import {routineFailure, routineHostWarning, skipNeedsNotice, supersededBy,} from "./routine-execution.ts";import {- dispatchRefusal, engineFacts, loadOwnerNotices, recoverRun, requeueOnce, weekRuns, type RoutineAlert, type RoutineFailureFacts, type RoutineOwnerNotice,+ dispatchRefusal, engineFacts, loadOwnerNotices, recoverRun, requeueOnce, weekRuns, type RoutineAlert, type RoutineFailureFacts, type RoutineOwnerNotice, scheduledRecurringRun,} from "./routine-recovery.ts";import { activeMs, askOf, settleAsk, waitingFor, type RoutineRunAsk } from "./routine-waits.ts";import { failsLikeLastOutcome, outcomesNewestFirst } from "./routine-outcomes.ts";@@ -619,9 +619,7 @@ export class RoutineManager {if (!clean.access) delete routine.access;if (!clean.deliver) delete routine.deliver;if (!clean.checks) for (const key of ["checks", "checkedAt", "checkTrouble", "wakeAt"] as const) delete routine[key];- if (Object.hasOwn(patch, "timeoutMinutes") && patch.timeoutMinutes == null) {- delete routine.timeoutMinutes;- }+ if (Object.hasOwn(patch, "timeoutMinutes") && patch.timeoutMinutes == null) delete routine.timeoutMinutes;if (patch.enabled === false) {for (const run of this.runs) {if (run.routineId !== routine.id || run.status !== "queued") continue;@@ -1311,8 +1309,7 @@ export class RoutineManager {this.failureFacts.delete(run.id);if (this.closing) return;const held = facts.limit !== undefined || facts.limitResetsAt !== undefined ? facts.limit ?? "engine" : facts.stopReason === "auth_required" ? "signed-out" : undefined, backupReady = held !== undefined && this.options.limitBackup?.(run.botId, held) === true;- const skipLimitReplay = this.options.skipLimitReplay?.() === true && this.scheduledRecurringRun(run);- const recovery = recoverRun(run, failure, { ...facts, ...(backupReady ? { backupReady } : {}), ...(skipLimitReplay ? { skipLimitReplay } : {}) }, this.now(), this.ownerNotices);+ const recovery = recoverRun(run, failure, { ...facts, ...(backupReady ? { backupReady } : {}), ...(this.options.skipLimitReplay?.() === true && scheduledRecurringRun(run, this.routines) ? { skipLimitReplay: true } : {}) }, this.now(), this.ownerNotices);if (!recovery.queued) this.failRun(Object.assign(run, { partial: (facts.partial && Boolean(run.output)) || undefined }), recovery.error, "failed", recovery.alert);else {this.saveLater();@@ -1322,12 +1319,6 @@ export class RoutineManager {queueMicrotask(() => this.tickInBackground());}- private scheduledRecurringRun(run: RoutineRun): boolean {- if ((run.triggerSource ?? (run.manual ? "manual" : "schedule")) !== "schedule") return false;- const type = this.routines.find((routine) => routine.id === run.routineId)?.schedule.type;- return type !== undefined && type !== "once" && type !== "limit_reset";- }-finishGoalRun(runId: string, status: GroupGoalRunStatus, detail: string): RoutineRun | null {const run = this.runs.find((candidate) => candidate.id === runId &&