Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(coordinate-bots): a run that never says its refusal keeps none
Flex Builder6290560a7a33
diff --git a/server/host/refused-handoffs.test.ts b/server/host/refused-handoffs.test.tsindex ef19a60681..2307a8a5f3 100644--- a/server/host/refused-handoffs.test.ts+++ b/server/host/refused-handoffs.test.ts@@ -8,8 +8,9 @@ const B = { people: ["[email protected]"] };const rooms: RosterMember = { id: "rooms", name: "Rooms", visibility: B };const hours: RosterMember = { id: "hours", name: "Staff Hours", visibility: B };const books: RosterMember = { id: "books", name: "Bookkeeping", visibility: "admins" };+const ledger: RosterMember = { id: "ledger", name: "Ledger", visibility: "admins" };const mausbot: RosterMember = { id: "maus", name: "MausBot", visibility: { people: ["[email protected]"] }, defaultBot: { person: "[email protected]" } };-const bots = [rooms, hours, books, mausbot];+const bots = [rooms, hours, books, ledger, mausbot];const SAID = "Rooms couldn't hand this to Bookkeeping, because they're shared with different people. Nothing was sent.";const r1 = { id: "run_1", routineId: "r1", botId: "rooms" }, r2 = { id: "run_2", routineId: "r2", botId: "rooms" };@@ -72,6 +73,25 @@ describe("a routine's refused hand-off", () => {expect(refused.take("t"), "the run that started since never made that call").toBeNull();});+ it("keeps nothing for a run that recorded a refusal and never took it, once another run holds the conversation", () => {+ const { refused, now } = fixture({ writer: "p_olive", asked: "p_mara" });+ refused.settled("t", rooms, ["Ledger"], 403, r1);+ now(r2);+ refused.settled("t", rooms, ["Bookkeeping"], 403, r2);+ now(r1);+ expect(refused.take("t"), "the run that failed or was cancelled before saying it kept nothing to say").toBeNull();+ });++ it("says only the refusal of the run that holds the conversation after an abandoned run's is dropped", () => {+ const { refused, lines, now } = fixture({ writer: "p_olive", asked: "p_mara" });+ refused.settled("t", rooms, ["Ledger"], 403, r1);+ now(r2);+ refused.settled("t", rooms, ["Bookkeeping"], 403, r2);+ expect(refused.take("t")).toBe(SAID);+ expect(refused.take("t")).toBeNull();+ expect(lines.map((line) => line.to), "and its writer heard it once").toEqual(["p_olive"]);+ });+it("still makes the run that made the call say so before the conversation moves on", () => {const { refused, lines, now } = fixture({ writer: "p_olive", asked: "p_mara" });const madeIn = r1;diff --git a/server/host/refused-handoffs.ts b/server/host/refused-handoffs.tsindex 697f9687e6..adb8a9b92b 100644--- a/server/host/refused-handoffs.ts+++ b/server/host/refused-handoffs.ts@@ -46,6 +46,8 @@ export function createRefusedHandoffs(deps: RefusedHandoffDeps) {// The run must still hold this conversation: another run's answer is not this one's.if (deps.runOf(threadId)?.id !== run.id) return;const byRun = refused.get(threadId) ?? new Map<string, Map<string, Refused>>();+ // No other run can ever say a refusal here, so none of theirs is worth keeping once one is recorded.+ for (const id of byRun.keys()) if (id !== run.id) byRun.delete(id);const mine = byRun.get(run.id) ?? new Map<string, Refused>();for (const raw of named) {const target = status >= 400 ? unreachableTeammate(deps.bots(), from, raw, (bot) => deps.hides?.(from, bot) === true) : null;@@ -59,7 +61,9 @@ export function createRefusedHandoffs(deps: RefusedHandoffDeps) {},/** The run in this conversation is ending well: what it must say instead, once; null when nothing was refused, or another run was. */take(threadId: string): string | null {- const run = deps.runOf(threadId), byRun = refused.get(threadId), seen = [...(run ? byRun?.get(run.id)?.values() ?? [] : [])];+ const run = deps.runOf(threadId), byRun = refused.get(threadId);+ if (byRun) for (const id of byRun.keys()) if (id !== run?.id) byRun.delete(id);+ const seen = [...(run ? byRun?.get(run.id)?.values() ?? [] : [])];// Another run's records here belong to a run that no longer holds the thread, so they can never be said.refused.delete(threadId);if (!seen.length) return null;