Skip to content

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

fix(brief): Dismiss on an earlier day's brief card is handled by the server

AdityaUmale8a3f85cabca6
diff --git a/server/host/brief.test.ts b/server/host/brief.test.ts
index 9a57bec81e..9977d3358e 100644
--- a/server/host/brief.test.ts
+++ b/server/host/brief.test.ts
@@ -281,6 +281,24 @@ describe("the brief", () => {
expect(s.brief.dismissedFrom()).toEqual(["[email protected]"]);
});
+ it("Dismiss on an earlier day's brief takes the row off today's, with no turn, after a restart too", async () => {
+ const s = setup();
+ await s.brief.active("desktop", "UTC");
+ s.items.set("chk-1", { mail: [ada], prep: [] });
+ await s.brief.consume(s.watchRun("chk-1", '{"important": [{"id": "m1", "why": "Needs a reply.", "needsReply": false}]}'), "turn-1");
+ const yesterday = s.card()!;
+ s.advance(24 * 60 * MINUTE);
+ await s.brief.active("desktop");
+ expect(s.card()!.id).not.toBe(yesterday.id);
+ expect(s.shown()).toContain("Q3 numbers");
+ s.restart();
+ const dismiss = { type: "dismiss_row", payload: { messageId: "m1" } };
+ expect(s.brief.serverPress(s.chief, s.thread(), yesterday.id, dismiss, guest)).toBe("refused");
+ expect(s.brief.serverPress({ id: "someone-else" }, s.thread(), yesterday.id, dismiss, owner)).toBeNull();
+ expect(s.brief.serverPress(s.chief, s.thread(), yesterday.id, dismiss, owner)).toBe("handled");
+ await vi.waitFor(() => expect(s.shown()).not.toContain("Q3 numbers"));
+ });
+
it("a Draft a reply press carries the email as records, by its id only", async () => {
const s = setup();
await s.brief.active("desktop", "UTC");
diff --git a/server/host/brief.ts b/server/host/brief.ts
index 4f3dee0e78..77dd003f07 100644
--- a/server/host/brief.ts
+++ b/server/host/brief.ts
@@ -37,6 +37,7 @@ const CLOCK_SKEW_MS = 5 * MINUTE;
const IMPORTANT_DAYS_MS = 7 * DAY;
const DISMISSED_MS = 14 * DAY;
const MAX_ROWS = 60;
+const EARLIER_CARDS = 14;
/** A watch run still sorting the night's mail at the morning time gets this long before the brief goes without it. */
const MORNING_WAIT_MIN = 20;
/** A sleeping Cloud wakes this early, so the watch reads the night's mail before the brief. */
@@ -60,6 +61,8 @@ const stateSchema = z.object({
/** The day the first brief was posted: that day's card says what it does. */
introducedOn: z.string().max(10).optional(),
card: z.object({ day: z.string().max(10), botId: id, threadId: id, messageId: id, postedAt: at }).optional(),
+ /** Earlier days' cards: their Dismiss presses are still the brief's own. */
+ earlier: z.array(z.object({ threadId: id, messageId: id })).max(EARLIER_CARDS).optional(),
important: z.array(z.object({ messageId: id, threadId: id, at, judgedAt: at, needsReply: z.boolean() })).max(MAX_ROWS),
dismissed: z.array(z.object({ messageId: id, from: z.string().max(320), at })).max(MAX_ROWS),
preps: z.array(z.object({ key: id, at })).max(MAX_ROWS),
@@ -369,6 +372,7 @@ export function createBrief(deps: BriefDeps) {
if (!shown) return null;
written = { messageId: shown, json };
if (!existing) {
+ if (state.card) state.earlier = [...(state.earlier ?? []), { threadId: state.card.threadId, messageId: state.card.messageId }].slice(-EARLIER_CARDS);
state.card = { day: today(), botId: bot.id, threadId, messageId: shown, postedAt: now() };
state.introducedOn ??= state.card.day;
}
@@ -536,10 +540,8 @@ export function createBrief(deps: BriefDeps) {
return next - MORNING_WAKE_EARLY_MS;
}
- const briefRow = (threadId: string, messageId: string): boolean => {
- const card = state.card;
- return card !== undefined && card.threadId === threadId && card.messageId === messageId;
- };
+ const briefRow = (threadId: string, messageId: string): boolean =>
+ [state.card, ...(state.earlier ?? [])].some((card) => card?.threadId === threadId && card.messageId === messageId);
/** Security invariant: only the owner or an admin dismisses, only on the brief card itself, and the press starts no
* turn. Null for any other press, which goes to the bot as usual. */