Skip to content

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

fix(rooms): refuse a page pick when any page bot left the room or is on hold

AdityaUmale46225cff47da
diff --git a/server/room-pages-point.e2e.test.ts b/server/room-pages-point.e2e.test.ts
index bc2a030677..a467233f2c 100644
--- a/server/room-pages-point.e2e.test.ts
+++ b/server/room-pages-point.e2e.test.ts
@@ -70,4 +70,11 @@ it("sends a pick on a room page to the bot that made it, and to no other member"
// A pick must name a page in this room, and a goal is a plain typed line.
expect((await api(`/api/groups/${group.id}/messages`, { text: "This", pointed: [{ ...pointed, appId: "not-a-page" }] })).status).toBe(404);
expect((await api(`/api/groups/${group.id}/messages`, { text: "This", mode: "goal", pointed: [pointed] })).status).toBe(400);
+
+ // A pick whose page bot is on hold would reach no one, so it is refused until the bot may answer again.
+ expect((await api(`/api/groups/${group.id}/holds`, { botId: designer.id, held: true })).status).toBeLessThan(300);
+ const held = await api(`/api/groups/${group.id}/messages`, { text: "This", pointed: [pointed] });
+ expect(held.status, JSON.stringify(held.body)).toBe(409);
+ expect(held.body.error).toContain("on hold");
+ expect(evidence(designer.id).length).toBe(designerTurns + 1);
}, 120_000);
diff --git a/server/routes/channels.ts b/server/routes/channels.ts
index 5185e2295e..8a70dc2d35 100644
--- a/server/routes/channels.ts
+++ b/server/routes/channels.ts
@@ -362,9 +362,14 @@ export function createChannelRoutes(deps: ChannelRouteDeps): RouteHandler {
const pointed = pointing ? prepareRoomPointed(store, threadId, body.pointed) : null;
if (pointed && !pointed.ok) return json(res, pointed.status, refusalBody(pointed));
const pick = pointed?.pick;
- if (pick && !roomPickBots(pick).some((id) => group.memberIds.includes(id) && store.bot(id))) {
+ // Every page bot must still be here and free to answer, or part of the pick would reach no one.
+ const pageBotIds = roomPickBots(pick);
+ if (!pageBotIds.every((id) => group.memberIds.includes(id) && store.bot(id))) {
return json(res, 409, { error: "the bot that made this page is no longer in this room" });
}
+ if (!group.dm && pageBotIds.some((id) => group.holds?.[id])) {
+ return json(res, 409, { error: "the bot that made this page is on hold in this room; let it answer again first" });
+ }
const sendId = parseSendId(body.sendId);
const replyTo = resolveReplyTarget(threadId, body.replyToId);
// A bot's shell is a loopback caller too: with no paired session and no browser origin the message