Skip to content

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

fix(automations): a run waiting on handed-on work is not "waiting for your answer"

AdityaUmale1ad75d14c10e
diff --git a/server/routines.ts b/server/routines.ts
index 2dc3718f1f..77e3a39e3e 100644
--- a/server/routines.ts
+++ b/server/routines.ts
@@ -15,7 +15,7 @@ import { intervalAllowsOccurrence, intervalHasRestrictions, isSameLocalDay, late
import { cloneSchedule, limitResetOccurrence, mergeScheduleUpdate, nextOccurrence, RoutineScheduleError, type RoutineSchedule, type RoutineScheduleInput } from "./routine-schedules.ts";
import { runsOnce } from "../shared/limit-reset.ts";
import {
- isRoutineProblemRun, type RoutineAccess, type RoutineCheck, type RoutineContextAttachment, type RoutineDelivery, type RoutineIntervalWindow, type RoutineRetryCause,
+ ROUTINE_HANDOFF_WAIT, isRoutineProblemRun, type RoutineAccess, type RoutineCheck, type RoutineContextAttachment, type RoutineDelivery, type RoutineIntervalWindow, type RoutineRetryCause,
type RoutineHoldCause, type RoutineRunReport, type RoutineRunStatus, type RoutineRunTrigger,
} from "../shared/routines.ts";
import type { PartPair, RoutinePart } from "./package-parts.ts";
@@ -362,7 +362,7 @@ export class RoutineManager {
for (const run of this.runs.filter((candidate) => candidate.status === "running" || candidate.status === "waiting")) {
settleAsk(run, undefined, this.now());
if (run.threadId && run.target === "bot" && this.options.hasPendingDelegations?.(run.threadId) === true) {
- this.wait(run, "Waiting for work it handed on to finish");
+ this.wait(run, ROUTINE_HANDOFF_WAIT);
continue;
}
if (!requeueOnce(run, "restarted", ROUTINE_RESTARTED, this.now())) {
@@ -1280,7 +1280,7 @@ export class RoutineManager {
this.failureFacts.delete(run.id);
const waitsOnTeammates = this.options.hasPendingDelegations?.(event.threadId) === true, handoffRefused = waitsOnTeammates ? null : this.options.refusedHandoff?.(event.threadId);
if (handoffRefused) { this.failRun(Object.assign(run, { partial: Boolean(run.output) || undefined }), handoffRefused); queueMicrotask(() => this.tickInBackground()); return cloneRun(run); }
- if (waitsOnTeammates) this.wait(run, "Waiting for work it handed on to finish");
+ 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 {
diff --git a/shared/routines.ts b/shared/routines.ts
index d38ae8f8c1..e1e8c6d38a 100644
--- a/shared/routines.ts
+++ b/shared/routines.ts
@@ -109,6 +109,9 @@ export type RoutineRetryCause = "stalled" | "restarted" | "rate_limited" | "prov
* not been acknowledged. */
export const ROUTINE_PROBLEM_STATUSES: readonly RoutineRunStatus[] = ["failed", "missed"];
+/** A run's `attention` while it waits only on work it handed to teammates: nothing is asked of the person. */
+export const ROUTINE_HANDOFF_WAIT = "Waiting for work it handed on to finish";
+
export function isRoutineProblemRun(run: { status: RoutineRunStatus }): boolean {
return ROUTINE_PROBLEM_STATUSES.includes(run.status);
}
diff --git a/src/lib/automations.test.ts b/src/lib/automations.test.ts
index 40f32f4c14..9250249c0b 100644
--- a/src/lib/automations.test.ts
+++ b/src/lib/automations.test.ts
@@ -129,6 +129,13 @@ describe("status: Working, Paused, Needs you", () => {
.toMatchObject({ state: "needs-you", fix: "run", reason: "It didn't finish the last 2 times." });
});
+ it("is still working, not asking the person, while its last run waits only on work it handed to teammates", () => {
+ const handedOn = run("waiting", at(0, 9), { attention: "Waiting for work it handed on to finish" });
+ expect(automationStatus(automation([handedOn]))).toEqual({ state: "working" });
+ expect(runLine(handedOn, NOW)).toMatchObject({ mark: "…", text: "Waiting for work it handed on to finish" });
+ expect(runLine(run("waiting", at(0, 9), { attention: "Approve the reply?" }), NOW)).toMatchObject({ mark: "!", text: "It's waiting for your answer." });
+ });
+
it("ignores runs still waiting to start and runs a person stopped when judging the last run", () => {
expect(automationStatus(automation([run("queued", at(0, 11)), run("cancelled", at(0, 10)), run("completed", at(0, 9))])).state).toBe("working");
expect(automationStatus(automation([run("queued", at(0, 11)), run("cancelled", at(0, 10)), run("failed", at(0, 9)), run("failed", at(-1, 9))])).state).toBe("needs-you");
diff --git a/src/lib/automations.ts b/src/lib/automations.ts
index 378aa05efd..6bacbaa090 100644
--- a/src/lib/automations.ts
+++ b/src/lib/automations.ts
@@ -4,7 +4,7 @@ import { cronPresetText, cronText } from "@/lib/cron-text";
import { clockOptions } from "@/lib/clock-time";
import { activeLocale, t } from "@/lib/i18n";
import type { LocaleKey } from "@/locales";
-import { isRoutineProblemRun, type Routine, type RoutineRun, type RoutineSchedule } from "@/lib/routines";
+import { ROUTINE_HANDOFF_WAIT, isRoutineProblemRun, type Routine, type RoutineRun, type RoutineSchedule } from "@/lib/routines";
import type { WebhookAttempt, WebhookTrigger } from "@/lib/webhooks";
import type { AppTrigger } from "@/lib/app-triggers";
import { appProblem, appStatusParts, appWhen, skippedToday } from "@/lib/app-automations";
@@ -249,6 +249,9 @@ function ownerFix(run: RoutineRun): { reason: string; fix: AutomationFix } | nul
return null;
}
+/** A waiting run that waits only on work it handed to teammates: nothing is asked of the person. */
+const waitsOnTeammates = (run: Pick<RoutineRun, "attention">) => run.attention === ROUTINE_HANDOFF_WAIT;
+
/** Done when a one-time automation's time has passed, Paused when switched off. Needs you when its last run waits on the
* person, its app needs reconnecting, failed for a reason only the person can fix, or failed twice running. A run that
* failed and then recovered is Working. */
@@ -259,7 +262,7 @@ export function automationStatus(automation: Pick<Automation, "enabled" | "runs"
if (automation.checkTrouble) return { state: "needs-you", reason: routineLineText(automation.checkTroubleCode, automation.checkTrouble), fix: SIGNED_OUT.test(automation.checkTrouble) ? "reconnect" : "run" };
const settled = automation.runs.filter((run) => run.status !== "cancelled" && run.status !== "queued");
const latest = settled[0];
- if (latest?.status === "waiting") return { state: "needs-you", reason: t("automations.reason.answer"), fix: "answer" };
+ if (latest?.status === "waiting" && !waitsOnTeammates(latest)) return { state: "needs-you", reason: t("automations.reason.answer"), fix: "answer" };
if (latest && isProblem(latest)) {
const owner = ownerFix(latest);
if (owner) return { state: "needs-you", ...owner };
@@ -322,7 +325,7 @@ export function runLine(run: RoutineRun, now = Date.now()): { when: string; mark
const short = (text: string) => (text.length > 110 ? `${text.slice(0, 109).trimEnd()}…` : text);
const when = capital(lastWhen(runTime(run), now));
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 { when, mark: "!", text: t("automations.reason.answer") };
+ 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") {
const reason = short(firstLine(run.error && routineLineText(run.errorCode, run.error, run.errorParams)));
diff --git a/src/lib/routines.ts b/src/lib/routines.ts
index 37f6004630..c3e2322a90 100644
--- a/src/lib/routines.ts
+++ b/src/lib/routines.ts
@@ -12,4 +12,4 @@ export type {
RoutineRun,
RoutineInput,
} from "../../shared/routines";
-export { ROUTINE_PROBLEM_STATUSES, isRoutineProblemRun, type RoutineRunStatusFilter } from "../../shared/routines";
+export { ROUTINE_HANDOFF_WAIT, ROUTINE_PROBLEM_STATUSES, isRoutineProblemRun, type RoutineRunStatusFilter } from "../../shared/routines";
diff --git a/src/locales/en.json b/src/locales/en.json
index 1354da1a07..c92f654f75 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -5184,6 +5184,7 @@
"automations.toggle": "Turn “{name}” on or off",
"automations.run.done": "Done",
"automations.run.nothingNew": "Nothing new",
+ "automations.run.waitingOnTeam": "Waiting for work it handed on to finish",
"automations.run.stopped": "Stopped",
"automations.run.stoppedBecause": "Stopped: {reason}",
"automations.run.failed": "It didn't finish",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 3cc07ce43b..ea0f476a5b 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -4915,6 +4915,7 @@
"automations.toggle": "Ligar ou desligar “{name}”",
"automations.run.done": "Concluída",
"automations.run.nothingNew": "Nada de novo",
+ "automations.run.waitingOnTeam": "Aguardando o trabalho que repassou terminar",
"automations.run.stopped": "Interrompida",
"automations.run.stoppedBecause": "Interrompida: {reason}",
"automations.run.failed": "Não terminou",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index 5fc3eec69f..59d70ff99a 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -5147,6 +5147,7 @@
"automations.toggle": "開啟或關閉「{name}」",
"automations.run.done": "已完成",
"automations.run.nothingNew": "沒有新內容",
+ "automations.run.waitingOnTeam": "正在等待交給其他助手的工作完成",
"automations.run.stopped": "已停止",
"automations.run.stoppedBecause": "已停止:{reason}",
"automations.run.failed": "未完成",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 425207c199..e73df706a2 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -4945,6 +4945,7 @@
"automations.toggle": "开启或关闭「{name}」",
"automations.run.done": "已完成",
"automations.run.nothingNew": "没有新内容",
+ "automations.run.waitingOnTeam": "正在等待交给其他助手的工作完成",
"automations.run.stopped": "已停止",
"automations.run.stoppedBecause": "已停止:{reason}",
"automations.run.failed": "未能完成",