Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(routines): an empty item does not erase the report a run delivered
David Neyrabbbb73f44722
diff --git a/server/routine-lines.ts b/server/routine-lines.tsindex a8600bdfa7..9305030f5e 100644--- a/server/routine-lines.ts+++ b/server/routine-lines.ts@@ -144,3 +144,8 @@ export function clipRunOutput(text: string, max: number): string {const room = max - tail.length - 3;return room > 0 ? `${text.slice(0, room).trimEnd()}\n…\n${tail}` : tail;}++/** A run's reply, kept: a later item that says nothing does not erase the report the run already delivered. */+export function keptRunOutput(delivered: string | undefined, text: string, max: number): string | undefined {+ return clipRunOutput(text, max) || delivered;+}diff --git a/server/routines.test.ts b/server/routines.test.tsindex bac262059a..3131d1ac86 100644--- a/server/routines.test.ts+++ b/server/routines.test.ts@@ -2422,6 +2422,34 @@ describe("RoutineManager", () => {});});+ it("keeps the report it delivered when a later empty item arrives before its limit stops it", async () => {+ const h = harness();+ const routine = h.manager.create({+ name: "Bounded check",+ prompt: "Check the queue",+ botId: "maus-timeout",+ schedule: { type: "daily", time: "23:59", weekdays: [1] },+ timeoutMinutes: 5,+ });+ const run = h.manager.runNow(routine.id)!;+ await h.manager.tick();+ const startedAt = h.manager.listRuns().find((candidate) => candidate.id === run.id)?.startedAt;+ const say = (itemId: string, text: string) => h.manager.handleRuntimeEvent({ eventId: itemId, provider: "fake", threadId: "thread-1", createdAt: new Date().toISOString(), type: "item.completed", itemType: "assistant_text", itemId, text } as Parameters<typeof h.manager.handleRuntimeEvent>[0]);+ say("reply", "The invoice is issued and validated.");+ say("blank", " ");+ say("empty", "");++ h.setNow(startedAt! + 5 * 60_000);+ await h.manager.tick();++ expect(h.manager.listRuns().find((candidate) => candidate.id === run.id)).toMatchObject({+ status: "failed",+ partial: true,+ output: "The invoice is issued and validated.",+ error: "Stopped after reaching the 5-minute run limit",+ });+ });+it("keeps legacy duration metadata without imposing a timeout", async () => {const h = harness();const routine = h.manager.create({diff --git a/server/routines.ts b/server/routines.tsindex 3d50fe7658..2bfa9719ef 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -38,7 +38,7 @@ import { loadInstalledPackage, matchingRequestReceipt, rememberRequest } from ".import { applyHolds, holdCauses, type AppliedHolds } from "./routine-holds.ts";import { cancelUnfinishedRuns, interruptRunTurns } from "./routine-stops.ts";import { sanitizeInput } from "./routine-input.ts";-import { applyCheckResult, clipRunOutput, codedLine, routineLine, runLineFields, type RoutineLine, type RoutineLineCodes, type RoutineTroubleCode } from "./routine-lines.ts";+import { applyCheckResult, clipRunOutput, codedLine, keptRunOutput, routineLine, runLineFields, type RoutineLine, type RoutineLineCodes, type RoutineTroubleCode } from "./routine-lines.ts";import { checkHold, CHECK_BOOT_HOLD_MS, type CheckHold } from "./routine-check-pacing.ts";import { resolveRoutineResultsThread, routineRunDefinition, type ResultsThreadAllocation } from "./routine-run-definition.ts";@@ -1280,7 +1280,7 @@ export class RoutineManager {}this.clock.work(run, this.now());} else if (event.type === "item.completed" && event.itemType === "assistant_text") {- run.output = clipRunOutput(redactSecretsInText(event.text).trim(), 2_000);+ run.output = keptRunOutput(run.output, redactSecretsInText(event.text).trim(), 2_000);} else if (event.type === "runtime.error") {Object.assign(run, runLineFields("error", event.message, event.text));this.failureFacts.set(run.id, engineFacts(event));