Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(handoffs): check a reply only where its requester could skip the turn
milind-soni709d410ae0ab
diff --git a/server/runtime/status-reply.test.ts b/server/runtime/status-reply.test.tsnew file mode 100644index 0000000000..19e22c845c--- /dev/null+++ b/server/runtime/status-reply.test.ts@@ -0,0 +1,45 @@+import { describe, expect, it } from "vitest";++import { isStatusOnly, mayBeStatusOnly, statusReplyPrompt } from "./status-reply.ts";+import type { Assignment } from "./types.ts";++const root: Assignment = {+ id: "gen-1", rootId: "gen-1", depth: 0,+ origin: { kind: "person", source: "chat", ref: "chief-chat" },+ requester: { kind: "person", threadId: "chief-chat" },+ assignee: { botId: "chief", destination: { kind: "standing_thread", threadId: "chief-chat" } },+ mode: "work", reply: "resume", brief: "Tell the builder", status: "waiting", level: "ask", levelSource: "own",+ executions: 1, restarts: 0, createdAt: 1_000, lastActivityAt: 2_000, result: "", rework: false, version: 1,+};+const child: Assignment = {+ ...root, id: "as-1", parentId: "gen-1", depth: 1, brief: "FYI: the mailbox moved.", status: "running",+ requester: { kind: "bot_turn", botId: "chief", threadId: "chief-chat" },+ assignee: { botId: "builder", destination: { kind: "work_thread", threadId: "builder-work" } },+};++describe("which replies are asked about", () => {+ it("a short reply to plain work under a person's or a bot's turn", () => {+ expect(mayBeStatusOnly(child, root, "Noted.", undefined)).toBe(true);+ expect(mayBeStatusOnly(child, { ...root, requester: { kind: "bot_turn", botId: "lead", threadId: "lead-work" } }, "Noted.", undefined)).toBe(true);+ });++ it("never one under a routine's run or an outside runtime, which take their turn anyway", () => {+ expect(mayBeStatusOnly(child, { ...root, requester: { kind: "routine_run", runId: "run-1", botId: "chief", threadId: "chief-chat" } }, "Noted.", undefined)).toBe(false);+ expect(mayBeStatusOnly(child, { ...root, requester: { kind: "external_runtime", runId: "run-1" }, reply: "poll" }, "Noted.", undefined)).toBe(false);+ });++ it("never a question, a done_when, work that used a tool, an empty or a long reply, or a reply deeper in the tree", () => {+ expect(mayBeStatusOnly({ ...child, mode: "consult" }, root, "Noted.", undefined)).toBe(false);+ expect(mayBeStatusOnly({ ...child, doneWhen: "the mailbox works" }, root, "Noted.", undefined)).toBe(false);+ expect(mayBeStatusOnly(child, root, "Noted.", { toolCalls: 1 })).toBe(false);+ expect(mayBeStatusOnly(child, root, " ", undefined)).toBe(false);+ expect(mayBeStatusOnly(child, root, "x".repeat(601), undefined)).toBe(false);+ expect(mayBeStatusOnly(child, { ...root, parentId: "above" }, "Noted.", undefined)).toBe(false);+ });++ it("reads a plain ACK as status only, and anything else as needing the requester", () => {+ expect(isStatusOnly(" ack ")).toBe(true);+ for (const answer of ["NEEDS", "ACK, nothing needed", "", undefined]) expect(isStatusOnly(answer)).toBe(false);+ expect(statusReplyPrompt("FYI", "Noted.")).toContain("<teammate_reply>\nNoted.\n</teammate_reply>");+ });+});diff --git a/server/runtime/status-reply.ts b/server/runtime/status-reply.tsindex 1ac4f04d2a..05c4bb51d0 100644--- a/server/runtime/status-reply.ts+++ b/server/runtime/status-reply.ts@@ -13,6 +13,9 @@ export const STATUS_REPLY_TIMEOUT_MS = 8_000;* (done_when), work that did anything (a tool, a file, a send) or a requester that owes someone above it an answer still wakes it. */export function mayBeStatusOnly(a: Assignment, parent: Assignment | undefined, text: string, evidence: TurnEvidence | undefined): boolean {if (!parent || parent.parentId !== undefined) return false;+ // Only a person's or a bot's own turn can skip its wake (runtime.ts nothingToAnswer): a routine's run or an outside runtime+ // always takes it, so asking would only spend a call.+ if (parent.requester.kind !== "person" && parent.requester.kind !== "bot_turn") return false;if (a.requester.kind !== "bot_turn" || a.mode !== "work" || a.reply !== "resume" || a.doneWhen) return false;if (a.assignee.destination.groupId !== undefined || parent.assignee.destination.groupId !== undefined) return false;if (evidence?.toolCalls || evidence?.commands || evidence?.filesChanged?.length || evidence?.outward?.length) return false;