The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(backend): a digest already sent today is never due again, so the Lead's poll stops rereading closed groups (#1960)
0xken15b33cbbe71c8e
diff --git a/backend/integration/superTabLiveness.test.ts b/backend/integration/superTabLiveness.test.tsindex ab94a629f..c142564fd 100644--- a/backend/integration/superTabLiveness.test.ts+++ b/backend/integration/superTabLiveness.test.ts@@ -5,9 +5,10 @@ import { join } from 'node:path'import { tmpdir } from 'node:os'import { afterAll, beforeAll, describe, expect, it } from 'vitest'import { MongoMemoryReplSet } from 'mongodb-memory-server-core'-import { PrismaClient } from '@prisma/client'+import { PrismaClient, type Prisma } from '@prisma/client'import type { AuthUser } from '../src/lib/ssoAuth.js'import { SuperTabStore, type SuperTabStoreHooks } from '../src/superTabs/store.js'+import { stableId } from '../src/superTabs/model.js'import type { Command } from '../src/superTabs/commands.js'import type { MachineObservation } from '../src/superTabs/machines.js'import * as parts from '../src/superTabs/parts/index.js'@@ -801,6 +802,34 @@ describe('the morning digest', () => {expect((await db.superTabMessage.findMany({ where: { tabId: f.tab } })).filter(m => (m.source as { kind?: string } | null)?.kind === 'digest-request')).toHaveLength(1)})+ // Prod slow log, 2026-10-28: a day's digest stored without its project marked sent (its time moved later that day, on a+ // server before this fix) stayed due, and every Lead poll read the dormant groups again, then failed on the duplicate.+ it('counts a due digest whose message is already stored as sent: the polls succeed and read nothing for it', async () => {+ const queries: Array<{ model?: string; args: { where?: Record<string, unknown> } }> = []+ const client = db.$extends({ query: { $allModels: { async $allOperations({ model, args, query }) {+ queries.push({ model, args: args as { where?: Record<string, unknown> } })+ return query(args)+ } } } }) as unknown as PrismaClient+ const f = await swarm({ client })+ const projectId = (await f.timed.read(owner, f.tab)).state.projects![0]!.id+ await f.execute({ type: 'project.digest', projectId, time: '03:00', timeZone: 'UTC' })+ f.clock.now = 3 * 60 * 60_000+ await f.leadInbox()+ const sent = (await db.superTabMessage.findMany({ where: { tabId: f.tab } })).find(m => (m.source as { kind?: string } | null)?.kind === 'digest-request')!+ // The next day's digest, already stored.+ const nextDay = { ...sent, id: stableId('digest', f.tab, projectId, '1970-01-02'), sequence: sent.sequence + 1_000,+ source: { kind: 'digest-request', projectId, on: '1970-01-02' } } as Prisma.SuperTabMessageUncheckedCreateInput+ await db.superTabMessage.create({ data: nextDay })+ f.clock.now += 24 * 60 * 60_000+ queries.length = 0+ await f.leadInbox()+ f.clock.now += 30_000+ await f.leadInbox()+ expect(queries.filter(q => q.model === 'SwarmGroup' && q.args.where?.dormant === true && q.args.where.lastActivityAt)).toEqual([])+ expect((await db.superTabMessage.findMany({ where: { tabId: f.tab } })).filter(m => (m.source as { kind?: string } | null)?.kind === 'digest-request')).toHaveLength(2)+ expect((await f.timed.read(owner, f.tab)).state.projects![0]!.digest).toMatchObject({ lastOn: '1970-01-02' })+ })+it('is sent once when two of the Lead\'s polls run at the same moment', async () => {const f = await swarm()const projectId = (await f.timed.read(owner, f.tab)).state.projects![0]!.iddiff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex fdfbf0ea1..9b355e3a9 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -2818,6 +2818,20 @@ describe('the morning digest setting (digest.ts)', () => {expect(digest()).toBeUndefined()})+ // Today's digest message has a stable id (digest.ts digestRequest): sent again at the later time, it is a duplicate, and+ // every Lead poll failed on it for the rest of the day (prod slow log, 2026-10-28).+ it('keeps today\'s digest counted as sent when its time moves later the same day', () => {+ const { f, digest } = setup()+ // 07:00 on 27 October in Vietnam, after today's 06:30 digest.+ const at = { now: Date.UTC(2026, 9, 27, 0, 0) }+ f.run({ type: 'project.digest', projectId: 'lead', time: '06:30', timeZone: 'Asia/Ho_Chi_Minh' }, owner, at)+ f.run({ type: 'project.digest', projectId: 'lead', time: '09:00', timeZone: 'Asia/Ho_Chi_Minh' }, owner, at)+ expect(digest()).toEqual({ time: '09:00', timeZone: 'Asia/Ho_Chi_Minh', lastOn: '2026-10-27' })+ // Another day's mark does not hold today's back.+ f.run({ type: 'project.digest', projectId: 'lead', time: '10:00', timeZone: 'Asia/Ho_Chi_Minh' }, owner, { now: Date.UTC(2026, 9, 28, 0, 0) })+ expect(digest()).toEqual({ time: '10:00', timeZone: 'Asia/Ho_Chi_Minh' })+ })+it('refuses a worker, an unknown time zone and a time that is not a time of day', () => {const { f, worker, as, digest } = setup()expect(() => f.run({ type: 'project.digest', projectId: 'lead', time: '08:00', timeZone: 'UTC' }, as(worker))).toThrow('A person or the project’s Lead sets its morning digest.')diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 9c7c8123b..7ed408b40 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -900,8 +900,9 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commaconst stored = projectOf(state, project.id)if (command.time === null) delete stored.digestelse {- // Set after today's time, the first digest comes tomorrow rather than at once.- const lastOn = digestStartsAfter(command.time, command.timeZone, context.now)+ // Set after today's time, the first digest comes tomorrow rather than at once; moved later on a day its digest went+ // out, it stays sent for today.+ const lastOn = digestStartsAfter(command.time, command.timeZone, context.now, stored.digest?.lastOn)stored.digest = { time: command.time, timeZone: command.timeZone, ...lastOn ? { lastOn } : {} }}breakdiff --git a/backend/src/superTabs/digest.ts b/backend/src/superTabs/digest.tsindex 85c144a6f..eb59aca31 100644--- a/backend/src/superTabs/digest.ts+++ b/backend/src/superTabs/digest.ts@@ -35,12 +35,16 @@ export function digestDue(project: SwarmProject, now: number): string | null {/** Where a project's digest starts: its last one, or the day before the first. */export const digestSince = (project: SwarmProject, now: number): number => project.digest?.lastAt ?? now - FIRST_SPAN_MS-/** The date a newly set digest counts as sent for: today, when today's time has already passed, so it starts tomorrow. */-export function digestStartsAfter(time: string, timeZone: string, now: number): string | undefined {+/** The date a newly set digest counts as sent for: today, when today's time has already passed, so it starts tomorrow, or+ * when today's was already sent (`sentOn`): its message has today's id (digestMessageId), so it is never sent twice. */+export function digestStartsAfter(time: string, timeZone: string, now: number, sentOn?: string): string | undefined {const local = localNow(timeZone, now)- return local.time >= time ? local.date : undefined+ return local.time >= time || sentOn === local.date ? local.date : undefined}+/** The id of a project's digest wake-up for one local date: one a day. */+export const digestMessageId = (tabId: string, projectId: string, on: string): string => stableId('digest', tabId, projectId, on)+/*** A project's digest: what shipped since `since` (finished with a pull request; the Lead checks each is merged), what is* in progress, what is held up, and the decisions waiting for people. Each part is left out when it is empty, so the@@ -98,7 +102,7 @@ export function digestRequest(state: SuperTabState, target: Agent, now: number,+ 'Check that each pull request under Shipped is merged, and move one that is not to In progress. Then post one message to the people in this chat '+ 'with these parts, in plain words, without commands or internal IDs.\n\n'+ projectDigest(state, project, digestSince(project, now), decisionLines(state, project, waiting))- return { id: stableId('digest', state.id, project.id, on), conversationId: project.leadConversationId,+ return { id: digestMessageId(state.id, project.id, on), conversationId: project.leadConversationId,author: author(state, { kind: 'agent', agentId: target.id, machineOwnerId: target.machineOwnerId }),text, replyTo: null, recipients: [target.id], source: { kind: 'digest-request', projectId: project.id, on } }}diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex f2c45f33e..c37566395 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -20,7 +20,7 @@ import { canReadAgent, canReadGroup, canWatchAgent, groupProject, ledProject, primport { bindSession, makeProjectPrivate } from './sessionScope.js'import { confidentialSessions, otherRegistrations, recordConfidential } from './confidential.js'import { answersRequest, dirtyGroups, noteProjectReports, projectUpdateRequest } from './projectUpdates.js'-import { digestDue, digestRequest, digestSince } from './digest.js'+import { digestDue, digestMessageId, digestRequest, digestSince } from './digest.js'import { judgedMachines, loseTasks, sweepLiveness, SWEEP_EVERY_MS } from './liveness.js'import { archivable, archiveLine, stopIdleWorkers, stoppedMachines } from './tidy.js'import { clock, insertParts, loadActive, reassemble, split, type HeadData, type SwarmParts } from './parts/index.js'@@ -1909,7 +1909,11 @@ export class SuperTabStore {// due: it loads nothing for it, or every poll repeats the loads over a growing window (Diego's issue file, 2026-10-27).const led = ledProject(loaded.state, agentId)let asked: Array<{ conversationId: string; personId: string; count: number }> = []- if (led && !loaded.state.paused && digestDue(led, this.now())) {+ const due = led && !loaded.state.paused ? digestDue(led, this.now()) : null+ // A day's digest stored while its project was not marked sent (its time moved later that day, on an older server) went+ // out: it only gets marked, or every poll would read for it again and fail on the duplicate (prod slow log, 2026-10-28).+ const sentAlready = !!due && !!await tx.superTabMessage.findUnique({ where: { id: digestMessageId(tabId, led!.id, due) }, select: { id: true } })+ if (led && due && !sentAlready) {const finished = await tx.swarmGroup.findMany({ where: { tabId, deleted: false, dormant: true, lastActivityAt: { gte: new Date(digestSince(led, this.now())) },OR: [{ projectId: led.id }, ...led.id === 'lead' ? [{ projectId: null }] : []] }, select: { key: true } })// A decision waits in its conversation even once that conversation went quiet.@@ -1918,6 +1922,10 @@ export class SuperTabStore {if (groupIds.length) loaded = await this.ensure(tx, loaded, { groupIds })}const state = structuredClone(loaded.state)+ if (sentAlready) {+ const project = projectOf(state, led!.id)+ project.digest = { ...project.digest!, lastOn: due! }+ }author(state, await this.actor(tx, user, state, agentId), true)const target = agent(state, agentId)// A Lead's poll runs the time checks (liveness.ts): lost work wakes it in this same poll.