Skip to content

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

Take the partly-done routine change back out of train X

milind-soni253820d0ff15
diff --git a/server/routines.test.ts b/server/routines.test.ts
index 1cf1f981d2..bf953002d1 100644
--- a/server/routines.test.ts
+++ b/server/routines.test.ts
@@ -301,25 +301,24 @@ describe("bounded scheduled overlap and run health", () => {
await h.manager.tick();
});
- it("does not fail a run whose reply came back before its last tool call went wrong: it completes partly done", async () => {
+ it("keeps a run that failed only on a step, after its reply came back, failed but marked partly done", async () => {
const h = harness(start);
const routine = h.manager.create({ ...input(), enabled: false });
const event = (threadId: string, patch: Record<string, unknown>) => h.manager.handleRuntimeEvent({ eventId: `e-${Math.random()}`, provider: "fake", threadId, createdAt: new Date().toISOString(), ...patch } as Parameters<typeof h.manager.handleRuntimeEvent>[0]);
- const attempt = async (threadId: string, partial: boolean, { reply = true, cutOff = false, stopReason }: { reply?: boolean; cutOff?: boolean; stopReason?: string } = {}) => {
+ const attempt = async (threadId: string, partial: boolean, { reply = true, cutOff = false } = {}) => {
h.manager.runNow(routine.id); await h.manager.tick();
if (reply) event(threadId, { type: "item.completed", itemType: "assistant_text", itemId: "reply", text: "Here is the summary." });
event(threadId, { type: "runtime.error", message: "Stopped because the tool call “read_file” failed.", terminal: true, ...(partial ? { partial: true } : {}) });
if (cutOff) h.manager.failThread(threadId, "Provider settings changed");
- else event(threadId, { type: "turn.completed", ok: false, stopReason: stopReason ?? (partial ? "tool_error" : "refusal") });
+ else event(threadId, { type: "turn.completed", ok: false, stopReason: partial ? "tool_error" : "refusal" });
};
await attempt("thread-1", true);
await attempt("thread-2", false);
await attempt("thread-3", true, { reply: false });
await attempt("thread-4", true, { cutOff: true });
- await attempt("thread-5", true, { stopReason: "refusal" });
- const [done, failed, silent, cutOff, limited] = h.manager.listRuns().sort((a, b) => a.threadId!.localeCompare(b.threadId!));
- expect(done).toMatchObject({ status: "completed", partial: true, output: "Here is the summary.", error: expect.stringContaining("read_file") });
- expect([failed, silent, cutOff, limited].map((run) => [run.status, run.partial])).toEqual([["failed", undefined], ["failed", undefined], ["queued", undefined], ["failed", true]]);
+ const [partly, failed, silent, cutOff] = h.manager.listRuns().sort((a, b) => a.threadId!.localeCompare(b.threadId!));
+ expect(partly).toMatchObject({ status: "failed", partial: true, output: "Here is the summary.", error: expect.stringContaining("read_file") });
+ expect([failed, silent, cutOff].map((run) => [run.status, run.partial])).toEqual([["failed", undefined], ["failed", undefined], ["queued", undefined]]);
});
it("tells of a failure once per streak, and again when it changes or after a run completes", async () => {
diff --git a/server/routines.ts b/server/routines.ts
index 54db9f4752..406f060a66 100644
--- a/server/routines.ts
+++ b/server/routines.ts
@@ -1288,16 +1288,16 @@ export class RoutineManager {
if (this.closing && (!event.ok || event.stopReason === "cancelled" || event.stopReason === "interrupted")) return null;
if (event.cost != null) run.cost = (run.cost ?? 0) + event.cost;
if (event.denials?.length) run.denials = [...new Set([...(run.denials ?? []), ...event.denials])];
- const facts = { ...this.failureFacts.get(run.id), stopReason: event.stopReason };
- // A last tool call that failed after the reply was delivered (partial) leaves a finished deliverable: the run completes partly done, its failing step kept in its error line. Any other stop fails it.
- const delivered = !event.ok && event.stopReason === "tool_error" && facts.partial === true && Boolean(run.output);
- if (!event.ok && !delivered) { this.settleFailure(run, routineFailure(run.error, event.stopReason), facts); return cloneRun(run); }
+ if (!event.ok) {
+ this.settleFailure(run, routineFailure(run.error, event.stopReason), { ...this.failureFacts.get(run.id), stopReason: event.stopReason });
+ return cloneRun(run);
+ }
this.failureFacts.delete(run.id);
const waitsOnTeammates = this.options.hasPendingDelegations?.(event.threadId) === true, handoffRefused = waitsOnTeammates ? null : this.options.refusedHandoff?.(event.threadId);
if (handoffRefused) { const said = typeof handoffRefused === "string" ? { text: handoffRefused } : handoffRefused; this.failRun(Object.assign(run, { partial: (said.partial !== false && Boolean(run.output)) || undefined }, said.lendingRefused ? { lendingRefused: true as const } : {}), said.text); queueMicrotask(() => this.tickInBackground()); return cloneRun(run); }
if (waitsOnTeammates) this.wait(run, ROUTINE_HANDOFF_WAIT);
- else { Object.assign(run, { status: "completed", attention: undefined, finishedAt: this.now() } satisfies Partial<RoutineRun>, delivered ? { partial: true } : {}); this.ownerNotices = this.ownerNotices.filter((notice) => notice.botId !== run.botId); }
- if (!delivered) run.error = undefined;
+ else { Object.assign(run, { status: "completed", attention: undefined, finishedAt: this.now() } satisfies Partial<RoutineRun>); this.ownerNotices = this.ownerNotices.filter((notice) => notice.botId !== run.botId); }
+ run.error = undefined;
} else {
return null;
}
diff --git a/src/lib/automations.test.ts b/src/lib/automations.test.ts
index cfd80b93bb..a5bd40d5c0 100644
--- a/src/lib/automations.test.ts
+++ b/src/lib/automations.test.ts
@@ -254,9 +254,6 @@ describe("order and the grey line", () => {
expect(statusLine(automation([partly]), NOW)).toBe("On · last ran today 9:02 AM ! · next: Monday 9:00 AM");
expect(runLine(run("failed", at(0, 9, 2), { error: "Stopped because the tool call failed." }), NOW)).toMatchObject({ mark: "✗" });
expect(statusLine(automation([run("failed", at(0, 9, 2))]), NOW)).toBe("On · last ran today 9:02 AM ✗ · next: Monday 9:00 AM");
- const completedPartly = run("completed", at(0, 9, 2), { error: "Stopped because the tool call failed.\nmore", output: "Here is the summary.", partial: true });
- expect(runLine(completedPartly, NOW)).toEqual({ when: "Today 9:02 AM", mark: "!", text: "Partly done: Stopped because the tool call failed." });
- expect(statusLine(automation([completedPartly]), NOW)).toBe("On · last ran today 9:02 AM ! · next: Monday 9:00 AM");
});
it("says a run that found nothing to tell found nothing new, whatever its last words were", () => {
diff --git a/src/lib/automations.ts b/src/lib/automations.ts
index 1eabeb4064..daedc06e0f 100644
--- a/src/lib/automations.ts
+++ b/src/lib/automations.ts
@@ -334,13 +334,7 @@ export function runLine(run: RoutineRun, now = Date.now()): { when: string; mark
const firstLine = (text: string | undefined) => (text ?? "").split("\n").map((line) => line.trim()).find(Boolean) ?? "";
const short = (text: string) => (text.length > 110 ? `${text.slice(0, 109).trimEnd()}…` : text);
const when = capital(lastWhen(runTime(run), now));
- if (run.status === "completed") {
- if (partlyDone(run)) {
- const reason = short(firstLine(run.error && routineLineText(run.errorCode, run.error, run.errorParams)));
- return { when, mark: "!", text: t("automations.run.partial", { reason }) };
- }
- return { when, mark: "✓", text: run.report?.state === "quiet" ? t("automations.run.nothingNew") : short(firstLine(run.output)) || t("automations.run.done") };
- }
+ if (run.status === "completed") return { when, mark: "✓", text: run.report?.state === "quiet" ? t("automations.run.nothingNew") : short(firstLine(run.output)) || t("automations.run.done") };
if (run.status === "waiting") return waitsOnTeammates(run) ? { when, mark: "…", text: t("automations.run.waitingOnTeam") } : { when, mark: "!", text: t("automations.reason.answer") };
if (run.status === "running" || run.status === "queued") return { when, mark: "…", text: t("automations.runningNow") };
if (run.status === "cancelled") {
diff --git a/src/lib/routine-display.test.ts b/src/lib/routine-display.test.ts
index c1a884eceb..c9ca313f2b 100644
--- a/src/lib/routine-display.test.ts
+++ b/src/lib/routine-display.test.ts
@@ -77,10 +77,4 @@ describe("a run's status", () => {
expect(routineRunTone(run({}))).toBe("text-danger");
expect(routineRunLabel(run({ status: "completed", partial: true }))).toBe("Completed");
});
-
- it("reads a completed run that kept its failing step partly done, in the waiting colour", () => {
- expect(routineRunLabel(run({ status: "completed", partial: true, error: "Stopped because the tool call “read_file” failed." }))).toBe("Partly done");
- expect(routineRunTone(run({ status: "completed", partial: true, error: "Stopped because the tool call “read_file” failed." }))).toBe("text-warning");
- expect(routineRunLabel(run({ status: "completed", partial: true }))).toBe("Completed");
- });
});
diff --git a/src/lib/routine-display.ts b/src/lib/routine-display.ts
index 45dc1274c7..7b93acdd17 100644
--- a/src/lib/routine-display.ts
+++ b/src/lib/routine-display.ts
@@ -13,11 +13,9 @@ export function latestRoutineRun(routineId: string, runs: readonly RoutineRun[])
.reduce<RoutineRun | undefined>((latest, run) => !latest || routineRunTime(run) > routineRunTime(latest) ? run : latest, undefined);
}
-/** A run that failed only because a step did, after its reply came back: either recorded as failed with the reply in
- * its output, or completed with the failing step kept in its error line. */
+/** A run that failed only because a step did, after its reply came back. */
export function partlyDone(run: RoutineRun): boolean {
- return !run.goalStatus && run.partial === true &&
- (run.status === "failed" || (run.status === "completed" && !!run.error));
+ return run.status === "failed" && run.partial === true && !run.goalStatus;
}
export function routineRunLabel(run: RoutineRun): string {