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
Backend follow-ups from today's reviews: stale decisions, unit tests without Redis, Buddy cannot-start line (Dee) (#2456)
0xken1563aff73044de
diff --git a/backend/integration/superTabRead.test.ts b/backend/integration/superTabRead.test.tsindex 1a1a6df54..53ab2d4e7 100644--- a/backend/integration/superTabRead.test.ts+++ b/backend/integration/superTabRead.test.ts@@ -17,7 +17,7 @@ import { noteChange, swarmTransaction } from '../src/superTabs/cache.js'import { guardedWrite } from '../src/superTabs/parts/write.js'import { migrateSwarm } from '../src/superTabs/migration/migrate.js'import { SwarmReads } from '../src/superTabs/read/service.js'-import { decisionsWaiting } from '../src/superTabs/decisions.js'+import { decisionsWaiting, MAX_OPEN_DECISIONS, REFLECTION_DECISION } from '../src/superTabs/decisions.js'import { waitingTagConversations } from '../src/superTabs/mentions.js'import { writeReadMark } from '../src/superTabs/readMarks.js'import { buddyChatId } from '../src/superTabs/buddies.js'@@ -893,6 +893,44 @@ describe('decisions asked of one person (v2)', () => {expect((await post(s.tabId, { type: 'decision.answer', decisionId: again, choice: 1 }, peer)).status).toBe(200)})+ // Review of #2454: closed only where work ends from then on, those of work already over stayed open, hidden: they counted+ // toward the asker's open limit and came back when the task reopened. The worker closes them once at startup.+ it('closes, once at startup, the decisions still waiting in work over before decisions closed, and no other', async () => {+ const s = await scene(), other = await scene()+ clock = Date.now()+ await writeGroup(s.tabId, s.secretGroup, Date.now(), group => { group.archived = true; group.dormant = true })+ await writeGroup(s.tabId, 'lead', Date.now(), group => { group.assignment = { ...(group.assignment ?? { id: 'x', agentId: s.lead, configuration: {} as never,+ execution: { machineId: 'host', harnessId: 'h', machineOwnerId: owner.sub }, result: null }), status: 'cancelled' } })+ // As an older server left them: the PM's open limit for peer filled by decisions in work since done.+ const row = (tabId: string, conversationId: string, n: string, extra: Record<string, unknown> = {}) => ({ id: `${tabId}-${n}`, tabId, batchId: `b-${n}`,+ projectId: 'lead', conversationId, assignmentId: null, personId: peer.sub, askerAgentId: s.lead, ...question(`Q ${n}?`), createdAt: new Date(clock - 60_000), ...extra })+ const stale = Array.from({ length: MAX_OPEN_DECISIONS - 1 }, (_, i) => row(s.tabId, s.done, `done-${i}`))+ const kept = [row(s.tabId, s.web, 'open-work'), row(s.tabId, 'lead', 'project-chat'), row(s.tabId, s.buddyId, 'buddy-chat'),+ row(s.tabId, s.privateId, 'chat-with-pm'), row(s.tabId, s.done, 'reflection', { kind: REFLECTION_DECISION }),+ // Asked after the pass read the work as over: in work reopened since, so it stays.+ row(s.tabId, s.done, 'later', { createdAt: new Date(clock + 60_000) })]+ const archived = row(s.tabId, s.secretGroup, 'archived'), elsewhere = [row(other.tabId, other.done, 'done'), row(other.tabId, other.web, 'open-work')]+ await db.superTabDecision.createMany({ data: [...stale, ...kept, archived, ...elsewhere] })+ const full = await post(s.tabId, { type: 'decision.ask', conversationId: s.web, personId: peer.sub, questions: [question('Ship how?')] }, owner, s.lead)+ expect(full.body.error?.code).toBe('DECISIONS_FULL')++ // At least these: the pass reads every Swarm of the database, where earlier tests left theirs.+ expect(await new SuperTabStore(db, () => clock).withdrawEndedDecisions()).toBeGreaterThanOrEqual(stale.length + 2)+ const withdrawn = [...stale, archived, elsewhere[0]!].map(r => r.id)+ for (const id of withdrawn) expect(await db.superTabDecision.findUnique({ where: { id } })).toMatchObject({ withdrawn: true, choice: null, answeredAt: new Date(clock) })+ for (const { id } of [...kept, elsewhere[1]!]) expect(await db.superTabDecision.findUnique({ where: { id } })).toMatchObject({ answeredAt: null, withdrawn: null })+ // Once: a second start finds nothing more to close.+ expect(await new SuperTabStore(db, () => clock).withdrawEndedDecisions()).toBe(0)+ // The limit has room again, and a reopened task does not bring them back.+ const asked = await post(s.tabId, { type: 'decision.ask', conversationId: s.web, personId: peer.sub, questions: [question('Ship how?')] }, owner, s.lead)+ expect(asked.status, JSON.stringify(asked.body)).toBe(200)+ // Reopened as stored (the fixture's worker is busy in other tests' Swarms, so no work.assign here).+ await writeGroup(s.tabId, s.done, Date.now(), group => { group.assignment = { ...group.assignment!, status: 'working' } })+ const open = (await decisions(s.tabId, peer)).map(d => d.id)+ for (const id of withdrawn) expect(open).not.toContain(id)+ expect(open).toContain(`${s.tabId}-later`)+ })+it('stops counting one in work that ended before decisions closed (no command closed it): not counted, listed, in catch-up or answerable', async () => {const s = await scene()clock = Date.now()diff --git a/backend/integration/superTabSwarmBuddy.test.ts b/backend/integration/superTabSwarmBuddy.test.tsindex 6da2b1dc1..8603a2b99 100644--- a/backend/integration/superTabSwarmBuddy.test.ts+++ b/backend/integration/superTabSwarmBuddy.test.ts@@ -429,6 +429,51 @@ describe('security re-check 2 of #2435', () => {})})+// Review of #2447: a phone's message in an older Buddy chat that no Buddy can answer was kept, and its person heard nothing.+describe('a phone\'s message no Buddy can answer', () => {+ const line = (why: string) => `I can't start in this chat right now: ${why}. Your message is kept.`+ const rows = async (f: Swarm, chat: string) => (await f.store.messages(peer, f.tab, chat, {})).messages++ it('tells its person why, in plain words, once per outage and not once per message, from their Buddy, to them alone', async () => {+ const cases: Array<[string, string, (f: Swarm) => Promise<unknown>]> = [+ ['at its limit', 'Peer Mac already runs as many agents as it takes', async () => undefined],+ ['paused by its owner', 'Peer Mac is paused', f => f.execute({ type: 'machine.pause', machineId: 'peer-mac', paused: true }, peer)],+ ['in a paused Swarm', 'the Swarm is paused', f => f.execute({ type: 'tab.pause', paused: true })],+ ['offline', 'Peer Mac is offline', async f => { f.clock.now += 60 * 60_000 }],+ ]+ for (const [label, why, outage] of cases) {+ const f = await swarm({ maxAgents: label === 'at its limit' ? 1 : 8 })+ const { main } = await buddy(f)+ const old = String((await f.execute({ type: 'buddy.chat', projectId: f.web.projectId }, peer)).result.conversationId)+ await outage(f)+ for (const n of [1, 2, 3]) expect((await send(f, old, `From the phone ${n}`)).result.startId, label).toBeUndefined()+ const seen = await rows(f, old)+ expect(seen.map(m => m.text), label).toEqual(['From the phone 1', line(why), 'From the phone 2', 'From the phone 3'])+ expect(seen[1]!.author, label).toMatchObject({ kind: 'agent', id: main })+ // Their own chat: the Swarm's owner reads none of it.+ await expect(f.store.messages(owner, f.tab, old, {}), label).rejects.toThrow(UNAVAILABLE)+ }+ })++ it('tells again in the next outage, once a Buddy could start in between', async () => {+ const f = await swarm()+ await buddy(f)+ const old = String((await f.execute({ type: 'buddy.chat', projectId: f.web.projectId }, peer)).result.conversationId)+ const pause = (paused: boolean) => f.execute({ type: 'machine.pause', machineId: 'peer-mac', paused }, peer)+ await pause(true)+ await send(f, old, 'First outage')+ await pause(false)+ const started = String((await send(f, old, 'Back')).result.startId)+ expect(started).not.toBe('undefined')+ await f.host({ type: 'agent.startFailed', startId: started, error: 'The session could not open.' })+ await pause(true)+ await send(f, old, 'Second outage')+ await send(f, old, 'Still out')+ expect((await rows(f, old)).map(m => m.text)).toEqual(['First outage', line('Peer Mac is paused'), 'Back',+ expect.stringMatching(/^Could not start peer's Buddy/), 'Second outage', line('Peer Mac is paused'), 'Still out'])+ })+})+describe('older apps', () => {it('keeps an old project chat readable, and a message there reaches a session of that project', async () => {const f = await swarm()diff --git a/backend/src/lib/noRedis.test-support.ts b/backend/src/lib/noRedis.test-support.tsnew file mode 100644index 000000000..3d04f26cc--- /dev/null+++ b/backend/src/lib/noRedis.test-support.ts@@ -0,0 +1,20 @@+// Shared setup of the backend unit and Super Tab integration runners (vitest.config.ts, vitest.super-tabs.config.ts): no+// test opens Redis (#2434). The bus (bus.ts) makes its clients on import, so a file that imports it without stubbing it,+// even through another module, opened four real connections whose reconnect errors logged after the file ended ("Closing+// rpc while onUserConsoleLog was pending").+// Here every client stays unconnected: its commands fail at once, as in a Redis outage, and a subscription waits.+// A file that stubs ioredis or the bus itself keeps its own stub. Every file that needs real clients calls+// vi.unmock('ioredis'): against a fake server of its own (redisGuard.test.ts), or a real Redis (redisRateCounter.test.ts+// where redis-server is installed; terminalRouteRedis.test.ts and superTabs/cacheRedis.test.ts with REDIS_TEST_URL).+import { vi } from 'vitest'++vi.mock('ioredis', async original => {+ const real = await original<typeof import('ioredis')>()+ // Every connect, the constructor's and each command's, goes through here: no socket opens and the status stays "wait".+ class UnconnectedRedis extends real.Redis {+ override connect(): Promise<void> {+ return Promise.reject(new Error('Unit tests run with no Redis (noRedis.test-support.ts).'))+ }+ }+ return { ...real, Redis: UnconnectedRedis, default: UnconnectedRedis }+})diff --git a/backend/src/lib/noRedis.test.ts b/backend/src/lib/noRedis.test.tsnew file mode 100644index 000000000..529cf3549--- /dev/null+++ b/backend/src/lib/noRedis.test.ts@@ -0,0 +1,15 @@+import { describe, expect, it } from 'vitest'++// Unit tests run with no Redis (#2434): a file that imports the bus without stubbing it, as webWs.test.ts does through+// webWs.ts, used to open four real clients whose reconnect errors logged after the file ended ("Closing rpc while+// onUserConsoleLog was pending"). The shared setup (noRedis.test-support.ts) gives every file clients that never connect.+describe('the bus in unit tests', () => {+ it('opens no connection, and its commands fail at once as in an outage', async () => {+ const bus = await import('./bus.js')+ // Long enough for a real client to have started connecting and failed once.+ await new Promise(resolve => setTimeout(resolve, 50))+ expect(bus.pub.status).toBe('wait')+ await expect(bus.pub.get('anything')).rejects.toThrow("Stream isn't writeable")+ expect(bus.pub.status).toBe('wait')+ })+})diff --git a/backend/src/lib/redisGuard.test.ts b/backend/src/lib/redisGuard.test.tsindex 4e384abc9..7916bd511 100644--- a/backend/src/lib/redisGuard.test.ts+++ b/backend/src/lib/redisGuard.test.ts@@ -1,9 +1,12 @@-import { afterEach, describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { createServer, type AddressInfo, type Server, type Socket } from 'node:net'import { Redis } from 'ioredis'import { createCircuitBreaker, CircuitOpenError } from './circuitBreaker.js'import { guardRedisCommands, isRedisFailure, wasNotSent } from './redisGuard.js'+// Real clients, against the fake server below: the shared setup's never connect (noRedis.test-support.ts).+vi.unmock('ioredis')+// A real ioredis client against a loopback server that speaks just enough RESP: while `answering` is false it reads// commands and never replies (a Redis that is up but stuck); once answering it owes, and sends in order, a nil for every// command it has read, as a Redis that comes unstuck does.diff --git a/backend/src/lib/redisRateCounter.test.ts b/backend/src/lib/redisRateCounter.test.tsindex 0062c4564..cae574791 100644--- a/backend/src/lib/redisRateCounter.test.ts+++ b/backend/src/lib/redisRateCounter.test.ts@@ -1,9 +1,12 @@-import { afterAll, beforeAll, describe, expect, it } from 'vitest'+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'import { execFileSync, spawn, type ChildProcess } from 'node:child_process'import { createServer, type AddressInfo } from 'node:net'import { Redis } from 'ioredis'import { redisWindowCounter } from './redisRateCounter.js'+// A real client: the shared setup's never connects (noRedis.test-support.ts).+vi.unmock('ioredis')+// Against a real redis-server, so the script is what is tested. Skipped where none is installed (CI's Linux runners).const hasRedis = (() => { try { execFileSync('redis-server', ['--version'], { stdio: 'pipe' }); return true } catch { return false } })()diff --git a/backend/src/lib/terminalRouteRedis.test.ts b/backend/src/lib/terminalRouteRedis.test.tsindex 750b22778..03865e2b8 100644--- a/backend/src/lib/terminalRouteRedis.test.ts+++ b/backend/src/lib/terminalRouteRedis.test.ts@@ -6,6 +6,8 @@ import type { UpBusMsg } from './tunnel.js'// so subscribing to another id here is what that other process would do.const url = process.env.REDIS_TEST_URLvi.hoisted(() => { if (process.env.REDIS_TEST_URL) process.env.REDIS_URL = process.env.REDIS_TEST_URL })+// A real client: the shared setup's never connects (noRedis.test-support.ts).+vi.unmock('ioredis')vi.mock('../utils/logger.js', () => ({ logger: { warn: vi.fn(), info: vi.fn(), error: vi.fn(), debug: vi.fn() } }))describe.skipIf(!url)('terminal routes over a real Redis', () => {diff --git a/backend/src/superTabs/cacheRedis.test.ts b/backend/src/superTabs/cacheRedis.test.tsindex 9317a288a..2c210caa5 100644--- a/backend/src/superTabs/cacheRedis.test.ts+++ b/backend/src/superTabs/cacheRedis.test.ts@@ -1,11 +1,13 @@import { randomUUID } from 'node:crypto'import { Redis } from 'ioredis'-import { afterAll, beforeAll, describe, expect, it } from 'vitest'+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'import { redisStamps, STAMP_TTL_MS, type StampScope } from './cache.js'// A real Redis: REDIS_TEST_URL, e.g. redis://127.0.0.1:6379/15 (CI has none, so this file is skipped there). Only keys of// this run are touched, and they are removed afterwards.const url = process.env.REDIS_TEST_URL+// A real client: the shared setup's never connects (noRedis.test-support.ts).+vi.unmock('ioredis')describe.skipIf(!url)('redisStamps', () => {let redis: Redisdiff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex beedc7e76..6c7453e51 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -453,6 +453,8 @@ const FINDINGS_CHARS = 500/** The source of the Lead's notice about a pair (LOOP_NOTICE_AT), which pairLoop passes over: counted as a break, it would* start the count again and repeat the notice every LOOP_NOTICE_AT messages (final review of phase 1). */export const PAIR_LOOP_SOURCE = 'pair-loop'+/** The source of a Buddy's line that it cannot start in its person's older project chat (buddyDownLine). */+export const BUDDY_DOWN_SOURCE = 'buddy-cannot-start'const isPairLoopNotice = (source: unknown) => (source as { kind?: unknown } | null)?.kind === PAIR_LOOP_SOURCE/** How many of the newest [recent] messages in a row went between agents [a] and [b], each from one of them to the other,* inside the last LOOP_WINDOW_MS; a person's message, another notice or a message to anyone else ends the run. */@@ -997,20 +999,26 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma/*** The person's one Buddy answers in their older project chat [chat] (spec: Older apps): a Buddy of that project alone, on the* one Buddy's machine, engine and name, in that project's folder and never widened (buddyNarrow). This message waits for it;- * one already starting takes it too. Nothing while they have no one Buddy, or its host can't run one, as before.+ * one already starting takes it too. Nothing while they have no one Buddy, as before. When it cannot start, why, in plain+ * words, for the line that tells its person (buddyDownLine).*/- const startOldChatBuddy = (chat: Conversation) => {+ const startOldChatBuddy = (chat: Conversation): string | undefined => {if (command.type !== 'message.send' || actor.kind !== 'person') returnconst owner = requireChatOwner(state, chat, actor.userId)const pending = state.starts?.find(s => s.request.conversationId === chat.id && !s.request.buddySession && !s.harnessId && !s.error)if (pending) {if ((pending.request.buddyWaiting?.length ?? 0) < MAX_SESSION_WAITING) pending.request.buddyWaiting = [...pending.request.buddyWaiting ?? [], operationId]+ delete chat.buddyDownToldreturn}const main = state.agents.find(a => isSwarmBuddy(a) && !a.buddySession && a.buddyOf!.personId === owner.id && a.buddyOf!.generation === owner.generation)- if (!main || downSince(state, main, context.now) || main.configuration.engine !== 'claude' || state.paused) return- const pool = machineContribution(state, main.machineId)- if (!pool?.observation?.capabilities?.includes(SWARM_BUDDY_CAPABILITY)) return+ if (!main) return+ const pool = machineContribution(state, main.machineId), machine = pool?.name ?? 'my machine'+ if (state.paused) return 'the Swarm is paused'+ if (downSince(state, main, context.now)) return `${machine} is offline`+ if (main.configuration.engine !== 'claude') return 'I run on Codex, which answers only in # buddy'+ if (!pool) return 'my machine is no longer in the Swarm'+ if (!pool.observation?.capabilities?.includes(SWARM_BUDDY_CAPABILITY)) return `${machine} needs a newer Harness to run me here`const project = groupProject(state, chat)const contributor = person(state, main.contributorId)const request: AgentStartRequest = { conversationId: chat.id, machineId: main.machineId, engine: main.configuration.engine,@@ -1022,16 +1030,32 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma// before any Buddy answered there (security review 2 of #2435: its slots are counted, touches.ts).let admitted: ReturnType<typeof admitMachineStart>try { admitted = admitMachineStart(state, request, context.now, undefined, context.teamMachines, context.otherWorkspaceMachines) } catch (error) {- if (error instanceof SuperTabError && error.status < 500) return- throw error+ if (!(error instanceof SuperTabError && error.status < 500)) throw error+ return error.code === 'MACHINE_PAUSED' ? `${machine} is paused` : error.code === 'MACHINE_OFFLINE' ? `${machine} is offline`+ : error.code === 'MACHINE_FULL' ? `${machine} already runs as many agents as it takes`+ : error.code === 'MACHINE_REMOVED' ? `${machine} is being removed from the Swarm` : `${machine} cannot take me right now`}- if (!admitted) return+ if (!admitted) return 'my machine is no longer in the Swarm'state.starts ??= []- if (state.starts.filter(s => !s.harnessId && !s.error).length >= 32) return+ if (state.starts.filter(s => !s.harnessId && !s.error).length >= 32) return 'too many agents are starting in this Swarm'state.starts.push({ poolGeneration: admitted.generation, id: operationId, creationId: `super-${operationId}`, actorKey: actorKey(actor),contributorId: contributor.id, membershipGeneration: contributor.generation, machineOwnerId: main.machineOwnerId,hostGrant: main.hostGrant ?? null, request, harnessId: null, dispatched: false, error: null, requestedAt: context.now })result.startId = operationId+ delete chat.buddyDownTold+ }++ /** The line its person reads in their older project chat [chat] when their one Buddy cannot start there [why]: from that+ * Buddy, once per outage (Conversation.buddyDownTold, cleared once one can start), not once per message. */+ const buddyDownLine = (chat: Conversation, why: string) => {+ if (chat.buddyDownTold) return+ const owner = chatOwner(chat)+ const main = owner && state.agents.find(a => isSwarmBuddy(a) && !a.buddySession && a.buddyOf!.personId === owner.id && a.buddyOf!.generation === owner.generation)+ if (!main) return+ chat.buddyDownTold = true+ effects.messages.push({ id: stableId(operationId, BUDDY_DOWN_SOURCE), conversationId: chat.id, replyTo: null, recipients: [],+ author: { kind: 'agent', id: main.id, name: main.name, displayName: agentDisplayName(state.agents, main.id), membershipGeneration: main.membershipGeneration },+ text: `I can't start in this chat right now: ${why}. Your message is kept.`, source: { kind: BUDDY_DOWN_SOURCE } })}/** Ends every project session of [project] in a one Buddy chat whose person no longer reads it, and fails those starting. */@@ -2434,7 +2458,8 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commaif (command.newSession && !session) fail('BUDDY_SESSION_CHAT', 'Start a session from a thread of your own Buddy chat.', 400)// An older project chat with no Buddy in it: the person's one Buddy answers there through a session of that project, so// the phone and older apps keep a working Buddy (spec: Older apps). Started on this message, which waits for it.- if (actor.kind === 'person' && isBuddyChat(group) && !isSwarmBuddyChat(group) && !session?.inSession && !mainBuddyOf(state, group)) startOldChatBuddy(group)+ const buddyDown = actor.kind === 'person' && isBuddyChat(group) && !isSwarmBuddyChat(group) && !session?.inSession && !mainBuddyOf(state, group)+ ? startOldChatBuddy(group) : undefined// A Buddy chat has no Lead: its owner talks to its Buddy.const automatic = actor.kind === 'person' ? (isBuddyChat(group) ? (session?.inSession ? session.to : mainBuddyOf(state, group)?.id ?? null): replyAgent && group.agentIds.includes(replyAgent) ? replyAgent : group.leadId) : agentRecipient@@ -2457,6 +2482,8 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma}// The transcript still accepts a human message while the lead is unavailable. The UI can say why no delivery was created.message(group.id, text, recipients, command.replyTo, command.agentOnly ? AGENT_ONLY : undefined, attachments, mentions, command.mentionsIfNoWorker)+ // After the person's message: nobody answers it, so its person is told why (Dee, review of #2447).+ if (buddyDown) buddyDownLine(group, buddyDown)// The message that makes it LOOP_NOTICE_AT in a row between two agents tells their Lead, once; delivery is never held.const speaker = actor.kind === 'agent' ? agent(state, actor.agentId) : nullconst partner = speaker && recipients.length === 1 && recipients[0] !== speaker.id ? agent(state, recipients[0]!) : nulldiff --git a/backend/src/superTabs/decisions.ts b/backend/src/superTabs/decisions.tsindex ef1e530d3..16fa6625f 100644--- a/backend/src/superTabs/decisions.ts+++ b/backend/src/superTabs/decisions.ts@@ -169,17 +169,29 @@ export async function waitingFor(tx: Tx, tabId: string, conversationId: string,/** Closes the decisions still waiting in these conversations, whose work is over (workOver), as withdrawn: answered at* [now] with no choice, so none waits, none is listed, none can be answered and a new ask of the same question is a new* decision. Never a routing reflection's, which expires on its own (expireReflections). Run in the transaction that ends- * the work (store.ts), so a concurrent answer conflicts with it and only one of them counts. The number closed. */-export async function withdrawIn(tx: Tx, tabId: string, conversationIds: readonly string[], now: number): Promise<number> {+ * the work (store.ts), so a concurrent answer conflicts with it and only one of them counts. With [askedBy], only those+ * asked by then: the work was read as over at that time (store.ts withdrawEndedDecisions). The number closed. */+export async function withdrawIn(tx: Tx, tabId: string, conversationIds: readonly string[], now: number, askedBy?: number): Promise<number> {let closed = 0// One by one through the conversation index: a command ends one conversation's work, rarely a few (hotFilters.test.ts).for (const conversationId of new Set(conversationIds)) {- closed += (await tx.superTabDecision.updateMany({ where: { tabId, conversationId, AND: [waiting, notReflection] },+ closed += (await tx.superTabDecision.updateMany({ where: { tabId, conversationId, AND: [waiting, notReflection],+ ...askedBy === undefined ? {} : { createdAt: { lte: new Date(askedBy) } } },data: { answeredAt: new Date(now), withdrawn: true } })).count}return closed}+/** The conversations, by Swarm, where a decision still waits, a routing reflection's aside (store.ts withdrawEndedDecisions,+ * once at worker startup). Open decisions are few: at most MAX_OPEN_DECISIONS per asker and person. */+export async function waitingConversations(tx: Tx): Promise<Map<string, string[]>> {+ const rows = await tx.superTabDecision.findMany({ where: { AND: [waiting, notReflection] }, select: { tabId: true, conversationId: true },+ distinct: ['tabId', 'conversationId'] })+ const byTab = new Map<string, string[]>()+ for (const row of rows) byTab.set(row.tabId, [...byTab.get(row.tabId) ?? [], row.conversationId])+ return byTab+}+/** The conversations whose work this write ended (workOver in [after], not in [before]): their waiting decisions close. */export function workEnded(before: SuperTabState, after: SuperTabState): string[] {const was = new Map(before.conversations.map(c => [c.id, c]))diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.tsindex 2e382b672..bdbcda53d 100644--- a/backend/src/superTabs/model.ts+++ b/backend/src/superTabs/model.ts@@ -323,6 +323,9 @@ export interface Conversation {buddyName?: string/** A Buddy chat's live and starting thread sessions (buddySessions.ts); absent while it has none. */buddySessions?: BuddySessionEntry[]+ /** An older project Buddy chat whose person was told their one Buddy cannot start there now (commands.ts buddyDownLine):+ * told once per outage, so absent again once one can start. */+ buddyDownTold?: true/** The person who asked for this work: whoever opened it, or the person its Lead named (leaderboard/record.ts). */requesterId?: string/** What the leaderboard counts here (leaderboard/record.ts); bookkeeping readers never get whole. */@@ -511,6 +514,8 @@ export const NOTICE_READERS = {// A project PM's private line in a person's one Buddy chat, marked with its project (commands.ts person.tell): its person// reads it, as they read the line in their older project chat.'pm-line': 'people',+ // Their one Buddy cannot start in a person's older project chat, told to them there once per outage (commands.ts buddyDownLine).+ 'buddy-cannot-start': 'people','auto-archive': 'people', native: 'people',// The nightly routing reflection, for the project's people; never a Buddy's (buddies.ts routingRow).'routing-reflection': 'people',diff --git a/backend/src/superTabs/parts/light.test.ts b/backend/src/superTabs/parts/light.test.tsindex 8ae78ecd4..c4547186f 100644--- a/backend/src/superTabs/parts/light.test.ts+++ b/backend/src/superTabs/parts/light.test.ts@@ -15,7 +15,7 @@ const conversation: Required<Conversation> = {id: 'g', kind: 'leads', projectId: 'p', number: 1, title: 't', leadId: null, agentIds: [], archived: false, brief: '',task: { goal: '', changes: '', constraints: '', owns: [] }, reviewOf: 'r', reviewStamp: { assignmentId: 'w', handoff: 1 }, checks: [], assignment, lastMessageSequence: 0, lastMainSequence: 0, pullRequestUrls: [], cards: {},messageSeq: 0, reportSeq: 0, dormant: false, lastActivityAt: '', audience: { people: [] }, lostAttempt: { id: 'w', agentId: 'a' }, reactionSeq: 0,- requesterId: 'p', ledger: {}, proposals: [], buddyName: 'Sparky', buddySessions: [], liveness: { state: 'quiet', why: 'silent', since: 1 }, leadAction: { kind: 'post', at: 1 },+ requesterId: 'p', ledger: {}, proposals: [], buddyName: 'Sparky', buddySessions: [], buddyDownTold: true, liveness: { state: 'quiet', why: 'silent', since: 1 }, leadAction: { kind: 'post', at: 1 },stepUp: { attempt: 2, floor: 2, reason: 'r', at: 1, carry: '' },}diff --git a/backend/src/superTabs/parts/light.ts b/backend/src/superTabs/parts/light.tsindex 739e678a2..597166db1 100644--- a/backend/src/superTabs/parts/light.ts+++ b/backend/src/superTabs/parts/light.ts@@ -27,7 +27,7 @@ export const GROUP_FIELDS = {always: ['id', 'kind', 'projectId', 'leadId', 'agentIds', 'archived', 'audience', 'dormant', 'assignment.id', 'assignment.agentId', 'assignment.status','assignment.lost'],whenRunning: ['title', 'task.owns', 'assignment.execution', 'assignment.result'],- unread: ['number', 'brief', 'reviewOf', 'reviewStamp', 'checks', 'lastMessageSequence', 'lastMainSequence', 'pullRequestUrls', 'cards', 'messageSeq', 'reportSeq', 'lastActivityAt', 'lostAttempt', 'requesterId', 'ledger', 'reactionSeq', 'proposals', 'buddyName', 'buddySessions', 'liveness', 'leadAction', 'stepUp',+ unread: ['number', 'brief', 'reviewOf', 'reviewStamp', 'checks', 'lastMessageSequence', 'lastMainSequence', 'pullRequestUrls', 'cards', 'messageSeq', 'reportSeq', 'lastActivityAt', 'lostAttempt', 'requesterId', 'ledger', 'reactionSeq', 'proposals', 'buddyName', 'buddySessions', 'buddyDownTold', 'liveness', 'leadAction', 'stepUp','assignment.configuration', 'assignment.recordingProgress', 'assignment.leaseUntil', 'assignment.progressAt', 'assignment.askedOf', 'assignment.reviewFoundAt','assignment.handoffs', 'assignment.verdicts'],} as constdiff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 8f166a30b..471a2453a 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -69,7 +69,7 @@ import { APPROVE, approvedLine, localDate, MAX_PROPOSALS, proposalQuestion, propimport { readEvidence, recordEvidence } from './evidence/store.js'import { closeAssignment, closeUnassignedStart, LIST_SIZE, newestConversations, newestDecisions, readDecision, recentDecisions, recordAttempts, timedDecisionOf, writeRouteEffects } from './routeDecisions.js'import { dropHeldTags, listMentions, markDone, mentionsWaiting, openTags, readMention, resolveByReply, resolveWhenWorked, writeMentions } from './mentions.js'-import { answerable, askDecisions, MAX_OPEN_DECISIONS, REFLECTION_DECISION, reflectionDecisions, expireReflections, fullFor, listDecisions, type DecisionList, readAskedDecision, recordAnswer, repeatOf, waitingFor, waitingInProject, withdrawIn, workEnded, workOver, writeDecisions } from './decisions.js'+import { answerable, askDecisions, MAX_OPEN_DECISIONS, REFLECTION_DECISION, reflectionDecisions, expireReflections, fullFor, listDecisions, type DecisionList, readAskedDecision, recordAnswer, repeatOf, waitingConversations, waitingFor, waitingInProject, withdrawIn, workEnded, workOver, writeDecisions } from './decisions.js'import { CATCH_UP_SCAN, catchUpSummary, type CatchUp } from './catchUp.js'import { recordMessageRead, type MessageReadKey } from './messageReadStats.js'import { DEFAULT_ROUTING_POLICY, type RoutingPolicy } from './routingPolicy.js'@@ -3289,11 +3289,35 @@ export class SuperTabStore {})}+ /** Closes as withdrawn the decisions still waiting in work that was over before #2454 closed them where the work ends+ * (Dee, 10-31): hidden from every list, they still counted toward the asker's open limit (MAX_OPEN_DECISIONS) and came+ * back when the task reopened. Run once at worker startup; remove it in the release after the one that ran it. Reads the+ * waiting decisions, then each Swarm's conversations they are in, and closes those whose work is over (decisions.ts+ * workOver: never open work, a project chat or a Buddy chat), asked by the time of that read. One Swarm's failure skips+ * that Swarm with a warning. The number closed. */+ async withdrawEndedDecisions(): Promise<number> {+ let closed = 0+ for (const [tabId, conversationIds] of await waitingConversations(this.db)) {+ try {+ closed += await transaction(this.db, async tx => {+ const row = await tx.superTab.findUnique({ where: { id: tabId }, select: SWARM_ROW })+ if (row?.format !== 2) return 0+ const { state } = await loadRow(tx, row, { groupIds: conversationIds }), now = this.now()+ const over = conversationIds.filter(id => { const group = state.conversations.find(c => c.id === id); return !!group && workOver(state, group) })+ return over.length ? withdrawIn(tx, tabId, over, now, now) : 0+ })+ } catch (error) {+ logger.warn('[swarm-decisions] Swarm skipped', { tabId, error: error instanceof Error ? error.message : String(error) })+ }+ }+ return closed+ }+/** Archives a finished group whose pull requests `checked` were all read merged or closed (archive.ts), only if it still- * qualifies inside this write: no message since, no decision waiting and no pull request linked since the read. Its- * waiting deliveries end, as a person's archive ends them. With `reviewOf`, the group the pass read as the one it- * reviews, a review nobody is reviewing closes the same way once those of the work it reviews are too (tidy.ts- * reviewClosable). True when it archived. */+ * qualifies inside this write: no message and no pull request linked since the read. A decision still waiting there+ * closes as withdrawn (decisions.ts withdrawIn), and its waiting deliveries end, as a person's archive ends them. With+ * `reviewOf`, the group the pass read as the one it reviews, a review nobody is reviewing closes the same way once those+ * of the work it reviews are too (tidy.ts reviewClosable). True when it archived. */async archiveFinished(tabId: string, groupId: string, checked: Readonly<Record<string, 'merged' | 'closed'>>, reviewOf?: string): Promise<boolean> {return transaction(this.db, async tx => {const row = await tx.superTab.findUnique({ where: { id: tabId }, select: SWARM_ROW })diff --git a/backend/src/worker.ts b/backend/src/worker.tsindex a8219733c..26d664c42 100644--- a/backend/src/worker.ts+++ b/backend/src/worker.ts@@ -109,6 +109,9 @@ async function start(): Promise<void> {// groups they changed.const swarms = new SuperTabStore(prisma, Date.now, null, { deliveriesWaiting: announceSwarmDeliveries, hostsChanged: announceSwarmHostChanges,swarmChanged: announceSwarmChanges })+ // Decisions still waiting in work that was over before #2454 closed them where work ends: they counted toward the open+ // limit and came back on a reopen (store.ts withdrawEndedDecisions). Remove in the release after the one that runs it.+ logger.info('[swarm-decisions] closed waiting decisions of finished work', { closed: await swarms.withdrawEndedDecisions() })stopSweeps = startSwarmSweeps(prisma, undefined, () => swarms.workspaces.finishRemovals())// The dead old state of migrated Swarms goes by itself, a few at a time (superTabs/migration/dropLegacyJob.ts).stopLegacyDrop = startLegacyDrop(prisma)diff --git a/backend/vitest.config.ts b/backend/vitest.config.tsindex 9e7951b2d..3e9200275 100644--- a/backend/vitest.config.ts+++ b/backend/vitest.config.ts@@ -4,5 +4,7 @@ export default defineConfig({test: {include: ['src/**/*.test.ts'],exclude: ['dist/**', 'node_modules/**'],+ // No unit test opens Redis (#2434).+ setupFiles: ['src/lib/noRedis.test-support.ts'],},})diff --git a/backend/vitest.super-tabs.config.ts b/backend/vitest.super-tabs.config.tsindex 991ae8c19..28e7071e8 100644--- a/backend/vitest.super-tabs.config.ts+++ b/backend/vitest.super-tabs.config.ts@@ -8,5 +8,5 @@ export default defineConfig({ test: { include: ['integration/superTabs.test.ts','integration/superTabBuddyProbes.test.ts', 'integration/superTabBuddySessions.test.ts', 'integration/superTabSwarmBuddy.test.ts', 'integration/superTabCosts.test.ts', 'integration/harnessSharesList.test.ts', 'integration/atlasSnapshot.test.ts', 'integration/queryStats.test.ts','integration/superTabEvidence.test.ts', 'integration/superTabAttemptModels.test.ts', 'integration/superTabNamedReads.test.ts', 'integration/swarmSweepPlans.test.ts', 'integration/workerIndexPlans.test.ts', 'integration/superTabReflection.test.ts','integration/superTabMessagePages.test.ts', 'integration/superTabDeliveryCompaction.test.ts', 'integration/superTabThreads.test.ts',- 'integration/superTabInstructions.test.ts', 'integration/superTabWorkflow.test.ts'], hookTimeout: 120000, testTimeout: 30000, setupFiles: ['integration/cacheOn.test-support.ts'],+ 'integration/superTabInstructions.test.ts', 'integration/superTabWorkflow.test.ts'], hookTimeout: 120000, testTimeout: 30000, setupFiles: ['integration/cacheOn.test-support.ts', 'src/lib/noRedis.test-support.ts'],fileParallelism: false, env: { NODE_ENV: 'test', HARNESS_CREDENTIAL_ENCRYPTION_KEY: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=' } } })