Skip to content

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

fix(runtime): name the request held in this conversation first when several wait

AdityaUmale35f3b0755dfe
diff --git a/server/runtime-coordinator.test.ts b/server/runtime-coordinator.test.ts
index 0395f0d063..5e85d58d9d 100644
--- a/server/runtime-coordinator.test.ts
+++ b/server/runtime-coordinator.test.ts
@@ -586,6 +586,14 @@ describe("RuntimeCoordinator: a request back to a bot that is waiting on you", (
expect(w.coordinator.children("gen-cos-work")).toEqual([]);
});
+ it("names the request held in this conversation even when an older one waits in the thread the new request goes to", () => {
+ const w = world(holdCos);
+ send(w, mailWork, "gen-mail-work", undefined, { botId: "cos", threadId: "cos-elsewhere" }, "Which mailbox should I check?");
+ 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 in this conversation (assignment ${asked.node.id}), and you have not finished it yet.`);
+ });
+
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.
diff --git a/server/runtime-coordinator.ts b/server/runtime-coordinator.ts
index bf73a8f9c6..11b6f0de55 100644
--- a/server/runtime-coordinator.ts
+++ b/server/runtime-coordinator.ts
@@ -775,16 +775,19 @@ 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. */
+ * conversation `bot` asks from or waiting in the one the new request goes to. A request held here wins over one waiting there. */
private waitingOn(bot: RoomAddress, asker: RoomAddress): { request: Assignment; parent: Assignment; here: boolean } | undefined {
+ let there: { 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;
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, here };
+ if (!parent || isTerminal(parent)) continue;
+ if (here) return { request, parent, here };
+ there ??= { request, parent, here };
}
- return undefined;
+ return there;
}
private parkedIn(threadId: string): Assignment | undefined {