Skip to content

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

Mark as unread from the bot menu skips a routine run or an archived conversation

milind-soni09ac4aac1b62
diff --git a/server/routes/bot-patch.test.ts b/server/routes/bot-patch.test.ts
index 1b8d3cf234..5183396976 100644
--- a/server/routes/bot-patch.test.ts
+++ b/server/routes/bot-patch.test.ts
@@ -570,4 +570,17 @@ describe("PATCH /api/bots/:id unread", () => {
store.appendMessage(bot.threadId, { role: "bot", kind: "text", text: "A new answer.", at: 0 });
expect(store.taskByThread(bot.id, bot.threadId)?.heldUnread, "a reply written after it ends it, whatever its clock").toBeUndefined();
});
+
+ it("marks the open main conversation, not a routine run on screen", async () => {
+ const { store, bot, patch } = fixture();
+ const openThreadId = bot.threadId;
+ const routine = store.createTask(bot.id, "Daily check", true)!;
+ store.patchTask(bot.id, routine.threadId, { routineRunId: "run-1", unread: false });
+ expect(store.bot(bot.id)!.threadId).toBe(routine.threadId);
+ expect((await patch(bot.id, { unread: true })).status).toBe(200);
+ expect(store.taskByThread(bot.id, routine.threadId)?.unread).toBe(false);
+ expect(store.taskByThread(bot.id, openThreadId)?.unread).toBe(true);
+ expect(store.taskByThread(bot.id, openThreadId)?.heldUnread).toBeDefined();
+ expect(store.bot(bot.id)?.unread).toBe(true);
+ });
});
diff --git a/server/routes/bot-patch.ts b/server/routes/bot-patch.ts
index ea008ff8a7..ed27b09327 100644
--- a/server/routes/bot-patch.ts
+++ b/server/routes/bot-patch.ts
@@ -26,6 +26,7 @@ import type { createApprovalModeSupport } from "../harness-capabilities.ts";
import type { ProviderRegistry } from "../harness/registry.ts";
import type { hostedModelPolicy } from "../hosted-models.ts";
import { heldFrom } from "../host/room-reads.ts";
+import { unreadTargetTask } from "../task-record.ts";
import { MAX_MCP_SERVERS, mcpServerNameError } from "../mcp-registry.ts";
import type { MemoryUpkeep } from "../memory-upkeep.ts";
import { phoneAppsFor } from "../phones/access.ts";
@@ -741,7 +742,10 @@ export function createBotPatchRoutes(deps: BotPatchRouteDeps): RouteHandler {
}
if (!bot) return json(res, 404, { error: "no such bot" });
if (typeof body.unread === "boolean") {
- store.patchTask(bot.id, bot.threadId, { unread: body.unread, heldUnread: body.unread ? heldFrom(store.activePath(bot.threadId), store.messagesFor(bot.threadId)) : undefined });
+ // A mark skips a routine run or an archived conversation for the open main one (task-record.ts).
+ const target = unreadTargetTask(bot, store.activeTask(bot.id), body.unread);
+ if (target) store.patchTask(bot.id, target.threadId, { unread: body.unread, heldUnread: body.unread ? heldFrom(store.activePath(target.threadId), store.messagesFor(target.threadId)) : undefined });
+ else if (!bot.tasks?.length) bot = store.patchBot(bot.id, { unread: body.unread }) ?? bot;
}
if (body.applyToAllThreads === true && requestedApprovalMode !== "custom") store.setAllThreadApprovalMode(bot.id, requestedApprovalMode);
if (body.memoryUpkeep === false || body.memoryEnabled === false) memoryUpkeep.dropBot(bot.id);