Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
coordinate_bots to teammates elsewhere: a success never carries the local error, and keeps the local not-sent list
Bugfixer 241c9ebf449f8
diff --git a/server/peer-delivery.test.ts b/server/peer-delivery.test.tsindex daf28c5449..483a064be3 100644--- a/server/peer-delivery.test.ts+++ b/server/peer-delivery.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { peerDeliveryReceipt, renderPeerDeliveryReceipts, type PeerDeliveryReceipt } from "./peer-delivery.ts";+import { peerDeliveryReceipt, renderPeerDeliveryReceipts, withTargetsHere, type PeerDeliveryReceipt } from "./peer-delivery.ts";describe("peerDeliveryReceipt", () => {it("keeps the ids and tickets and clips a hostile detail onto one line", () => {@@ -73,3 +73,30 @@ describe("renderPeerDeliveryReceipts", () => {expect(text).not.toContain("]");});});++describe("withTargetsHere", () => {+ const remote = (outcome: "queued" | "failed", detail: string) => peerDeliveryReceipt({ botId: "remote:1:a", botName: "Far", outcome, detail });+ const call = { botIds: ["remote:1:a", "bot-here"] };++ it("reports this server's failure as not sent, never as an error, when the other server took the work", async () => {+ const result = await withTargetsHere(call, ["bot-here"], { receipts: [remote("queued", "sent")], refused: [], message: "Far has it." },+ async () => ({ status: 409, body: { error: "Helper is busy" } }));+ expect(result.status).toBe(200);+ expect(result.body).not.toHaveProperty("error");+ expect(result.body).toMatchObject({ message: "Far has it.", notSent: "Helper is busy" });+ });++ it("lists a refusal on the other server and this server's own unsent bots together", async () => {+ const result = await withTargetsHere(call, ["bot-here"], { receipts: [remote("failed", "key refused")], refused: ["Far: key refused"], message: "" },+ async () => ({ status: 200, body: { message: "Helper has it.", notSent: "bot-gone: no such bot" } }));+ expect(result.body).toMatchObject({ message: "Helper has it.", notSent: "Far: key refused; bot-gone: no such bot" });+ expect(result.body).not.toHaveProperty("error");+ });++ it("fails with every reason when nothing was sent anywhere", async () => {+ const result = await withTargetsHere(call, ["bot-here"], { receipts: [remote("failed", "key refused")], refused: ["Far: key refused"], message: "" },+ async () => ({ status: 404, body: { error: "no such bot" } }));+ expect(result).toMatchObject({ status: 404, body: { error: "Far: key refused; no such bot" } });+ expect(result.body).not.toHaveProperty("message");+ });+});diff --git a/server/peer-delivery.ts b/server/peer-delivery.tsindex 973cb10068..0b2a097c2c 100644--- a/server/peer-delivery.ts+++ b/server/peer-delivery.ts@@ -65,13 +65,15 @@ export async function withTargetsHere<Call extends { botIds: string[] }>(call: Cconst rest = await local({ ...call, botIds: [...here] });const theirs = Array.isArray(rest.body.receipts) ? rest.body.receipts as PeerDeliveryReceipt[] : [];const ok = delivered || rest.status === 200;- const errors = [...refused, ...(typeof rest.body.error === "string" ? [rest.body.error] : [])];+ // The local part's error and not-sent list are rebuilt below, so a success never carries its error.+ const { instructionOnly: localInstructionOnly, error: localError, notSent: localNotSent, ...restBody } = rest.body;+ const errors = [...refused, ...(typeof localError === "string" ? [localError] : [])];+ const notSent = [...errors, ...(typeof localNotSent === "string" ? [localNotSent] : [])];// Instruction-only is the whole call's verdict: nothing was delivered anywhere and no refusal elsewhere is a real// failure. One genuine refusal, or a delivery, keeps this a failed call however the local part answered.- const { instructionOnly: localInstructionOnly, ...restBody } = rest.body;const instructionOnly = !ok && refused.length === 0 && localInstructionOnly === true;return { status: ok ? 200 : rest.status, body: { ...restBody, receipts: [...receipts, ...theirs],- ...(ok ? { message: [mine, rest.body.message].filter(Boolean).join(" "), ...(errors.length ? { notSent: errors.join("; ") } : {}) } : { error: errors.join("; ") }),+ ...(ok ? { message: [mine, rest.body.message].filter(Boolean).join(" "), ...(notSent.length ? { notSent: notSent.join("; ") } : {}) } : { error: errors.join("; ") }),...(instructionOnly ? { instructionOnly: true } : {}) } };}