Skip to content

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.

Batch F: #2038 #2009 #2041 (#2052)

0xken15b025be8487ad
diff --git a/backend/integration/superTabHotReads.test.ts b/backend/integration/superTabHotReads.test.ts
index 62f8f4464..ad01b75ba 100644
--- a/backend/integration/superTabHotReads.test.ts
+++ b/backend/integration/superTabHotReads.test.ts
@@ -17,7 +17,7 @@ import { cursorFor } from '../src/superTabs/read/cursor.js'
import { lastChangedAt } from '../src/superTabs/parts/index.js'
import type { SuperTabState } from '../src/superTabs/model.js'
import { writeLegacySwarm } from '../scripts/swarm-parts/legacy.js'
-import { NOW, owner as ownerActor, swarm } from '../src/superTabs/read/fixture.test-support.js'
+import { NOW, outsider, owner as ownerActor, peer, swarm } from '../src/superTabs/read/fixture.test-support.js'
import { PROFILE_STAGES, profileEntry, queryShape, type ProfileEntry } from './bench/profile.js'
// The hot reads of the roadmap's 2.7 (indexes) under Mongo's profiler: each must read only the documents it returns, never
@@ -51,7 +51,7 @@ afterAll(async () => {
/** A Swarm on two machines of the owner's: a Lead, and on the other a worker with running work, finished work, and OTHERS quiet conversations,
* closed deliveries of other messages to other agents, and open decisions in other conversations. */
-async function scene() {
+async function scene(edit: (s: ReturnType<typeof swarm>) => void = () => {}) {
const [machineId, leadMachine] = [`m-${randomUUID().slice(0, 8)}`, `l-${randomUUID().slice(0, 8)}`]
for (const id of [machineId, leadMachine]) {
await db.machine.create({ data: { machineId: id, userId: owner.sub, apiKey: 'fixture-only', managerId: 'fixture', autonomousEnv: 'prod', authMode: 'remote' } })
@@ -65,6 +65,7 @@ async function scene() {
s.run({ type: 'work.assign', conversationId: web, agentId: worker })
const done = s.group('Done work')
const quiet = Array.from({ length: OTHERS }, (_, i) => s.group(`Quiet ${i}`))
+ edit(s)
s.edit(state => {
state.conversations.find(c => c.id === done)!.assignment = { ...state.conversations.find(c => c.id === web)!.assignment!, id: 'old-work', status: 'done' }
})
@@ -262,3 +263,30 @@ describe('which machines take teammates\' work is read once per 15 s per Swarm',
expect(teamReads(later)).toHaveLength(1)
})
})
+
+describe('the owner\'s grid poll', () => {
+ it('reads each Swarm\'s head and only the people of those with Local models, never their groups, agents, machines or starts', async () => {
+ const off = await scene(s => s.edit(state => { delete state.localModels }))
+ const on = await scene(s => s.join(peer))
+ let grids: Awaited<ReturnType<SuperTabStore['hostGrids']>> = []
+ const entries = await profiled(async () => { grids = await store.hostGrids(owner) })
+ expect(grids.filter(g => g.tabId === off.tabId)).toEqual([])
+ const head = await db.swarmHead.findFirstOrThrow({ where: { tabId: on.tabId } })
+ expect(grids.filter(g => g.tabId === on.tabId)).toEqual([{ tabId: on.tabId, grid: (head.data as { localModels: { grid: string } }).localModels.grid,
+ enabled: true, ready: null, members: [peer.email] }])
+ const heavy = entries.filter(e => /\.Swarm(Group|Agent|Machine|Start|Progress)$/.test(e.ns))
+ expect(heavy.map(e => e.ns.slice(e.ns.indexOf('.') + 1))).toEqual([])
+ // The people read asks for the Swarms with Local models only.
+ const people = entries.filter(e => e.ns.endsWith('.SwarmMember'))
+ expect(people.length).toBeGreaterThan(0)
+ expect(JSON.stringify(people.map(e => e.command))).not.toContain(off.tabId)
+ })
+
+ it('leaves out someone removed from a Swarm with Local models', async () => {
+ const s = await scene(s => { s.join(peer); s.join(outsider) })
+ clock = Date.now()
+ await store.execute(owner, s.tabId, { operationId: randomUUID(), command: { type: 'member.remove', userId: outsider.userId } })
+ expect(await db.swarmMember.findFirst({ where: { tabId: s.tabId, key: outsider.userId }, select: { deleted: true } })).toEqual({ deleted: true })
+ expect((await store.hostGrids(owner)).find(g => g.tabId === s.tabId)!.members).toEqual([peer.email])
+ })
+})
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index 79d453737..51d717eeb 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -38,7 +38,7 @@ import { activeMember, addMember, hasWorkspaceAccess, listWorkspaces, memberId,
import { WORKSPACE_LABEL, type WorkspaceRole } from './workspaces.js'
import {
activeWork, actorKey, agent, agentOnly, agentRole, appendPullRequestUrls, author, conversation, createSuperTab, fail, person, stableId, visibleState, finishWorker,
- SuperTabError, isLeads, parkLaterConversations, syncLeads, type Actor, type Agent, type Assignment, type Author, type Conversation, type MessageDraft, type SuperTabState,
+ SuperTabError, isLeads, parkLaterConversations, syncLeads, type Actor, type Agent, type Assignment, type Author, type Conversation, type MessageDraft, type Person, type SuperTabState,
} from './model.js'
import type { HoldReason } from './holdReason.js'
import { stuck } from './deliverySettle.js'
@@ -1855,14 +1855,20 @@ export class SuperTabStore {
})
}
- /** The owner's Swarms with the Local models add-on: what the owner's computer creates on grid and keeps in step. */
+ /** The owner's Swarms with the Local models add-on: what the owner's computer creates on grid and keeps in step. Every
+ * daemon of the owner's asks every minute, add-on on or off, so it reads only the Swarms' heads and the people of those
+ * with the add-on: a full load of each Swarm sent about 1 MB per Swarm per poll (Diego, 2026-10-28). */
async hostGrids(user: AuthUser) {
this.personOnly(user)
- const rows = await this.db.superTab.findMany({ where: { autonomousEnv: user.autonomousEnv, ownerId: user.sub, format: 2 }, take: 100, select: SWARM_ROW })
+ const rows = await this.db.superTab.findMany({ where: { autonomousEnv: user.autonomousEnv, ownerId: user.sub, format: 2 }, take: 100, select: { id: true } })
return transaction(this.db, async tx => {
- const grids = []
- for (const row of rows) { const grid = swarmGridRow(row.id, (await loadRow(tx, row)).state); if (grid) grids.push(grid) }
- return grids
+ const heads = await tx.swarmHead.findMany({ where: { tabId: { in: rows.map(row => row.id) }, key: 'head' }, select: { tabId: true, data: true } })
+ const withGrid = new Map(heads.map(head => [head.tabId, head.data as unknown as HeadData] as const).filter(([, head]) => head.localModels))
+ const people = new Map<string, Person[]>([...withGrid.keys()].map(tabId => [tabId, []]))
+ for (const member of await tx.swarmMember.findMany({ where: { tabId: { in: [...withGrid.keys()] }, deleted: false },
+ orderBy: { ordinal: 'asc' }, select: { tabId: true, data: true } })) people.get(member.tabId)!.push(member.data as unknown as Person)
+ return rows.flatMap(row => withGrid.has(row.id)
+ ? [swarmGridRow(row.id, { ...withGrid.get(row.id)!, people: people.get(row.id)! } as SuperTabState)!] : [])
})
}
diff --git a/cli/src/core/devicesLink.spec.ts b/cli/src/core/devicesLink.spec.ts
index fb123a428..ad81fd9b4 100644
--- a/cli/src/core/devicesLink.spec.ts
+++ b/cli/src/core/devicesLink.spec.ts
@@ -222,7 +222,7 @@ describe('what the devices tell the core', () => {
})
describe('the devices\' Swarm card requests to the Super Tab service', () => {
- it('hands the core only the fields of the three card requests (the core allows those and no other action)', async () => {
+ it('hands the core only the fields of the card requests (the core allows those and no other action)', async () => {
const superTabRequest = vi.fn(async (payload: Record<string, unknown>) => ({ ok: true, echoed: payload }))
const core = fakeCore()
core.superTabRequest = superTabRequest
@@ -232,6 +232,7 @@ describe('the devices\' Swarm card requests to the Super Tab service', () => {
expect(await devices.answer('super_tabs', { action: 'cardRecap', tabId: 't1', leadId: 'l1', extra: 1 })).toMatchObject({ echoed: { action: 'cardRecap', tabId: 't1', leadId: 'l1' } })
expect(await devices.answer('super_tabs', { action: 'cardOpen', session: 'c1', tabId: 't1', leadId: null })).toMatchObject({ echoed: { action: 'cardOpen', session: 'c1', tabId: 't1', leadId: null } })
expect((await devices.answer('super_tabs', { action: 'cardSay', harnessId: 'h1', text: 'ship it', tabId: 't1' })).echoed).toEqual({ action: 'cardSay', harnessId: 'h1', text: 'ship it' })
+ expect((await devices.answer('super_tabs', { action: 'cardWorker', machineId: 'm2', harnessId: 'h1', text: 'x', tabId: 't1' })).echoed).toEqual({ action: 'cardWorker', machineId: 'm2', harnessId: 'h1' })
// A core with no way to the service says so.
const bare = createDevicesLink({ core: fakeCore(), notify: () => true, call: vi.fn(), state: () => STATE })
expect(await bare.answer('super_tabs', { action: 'cardsWanted', on: true })).toEqual({ error: 'SERVICE_UNAVAILABLE' })
diff --git a/cli/src/core/devicesLink.ts b/cli/src/core/devicesLink.ts
index 41660a809..336d1f21c 100644
--- a/cli/src/core/devicesLink.ts
+++ b/cli/src/core/devicesLink.ts
@@ -125,12 +125,13 @@ export function createDevicesLink(deps: DevicesLinkDeps) {
// The Swarm cards' requests (core/main.ts `superTabRequest` allows those and no other action of the Super Tab service).
super_tabs: async (payload) => {
if (!core.superTabRequest) return { error: 'SERVICE_UNAVAILABLE' }
- const { action, tabId, leadId, on, include, session, harnessId, text, focus } = payload
+ const { action, tabId, leadId, on, include, session, harnessId, machineId, text, focus } = payload
// A round dial that speaks swarmChat asks for the chat on the face, and the window's open conversation rides with the
// wish (superTabs/inCore/cards.ts checks both); absent, the request is today's.
const chat = payload.chat === true ? { chat: true } : {}
return core.superTabRequest(action === 'cardsWanted' ? { action, on: on === true, include, ...(focus !== undefined ? { focus } : {}) }
- : action === 'cardSay' ? { action, harnessId, text, ...chat } : { action, tabId, leadId, session, ...chat })
+ : action === 'cardSay' ? { action, harnessId, text, ...chat } : action === 'cardWorker' ? { action, machineId, harnessId }
+ : { action, tabId, leadId, session, ...chat })
},
// The transcriber's and the fleet's lane's sign-in, and the lane's sealing, asked of the core at every
// use as every service in its own process asks them (core/accountQueries.ts): the devices hold no
diff --git a/cli/src/services/devices.spec.ts b/cli/src/services/devices.spec.ts
index a38ff202c..95218fb8a 100644
--- a/cli/src/services/devices.spec.ts
+++ b/cli/src/services/devices.spec.ts
@@ -1166,6 +1166,83 @@ describe('a failed turn of a Swarm worker', () => {
expect(calls('turnDone')).toEqual([])
})
+ describe('on another of the person\'s computers', () => {
+ // The Swarm service says which agent on which machine is a worker, from the Swarms it read last (superTabs/cards.ts).
+ const askedWorker = (workers: string[], fail = false, now?: () => number) => {
+ const superTabRequest = vi.fn(async (payload: Record<string, unknown>) => {
+ if (fail) throw new Error('service gone')
+ return payload.action === 'cardWorker' ? { ok: true, worker: workers.includes(`${payload.machineId}/${payload.harnessId}`) } : { ok: true }
+ })
+ return { superTabRequest, ...start({ core: { ...fakeCore({ dataDir }), superTabRequest } as CoreApi, now }) }
+ }
+ const failed = (agentId: string, text = 'boom') => seen.fleet!.events!({ machineId: 'mac-mini', kind: 'error', agentId, text, recap: '' })
+ const asks = (request: ReturnType<typeof vi.fn>) => request.mock.calls.filter(([p]) => (p as { action?: string }).action === 'cardWorker')
+
+ it('keeps a Swarm worker\'s failure off the dial, asking once a minute at most', async () => {
+ let clock = 0
+ const { superTabRequest } = askedWorker(['mac-mini/builder'], false, () => clock)
+ failed('builder')
+ failed('builder')
+ await vi.waitFor(() => expect(calls('turnDone')).toEqual([['builder'], ['builder']]))
+ expect(calls('turnError')).toEqual([])
+ expect(asks(superTabRequest)).toEqual([[{ action: 'cardWorker', machineId: 'mac-mini', harnessId: 'builder' }]])
+ // A minute on, the Swarm may have changed: it is asked again.
+ clock = 60_001
+ failed('builder')
+ await vi.waitFor(() => expect(calls('turnDone')).toHaveLength(3))
+ expect(asks(superTabRequest)).toHaveLength(2)
+ })
+
+ it('shows the person\'s own agent\'s failure, and asks nothing for an agent on a tab', async () => {
+ const { superTabRequest, port } = askedWorker(['mac-mini/builder'])
+ port.swarms({ active: 't1', swarms: [{ id: 't1', name: 'api', agentIds: ['builder'], panes: 1 }], tiles: [] })
+ failed('mine', 'mine broke')
+ failed('builder', 'builder broke')
+ // Each agent's cards keep their order; two agents' need not, and the one on a tab is not waited on.
+ await vi.waitFor(() => expect(calls('turnError')).toHaveLength(2))
+ expect(calls('turnError')).toEqual(expect.arrayContaining([['mine', 'mine broke'], ['builder', 'builder broke']]))
+ expect(asks(superTabRequest)).toEqual([[{ action: 'cardWorker', machineId: 'mac-mini', harnessId: 'mine' }]])
+ })
+
+ it('forgets every answer once it holds 256, rather than grow with each agent that ever failed', async () => {
+ const { superTabRequest } = askedWorker([])
+ for (let n = 0; n < 256; n++) failed(`agent-${n}`)
+ await vi.waitFor(() => expect(calls('turnError')).toHaveLength(256))
+ failed('agent-0')
+ failed('agent-256')
+ await vi.waitFor(() => expect(calls('turnError')).toHaveLength(258))
+ failed('agent-0')
+ await vi.waitFor(() => expect(calls('turnError')).toHaveLength(259))
+ // agent-0 was still held; agent-256 filled the store past 256, so agent-0 is asked again.
+ expect(asks(superTabRequest).filter(([p]) => (p as { harnessId: string }).harnessId === 'agent-0')).toHaveLength(2)
+ })
+
+ it('waits 2 s at most for an answer, then shows the failure, so a hung service never leaves a tile working', async () => {
+ vi.useFakeTimers()
+ try {
+ const superTabRequest = vi.fn((payload: Record<string, unknown>) =>
+ payload.action === 'cardWorker' ? new Promise<Record<string, unknown>>(() => {}) : Promise.resolve({ ok: true }))
+ start({ core: { ...fakeCore({ dataDir }), superTabRequest } as CoreApi })
+ failed('builder', 'builder broke')
+ await vi.advanceTimersByTimeAsync(1_999)
+ expect(calls('turnError')).toEqual([])
+ await vi.advanceTimersByTimeAsync(1)
+ expect(calls('turnError')).toEqual([['builder', 'builder broke']])
+ // Its next failure within the minute does not wait again.
+ failed('builder', 'again')
+ await vi.advanceTimersByTimeAsync(0)
+ expect(calls('turnError')).toHaveLength(2)
+ expect(asks(superTabRequest)).toHaveLength(1)
+ } finally { vi.useRealTimers() }
+ })
+
+ it('shows the failure when the Swarm service cannot say', async () => {
+ askedWorker([], true)
+ failed('builder', 'builder broke')
+ await vi.waitFor(() => expect(calls('turnError')).toEqual([['builder', 'builder broke']]))
+ })
+ })
+
it('leaves a Lead\'s own failure as it was', async () => {
const { port } = start({ core: swarmAgents([{ agentId: 'lead', swarmSkill: { role: 'lead', key: 'k' } }]) })
port.card({ type: 'commander_event', agentId: 'lead', payload: { kind: 'error', text: 'lead broke' } })
diff --git a/cli/src/services/devices.ts b/cli/src/services/devices.ts
index d1102cf04..aeaea38db 100644
--- a/cli/src/services/devices.ts
+++ b/cli/src/services/devices.ts
@@ -384,13 +384,20 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)
// A Swarm Reviewer on a Mac's Harness Team account failed every turn in 1-2 s (2026-10-28), and each failure took over
// the round dial with the engine's raw error for 8 s. A Swarm's workers answer to their Lead, who hears of it in the
// Swarm: one the person has not put on a tab ends its tile quietly, as a finished turn does, and never stays Working.
- if (swarmWorker(event) && !onDesk(event.agentId)) {
+ const quiet = (): void => {
tally(cableHost.describe(event.agentId)?.name ?? '', 'silent', 'rule:swarm-worker', 'turn.error', 0)
void cable.turnDone(event.agentId)
- return
}
- tally(cableHost.describe(event.agentId)?.name ?? '', 'alert', 'rule:failed', 'turn.error', 0)
- void cable.turnError(event.agentId, event.text)
+ const shown = (): void => {
+ tally(cableHost.describe(event.agentId)?.name ?? '', 'alert', 'rule:failed', 'turn.error', 0)
+ void cable.turnError(event.agentId, event.text)
+ }
+ if (onDesk(event.agentId)) return shown()
+ if (swarmWorker(event)) return quiet()
+ // Another of the person's computers says nothing of the Swarm in its card: the Swarm service is asked, and returned so
+ // the agent's next card waits behind the answer. No answer (an older computer, the service down) shows it, as before.
+ if (!event.machineId) return shown()
+ return remoteWorker(event.machineId, event.agentId).then((worker) => worker ? quiet() : shown())
}
}
/** A Builder or Reviewer the Swarm started here (its record's Swarm role, and an agent started it, as every Swarm start
@@ -401,6 +408,27 @@ export function startDevices(core: CoreApi, ports: CorePorts, deps: DevicesDeps)
const role = session?.startedBy === 'agent' ? session.swarmSkill?.role : undefined
return role === 'dev' || role === 'review' || (!!event.machineId && teamMachines.has(event.machineId))
}
+ /** Whether an agent on another machine is a Swarm's Builder or Reviewer, as the Swarm service read it last
+ * (superTabs/cards.ts `worker`). Asked once a minute at most per agent: a failing worker fails every 1-2 s. */
+ const WORKER_ANSWER_MS = 60_000
+ /** How long a failure waits for the answer before it shows as before: a hung service must not leave the tile working. */
+ const WORKER_WAIT_MS = 2_000
+ const workerAnswers = new Map<string, { worker: boolean; at: number }>()
+ const remoteWorker = async (machineId: string, agentId: string): Promise<boolean> => {
+ const key = `${machineId}/${agentId}`
+ const held = workerAnswers.get(key)
+ if (held && monotonic() - held.at < WORKER_ANSWER_MS) return held.worker
+ let timer: ReturnType<typeof setTimeout> | undefined
+ // No answer in time is held as "not a worker" like any other, so the next failures in the minute do not wait again.
+ const worker = await Promise.race([
+ askCards({ action: 'cardWorker', machineId, harnessId: agentId }).then((answer) => answer.worker === true),
+ new Promise<false>((resolve) => { timer = setTimeout(() => resolve(false), WORKER_WAIT_MS) }),
+ ]).finally(() => clearTimeout(timer))
+ // Each key is an agent that failed off the desk; a long-lived process forgets them all rather than grow.
+ if (workerAnswers.size >= 256) workerAnswers.clear()
+ workerAnswers.set(key, { worker, at: monotonic() })
+ return worker
+ }
/** On any of the window's tabs, or the desk the dial walks: the person put it there, so its failure is theirs to see. */
const onDesk = (agentId: string): boolean =>
desk.includes(agentId) || cableHost.listSwarms().swarms.some((tab) => tab.agentIds?.includes(agentId))
diff --git a/cli/src/superTabs/cards.spec.ts b/cli/src/superTabs/cards.spec.ts
index 668c03835..363700078 100644
--- a/cli/src/superTabs/cards.spec.ts
+++ b/cli/src/superTabs/cards.spec.ts
@@ -785,3 +785,60 @@ describe('SwarmCards chats', () => {
t.cards.want(false)
})
})
+
+// A Swarm Reviewer on another computer failing every turn took over the round dial with the engine's raw error (2026-10-28):
+// the devices ask whether the agent a card names is one of a Swarm's workers, and are answered from the Swarms read last.
+describe('SwarmCards.worker', () => {
+ /** The Swarm's record of starting a harness on a machine, as the backend keeps it. */
+ const started = (id: string, harnessId: string, machineId: string, over: Record<string, unknown> = {}) =>
+ ({ id, creationId: `super-${id}`, harnessId, request: { machineId, name: 'Builder' }, error: null, ...over })
+ // h1 is a session the person opened by hand and added as an Engineer: no start of the Swarm's names it.
+ type Rows = Record<'agents' | 'conversations' | 'starts', Array<Record<string, unknown>>>
+ const roster = (more: Partial<Rows> = {}) => swarm({
+ agents: [agent('a1'), agent('b1', { machineId: 'm2' }), agent('r1', { machineId: 'm2', role: 'reviewer' }), agent('b2', { machineId: 'm1' }),
+ agent('h1', { machineId: 'm2' }), ...more.agents ?? []],
+ conversations: [conv('lead-web', 'a1', { projectId: 'web' }), conv('w-web', null, { projectId: 'web', agentIds: ['b1', 'r1', 'h1'] }),
+ ...more.conversations ?? []],
+ starts: [started('s1', 'h-b1', 'm2'), started('s2', 'h-r1', 'm2'), started('s3', 'h-b2', 'm1'),
+ // Not proof that the Swarm started h1: a start that failed, one on another machine, one under another creation id.
+ started('s4', 'h-h1', 'm2', { error: 'Its machine did not start it within 3 minutes.' }), started('s5', 'h-h1', 'm1'),
+ started('s6', 'h-h1', 'm2', { creationId: 'other' }), ...more.starts ?? []],
+ })
+
+ it('says yes for a Builder or Reviewer on the machine the card came from, and no for its Lead', async () => {
+ const t = setup({ t1: { lastChangedAt: 1, state: roster() } })
+ await t.cards.tick()
+ expect(t.cards.worker('m2', 'h-b1')).toBe(true)
+ expect(t.cards.worker('m2', 'h-r1')).toBe(true)
+ expect(t.cards.worker('m1', 'h-a1')).toBe(false)
+ })
+
+ it('says no for a member the person started by hand and added, the rule this computer\'s own workers follow', async () => {
+ const t = setup({ t1: { lastChangedAt: 1, state: roster() } })
+ await t.cards.tick()
+ expect(t.cards.worker('m2', 'h-h1')).toBe(false)
+ expect(t.cards.worker('m1', 'h-b2')).toBe(true)
+ })
+
+ // A Buddy is started by the Swarm and leads nothing, yet it is its owner's own agent (combination review of batch #2043).
+ it('says no for a Buddy, whose failures on another of its owner\'s computers stay on the owner\'s dial', async () => {
+ const owner = { personId: 'p1', generation: 'g1' }
+ const state = roster({
+ agents: [agent('y1', { machineId: 'm2', buddyOf: owner })],
+ conversations: [conv('buddy-p1', null, { projectId: 'web', kind: 'buddy', agentIds: ['y1'] })],
+ starts: [started('s7', 'h-y1', 'm2', { request: { machineId: 'm2', name: 'Buddy', buddyOf: owner } })],
+ })
+ const t = setup({ t1: { lastChangedAt: 1, state } })
+ await t.cards.tick()
+ expect(t.cards.worker('m2', 'h-y1')).toBe(false)
+ expect(t.cards.worker('m2', 'h-b1')).toBe(true)
+ })
+
+ it('matches the machine as well as the harness, and knows nothing before a read or of an agent no Swarm lists', async () => {
+ const t = setup({ t1: { lastChangedAt: 1, state: roster() } })
+ expect(t.cards.worker('m2', 'h-b1')).toBe(false)
+ await t.cards.tick()
+ expect(t.cards.worker('m1', 'h-b1')).toBe(false)
+ expect(t.cards.worker('m2', 'h-nobody')).toBe(false)
+ })
+})
diff --git a/cli/src/superTabs/cards.ts b/cli/src/superTabs/cards.ts
index 16c84871d..a06347de6 100644
--- a/cli/src/superTabs/cards.ts
+++ b/cli/src/superTabs/cards.ts
@@ -250,6 +250,21 @@ export class SwarmCards {
this.openBy.set(session, key)
}
+ /** Whether a Swarm read last lists this harness on that machine as one of its workers (a Builder or Reviewer): a member
+ * that leads no conversation and that the Swarm started, by its start record (the proof superTabs/host.ts closes workers
+ * by). A session the person opened by hand and added is theirs, as on this computer (services/devices.ts). A Swarm
+ * Reviewer on another computer failing every turn took over the round dial (2026-10-28), so the devices ask before they
+ * show a card's failure. Nothing is read for it: before the first poll, nobody is one. A Buddy (`buddyOf`) is started
+ * the same way but is its owner's own agent, so its failures stay on their dial (combination review of batch #2043). */
+ worker(machineId: string, harnessId: string): boolean {
+ return [...this.tabs.values()].some(({ state }) => {
+ const member = list(state.agents).find(a => a.machineId === machineId && a.harnessId === harnessId)
+ return !!member && !member.buddyOf && !list(state.conversations).some(c => c.leadId === member.id)
+ && list(state.starts).some(s => s.harnessId === harnessId && object(s.request).machineId === machineId && !s.error
+ && s.creationId === `super-${String(s.id)}`)
+ })
+ }
+
async tick(): Promise<void> {
if (this.busy) return
this.busy = true
diff --git a/cli/src/superTabs/inCore/cards.spec.ts b/cli/src/superTabs/inCore/cards.spec.ts
index d887d7dca..7e655e8e5 100644
--- a/cli/src/superTabs/inCore/cards.spec.ts
+++ b/cli/src/superTabs/inCore/cards.spec.ts
@@ -179,7 +179,7 @@ describe('whether the Swarm cards are wanted, which the core owns', () => {
cards.replay()
expect(swarmCards).not.toHaveBeenCalled()
})
- it('lets the devices ask three things of the service and nothing else, whatever the path', async () => {
+ it('lets the devices ask four things of the service and nothing else, whatever the path', async () => {
const { cards, request } = wanting()
expect(await cards.ask({ action: 'cardsWanted', on: true, include: ['t1'] })).toEqual({ ok: true })
expect(request.mock.calls).toEqual([[{ action: 'cardsWanted', on: true, include: ['t1'] }]])
@@ -187,8 +187,9 @@ describe('whether the Swarm cards are wanted, which the core owns', () => {
await cards.ask({ action: 'cardRecap', tabId: 't1', leadId: 'l1', extra: 1 })
await cards.ask({ action: 'cardOpen', session: 's1', tabId: 't1', leadId: null, extra: 1 })
await cards.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it', extra: 1 })
+ await cards.ask({ action: 'cardWorker', machineId: 'm2', harnessId: 'h1', text: 'x', extra: 1 })
expect(request.mock.calls).toEqual([[{ action: 'cardRecap', tabId: 't1', leadId: 'l1' }], [{ action: 'cardOpen', session: 's1', tabId: 't1', leadId: null }],
- [{ action: 'cardSay', harnessId: 'h1', text: 'ship it' }]])
+ [{ action: 'cardSay', harnessId: 'h1', text: 'ship it' }], [{ action: 'cardWorker', machineId: 'm2', harnessId: 'h1' }]])
request.mockClear()
for (const action of ['backend', 'command', 'wake', 'prepareContribution', undefined]) expect(await cards.ask({ action, path: '/api/super-tabs' })).toEqual({ error: 'INVALID_REQUEST' })
expect(request).not.toHaveBeenCalled()
diff --git a/cli/src/superTabs/inCore/cards.ts b/cli/src/superTabs/inCore/cards.ts
index ffad068eb..6ca50401b 100644
--- a/cli/src/superTabs/inCore/cards.ts
+++ b/cli/src/superTabs/inCore/cards.ts
@@ -165,7 +165,7 @@ export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log =
swarmCardRecap(recap)
},
/** What the devices may ask of the Super Tab service, and nothing else of it: `cardsWanted` is kept here, `cardRecap`,
- * `cardOpen` and `cardSay` go to the service; any other action is refused. */
+ * `cardOpen`, `cardSay` and `cardWorker` go to the service; any other action is refused. */
ask(payload: Record<string, unknown>): Promise<Record<string, unknown>> {
if (payload.action === 'cardsWanted') { api.want(payload.on === true, payload.include, payload.focus); return Promise.resolve({ ok: true }) }
// A round dial that speaks swarmChat asks for the chat on its face; without the flag, the request is today's.
@@ -173,6 +173,8 @@ export function createSuperTabCards({ swarmCards, swarmCardRecap, request, log =
if (payload.action === 'cardRecap') return route({ action: 'cardRecap', tabId: payload.tabId, leadId: payload.leadId, ...chat })
if (payload.action === 'cardSay') return route({ action: 'cardSay', harnessId: payload.harnessId, text: payload.text, ...chat })
if (payload.action === 'cardOpen') return route({ action: 'cardOpen', session: payload.session, tabId: payload.tabId, leadId: payload.leadId, ...chat })
+ // A card's failure from another computer: whether its agent is a Swarm's worker (services/devices.ts asks; it decides).
+ if (payload.action === 'cardWorker') return route({ action: 'cardWorker', machineId: payload.machineId, harnessId: payload.harnessId })
return Promise.resolve({ error: 'INVALID_REQUEST' })
},
/** A dial attached: it has nothing, so it is shown the last list again. */
diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.ts
index a5467ccd1..427352fdb 100644
--- a/cli/src/superTabs/service.spec.ts
+++ b/cli/src/superTabs/service.spec.ts
@@ -650,7 +650,7 @@ it('documents finished worker decisions and explains an older backend without re
describe('the Swarm cards the devices ask for', () => {
function withCards() {
- const cards = { want: vi.fn(), open: vi.fn(), say: vi.fn(async () => true), recap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'Shipped', at: 5, none: false })), onCards: undefined as unknown, onRecap: undefined as unknown }
+ const cards = { want: vi.fn(), open: vi.fn(), say: vi.fn(async () => true), worker: vi.fn((machineId: string, harnessId: string) => machineId === 'm2' && harnessId === 'h-r1'), recap: vi.fn(async (tabId: string, leadId: string) => ({ tabId, leadId, text: 'Shipped', at: 5, none: false })), onCards: undefined as unknown, onRecap: undefined as unknown }
const superTabs = { attention: vi.fn(), cards: vi.fn(), cardRecap: vi.fn(), shareObservers: vi.fn(), screen: vi.fn(), input: vi.fn() }
const core = fakeCore({ superTabs })
const make = vi.fn(() => cards as never)
@@ -713,6 +713,15 @@ describe('the Swarm cards the devices ask for', () => {
await t.ask({ action: 'cardSay', harnessId: 'h1', text: 'ship it' }, owner)
expect(t.cards.say).toHaveBeenLastCalledWith('h1', 'ship it', false)
})
+ it('cardWorker says whether a machine\'s harness is one of a Swarm\'s workers, for the devices to keep its failure quiet', async () => {
+ const t = withCards()
+ expect(await t.ask({ action: 'cardWorker', machineId: 'm2', harnessId: 'h-r1' }, owner)).toEqual({ ok: true, worker: true })
+ expect(await t.ask({ action: 'cardWorker', machineId: 'm1', harnessId: 'h-r1' }, owner)).toEqual({ ok: true, worker: false })
+ for (const bad of [{ action: 'cardWorker', machineId: 'bad id', harnessId: 'h-r1' }, { action: 'cardWorker', machineId: 'm2' }, { action: 'cardWorker', harnessId: 'h-r1' }]) {
+ expect(await t.ask(bad, owner)).toEqual({ error: 'INVALID_REQUEST' })
+ }
+ expect(await t.ask({ action: 'cardWorker', machineId: 'm2', harnessId: 'h-r1' }, { local: false, owner: true })).toEqual({ error: 'OWNER_REQUIRED' })
+ })
it('answers a backend refusal while reading a recap as the service does any other', async () => {
const t = withCards()
t.cards.recap.mockRejectedValueOnce(new SuperTabHostError('FORBIDDEN', 'Access withdrawn', 403))
diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.ts
index 25d973a46..dd88d6f7b 100644
--- a/cli/src/superTabs/service.ts
+++ b/cli/src/superTabs/service.ts
@@ -362,7 +362,7 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =
// The devices' (core/devicesLink.ts): a Harness Pro that shows the Swarm cards is attached or gone, wants a Lead's recap, or
// has one open. They read the account's Swarms as the person, and need no agent.
// Only this computer's own devices ask: an account owner on another machine does not make this one read the Swarms.
- if (payload.action === 'cardsWanted' || payload.action === 'cardRecap' || payload.action === 'cardOpen' || payload.action === 'cardSay') {
+ if (payload.action === 'cardsWanted' || payload.action === 'cardRecap' || payload.action === 'cardOpen' || payload.action === 'cardSay' || payload.action === 'cardWorker') {
if (!asker.local) return { error: 'OWNER_REQUIRED' }
// A round dial that speaks swarmChat asks for the chat on its face (design 2026-10-28-round-dial-swarm-chat).
const chat = payload.chat === true
@@ -377,6 +377,10 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =
if (payload.action === 'cardSay' && cardId(payload.harnessId) && typeof payload.text === 'string' && payload.text.trim() && payload.text.length <= 32_000) {
return { ok: true, said: await cards().say(payload.harnessId, payload.text.trim(), chat) }
}
+ // A card's failure from another computer: whether its agent is a Swarm's Builder or Reviewer, from the Swarms read last.
+ if (payload.action === 'cardWorker' && identifier(payload.machineId) && identifier(payload.harnessId)) {
+ return { ok: true, worker: cards().worker(payload.machineId, payload.harnessId) }
+ }
if (payload.action === 'cardOpen' && cardId(payload.session) && cardId(payload.tabId) && (payload.leadId === null || cardId(payload.leadId))) {
cards().open(payload.session, payload.tabId, payload.leadId, chat)
return { ok: true }
diff --git a/desktop/lib/super_tabs/controller.dart b/desktop/lib/super_tabs/controller.dart
index 244f3a79c..99f5de38f 100644
--- a/desktop/lib/super_tabs/controller.dart
+++ b/desktop/lib/super_tabs/controller.dart
@@ -699,6 +699,14 @@ class SuperTabController extends ChangeNotifier {
/// rest waits for [showLatest], so a long burst is not all held.
static const _pagesBelowReader = 3;
+ /// Whether [id]'s reader is scrolled up with all the pages that join below
+ /// them held: the rest waits for [showLatest], so no poll reads it.
+ bool _holding(String id) =>
+ _readingBack.contains(id) &&
+ _newer.contains(id) &&
+ !_latestWanted.contains(id) &&
+ (_pagesBelow[id] ?? 0) >= _pagesBelowReader;
+
/// Forgets reading back in [id], or in every conversation.
void _forgetNewer([String? id]) {
for (final kept in [_readingBack, _newer, _latestWanted]) {
@@ -717,12 +725,20 @@ class SuperTabController extends ChangeNotifier {
bool hasNewer(String id) => _newer.contains(id);
/// Brings [id]'s newest messages: when more are waiting than reads
- /// brought, the latest page replaces what is held.
+ /// brought, the latest page replaces what is held; otherwise what came
+ /// after it is read. Its own read: one already under way may have asked
+ /// for less (the rows held below a reader scrolled up).
Future<void> showLatest(String id) async {
_readingBack.remove(id);
- await _reading[(id, false)];
- if (_disposed || !_newer.contains(id)) return;
- _latestWanted.add(id);
+ for (
+ var under = _reading[(id, false)];
+ under != null;
+ under = _reading[(id, false)]
+ ) {
+ await under;
+ }
+ if (_disposed) return;
+ if (_newer.contains(id)) _latestWanted.add(id);
await _readMessages(id);
}
@@ -1829,6 +1845,8 @@ class SuperTabController extends ChangeNotifier {
// messages: the first read after it takes the latest page whole.
if (_showingSaved || _latestWanted.contains(id)) return '';
final tail = _messages[id]?.lastOrNull?.sequence;
+ // Holding: the rows shown, for their receipts and reactions.
+ if (tail != null && _holding(id)) return '?before=${tail + 1}';
return tail != null ? '?after=$tail' : '';
}
@@ -1911,11 +1929,14 @@ class SuperTabController extends ChangeNotifier {
return;
}
if (older && !hasOlder(id)) return;
+ // A light check asks only for new messages, which wait while holding.
+ if (light && _holding(id)) return;
try {
final known = _messages[id];
final tail = known != null && known.isNotEmpty
? known.last.sequence
: null;
+ final holding = !older && _holding(id);
final query = _query(id, older: older);
final latest = !older && _latestWanted.remove(id);
final from = _before[id];
@@ -1926,7 +1947,10 @@ class SuperTabController extends ChangeNotifier {
)
: await request('GET', '${_messagesPath(id)}$query');
final arrived =
- !older && tail != null && (answer['messages'] as List).isNotEmpty;
+ !older &&
+ !holding &&
+ tail != null &&
+ (answer['messages'] as List).isNotEmpty;
final reacted = !older && _reactionsMoved(id, answer);
// Recorded only once the rows are refreshed: a read that fails leaves
// the change for the next poll.
@@ -1938,7 +1962,6 @@ class SuperTabController extends ChangeNotifier {
// below them, and the rest waits for [showLatest].
final skipped = query.startsWith('?after=') && answer['next'] != null;
final keepPlace = skipped && _readingBack.contains(id);
- final full = keepPlace && (_pagesBelow[id] ?? 0) >= _pagesBelowReader;
if (!_disposed && skipped && !keepPlace) {
answer = await request('GET', _messagesPath(id));
} else if (!_disposed && keepPlace) {
@@ -1953,7 +1976,7 @@ class SuperTabController extends ChangeNotifier {
: const [];
answer = {
...answer,
- 'messages': [...shown, if (!full) ...answer['messages'] as List],
+ 'messages': [...shown, ...answer['messages'] as List],
};
} else if (!_disposed &&
!older &&
@@ -2062,8 +2085,8 @@ class SuperTabController extends ChangeNotifier {
_messages[id] = next;
if (keepPlace) {
_newer.add(id);
- if (!full) _pagesBelow[id] = (_pagesBelow[id] ?? 0) + 1;
- } else if (!older) {
+ _pagesBelow[id] = (_pagesBelow[id] ?? 0) + 1;
+ } else if (!older && !holding) {
_newer.remove(id);
_pagesBelow.remove(id);
}
diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dart
index e43b5069d..8677383f9 100644
--- a/desktop/lib/super_tabs/view.dart
+++ b/desktop/lib/super_tabs/view.dart
@@ -1165,15 +1165,14 @@ class _SuperTabViewState extends State<SuperTabView>
SuperTabMessage? held() =>
c.messages(id).where((m) => m.id == mention.messageId).firstOrNull;
var message = held();
- // The tag is what to see, not the rows read back: the first read goes up
- // to the latest, never only a few pages below them.
- if (message == null) c.readingBack(id, false);
// Up to 50 pages (5,000 messages). A tag newer than what was read earlier
- // is after it, so the first read is up to the latest; the rest go back.
+ // is after it, so the first read is up to the latest, its own even with
+ // a poll's read under way (that one may hold rows below a reader scrolled
+ // up); the rest go back.
for (var page = 0; message == null && page < 50; page++) {
final older = page > 0;
if (older && !c.hasOlder(id)) break;
- await c.loadMessages(id, older: older);
+ await (older ? c.loadMessages(id, older: true) : c.showLatest(id));
if (!mounted) return;
message = held();
}
diff --git a/desktop/test/super_tab_mentions_test.dart b/desktop/test/super_tab_mentions_test.dart
index c4f9e6a95..a6199ba96 100644
--- a/desktop/test/super_tab_mentions_test.dart
+++ b/desktop/test/super_tab_mentions_test.dart
@@ -601,6 +601,53 @@ void main() {
);
});
+ testWidgets(
+ 'a tag opened while a poll reads the rows held below a reader scrolled '
+ 'up still opens at its message',
+ (tester) async {
+ final server = ConversationServer();
+ server.state['conversations'] = [
+ ...server.state['conversations'] as List,
+ conversationFixture('group', 'Release'),
+ ];
+ for (var i = 1; i <= 100; i++) {
+ server.append('Note $i', conversationId: 'group');
+ }
+ final c = await showView(tester, server);
+ await c.loadMessages('group');
+ c.readingBack('group', true);
+ for (var i = 101; i <= 700; i++) {
+ server.append('Note $i', conversationId: 'group');
+ }
+ // Three pages join below the reader; newer ones wait.
+ for (var poll = 0; poll < 3; poll++) {
+ await c.loadMessages('group');
+ }
+ expect(c.hasNewer('group'), isTrue);
+ server.tag('message-650', conversationId: 'group', text: 'Note 650');
+ await tester.tap(notificationsEntry());
+ await tester.pumpAndSettle();
+ // A background poll is reading the rows held when the tag opens.
+ final held = server.holdReads = Completer<void>();
+ final poll = c.loadMessages('group');
+ await tester.tap(find.byKey(const ValueKey('super-mention-mention-1')));
+ await tester.pump();
+ server.holdReads = null;
+ held.complete();
+ await poll;
+ await tester.pumpAndSettle();
+ expect(
+ find.text('This message is no longer in the conversation.'),
+ findsNothing,
+ );
+ expect(c.selectedId, 'group');
+ expect(
+ find.byKey(const ValueKey('super-message-message-650')).hitTestable(),
+ findsOneWidget,
+ );
+ },
+ );
+
testWidgets('opening a tag shows its message with the reply box on it', (
tester,
) async {
diff --git a/desktop/test/super_tab_reading_test.dart b/desktop/test/super_tab_reading_test.dart
index e4522d69d..dee69f96e 100644
--- a/desktop/test/super_tab_reading_test.dart
+++ b/desktop/test/super_tab_reading_test.dart
@@ -283,6 +283,38 @@ void main() {
});
});
+ test('a reader scrolled up holding three pages below reads no newer page '
+ 'only to drop it', () {
+ fakeAsync((async) {
+ final server = ConversationServer()..messagePage = 2;
+ for (final text in ['one', 'two']) {
+ server.append(text);
+ }
+ final reads = _Reads(server);
+ final c = _controller(reads, reading: _web)..start();
+ async.elapse(const Duration(seconds: 61));
+ c.readingBack('lead', true);
+ for (var i = 3; i <= 40; i++) {
+ _reply(server, 'Update $i');
+ }
+ // Polls join three pages of two below the reader.
+ async.elapse(const Duration(seconds: 30));
+ expect(
+ c.messages('lead').map((m) => m.sequence),
+ List.generate(8, (i) => i + 1),
+ );
+ expect(c.hasNewer('lead'), isTrue);
+
+ reads.clear();
+ async.elapse(const Duration(seconds: 60));
+
+ expect(reads.tails, 0);
+ expect(c.messages('lead'), hasLength(8));
+ expect(c.hasNewer('lead'), isTrue);
+ c.dispose();
+ });
+ });
+
test('a full read asks for new messages beside the state', () {
fakeAsync((async) {
final server = ConversationServer()..append('Hello');