Skip to content

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

fix(notifications): a thread a bot opened stays quiet until the person asks in it

Absterrg03690087d500b
diff --git a/docs/notification-and-proactivity-qa.md b/docs/notification-and-proactivity-qa.md
index f304a2ddf8..a693d95306 100644
--- a/docs/notification-and-proactivity-qa.md
+++ b/docs/notification-and-proactivity-qa.md
@@ -16,6 +16,12 @@ notifications disabled remains quiet. Otherwise it may emit:
- **Finished** only when there is a non-empty result to summarize.
- **Routine failed** when a scheduled or manual routine run cannot complete.
+A thread a bot opened (a teammate's assignment, a bot's own `start_thread`)
+sends no **Finished** and no **resumed with results** while the newest request
+in it is a bot's. The person's own message there is announced as anywhere
+else, and so is a Chief of Staff's report on a failure the person was not told
+of. Approvals, questions, sign-ins and failures notify in every thread.
+
Every notification carries both the bot ID and the exact task thread ID. A
click must select that bot **and switch to that task**, including a routine's
detached task; opening whichever task happens to be active is a failure.
@@ -33,6 +39,7 @@ alone cannot provide closed-app delivery.
| Contract | Test |
|---|---|
| Per-agent off means quiet; empty completions stay quiet; summaries are bounded | `server/notify.test.ts` |
+| A bot-opened thread stays quiet until the person asks in it | `server/notify.test.ts`, `server/notification-routing.e2e.test.ts`, `server/direct-coordination.e2e.test.ts` |
| Browser click returns the exact bot/task target | `src/lib/notify.test.ts` |
| Store navigation selects the bot and switches the task | `src/state/store.test.ts` |
| Opening a conversation reads only its own feed entries, live in every open app | `server/notification-read.e2e.test.ts` |
diff --git a/server/direct-coordination.e2e.test.ts b/server/direct-coordination.e2e.test.ts
index 4848b30412..f2b8cff138 100644
--- a/server/direct-coordination.e2e.test.ts
+++ b/server/direct-coordination.e2e.test.ts
@@ -195,20 +195,15 @@ it("coordinates a lead and its specialist from ordinary chat, returns to Clive,
expect(turn.system).toContain("only an actual coordinate_bots result proves that teammate participated");
}), 45_000);
-it("announces a settled delegation and its resume in the parent thread", () => fixture(async f => {
+it("announces a settled delegation in the parent thread, not in the thread the Chief opened for its lead", () => fixture(async f => {
const stream = await openSse(`${f.session.info.url}/api/events`);
try {
await f.start();
expect((await f.wait()).status).toBe("settled");
- // f.wait() resolves through the control CLI poll, independent of the SSE reader: until() proves both settles are stored first.
- await Promise.all([
- stream.until(frame => frame.kind === "notify"
- && frame.notification?.kind === "delegation-settled"
- && frame.notification.botId === f.chief.id),
- stream.until(frame => frame.kind === "notify"
- && frame.notification?.kind === "delegation-settled"
- && frame.notification.botId === f.lead.id),
- ]);
+ // f.wait() resolves through the control CLI poll, independent of the SSE reader: until() proves the Chief's settle is stored first.
+ await stream.until(frame => frame.kind === "notify"
+ && frame.notification?.kind === "delegation-settled"
+ && frame.notification.botId === f.chief.id);
const settles = () => stream.frames.filter(frame => frame.kind === "notify" && frame.notification?.kind === "delegation-settled");
const chiefFrames = settles().filter(frame => frame.notification.botId === f.chief.id);
expect(chiefFrames).toHaveLength(1);
@@ -217,9 +212,7 @@ it("announces a settled delegation and its resume in the parent thread", () => f
title: "Clive resumed with results",
body: "Results in from Engineering lead",
});
- const leadFrames = settles().filter(frame => frame.notification.botId === f.lead.id);
- expect(leadFrames).toHaveLength(1);
- expect(leadFrames[0].notification.threadId).not.toBe(f.lead.activeTaskId);
+ expect(settles().some(frame => frame.notification.botId === f.lead.id)).toBe(false);
expect(settles().some(frame => frame.notification.botId === f.specialist.id)).toBe(false);
expect(stream.frames.some(frame => frame.kind === "notify" && frame.notification?.kind === "done"
&& (frame.notification.botId === f.lead.id || frame.notification.botId === f.specialist.id))).toBe(false);
diff --git a/server/index.ts b/server/index.ts
index e5feaecff6..752ca39aac 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -197,7 +197,7 @@ import { assertWithinBudget, noteSpend, spendAlertText, spendState, takeSpendAle
import { fleetAvailable, fleetSocketPath } from "./fleet-client.ts";
import { HOSTED_CONTRACT_HEADER, HOSTED_CONTRACT_METADATA, HOSTED_CONTRACT_VERSION } from "./hosted-contract.ts";
import { cliProbeEnvironment, testCliBinary } from "./cli-probe.ts";
-import { buildMentionNotification, buildNoticeNotification, buildNotification, buildSpendNotification, type Notification } from "./notify.ts";
+import { buildMentionNotification, buildNoticeNotification, buildNotification, buildSpendNotification, type Notification, unaskedBotThread } from "./notify.ts";
import {
isModelVariant,
TurnNotStartedError, TurnAuthenticationRefusedError, TurnUsageLimitRefusedError,
@@ -4100,7 +4100,7 @@ const coordinator: Coordinator = createCoordinator({
});
const quiet = turnAnswers(node.threadId, { cardContinuation: true, coordination: node }).quiet;
const routineRoot = !node.parentId && activeRoutineRunForThread(node.threadId) !== null;
- if (node.restart !== "rerun" && !quiet && !routineRoot && asking.length === 0) {
+ if (node.restart !== "rerun" && !quiet && !routineRoot && asking.length === 0 && !unaskedBotThread(store.taskByThread(bot.id, node.threadId), store.activePath(node.threadId), node.parentId ? node.createdAt : undefined)) {
notify(buildNotification("delegation-settled", bot, node.threadId, `Results in from ${who}`, { avatarUrl: bot.avatarUrl }));
}
if (!node.parentId && !quiet) reviewAnswerThreads.add(node.threadId);
@@ -6949,7 +6949,7 @@ bus.subscribe((event: RuntimeEvent) => {
const routineReportThread = routineRun ? routineSourceThread(routineRun) : null;
if (!routineReportThread && (!internal || reviewAnswer)) store.patchTask(bot.id, event.threadId, { unread: true });
if (routineRun && routineReportThread !== event.threadId) automationReports.runSettled(routineRun, completedTurnId);
- else if ((!routineRun || routineRun.status === "completed") && !internal && !computerSelectionTurns.get(event.threadId)?.selected) {
+ else if ((!routineRun || routineRun.status === "completed") && !internal && !unaskedBotThread(settledTask, store.activePath(event.threadId)) && !computerSelectionTurns.get(event.threadId)?.selected) {
notify(buildNotification("done", bot, event.threadId, routineRun ? reply || routineRun.output || routineRun.routineName : reply, { avatarUrl: bot.avatarUrl }), routineRun ? { routine: true } : undefined);
}
if (screenPollers.has(event.threadId)) {
diff --git a/server/notification-routing.e2e.test.ts b/server/notification-routing.e2e.test.ts
index 7ef73b2cd0..5d95e63112 100644
--- a/server/notification-routing.e2e.test.ts
+++ b/server/notification-routing.e2e.test.ts
@@ -399,6 +399,62 @@ describe("bot-to-bot coordination is recorded, not announced", () => {
}
}, 60_000);
+ it("does not announce results coming back into a thread a bot opened", async () => {
+ const boss = await createBot("Ledger", "quick");
+ const asker = await createBot("Stylus", "asker");
+ const peer = await createBot("Quill", "quick");
+ const stream = await openSse(`${base}/api/events`);
+ try {
+ expect((await api("PATCH", `/api/bots/${asker.id}`, { peers: [peer.id] })).status).toBe(200);
+ const assigned = await api(
+ "POST",
+ "/api/internal/coordinate-bots",
+ { botIds: [asker.id], message: "Stylus, ask Quill whether the deploy can go.", thread: "new" },
+ await capability(boss.id, boss.threadId),
+ );
+ expect(assigned.status, JSON.stringify(assigned.body)).toBe(200);
+ const work = await consultation(assigned.body.receipts[0].requestId);
+ expect(work.threadId).not.toBe(asker.threadId);
+ await expect.poll(() => handoffs().some((node) => node.parentId === work.id && node.botId === peer.id), { timeout: 30_000 }).toBe(true);
+ await expect.poll(async () => ((await state(40)).bots.find((bot: { id: string }) => bot.id === asker.id)?.tasks ?? [])
+ .find((task: { threadId: string }) => task.threadId === work.threadId)?.busy, { timeout: 30_000 }).toBeFalsy();
+ await expect.poll(() => handoffs().find((node) => node.id === work.id)?.status, { timeout: 30_000 }).toBe("completed");
+
+ expect((await api("PATCH", `/api/bots/${asker.id}`, { name: "Stylus observed" })).status).toBe(200);
+ await stream.until(
+ (candidate) => candidate.kind === "bot" && candidate.bot?.id === asker.id && candidate.bot?.name === "Stylus observed",
+ );
+ const notified = stream.frames.filter((candidate) => candidate.kind === "notify").map((candidate) => candidate.notification);
+ expect(notified.filter((notification) => notification?.threadId === work.threadId), JSON.stringify(notified)).toEqual([]);
+ } finally {
+ stream.close();
+ await cleanup([], [boss.id, asker.id, peer.id]);
+ }
+ }, 90_000);
+
+ it("announces a thread a bot opened for itself only once the person asks in it", async () => {
+ const bot = await createBot("Margin", "quick");
+ const stream = await openSse(`${base}/api/events`);
+ try {
+ const opened = await api("POST", "/api/internal/threads", { title: "Sort the notes", message: "Sort the notes by date." }, await capability(bot.id, bot.threadId));
+ expect(opened.status, JSON.stringify(opened.body)).toBe(201);
+ await expect.poll(async () => ((await botState(bot.id))?.tasks ?? [])
+ .find((task: { threadId: string }) => task.threadId === opened.body.threadId)?.unread, { timeout: 20_000 }).toBe(true);
+
+ expect((await api("PATCH", `/api/bots/${bot.id}`, { name: "Margin observed" })).status).toBe(200);
+ await stream.until((candidate) => candidate.kind === "bot" && candidate.bot?.id === bot.id && candidate.bot?.name === "Margin observed");
+ const notified = stream.frames.filter((candidate) => candidate.kind === "notify").map((candidate) => candidate.notification);
+ expect(notified.filter((notification) => notification?.threadId === opened.body.threadId), JSON.stringify(notified)).toEqual([]);
+
+ expect((await api("POST", `/api/bots/${bot.id}/messages`, { text: "and the old ones?", threadId: opened.body.threadId })).status).toBe(202);
+ const frame = await stream.until((candidate) => candidate.kind === "notify" && candidate.notification?.threadId === opened.body.threadId, 20_000);
+ expect(frame.notification).toMatchObject({ kind: "done", title: "Margin observed finished" });
+ } finally {
+ stream.close();
+ await cleanup([], [bot.id]);
+ }
+ }, 45_000);
+
it("still announces the person's own next message after a hop that finished", async () => {
const asker = await createBot("Nib", "quick");
const peer = await createBot("Vellum", "quick");
diff --git a/server/notify.test.ts b/server/notify.test.ts
index 738db4697b..b5a19cb3db 100644
--- a/server/notify.test.ts
+++ b/server/notify.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { buildNotification, buildSpendNotification, summarize } from "./notify.ts";
+import { buildNotification, buildSpendNotification, summarize, unaskedBotThread } from "./notify.ts";
const bot = { id: "bot-1", name: "Scout", threadId: "thread-1" };
@@ -120,3 +120,26 @@ describe("buildSpendNotification", () => {
});
});
});
+
+describe("unaskedBotThread", () => {
+ const opened = { openedBy: { botId: "chief" } };
+ const person = (at: number) => ({ role: "user", kind: "text", at });
+ const peer = (at: number) => ({ role: "user", kind: "text", at, peerAsk: {} });
+ const reply = (at: number) => ({ role: "bot", kind: "text", at });
+
+ it("is quiet while the newest request in a bot-opened thread is a bot's", () => {
+ expect(unaskedBotThread(opened, [])).toBe(true);
+ expect(unaskedBotThread(opened, [peer(1), reply(2)])).toBe(true);
+ expect(unaskedBotThread(opened, [peer(1), reply(2), person(3), reply(4), peer(5)])).toBe(true);
+ expect(unaskedBotThread(opened, [person(1), reply(2)], 3)).toBe(true);
+ });
+
+ it("speaks for the person's own request, a failure report, and any thread a person opened", () => {
+ expect(unaskedBotThread(opened, [peer(1), reply(2), person(3), reply(4)])).toBe(false);
+ expect(unaskedBotThread(opened, [reply(2), person(3)], 1)).toBe(false);
+ expect(unaskedBotThread(opened, [{ ...peer(1), peerAsk: { incident: {} } }])).toBe(false);
+ expect(unaskedBotThread({}, [peer(1)])).toBe(false);
+ expect(unaskedBotThread({}, [person(1)], 2)).toBe(false);
+ expect(unaskedBotThread(undefined, [])).toBe(false);
+ });
+});
diff --git a/server/notify.ts b/server/notify.ts
index 09c6175d17..44dee88060 100644
--- a/server/notify.ts
+++ b/server/notify.ts
@@ -68,6 +68,17 @@ export function buildNotification(
return notification;
}
+export function unaskedBotThread(
+ task: { openedBy?: unknown } | undefined,
+ path: readonly { role: string; kind: string; at: number; peerAsk?: { incident?: unknown } }[],
+ assignedAt?: number,
+): boolean {
+ if (!task?.openedBy) return false;
+ const asked = path.findLast((message) => message.role === "user" && message.kind === "text");
+ if (!asked || (assignedAt !== undefined && asked.at < assignedAt)) return true;
+ return Boolean(asked.peerAsk && !asked.peerAsk.incident);
+}
+
type MentionSource = {
activePath(threadId: string): readonly { role: string; kind: string; text?: string; turnId?: string; from?: { botId: string } }[];
bot(id: string): { name: string; hidden?: boolean } | null | undefined;