Skip to content

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

fix(runtime): word the same-conversation refusal for the request being answered there

AdityaUmalee910fe3eb7b5
diff --git a/server/runtime-coordinator.test.ts b/server/runtime-coordinator.test.ts
index 5fca0be14f..0395f0d063 100644
--- a/server/runtime-coordinator.test.ts
+++ b/server/runtime-coordinator.test.ts
@@ -578,21 +578,27 @@ describe("RuntimeCoordinator: a request back to a bot that is waiting on you", (
expect(w.coordinator.node(asked.node.id)?.status).toBe("completed");
});
- it("refuses it from the conversation that holds the request it would answer, or into the one that waits, says which, and writes nothing", async () => {
+ it("refuses it from the conversation that holds the request it would answer, says so, and writes nothing", () => {
const w = world(holdCos);
const asked = send(w, mail, "gen-mail", undefined, cosWork, "Do you have the mailbox details from yesterday?");
expect(() => send(w, cosWork, "gen-cos-work", undefined, mailWork, "Why can't you fetch mail?"))
- .toThrow(`@mail is already waiting on you: it handed you a request (assignment ${asked.node.id}), and that has not reached you yet.`);
+ .toThrow(`@mail is already waiting on you: it handed you a request in this conversation (assignment ${asked.node.id}), and you have not finished it yet.`);
expect(w.coordinator.children("gen-cos-work")).toEqual([]);
- expect(() => send(w, cos, "gen-cos", undefined, mail, "Why can't you fetch mail?")).toThrow(/@mail is already waiting on you/);
+ });
+
+ it("refuses it into the conversation that waits, a thread you opened on the asker, says which, and lets it through once answered", async () => {
+ const w = world(holdCos);
+ // The mail bot asks from the work thread the chief of staff opened on it; a new hand-off to the mail bot goes to that thread.
+ const asked = send(w, mailWork, "gen-mail-work", undefined, cosWork, "Do you have the mailbox details from yesterday?");
+ expect(() => send(w, cos, "gen-cos", undefined, mailWork, "Why can't you fetch mail?"))
+ .toThrow(`@mail is already waiting on you: it handed you a request (assignment ${asked.node.id}), and that has not reached you yet.`);
expect(w.coordinator.children("gen-cos")).toEqual([]);
- ended(w, "gen-cos-work");
w.coordinator.tick();
expect(w.coordinator.node(asked.node.id)?.status).toBe("running");
- expect(() => send(w, cos, "gen-cos", undefined, mail, "Why can't you fetch mail?")).toThrow(/you are answering it in another conversation/);
+ expect(() => send(w, cos, "gen-cos", undefined, mailWork, "Why can't you fetch mail?")).toThrow(/you are answering it in another conversation/);
await w.host.release(asked.node.id, { ok: true, text: "No details stored" });
expect(w.coordinator.node(asked.node.id)?.status).toBe("completed");
- expect(send(w, cos, "gen-cos", undefined, mail, "Why can't you fetch mail?").node).toMatchObject({ botId: "mail", status: "queued" });
+ expect(send(w, cos, "gen-cos", undefined, mailWork, "Why can't you fetch mail?").node).toMatchObject({ botId: "mail", status: "queued" });
});
it("refuses a consultation the same way while the request waits on a question in that conversation", async () => {
@@ -619,8 +625,8 @@ describe("RuntimeCoordinator: a request back to a bot that is waiting on you", (
it("leaves a one-way notice, other teammates, rooms and the bot's own requester alone", async () => {
const w = world(holdCos);
send(w, mail, "gen-mail", undefined, cosWork, "Do you have the mailbox details from yesterday?");
- begun(w, cos, "gen-cos");
- expect(w.coordinator.enqueue(cos, "gen-cos", undefined, mailWork, "FYI: the person says it worked yesterday", { mode: "notify", reply: "none" }).node)
+ begun(w, cosWork, "gen-cos-work");
+ expect(w.coordinator.enqueue(cosWork, "gen-cos-work", undefined, mailWork, "FYI: the person says it worked yesterday", { mode: "notify", reply: "none" }).node)
.toMatchObject({ botId: "mail", reply: "none" });
expect(send(w, cos, "gen-cos", undefined, tester, "Check the mail server").node).toMatchObject({ botId: "tester" });
expect(send(w, inRoom("cos"), "gen-room", undefined, inRoom("mail"), "Why can't you fetch mail?").node).toMatchObject({ botId: "mail", groupId: "g1" });
diff --git a/server/runtime-coordinator.ts b/server/runtime-coordinator.ts
index 7d710a1ad7..bf73a8f9c6 100644
--- a/server/runtime-coordinator.ts
+++ b/server/runtime-coordinator.ts
@@ -146,7 +146,9 @@ function announcingWrites(store: RuntimeStore, wrote: () => void): RuntimeStore
* The ancestor rule covers this within one request; this covers two requests. A request from another of the asker's
* conversations goes through: each conversation answers its own. The waiting request's words are not repeated: it may come
* from another person's private chat. */
-const crossed = (asker: string, request: Assignment): string => `@${asker} is already waiting on you: it handed you a request (assignment ${
+const crossed = (asker: string, request: Assignment, here: boolean): string => here ? `@${asker} is already waiting on you: it handed you a request in this conversation (assignment ${
+ request.id}), and you have not finished it yet. Asking @${asker} for something now would leave each of you waiting on the other, so this was not sent. Answer that request here from what you know; once @${
+ asker} has your answer, you can ask it again.` : `@${asker} is already waiting on you: it handed you a request (assignment ${
request.id}), and ${request.status === "queued" ? "that has not reached you yet" : request.status === "running" ? "you are answering it in another conversation now"
: "you have not finished it yet"}. Asking @${asker} for something now would leave each of you waiting on the other, so this was not sent. Answer the person here from what you know; @${
asker}'s request reaches you in its own thread, and your answer there goes back to it. Once @${asker} has that answer, you can ask it again.`;
@@ -321,7 +323,7 @@ export class RuntimeCoordinator implements Coordinator {
if (kind === "work" && target.groupId && lineage.some(n => n.assignee.destination.groupId === target.groupId)) throw new Error(ROOM_ANCESTOR);
// A bot's own threads wait on it by design and can never ask it back (the ancestor rule above), so no two bots can cross.
const waiting = own || mode === "notify" || target.groupId !== undefined ? undefined : this.waitingOn(source, target);
- if (waiting) throw new Error(crossed(this.host.names(this.project(waiting.request), this.project(waiting.parent)).requester, waiting.request));
+ if (waiting) throw new Error(crossed(this.host.names(this.project(waiting.request), this.project(waiting.parent)).requester, waiting.request, waiting.here));
const requester: Requester = { kind: "bot_turn", botId: parent.assignee.botId, threadId: parent.assignee.destination.threadId,
chief: this.host.chiefOf(address(parent)), ...(parent.id === root.id && root.requester.runId !== undefined ? { runId: root.requester.runId } : {}) };
const level = this.host.levelOf(target, this.project(parent));
@@ -774,12 +776,13 @@ export class RuntimeCoordinator implements Coordinator {
/** Direct work `asker` handed to `bot` and still waits on: an open request whose requesting turn is still open, held in the
* conversation `bot` asks from or waiting in the one the new request goes to. */
- private waitingOn(bot: RoomAddress, asker: RoomAddress): { request: Assignment; parent: Assignment } | undefined {
+ private waitingOn(bot: RoomAddress, asker: RoomAddress): { request: Assignment; parent: Assignment; here: boolean } | undefined {
for (const request of this.live()) {
if (request.assignee.botId !== bot.botId || request.requester.botId !== asker.botId || request.reply === "none" || request.assignee.destination.groupId !== undefined) continue;
- if (request.assignee.destination.threadId !== bot.threadId && request.requester.threadId !== asker.threadId) continue;
+ const here = request.assignee.destination.threadId === bot.threadId;
+ if (!here && request.requester.threadId !== asker.threadId) continue;
const parent = request.parentId ? this.store.get(request.parentId) : undefined;
- if (parent && !isTerminal(parent)) return { request, parent };
+ if (parent && !isTerminal(parent)) return { request, parent, here };
}
return undefined;
}