Skip to content

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

fix(person-inbox): do not notify after shutdown begins during the answer write

Sebastian Bea9b1cb1644b
diff --git a/server/host/person-inbox.test.ts b/server/host/person-inbox.test.ts
index 1aeb6f7418..1c86cd90a1 100644
--- a/server/host/person-inbox.test.ts
+++ b/server/host/person-inbox.test.ts
@@ -103,6 +103,23 @@ describe("pending assistant answers", () => {
expect(f.team.inbox.view(key(BEN.email))!.rows[0]!.answers?.at(-1)).toMatchObject({ by: "person", text: "Actually, I am busy tomorrow." });
} finally { unsubscribe(); }
});
+
+ it("does not notify when shutdown begins during the assistant answer's write event", async () => {
+ const { f, inbox, row, complete } = await pending();
+ let stoppedDuringWrite = false;
+ const unsubscribe = f.store.onChange((change) => {
+ if (change.type !== "message.patch" || change.message.id !== row.id || stoppedDuringWrite || change.message.inbox?.answers?.at(-1)?.by !== "assistant") return;
+ stoppedDuringWrite = true;
+ f.team.stop();
+ });
+ try {
+ await complete();
+ expect(stoppedDuringWrite).toBe(true);
+ expect(f.continued.map((one) => one.relay?.kind)).toEqual(["assistant"]);
+ expect(f.lines(inbox)[0]!.inbox!.answers).toEqual([expect.objectContaining({ by: "assistant", text: "Ben is free tomorrow." })]);
+ expect(f.notified).toEqual([]);
+ } finally { unsubscribe(); }
+ });
});
describe("asks routed to a person", () => {
diff --git a/server/host/person-inbox.ts b/server/host/person-inbox.ts
index 28ea9c2bb9..3cf4f33397 100644
--- a/server/host/person-inbox.ts
+++ b/server/host/person-inbox.ts
@@ -322,7 +322,7 @@ export function createPersonInbox(deps: PersonInboxDeps) {
|| !deps.person(item.person) || personOf(item.threadId) !== item.person || !isHomeOf(item.threadId, item.person)
|| deps.starters.get(item.threadId) !== item.person) return;
if (answer && answerItem(item, answer, "assistant").status === 200) {
- if (line(item)?.inbox?.answers?.at(-1)?.by !== "assistant") return;
+ if (stopped || line(item)?.inbox?.answers?.at(-1)?.by !== "assistant") return;
notifyItem(item, serverLine(conversationLanguage(item.threadId), "server.notify.assistantAnswered", { title: delivery.title }), delivery.notify, `${delivery.text} → ${answer}`);
} else notifyItem(item, delivery.title, delivery.notify, delivery.text);
}