Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(rooms): name the holder in a queued room hand-off's reason
erywima957f83cc521
diff --git a/server/host/queued-reason.test.ts b/server/host/queued-reason.test.tsindex f639facbd1..682e85bc45 100644--- a/server/host/queued-reason.test.ts+++ b/server/host/queued-reason.test.ts@@ -7,7 +7,7 @@ const node = (over: Partial<HandoffView> = {}) => ({ id: "h-1", rootId: "h-0", pconst busy = [{ threadId: "t-a", title: "Weekly report" }, { threadId: "t-b", title: "Fix login" }];const reason = (over: Partial<QueuedReasonDeps> = {}) => createQueuedReason({botName: () => "Ops", waitsForComputer: () => false, threadBusy: () => false,- slots: () => ({ busy, limit: 2 }), groupTurn: () => false, behindPerson: () => undefined, ...over,+ slots: () => ({ busy, limit: 2 }), groupTurn: () => false, behindPerson: () => undefined, roomReason: () => undefined, ...over,});const full = "waiting for a free thread slot: Ops is already running 2 of 2 threads at once";@@ -30,6 +30,13 @@ describe("why a queued handoff has not started", () => {expect(reason({ slots: () => ({ busy: [], limit: 2 }), groupTurn: () => true })(node())).toBe("waiting for Ops to finish its turn in a room");});+ it("names the turn that holds a room, and keeps the plain line when the room cannot", () => {+ const room = node({ groupId: "room-1" });+ expect(reason({ roomReason: () => "waiting for Ada to finish its turn in this room" })(room)).toBe("waiting for Ada to finish its turn in this room");+ expect(reason()(room)).toBe("waiting for that teammate to be free");+ expect(reason({ roomReason: () => "waiting for Ada to finish its turn in this room" })(node())).toBe(full);+ });+it("falls back to the plain line when nothing explains it, and for a room's handoff", () => {expect(reason({ slots: () => ({ busy: [], limit: 2 }) })(node())).toBe("waiting for that teammate to be free");expect(reason()(node({ groupId: "room-1" }))).toBe("waiting for that teammate to be free");diff --git a/server/host/queued-reason.ts b/server/host/queued-reason.tsindex 91279b8275..696d0e2eff 100644--- a/server/host/queued-reason.ts+++ b/server/host/queued-reason.ts@@ -10,6 +10,8 @@ export interface QueuedReasonDeps {slots(botId: string): { busy: { threadId: string; title: string }[]; limit: number };groupTurn(botId: string): boolean;behindPerson(node: HandoffView): { kind: PersonWaitKind; title: string } | undefined;+ /** Why a room's hand-off waits, when the room can name the turn that holds it. */+ roomReason(node: HandoffView): string | undefined;}/** `showTitle`: name the busy threads it allows; only for the receiver itself, whose own threads they are. Otherwise just the count. */@@ -18,7 +20,7 @@ export function createQueuedReason(deps: QueuedReasonDeps) {const card = deps.behindPerson(node);if (card) return `waiting for a free slot: that teammate is waiting on the person's ${card.kind === "question" ? "answer" : card.kind} in its thread ${JSON.stringify(card.title)}; tell the person to open it`;// A room's handoff waits on the room, not on these.- if (node.groupId) return "waiting for that teammate to be free";+ if (node.groupId) return deps.roomReason(node) ?? "waiting for that teammate to be free";const name = deps.botName(node.botId) ?? "that teammate";if (deps.waitsForComputer(node)) return "waiting for the computer it needs, which another turn or a person is using";if (deps.threadBusy(node.botId, node.threadId)) return "waiting for an earlier turn in that thread to finish";diff --git a/server/index.ts b/server/index.tsindex 1dfb5fbf7e..2e43682abc 100644--- a/server/index.ts+++ b/server/index.ts@@ -3706,11 +3706,30 @@ function coordinationSystemInstructions(): string {const threadReadableFrom = (threadId: string) => (other: string): boolean => !proactive.fence.confines(other) && !botApiThread(other) && (CLOUD_TEAM ? teamHost.readableFrom(threadId)(other) : !CLOUD_HOME || cloudOwnerOnlyThread(other));const queuedDeps = { botName: (id: string) => store.bot(id)?.name, threadBusy, groupTurn: (id: string) => Boolean(activeGroupTurnForBot(id)), behindPerson: queuedBehindPerson,+ roomReason: roomQueuedReason,waitsForComputer: (node: HandoffView) => parkedSeatTaken(node.id),slots: (id: string) => ({ busy: store.tasks(id).filter((task) => threadBusy(id, task.threadId)).map(({ threadId, title }) => ({ threadId, title })), limit: maxConcurrentChildThreads(cfg, botThreadsHost(cloudPlanTier.starter())) }) }; const queuedStatus = createQueuedReason(queuedDeps), queuedNotes = createQueuedNotes({ ...queuedDeps, now: Date.now, language: (threadId) => threadLanguage(threadId), parent: (node) => node.parentId ? coordinator.node(node.parentId) : undefined, node: (id) => coordinator.node(id), post: (parent, node, line) => { const bot = store.bot(node.botId), title = store.taskByThread(node.botId, node.threadId)?.title; store.appendMessage(parent.threadId, { role: "bot", kind: "activity", ...(bot ? { from: { botId: bot.id, name: bot.name, color: bot.color } } : {}), tool: { name: line, ok: true }, ...(title ? { threadRef: { botId: node.botId, threadId: node.threadId, title } } : {}) }); } });const asksActingPerson = createAsksActingPerson({ team: Boolean(CLOUD_TEAM), requester: (threadId, generation) => actingPeople.requester(threadId, generation), askedPerson: (botId, threadId) => teamOwners.routing.askedPerson(botId, threadId) });const teammatePrompts = createTeammatePrompts({ store, asksActingPerson, outstandingDirect: (threadId) => coordinator.outstandingDirect(threadId), openPersonCard, queuedStatus, isUnattended, fullAccess: fullAccessForSource, startedOutside, guestDriven: cloudGuestDriven, confined: (threadId) => proactive.fence.confines(threadId), readableFrom: threadReadableFrom, waitingForPerson: (chief, teammates, readable) => questionRouting.waitingForPerson(chief, teammates, readable) });+/** A room hand-off waits on whatever holds that room, so name it instead of leaving every room node with the same line. */+function roomQueuedReason(node: HandoffView): string | undefined {+ if (!node.groupId) return undefined;+ const group = store.group(node.groupId);+ if (!group) return undefined;+ const ownsThread = (threadId: string) => group.dm ? threadId === group.threadId : Boolean(store.groupTaskByThread(group.id, threadId));+ const speaker = groupSpeakers.get(node.threadId)+ ?? groupSpeakers.get(group.threadId)+ ?? [...groupSpeakers].find(([threadId]) => ownsThread(threadId))?.[1];+ if (speaker) return `waiting for ${speaker.name} to finish its turn in this room`;+ const held = activeGroupTurnForBot(node.botId);+ if (!held) return undefined;+ const name = store.bot(node.botId)?.name ?? "that teammate";+ return held.group.id === group.id+ ? `waiting for ${name} to finish its turn in this room`+ : `waiting for ${name} to finish its turn in the room ${JSON.stringify(held.group.name)}`;+}+function queuedBehindPerson(node: HandoffView): { threadId: string; kind: PersonWaitKind; title: string } | undefined {if (node.groupId || node.status !== "queued" || threadBusy(node.botId, node.threadId) || !botAtThreadCapacity(node.botId, undefined, true)) return undefined;for (const task of store.tasks(node.botId)) {