The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Swarm: a removed machine's old cleanup gives way to its owner adding it again (#1986)
0xken15f6b87ede84b3
diff --git a/backend/integration/superTabTeam.test.ts b/backend/integration/superTabTeam.test.tsindex 0a2cd6cee..bcef8ff62 100644--- a/backend/integration/superTabTeam.test.ts+++ b/backend/integration/superTabTeam.test.ts@@ -610,4 +610,61 @@ describe('one machine: a Mac and its Harness Team account', () => {expect((await storedState(tab)).machineCleanups).toBeUndefined()expect(await said()).toHaveLength(1)})++ // Diego's Mac, 2026-10-28, after #1955: the Mac and its team account were removed together and went past the fallback+ // while their hosts kept reporting. Adding the Mac back said it was still cleaning up, and nothing finished it.+ it('a Mac and its team account past the fallback: each host is told its cleanup, both confirm, and the Mac is added again', 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))+ let now = Date.now()+ const timed = new SuperTabStore(db, () => now)+ const exec = (user: AuthUser, tab: string, command: Command, operationId: string = randomUUID()) => timed.execute(user, tab, { operationId, command })+ const tab = (await timed.create(owner, randomUUID(), 'Removed together')).id+ const invitation = await exec(owner, tab, { type: 'invite.create', email: person.email, role: 'collaborator', conversationId: 'lead' })+ await exec(person, tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string })+ const addMac = () => exec(person, tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 3 })+ await addMac()+ await exec(person, tab, { type: 'machine.contribute', machineId: 'team-mac', name: 'MacBook Pro · Team', cwd: '/team', scope: 'swarm', engines: ['codex'],+ maxAgents: 1, ifMissing: true })+ const hosts = [[person, 'personal-mac'], [team, 'team-mac']] as const+ const generations = new Map<string, string>()+ for (const [user, machineId] of hosts) generations.set(machineId, (await poolRows(timed, user, machineId)).find(p => p.tabId === tab)!.machine.generation)+ const report = async () => { for (const [user, machineId] of hosts) await timed.observeMachine(user, tab, machineId, reading(generations.get(machineId)!)).catch(() => null) }+ await report()+ await exec(person, tab, { type: 'machine.remove', machineId: 'personal-mac' })+ // Both hosts keep reporting and neither confirms, past the fallback.+ const removedAt = now+ for (let at = removedAt + 40_000; at <= removedAt + 31 * 60_000; at += 40_000) { now = at; await report() }+ expect((await storedState(tab)).machines?.map(m => m.machineId) ?? []).toEqual([])+ // Each host's feed names its own cleanup, and its confirmation, as cli/src/superTabs/machines.ts runCleanup sends it, clears it.+ for (const [user, machineId] of hosts) {+ const rows = (await rosterRows(timed, user, machineId)).filter(r => r.tabId === tab && 'cleanup' in r) as Array<{ cleanup: { machineId: string; removalId: string } }>+ expect(rows.map(r => r.cleanup.machineId)).toEqual([machineId])+ const { removalId } = rows[0]!.cleanup+ await exec(user, tab, { type: 'machine.cleaned', machineId, removalId }, `machine-cleaned-${removalId}`)+ }+ expect((await storedState(tab)).machineCleanups).toBeUndefined()+ await addMac()+ expect((await storedState(tab)).machines?.map(m => m.machineId)).toEqual(['personal-mac'])+ })++ // A cleanup's time is kept with it: lost, a fresh cleanup would read as overdue and let the add delete-race its host.+ it('keeps a fresh cleanup holding its owner\'s add until 30 minutes after the removal', async () => {+ let now = Date.now()+ const timed = new SuperTabStore(db, () => now)+ const exec = (user: AuthUser, tab: string, command: Command) => timed.execute(user, tab, { operationId: randomUUID(), command })+ const tab = (await timed.create(owner, randomUUID(), 'Fresh cleanup')).id+ const invitation = await exec(owner, tab, { type: 'invite.create', email: person.email, role: 'collaborator', conversationId: 'lead' })+ await exec(person, tab, { type: 'invite.accept', inviteId: invitation.result.inviteId as string })+ const add = () => exec(person, tab, { type: 'machine.contribute', machineId: 'personal-mac', name: 'MacBook Pro', cwd: '/work', scope: 'swarm', engines: ['codex'], maxAgents: 3 })+ await add()+ // Never reported, so offline: its records go at once and its cleanup waits for its host.+ await exec(person, tab, { type: 'machine.remove', machineId: 'personal-mac' })+ expect((await storedState(tab)).machineCleanups?.map(c => c.machineId)).toEqual(['personal-mac'])+ now += 30 * 60_000 - 1+ await expect(add()).rejects.toMatchObject({ code: 'MACHINE_CLEANING' })+ now += 1+ await add()+ expect((await storedState(tab)).machineCleanups).toBeUndefined()+ })})diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.tsindex a48873c64..0d0e7005b 100644--- a/backend/integration/superTabs.test.ts+++ b/backend/integration/superTabs.test.ts@@ -2813,7 +2813,7 @@ describe('machine removal', () => {expect((await later.read(owner, tab)).state.machines).toEqual([])await later.execute(owner, tab, { operationId: randomUUID(), command: { type: 'tab.rename', name: 'A day later' } })const stored = await storedState(tab)- expect([stored.machines ?? [], stored.machineCleanups]).toEqual([[], [{ machineId: 'test-host', removalId, machineOwnerId: host.sub }]])+ expect([stored.machines ?? [], stored.machineCleanups]).toEqual([[], [{ machineId: 'test-host', removalId, machineOwnerId: host.sub, requestedAt: expect.any(String) }]])expect(await cleanups(tab, later)).toEqual([{ tabId: tab, cleanup: { machineId: 'test-host', removalId } }])await later.execute(host, tab, { operationId: randomUUID(), command: { type: 'machine.cleaned', machineId: 'test-host', removalId } })expect(await cleanups(tab, later)).toEqual([])diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 2af9ba182..1857595c9 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -2080,14 +2080,50 @@ describe('machine.remove', () => {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' }])+ expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner', requestedAt: new Date(1000).toISOString() }])const add = { type: 'machine.contribute', machineId: 'host', name: 'Studio', cwd: '/repo', engines: ['claude'], maxAgents: 2 } as Command- expect(() => f.run(add, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' }, now: 1000 + day })).toThrow('still cleaning up')+ expect(() => f.run(add, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' }, now: 1000 + day - 1 })).toThrow('still cleaning up')// 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()})+ // Diego's Mac, 2026-10-28: its cleanup never finished, and adding it back said 'still cleaning up' for good. A cleanup that+ // has waited 30 minutes no longer holds its owner's add: the add goes through and that cleanup is dropped.+ it('lets its owner add the machine again once its cleanup has waited 30 minutes, and drops that cleanup', () => {+ const f = fixture()+ contribute(f, 'owner', 'host', null)+ f.run({ type: 'machine.remove', machineId: 'host' })+ const add = { type: 'machine.contribute', machineId: 'host', name: 'Studio', cwd: '/repo', engines: ['claude'], maxAgents: 2 } as Command+ const asOwner = (now: number) => ({ contribution: { machineOwnerId: 'owner', contributorId: 'owner' }, now })+ expect(() => f.run(add, owner, asOwner(1000 + 30 * 60_000 - 1))).toThrow(expect.objectContaining({ code: 'MACHINE_CLEANING' }))+ f.run(add, owner, asOwner(1000 + 30 * 60_000))+ expect(f.state.machineCleanups).toBeUndefined()+ expect(f.state.machines!.map(m => [m.machineId, m.removal])).toEqual([['host', undefined]])+ })++ it('lets its owner add the machine again over a cleanup recorded before cleanups carried their time', () => {+ const f = fixture()+ f.state.machineCleanups = [{ machineId: 'host', removalId: 'before', machineOwnerId: 'owner' }, { machineId: 'other', removalId: 'kept', machineOwnerId: 'owner' }]+ f.run({ type: 'machine.contribute', machineId: 'host', name: 'Studio', cwd: '/repo', engines: ['claude'], maxAgents: 2 }, owner,+ { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } })+ expect(f.state.machineCleanups).toEqual([{ machineId: 'other', removalId: 'kept', machineOwnerId: 'owner' }])+ expect(f.state.machines!.map(m => m.machineId)).toEqual(['host'])+ })++ it('lets only the owner of an old cleanup add its machine over it', () => {+ const f = fixture()+ f.invite()+ f.state.machineCleanups = [{ machineId: 'host', removalId: 'before', machineOwnerId: 'peer' }]+ const add = { type: 'machine.contribute', machineId: 'host', name: 'Studio', cwd: '/repo', engines: ['claude'], maxAgents: 2 } as Command+ // Another member is no owner of this machine at all.+ expect(() => f.run(add, peer, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } })).toThrow(expect.objectContaining({ code: 'OWNER_REQUIRED' }))+ // The machine's owner now is not the person whose host owes that cleanup: it still holds.+ expect(() => f.run(add, owner, { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } })).toThrow(expect.objectContaining({ code: 'MACHINE_CLEANING' }))+ f.run(add, peer, { contribution: { machineOwnerId: 'peer', contributorId: 'peer' } })+ 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 }@@ -2115,7 +2151,7 @@ describe('machine.remove', () => {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(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner', requestedAt: new Date(1000).toISOString() }])expect(visibleState(f.state, owner).machines).toEqual([])// Its host still gets the cleanup on its next connection; its later acknowledgement closes it and changes nothing else.f.run(cleaned(removalId))@@ -2132,7 +2168,7 @@ describe('machine.remove', () => {expect(visibleState(f.state, owner, away).machines).toEqual([])f.run({ type: 'tab.rename', name: 'Still away' }, owner, { now: away })f.run({ type: 'tab.rename', name: 'Away a day' }, owner, { now: 1000 + 86_400_000 })- expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner' }])+ expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner', requestedAt: new Date(1000).toISOString() }])// It comes back, is handed that one cleanup, and acknowledges it: nothing comes back to life.f.run(cleaned(removalId))expect(f.state.machineCleanups).toBeUndefined()@@ -2154,7 +2190,7 @@ describe('machine.remove', () => {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' }])+ expect(f.state.machineCleanups).toEqual([{ machineId: 'host', removalId, machineOwnerId: 'owner', requestedAt: new Date(1000).toISOString() }])f.run(cleaned(removalId))expect(f.state.machineCleanups).toBeUndefined()})diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 2bc9559ae..177774c78 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -1,4 +1,4 @@-import { admitMachineStart, expireRemoval, expireRemovals, failTeamWork, removalEnded, machineContribution, machineOffline, ownedMachine, requireTeamWork, teamMachineFor, teamPoolsOf, teamStartRequest, teamWorkCheck, type ContributedMachine } from './machines.js'+import { admitMachineStart, cleanupOverdue, 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 {@@ -929,9 +929,10 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commastate.machines ??= []// The owner's host adds the machine its Lead runs on by itself (cli/src/superTabs/host.ts). It only fills a gap:// on 2026-10-22 Ken's Mac ran the Lead of a Swarm it was never added to, so its starts bypassed the machine's slots.- // A late cleanup would delete the new contribution's folders.+ // A late cleanup would delete the new contribution's folders, but one that waited past the fallback no longer holds+ // its own owner's add: it goes, and the add takes its place (machines.ts cleanupOverdue).const cleaning = state.machines.some(m => m.machineId === command.machineId && m.removal)- || !!state.machineCleanups?.some(c => c.machineId === command.machineId)+ || !!state.machineCleanups?.some(c => c.machineId === command.machineId && !(c.machineOwnerId === actor.userId && cleanupOverdue(c, context.now)))// A Mac's Harness Team account joins by itself wherever its owner added the Mac, as that Mac (cli/src/superTabs/host.ts).const mac = context.contribution?.hostMachineId? state.machines.find(m => m.machineId === context.contribution!.hostMachineId && m.contributorId === actor.userId && !m.removal) : undefined@@ -958,6 +959,8 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma}if (state.starts?.some(s => s.request.machineId === command.machineId && (!s.harnessId || (s.poolGeneration && !s.poolSettled)) && !s.error)) fail('STARTS_PENDING', 'Reconcile pending starts before changing this contribution.')state.machines = state.machines.filter(m => m.machineId !== command.machineId)+ state.machineCleanups = state.machineCleanups?.filter(c => c.machineId !== command.machineId)+ if (!state.machineCleanups?.length) delete state.machineCleanupsconst host = context.contribution?.hostMachineIdstate.machines.push({ machineId: command.machineId, name: mac?.name ?? command.name, cwd: command.cwd, engines: [...new Set(command.engines)],maxAgents: mac?.maxAgents ?? command.maxAgents, ...(command.scope ? { scope: command.scope } : {}),diff --git a/backend/src/superTabs/machines.ts b/backend/src/superTabs/machines.tsindex 941636750..64c6615af 100644--- a/backend/src/superTabs/machines.ts+++ b/backend/src/superTabs/machines.ts@@ -32,10 +32,16 @@ export interface ContributedMachine {/** 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 }+/** A removed machine whose host never acknowledged in time: its records are gone, its host still cleans up on its next poll.+ * [requestedAt]: when its removal was asked for; none on one recorded before 2026-10-28. */+export interface MachineCleanup { machineId: string; removalId: string; machineOwnerId: string; requestedAt?: string }/** 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+/** A cleanup that has waited REMOVAL_FALLBACK_MS since its removal, or one too old to say when: it no longer holds its+ * owner's add (commands.ts machine.contribute). Diego's Mac, 2026-10-28: its cleanup never finished, and adding it back+ * said 'still cleaning up' for good. */+export const cleanupOverdue = (cleanup: MachineCleanup, now: number): boolean =>+ !cleanup.requestedAt || now - Date.parse(cleanup.requestedAt) >= REMOVAL_FALLBACK_MS/** 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@@ -392,7 +398,8 @@ export function machineOffline(pool: ContributedMachine, now: number): boolean {/** 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, now: number): RemovalEnd {- (state.machineCleanups ??= []).push({ machineId: pool.machineId, removalId: pool.removal!.id, machineOwnerId: pool.contributorId })+ (state.machineCleanups ??= []).push({ machineId: pool.machineId, removalId: pool.removal!.id, machineOwnerId: pool.contributorId,+ requestedAt: pool.removal!.requestedAt })state.machines = state.machines!.filter(m => m !== pool)return machineOffline(pool, now) ? 'offline' : 'timedOut'}diff --git a/backend/src/superTabs/parts/shape.ts b/backend/src/superTabs/parts/shape.tsindex b1f4d30c8..98f56902e 100644--- a/backend/src/superTabs/parts/shape.ts+++ b/backend/src/superTabs/parts/shape.ts@@ -37,7 +37,7 @@ function machineParts(state: SuperTabState): Map<string, MachineData> {for (const { machineId, harnessId, generation, renewed } of state.harnessReservations ?? []) of(machineId).reservations.push({ harnessId, generation, renewed })for (const { machineId, harnessId } of state.releasedHarnesses ?? []) of(machineId).released.push(harnessId)for (const { machineId, agentId, harnessId, machineOwnerId } of state.closingSessions ?? []) of(machineId).closingSessions.push({ agentId, harnessId, machineOwnerId })- for (const { machineId, removalId, machineOwnerId } of state.machineCleanups ?? []) of(machineId).cleanups.push({ removalId, machineOwnerId })+ for (const { machineId, ...cleanup } of state.machineCleanups ?? []) of(machineId).cleanups.push(cleanup)return machines}@@ -120,7 +120,7 @@ export function reassemble(parts: SwarmParts, { share = false }: { share?: booleconst reservations = flat(m => m.reservations.map(r => ({ machineId: m.machineId, ...r })))const released = flat(m => m.released.map(harnessId => ({ machineId: m.machineId, harnessId })))const closing = flat(m => m.closingSessions.map(c => ({ agentId: c.agentId, machineId: m.machineId, harnessId: c.harnessId, machineOwnerId: c.machineOwnerId })))- const cleanups: MachineCleanup[] = flat(m => m.cleanups.map(c => ({ machineId: m.machineId, removalId: c.removalId, machineOwnerId: c.machineOwnerId })))+ const cleanups: MachineCleanup[] = flat(m => m.cleanups.map(c => ({ machineId: m.machineId, ...c })))const list = <K extends typeof LISTS[number]>(key: K, items: NonNullable<SuperTabState[K]>) => {if (items.length || present.has(key)) state[key] = copy(items)}diff --git a/backend/src/superTabs/parts/types.ts b/backend/src/superTabs/parts/types.tsindex c00e2d0c5..876e58a6f 100644--- a/backend/src/superTabs/parts/types.ts+++ b/backend/src/superTabs/parts/types.ts@@ -46,7 +46,7 @@ export interface MachineData {/** Harnesses a host proved stopped, oldest first, at most RELEASED_CAP. */released: string[]closingSessions: Array<{ agentId: string; harnessId: string; machineOwnerId: string }>- cleanups: Array<{ removalId: string; machineOwnerId: string }>+ cleanups: Array<{ removalId: string; machineOwnerId: string; requestedAt?: string }>}/** One project's report watermark (section 3.6). Group sequences are per group; floors carry pre-split tab revisions. */diff --git a/cli/src/superTabs/machines.spec.ts b/cli/src/superTabs/machines.spec.tsindex 243b88d04..b46d82d16 100644--- a/cli/src/superTabs/machines.spec.ts+++ b/cli/src/superTabs/machines.spec.ts@@ -1451,6 +1451,33 @@ describe('removed machine cleanup', () => {await expect(host.clean('../escape', 'other')).rejects.toThrow('Invalid machine removal.')})+ // 2026-10-28: once a cleanup has waited past the backend's fallback, its owner can add the machine again and the backend+ // drops the cleanup (backend machines.ts cleanupOverdue). A cleanup that starts after that must not delete the new Swarm folders.+ it.each([['added again', {}], ['added again and being removed under a newer removal', { removal: { id: 'newer', state: 'cleaning' } }]])(+ 'deletes nothing and confirms nothing once this machine was %s', async (_why, listed) => {+ const m = machine()+ m.backend.mockImplementation(async (_core, method, path) => method === 'GET' && path.startsWith('/api/super-tabs/tab/')+ ? swarmReply(path, { starts: m.starts, machines: [{ machineId: 'host', contributorId: 'person', cwd: m.newRoot, ...listed }] }) : { parts: [] })+ const host = m.open()+ await host.clean('tab', 'removal')+ for (const kept of [join(m.data, 'swarm-projects', 'tab'), m.newRoot, m.recorded, m.earlier]) expect(existsSync(kept), kept).toBe(true)+ expect(m.core.agents.closeStarted).not.toHaveBeenCalled()+ expect(m.acks()).toEqual([])+ expect(m.log.mock.calls.flat().join('\n')).toContain('added to that Swarm again')+ // Settled: the next poll's row, if any, does not run it again.+ await host.clean('tab', 'removal')+ expect(m.backend.mock.calls.filter(c => c[1] === 'GET')).toHaveLength(1)+ })++ it('cleans up while the Swarm still lists this machine under this very removal', async () => {+ const m = machine()+ m.backend.mockImplementation(async (_core, method, path) => method === 'GET' && path.startsWith('/api/super-tabs/tab/')+ ? swarmReply(path, { starts: m.starts, machines: [{ machineId: 'host', contributorId: 'person', cwd: m.newRoot, removal: { id: 'removal', state: 'cleaning' } }] }) : { parts: [] })+ await m.open().clean('tab', 'removal')+ for (const gone of [join(m.data, 'swarm-projects', 'tab'), m.newRoot, m.recorded, m.earlier]) expect(existsSync(gone), gone).toBe(false)+ expect(m.acks()).toHaveLength(1)+ })+it('keeps a person\'s own worktree of the same repository even when the registry now lists it as the agent\'s folder', async () => {const m = machine()const outside = worktree(m.own, join(m.home, 'code', 'app-feature'), 'feature')diff --git a/cli/src/superTabs/machines.ts b/cli/src/superTabs/machines.tsindex 81a2a4e08..9f8715ffc 100644--- a/cli/src/superTabs/machines.ts+++ b/cli/src/superTabs/machines.ts@@ -600,8 +600,17 @@ export class ContributedMachines {// very agent the registry lists as agent-started in it. A start receipt read is required; a tab gone or no longer// readable by this owner leaves only the record.let starts: Record<string, unknown>[] = []- try { starts = list((await this.sources.reads.read(tabId)).state.starts) }+ let state: Record<string, unknown> = {}+ try { state = (await this.sources.reads.read(tabId)).state; starts = list(state.starts) }catch (error) { if (!(error instanceof SuperTabHostError) || ![403, 404].includes(error.status)) throw error }+ // A cleanup that waited past the backend's fallback gives way to its owner adding this machine again (backend machines.ts+ // cleanupOverdue, 2026-10-28). The Swarm listing this machine other than under this very removal means a newer add owns+ // the folders now: delete nothing, and confirm nothing, since the backend dropped this cleanup with that add.+ const listed = list(state.machines).find(m => m.machineId === this.machineId)+ if (listed && object(listed.removal).id !== removalId) {+ this.log(`Kept the Swarm folders of ${tabId}: this machine was added to that Swarm again.`)+ return+ }const swarm = new Set(recorded.map(w => w.harnessId))const candidates = recorded.map(w => ({ source: w.source, path: w.path, startId: w.startId, proven: true }))for (const start of starts) {