Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(routines): a delivered-then-failed run completes through the shared path
milind-sonib7a3e7795912
diff --git a/server/routines.ts b/server/routines.tsindex 34a7219154..54db9f4752 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -1288,27 +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])];- if (!event.ok) {- const facts = { ...this.failureFacts.get(run.id), stopReason: event.stopReason };- // A run whose reply was already delivered (partial: the answer streamed first) is not failed by the last tool- // call that went wrong after it: the output holds the finished deliverable, so the run completes with the- // failing step kept in its error line. A run-limit stop or a network failure still fails the run (#7186).- if (event.stopReason === "tool_error" && facts.partial && run.output) {- Object.assign(run, { status: "completed", attention: undefined, finishedAt: this.now(), partial: true } satisfies Partial<RoutineRun>);- this.saveLater();- this.emitRun(run);- queueMicrotask(() => this.tickInBackground());- return cloneRun(run);- }- this.settleFailure(run, routineFailure(run.error, event.stopReason), facts);- return cloneRun(run);- }+ 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); }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>); this.ownerNotices = this.ownerNotices.filter((notice) => notice.botId !== run.botId); }- run.error = undefined;+ 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 {return null;}diff --git a/src/lib/routine-display.ts b/src/lib/routine-display.tsindex b5f7cfcc55..45dc1274c7 100644--- a/src/lib/routine-display.ts+++ b/src/lib/routine-display.ts@@ -14,7 +14,7 @@ export function latestRoutineRun(routineId: string, runs: readonly RoutineRun[])}/** 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 (#7186). */+ * its output, or completed with the failing step kept in its error line. */export function partlyDone(run: RoutineRun): boolean {return !run.goalStatus && run.partial === true &&(run.status === "failed" || (run.status === "completed" && !!run.error));