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
Swarm decisions: the digest counts waiting decisions without groupBy (#1858)
0xken153064e214b403
diff --git a/backend/integration/superTabLiveness.test.ts b/backend/integration/superTabLiveness.test.tsindex bb9e15c09..807580a9e 100644--- a/backend/integration/superTabLiveness.test.ts+++ b/backend/integration/superTabLiveness.test.ts@@ -588,6 +588,24 @@ describe('the morning digest', () => {expect(await digestText()).toMatch(/\nDecisions waiting:\n- #1 Ship the parser: 201 for owner@example\.com$/)})+ // groupBy on SuperTabDecision once panicked the Prisma engine on Mongo (review of #1855): the same counts, read without it.+ it('counts the decisions waiting without groupBy, leaving out answered ones', async () => {+ const counted = counting()+ const f = await swarm({ client: counted.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' })+ const decision = (personId: string, i: number, answeredAt?: Date) => ({ id: randomUUID(), tabId: f.tab, batchId: 'batch', projectId,+ conversationId: f.group, assignmentId: null, personId, askerAgentId: f.lead, question: `Question ${i}?`, options: ['Yes', 'No'],+ recommended: 0, unblocks: 'Work', createdAt: new Date(1_000 + i), ...(answeredAt ? { answeredAt, choice: 0 } : {}) })+ await db.superTabDecision.createMany({ data: [decision(owner.sub, 1), decision(owner.sub, 2), decision(owner.sub, 3, new Date(2_000))] })+ f.clock.now = 3 * 60 * 60_000+ counted.ops.length = 0+ await f.leadInbox()+ expect(counted.ops).not.toContain('SuperTabDecision.groupBy')+ const digest = (await db.superTabMessage.findMany({ where: { tabId: f.tab } })).find(m => (m.source as { kind?: string } | null)?.kind === 'digest-request')!+ expect(digest.text).toMatch(/\nDecisions waiting:\n- #1 Ship the parser: 2 for owner@example\.com$/)+ })+it('lists a decision still waiting in a conversation that has gone quiet', async () => {const f = await swarm()const projectId = (await f.timed.read(owner, f.tab)).state.projects![0]!.iddiff --git a/backend/src/superTabs/decisions.test.ts b/backend/src/superTabs/decisions.test.tsindex ff8a0b364..33d6ff42e 100644--- a/backend/src/superTabs/decisions.test.ts+++ b/backend/src/superTabs/decisions.test.ts@@ -1,7 +1,8 @@import { describe, expect, it } from 'vitest'+import type { Prisma } from '@prisma/client'import { applyCommand, commandSchema, type Command, type CommandContext } from './commands.js'import { createSuperTab, type Actor, type AgentConfiguration } from './model.js'-import type { DecisionTarget } from './decisions.js'+import { waitingInProject, type DecisionTarget } from './decisions.js'const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }const peer: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'peer', email: '[email protected]' }@@ -108,3 +109,20 @@ describe('answering a decision', () => {expect(answered.messages[0]!.recipients).toEqual([s.lead])})})++// groupBy on SuperTabDecision once panicked the Prisma engine on Mongo: the digest counts the open decisions it reads instead.+describe('the decisions waiting in a project', () => {+ it('counts each conversation and person\'s open decisions without groupBy, reading only who and where', async () => {+ const asked: unknown[] = []+ const rows = [{ conversationId: 'c1', personId: 'owner' }, { conversationId: 'c2', personId: 'peer' }, { conversationId: 'c1', personId: 'owner' },+ { conversationId: 'c1', personId: 'peer' }, { conversationId: 'c1', personId: 'owner' }]+ const tx = { superTabDecision: {+ groupBy: async () => { throw new Error('groupBy on SuperTabDecision') },+ findMany: async (args: unknown) => { asked.push(args); return rows },+ } } as unknown as Prisma.TransactionClient+ expect(await waitingInProject(tx, 'tab', 'web')).toEqual([{ conversationId: 'c1', personId: 'owner', count: 3 },+ { conversationId: 'c2', personId: 'peer', count: 1 }, { conversationId: 'c1', personId: 'peer', count: 1 }])+ expect(asked).toEqual([{ where: { tabId: 'tab', projectId: 'web', OR: [{ answeredAt: null }, { answeredAt: { isSet: false } }] },+ select: { conversationId: true, personId: true } }])+ })+})diff --git a/backend/src/superTabs/decisions.ts b/backend/src/superTabs/decisions.tsindex 5cd203f2a..531de519b 100644--- a/backend/src/superTabs/decisions.ts+++ b/backend/src/superTabs/decisions.ts@@ -158,11 +158,19 @@ async function readable(tx: Tx, tabId: string, state: SuperTabState, actor: Acto}/** How many of a project's open decisions wait in each conversation for each person, for its digest (digest.ts- * decisionLines): never what they ask. Counted by the database, so every one counts, however many there are, and private- * ones filtered out later never crowd out shared ones (review of #1772). */+ * decisionLines): never what they ask. Every open one is read, so every one counts, however many there are, and private+ * ones filtered out later never crowd out shared ones (review of #1772). Counted here, reading only who and where:+ * groupBy on this model once panicked the Prisma engine on Mongo (review of #1855). */export async function waitingInProject(tx: Tx, tabId: string, projectId: string): Promise<Array<{ conversationId: string; personId: string; count: number }>> {- const groups = await tx.superTabDecision.groupBy({ by: ['conversationId', 'personId'], where: { tabId, projectId, ...waiting }, _count: { _all: true } })- return groups.map(g => ({ conversationId: g.conversationId, personId: g.personId, count: g._count._all }))+ const rows = await tx.superTabDecision.findMany({ where: { tabId, projectId, ...waiting }, select: { conversationId: true, personId: true } })+ const counts = new Map<string, { conversationId: string; personId: string; count: number }>()+ for (const { conversationId, personId } of rows) {+ const key = JSON.stringify([conversationId, personId])+ const entry = counts.get(key)+ if (entry) entry.count+++ else counts.set(key, { conversationId, personId, count: 1 })+ }+ return [...counts.values()]}/** A person's open decisions: how many, and a digest of which. A client reads its list again when the digest moves, as