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: machine removal finishes on its own (per-machine cleanup receipts, 30-minute fallback, ending line) (#1955)
0xken15491d18c80391
diff --git a/backend/integration/superTabTeam.test.ts b/backend/integration/superTabTeam.test.tsindex 5dc49efa8..0a2cd6cee 100644--- a/backend/integration/superTabTeam.test.ts+++ b/backend/integration/superTabTeam.test.ts@@ -543,4 +543,71 @@ describe('one machine: a Mac and its Harness Team account', () => {await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: null } })}})++ // Diego's Mac, 2026-10-28: the Mac and its team account leave under one removal, and each host confirms its own cleanup+ // as the same person with the same operation (cli/src/superTabs/machines.ts runCleanup). The Mac's confirmation, second,+ // was refused as a reused operation on every retry, so the Mac stayed 'Cleaning up' for the day-long fallback.+ it('leaves with its team account once both hosts confirmed their cleanup, the team account first', async () => {+ await db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: 'personal-mac' } })+ onTestFinished(() => db.machine.update({ where: { machineId: 'team-mac' }, data: { hostMachineId: null } }).then(() => undefined))+ const tab = (await store.create(owner, randomUUID(), 'Removed')).id+ const invitation = await run(tab, { type: 'invite.create', email: person.email, role: 'collaborator', conversationId: 'lead' })+ await run(tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string }, person)+ await run(tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 3 }, person)+ await run(tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', scope: 'swarm', engines: ['codex'],+ maxAgents: 1, ifMissing: true }, person)+ // Both online, so both stay listed while their hosts clean up.+ for (const [user, machineId] of [[person, 'personal-mac'], [team, 'team-mac']] as const) {+ await store.observeMachine(user, tab, machineId, reading((await poolRows(store, user, machineId)).find(p => p.tabId === tab)!.machine.generation))+ }+ const removalId = String((await run(tab, { type: 'machine.remove', machineId: 'personal-mac' }, person)).result.removalId)+ const listed = async () => (await store.read(person, tab)).state.machines!.filter(m => ['personal-mac', 'team-mac'].includes(m.machineId))+ .map(m => [m.machineId, m.removal?.state])+ expect(await listed()).toEqual([['personal-mac', 'cleaning'], ['team-mac', 'cleaning']])+ const cleaned = (user: AuthUser, machineId: string) => store.execute(user, tab, { operationId: `machine-cleaned-${removalId}`,+ command: { type: 'machine.cleaned', machineId, removalId } })+ await cleaned(team, 'team-mac')+ expect(await listed()).toEqual([['personal-mac', 'cleaning']])+ await cleaned(person, 'personal-mac')+ expect(await listed()).toEqual([])+ // A host repeating its confirmation gets its own receipt back.+ await expect(cleaned(person, 'personal-mac')).resolves.toBeDefined()+ await expect(cleaned(team, 'team-mac')).resolves.toBeDefined()+ expect((await store.messages(person, tab, 'lead', {})).messages.filter(m => m.text.includes('left the Swarm')).map(m => m.text))+ .toEqual(['MacBook Pro left the Swarm: its host confirmed its cleanup.'])+ })++ it('leaves 30 minutes after its removal while its host keeps reporting without confirming, and the project\'s chat says why', async () => {+ let now = Date.now()+ const timed = new SuperTabStore(db, () => now)+ const tab = (await timed.create(owner, randomUUID(), 'Silent host')).id+ const invitation = await timed.execute(owner, tab, { operationId: randomUUID(), command: { type: 'invite.create', email: person.email, role: 'collaborator', conversationId: 'lead' } })+ await timed.execute(person, tab, { operationId: randomUUID(), command: { type: 'invite.accept', inviteId: invitation.result.inviteId as string } })+ await timed.execute(person, tab, { operationId: randomUUID(), command: { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work',+ scope: 'swarm', engines: ['codex'], maxAgents: 3 } })+ const generation = (await poolRows(timed, person, 'personal-mac')).find(p => p.tabId === tab)!.machine.generation+ const report = () => timed.observeMachine(person, tab, 'personal-mac', reading(generation))+ await report()+ const removalId = String((await timed.execute(person, tab, { operationId: randomUUID(), command: { type: 'machine.remove', machineId: 'personal-mac' } })).result.removalId)+ const listed = async () => (await storedState(tab)).machines?.map(m => m.machineId) ?? []+ const said = async () => (await timed.messages(owner, tab, 'lead', {})).messages.filter(m => m.text.includes('left the Swarm')).map(m => m.text)+ // It keeps reporting, fresh each time; nothing ends the removal until half an hour has passed.+ const removedAt = now+ for (let at = removedAt + 40_000; at < removedAt + 30 * 60_000; at += 40_000) {+ now = at+ await report()+ }+ now = removedAt + 30 * 60_000 - 1+ await report()+ expect(await listed()).toEqual(['personal-mac'])+ now = removedAt + 30 * 60_000+ await report()+ expect(await listed()).toEqual([])+ expect(await said()).toEqual(['MacBook Pro left the Swarm: its host did not confirm its cleanup within 30 minutes. It finishes the cleanup when it next connects.'])+ // Its cleanup still reaches its host, whose late confirmation closes it without another line.+ expect((await rosterRows(timed, person, 'personal-mac')).filter(r => r.tabId === tab && 'cleanup' in r)).toEqual([{ tabId: tab, cleanup: { machineId: 'personal-mac', removalId } }])+ await timed.execute(person, tab, { operationId: `machine-cleaned-${removalId}`, command: { type: 'machine.cleaned', machineId: 'personal-mac', removalId } })+ expect((await storedState(tab)).machineCleanups).toBeUndefined()+ expect(await said()).toHaveLength(1)+ })})diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 9b355e3a9..12b7bddb6 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -1889,23 +1889,43 @@ describe('machine.remove', () => {expect(f.state.machines).toEqual([])})- it('drops the machine\'s records after 24 hours without an acknowledgement, and keeps the cleanup for its host', () => {+ // Diego's Mac, 2026-10-28: a host that keeps reporting but never confirms held its machine 'Cleaning up' for a day.+ it('drops the machine\'s records after 30 minutes without an acknowledgement, says so in the project\'s chat, and keeps the cleanup for its host', () => {const { f, removalId } = cleaning()- const day = 24 * 3_600_000- // Its host keeps reporting, so only the day-long fallback can expire it.+ const day = 30 * 60_000+ // Its host keeps reporting, so only the fallback can expire it.f.state.machines![0]!.observation!.receivedAt = 1000 + day - 1- f.run({ type: 'tab.rename', name: 'Still cleaning' }, owner, { now: 1000 + day - 1 })+ expect(f.run({ type: 'tab.rename', name: 'Still cleaning' }, owner, { now: 1000 + day - 1 }).messages).toEqual([])expect(f.state.machines!.map(m => m.removal?.id)).toEqual([removalId])expect(visibleState(f.state, owner, 1000 + day).machines).toEqual([])- f.run({ type: 'tab.rename', name: 'A day later' }, owner, { now: 1000 + day })+ expect(f.run({ type: 'tab.rename', name: 'Half an hour later' }, owner, { now: 1000 + day }).messages).toEqual([+ expect.objectContaining({ conversationId: 'lead', source: { kind: 'system' },+ text: 'Studio left the Swarm: its host did not confirm its cleanup within 30 minutes. It finishes the cleanup when it next connects.' })])expect(f.state.machines).toEqual([])expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner' }])const add = { type: 'machine.contribute', machineId: 'host', name: 'Studio', cwd: '/repo', engines: ['claude'], maxAgents: 2 } as Commandexpect(() => f.run(add, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' }, now: 1000 + day })).toThrow('still cleaning up')- f.run(cleaned(removalId), owner, { now: 1000 + day })+ // Its host's late confirmation closes the cleanup without telling anyone again.+ expect(f.run(cleaned(removalId), owner, { now: 1000 + day }).messages).toEqual([])expect(f.state.machineCleanups).toBeUndefined()})+ it('tells each project\'s chat that the machine left once its host confirmed the cleanup', () => {+ const { f, removalId } = cleaning()+ const docs = f.run({ type: 'project.create', name: 'Docs', visibility: 'public', brief: '' }).result as { conversationId: string }+ expect(f.run(cleaned(removalId)).messages).toEqual(['lead', docs.conversationId].map(conversationId => expect.objectContaining({+ conversationId, source: { kind: 'system' }, recipients: [], text: 'Studio left the Swarm: its host confirmed its cleanup.' })))+ })++ it('writes the line only in the chats of projects its machine owner can open', () => {+ const f = fixture()+ f.invite()+ contribute(f, 'peer')+ f.run({ type: 'project.create', name: 'Secret', visibility: 'private', brief: '' })+ const removalId = f.run({ type: 'machine.remove', machineId: 'host' }, peer).result.removalId as string+ expect(f.run(cleaned(removalId), peer).messages.map(m => [m.conversationId, m.author.id])).toEqual([['lead', 'peer']])+ })+it.each([['has no reading', null], ['was last read long ago', 1000 - 45_001]] as const)('drops a machine that is offline (%s) at once, and keeps its cleanup for its host', (_why, receivedAt) => {const f = fixture()@@ -1914,6 +1934,8 @@ describe('machine.remove', () => {expect(visibleState(f.state, owner).machines).toHaveLength(1)const effects = f.run({ type: 'machine.remove', machineId: 'host' })const removalId = effects.result.removalId as string+ expect(effects.messages).toEqual([expect.objectContaining({ conversationId: 'lead', source: { kind: 'system' },+ text: 'Studio left the Swarm: it is offline. It cleans up when it next connects.' })])expect(f.state.machines).toEqual([])expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner' }])expect(visibleState(f.state, owner).machines).toEqual([])@@ -1950,8 +1972,9 @@ describe('machine.remove', () => {expect(visibleState(f.state, owner, later).machines).toEqual([])expect(visibleState(f.state, owner, later).machineCleanups).toBeUndefined()expect(f.state.machines).toEqual([expect.objectContaining({ machineId: 'host' })])- // The next change applies the same rule and keeps the cleanup for its host.- f.run({ type: 'tab.rename', name: 'Still cleaning' }, owner, { now: later })+ // The next change applies the same rule, says why, and keeps the cleanup for its host.+ expect(f.run({ type: 'tab.rename', name: 'Still cleaning' }, owner, { now: later }).messages).toEqual([expect.objectContaining({+ conversationId: 'lead', text: 'Studio left the Swarm: it is offline. It cleans up when it next connects.' })])expect(f.state.machines).toEqual([])expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner' }])f.run(cleaned(removalId))diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 7ed408b40..b43f1181e 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -1,4 +1,4 @@-import { admitMachineStart, expireRemoval, expireRemovals, failTeamWork, machineContribution, machineOffline, ownedMachine, requireTeamWork, teamMachineFor, teamPoolsOf, teamStartRequest, teamWorkCheck, type ContributedMachine } from './machines.js'+import { admitMachineStart, expireRemoval, expireRemovals, failTeamWork, removalEnded, machineContribution, machineOffline, ownedMachine, requireTeamWork, teamMachineFor, teamPoolsOf, teamStartRequest, teamWorkCheck, type ContributedMachine } from './machines.js'import { assignAgentDisplayNames } from './agentNames.js'import { z } from 'zod'import {@@ -463,10 +463,10 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: CommasyncLeads(state)numberConversations(state)placeRules(state)- expireRemovals(state, context.now)+ const ended = expireRemovals(state, context.now)assignAgentDisplayNames(state.agents)const result: Record<string, unknown> = {}- const effects: CommandEffects = { state, messages: [], cancelledAgents: [], previousAttempts: [], routeDecisions: [], result }+ const effects: CommandEffects = { state, messages: ended, cancelledAgents: [], previousAttempts: [], routeDecisions: [], result }const operationId = stableId(state.id, actorKey(actor), context.operationId)// Acceptance is the only operation a non-member can perform; the verified account email owns the invite.@@ -498,6 +498,8 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commaconst pool = state.machines?.find(m => m.removal && owns(m.machineId, m.removal.id, m.contributorId))const cleanup = state.machineCleanups?.find(c => owns(c.machineId, c.removalId, c.machineOwnerId))if (!pool && !cleanup) fail('NOT_FOUND', 'This machine has no cleanup waiting.', 404)+ // One that already left the list said why then.+ if (pool) effects.messages.push(...removalEnded(state, pool, 'confirmed'))state.machines = state.machines?.filter(m => m !== pool)state.machineCleanups = state.machineCleanups?.filter(c => c !== cleanup)if (!state.machineCleanups?.length) delete state.machineCleanups@@ -686,9 +688,9 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commatext: `${how(machine)}, and ${join} with it.${task ? ` Its task "${group.title}" needs to be assigned again or closed.` : ''}`,replyTo: null, recipients: lead ? [lead] : [], source: SYSTEM_ROW })}- // Its host is offline and cannot acknowledge, so the day-long fallback applies at once: the machine leaves the list+ // Its host is offline and cannot acknowledge, so the fallback applies at once: the machine leaves the list// now and its cleanup waits for its next connection (spec 2026-10-23-remove-machine.md).- if (pool?.removal && machineOffline(pool, context.now)) expireRemoval(state, pool)+ if (pool?.removal && machineOffline(pool, context.now)) effects.messages.push(...removalEnded(state, pool, expireRemoval(state, pool, context.now)))return removed}diff --git a/backend/src/superTabs/machines.ts b/backend/src/superTabs/machines.tsindex 305188df5..73284de31 100644--- a/backend/src/superTabs/machines.ts+++ b/backend/src/superTabs/machines.ts@@ -1,7 +1,7 @@import { z } from 'zod'-import { activeWork, fail, person, type Actor, type Agent, type AgentStart, type AgentStartRequest, type SuperTabState } from './model.js'+import { activeWork, fail, person, stableId, type Actor, type Agent, type AgentStart, type AgentStartRequest, type MessageDraft, type SuperTabState } from './model.js'import { WORKSPACE_LABEL } from './workspaces.js'-import { agentProjectId, groupProject, ledProject, projectsOf, type SwarmProject } from './projects.js'+import { agentProjectId, canReadProject, groupProject, ledProject, projectsOf, type SwarmProject } from './projects.js'import { conversation } from './model.js'/** An explicit grant for this tab and project. It never creates a MachineShare. */@@ -27,14 +27,17 @@ export interface ContributedMachine {hostMachineId?: string/** Set by machine.remove: an online machine stays listed, paused, while its host deletes the Swarm's folders there, until* the host says it cleaned up (machine.cleaned) or REMOVAL_FALLBACK_MS passes. An offline one leaves the list at once and- * its cleanup waits for its host (expireRemovals). */+ * its cleanup waits for its host (expireRemovals). Each project's chat hears how it ended (removalEnded). */removal?: { id: string; state: 'cleaning'; requestedAt: string }/** Agent-time Swarm agents here spent on other people's tasks, by leaderboard week, kept by its readings (leaderboard/lent.ts). */lent?: import('./leaderboard/lent.js').LentWeek[]}/** A removed machine whose host never acknowledged in time: its records are gone, its host still cleans up on its next poll. */export interface MachineCleanup { machineId: string; removalId: string; machineOwnerId: string }-export const REMOVAL_FALLBACK_MS = 24 * 3_600_000+/** Was a day, until a host that kept reporting but never confirmed held Diego's Mac 'Cleaning up' for it (2026-10-28). */+export const REMOVAL_FALLBACK_MS = 30 * 60_000+/** Why a removal ended: its host confirmed, it was offline, or it kept reporting without confirming for REMOVAL_FALLBACK_MS. */+export type RemovalEnd = 'confirmed' | 'offline' | 'timedOut'/** Older contributions may name engines that Swarm no longer starts. Their fresh* observation lists the supported engines that are actually installed. */export function contributedEngines(pool: ContributedMachine, observation: MachineObservation | undefined = pool.observation): string[] {@@ -382,18 +385,36 @@ export function machineOffline(pool: ContributedMachine, now: number): boolean {return !pool.observation || now - pool.observation.receivedAt > MACHINE_FRESH_MS}-/** A removal its host cannot acknowledge (offline) or has not acknowledged in a day: the machine's records go, and the+/** A removal its host cannot acknowledge (offline) or has not acknowledged in REMOVAL_FALLBACK_MS: the machine's records go, and the* cleanup waits for its host on its next connection. */-export function expireRemoval(state: SuperTabState, pool: ContributedMachine): void {+export function expireRemoval(state: SuperTabState, pool: ContributedMachine, now: number): RemovalEnd {(state.machineCleanups ??= []).push({ machineId: pool.machineId, removalId: pool.removal!.id, machineOwnerId: pool.contributorId })state.machines = state.machines!.filter(m => m !== pool)+ return machineOffline(pool, now) ? 'offline' : 'timedOut'}-export function expireRemovals(state: SuperTabState, now: number): void {- for (const pool of state.machines?.filter(m => m.removal- && (machineOffline(m, now) || now - Date.parse(m.removal.requestedAt) >= REMOVAL_FALLBACK_MS)) ?? []) {- expireRemoval(state, pool)- }+/** The removals that ended, with the lines saying why. A read applies them without writing and drops the lines. */+export function expireRemovals(state: SuperTabState, now: number): MessageDraft[] {+ return (state.machines?.filter(m => m.removal+ && (machineOffline(m, now) || now - Date.parse(m.removal.requestedAt) >= REMOVAL_FALLBACK_MS)) ?? [])+ .flatMap(pool => removalEnded(state, pool, expireRemoval(state, pool, now)))+}++/** One line in each project's chat when a machine's removal ends, saying why (2026-10-28), so a machine that leaves the+ * Machines list without its host's confirmation does not go unexplained. Written as the machine's owner, or the Swarm's+ * owner once they left, only where that person can open the project. A Harness Team account follows its Mac and says+ * nothing of its own. */+export function removalEnded(state: SuperTabState, pool: ContributedMachine, how: RemovalEnd): MessageDraft[] {+ const writer = state.people.find(p => p.id === pool.contributorId) ?? state.people.find(p => p.id === state.ownerId)+ if (pool.hostMachineId || !pool.removal || !writer) return []+ const why = how === 'confirmed' ? 'its host confirmed its cleanup.'+ : how === 'offline' ? 'it is offline. It cleans up when it next connects.'+ : `its host did not confirm its cleanup within ${REMOVAL_FALLBACK_MS / 60_000} minutes. It finishes the cleanup when it next connects.`+ const reader: Actor = { kind: 'person', userId: writer.id, email: writer.email }+ return projectsOf(state).filter(p => canReadProject(state, reader, p) && state.conversations.some(c => c.id === p.leadConversationId)).map(p => ({+ id: stableId('machine-removal-ended', pool.removal!.id, pool.machineId, p.leadConversationId), conversationId: p.leadConversationId,+ author: { kind: 'person', id: writer.id, name: writer.email, membershipGeneration: writer.generation },+ text: `${pool.name} left the Swarm: ${why}`, replyTo: null, recipients: [], source: { kind: 'system' } }))}/** Pending intents reserve slots too. Only an explicit host stop frees a launched slot. A Mac and its Harness Team accountdiff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 719afed48..bf918b505 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -837,7 +837,10 @@ export class SuperTabStore {: hostMachineId && 'startId' in command? await this.poolHostActor(tx, user, original, hostMachineId, command.startId): await this.actor(tx, user, original, asAgentId, workspaceLeave && command.type === 'member.remove' && command.userId === user.sub && !asAgentId)- const receiptId = stableId(tabId, actorKey(actor), operationId)+ // A Mac and its Harness Team account leave under one removal, and each host confirms its cleanup as the same person+ // with the same operation (cli/src/superTabs/machines.ts runCleanup): each machine's confirmation is its own receipt.+ const receiptId = command.type === 'machine.cleaned' ? stableId(tabId, actorKey(actor), operationId, command.machineId)+ : stableId(tabId, actorKey(actor), operationId)const requestHash = hash(command)const prior = await tx.superTabOperation.findUnique({ where: { id: receiptId } })if (prior) {@@ -1789,16 +1792,17 @@ export class SuperTabStore {const now = this.now()// A machine that went silent while cleaning takes the fallback before this fresh reading can bring it back: its records// go, its cleanup waits for this host, as the next sweep would have done (machines.ts expireRemovals).- expireRemovals(state, now)+ const ended = expireRemovals(state, now)const stamp = clock.next()// A reading writes only its machine's part, and an agent's part only when its presence changes (spec); a group's only- // when a task there is lost.+ // when a task there is lost or a removal ends.const saved = async (lost: MessageDraft[] = []) => {- const sequences = numberMessages(state, lost, now)- const touches = judgedMachines(loaded.state, state, lost).filter(t => t.key !== machineId)+ const rows = [...ended, ...lost]+ const sequences = numberMessages(state, rows, now)+ const touches = judgedMachines(loaded.state, state, rows).filter(t => t.key !== machineId)await this.endRuns(tx, tabId, loaded.state, state)const version = (await this.save(tx, loaded, state, stamp, touches)).versions.get(`machine:${machineId}`) ?? 0- await this.writeMessages(tx, tabId, state, lost, sequences)+ await this.writeMessages(tx, tabId, state, rows, sequences)return { version }}if (!state.machines?.includes(pool)) return saved()