Skip to content

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

fix(coordination): a sibling chat reads a hand-off without marking its results delivered

AdityaUmale424aae69c9e6
diff --git a/server/external-runtime.e2e.test.ts b/server/external-runtime.e2e.test.ts
index 9eedc00825..269e4c6439 100644
--- a/server/external-runtime.e2e.test.ts
+++ b/server/external-runtime.e2e.test.ts
@@ -179,6 +179,35 @@ describe("a bot's external runtime", () => {
}
}, 40_000);
+ it("reads a hand-off from another of its own chats without taking that chat's results", async () => {
+ const runtime = await createBot("Two-chat gateway");
+ const peer = await createBot("Two-chat peer");
+ const pin = (threadId: string) => writeFileSync(runtimesFile(), JSON.stringify({ [runtime.id]: { token: TOKEN, threadId } }), { mode: 0o600 });
+ try {
+ pin(runtime.threadId);
+ const handed = await asRuntime("POST", "/api/internal/coordinate-bots", { botIds: [peer.id], message: "Peer, check this" });
+ expect(handed.status, JSON.stringify(handed.body)).toBe(200);
+ await expect.poll(() => rows().find((row) => row.id === handed.body.rootId)?.status, { timeout: 15_000 }).toBe("completed");
+ const second = (await api("POST", `/api/bots/${runtime.id}/tasks`, { title: "Second chat" })).body.task.threadId;
+
+ pin(second);
+ const sibling = await asRuntime("GET", `/api/internal/assignment-status?id=${handed.body.rootId}`);
+ expect(sibling.status, JSON.stringify(sibling.body)).toBe(200);
+ expect(sibling.body.inbox.length).toBeGreaterThan(0);
+ expect(sibling.body.inbox.filter((item: { deliveredAt?: number }) => item.deliveredAt !== undefined)).toEqual([]);
+
+ pin(runtime.threadId);
+ const owner = await asRuntime("GET", `/api/internal/assignment-status?id=${handed.body.rootId}`);
+ expect(owner.status, JSON.stringify(owner.body)).toBe(200);
+ expect(owner.body.inbox.filter((item: { deliveredAt?: number }) => item.deliveredAt === undefined)).toEqual([]);
+ } finally {
+ for (const bot of [runtime, peer]) {
+ await api("POST", `/api/bots/${bot.id}/interrupt`, {}).catch(() => undefined);
+ await api("DELETE", `/api/bots/${bot.id}`).catch(() => undefined);
+ }
+ }
+ }, 40_000);
+
it("revokes slow ask and delegate requests without starting the peer", async () => {
const runtime = await createBot("Revocable gateway");
const peer = await createBot("Unused peer");
diff --git a/server/index.ts b/server/index.ts
index a1ab24f385..4ee8c2f4d1 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -13767,7 +13767,8 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
const refused = readRefusal(status.assignment); if (refused) return json(res, 403, { error: refused });
if (!reachable(status.assignment)) return json(res, 403, { error: "Result withheld: team access changed while the teammate was working" });
if (settled.has(status.assignment.status) || Date.now() >= deadline) {
- if (EXTERNAL && !status.assignment.parentId) {
+ // Only the conversation that sent it takes its results; another of the bot's chats just reads them.
+ if (EXTERNAL && !status.assignment.parentId && coordinator.node(status.assignment.rootId)?.threadId === fromThreadId) {
const lanes = new Map<string, { botId?: string; threadId?: string; runId?: string }>();
for (const item of status.inbox) {
if (item.deliveredAt !== undefined) continue;