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 host: the starts awaiting their sessions are kept across a daemon restart
bitcoinbuilderafe643b2203f
diff --git a/cli/src/superTabs/machines.spec.ts b/cli/src/superTabs/machines.spec.tsindex 573de9870..54a1d9282 100644--- a/cli/src/superTabs/machines.spec.ts+++ b/cli/src/superTabs/machines.spec.ts@@ -3,10 +3,10 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSyncimport { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import { join } from 'node:path'-import { afterEach, describe, expect, it, vi } from 'vitest'+import { afterEach, describe, expect, it, onTestFinished, vi } from 'vitest'import type { RegisteredSession } from '../lib/registry.js'import { fakeCore } from '../testing/fakeCore.js'-import { apisOn, ContributedMachines, createQuietGit, liveOn, localModelsStamp, offered, refusedOn, servedOn, sharedWith, swarmWorktreesFile } from './machines.js'+import { apisOn, ContributedMachines, createQuietGit, liveOn, localModelsStamp, offered, refusedOn, servedOn, sharedWith, swarmUnconfirmedFile, swarmWorktreesFile } from './machines.js'import { SuperTabHostError } from './host.js'import { startAgent } from './start.js'import { hostForm, swarmReply } from './fixtures/read/index.js'@@ -790,6 +790,23 @@ describe('contributed machine executor', () => {expect(closeMember).toHaveBeenCalledTimes(1)})+ // A daemon restarted between the launch and the Swarm failing the start no longer forgets the agent it launched.+ it('still stops it after the daemon restarted, from the launches it kept on disk', async () => {+ const { f, closeMember, fail } = failedLater(() => ({ error: 'Mac Auto did not start it within 3 minutes' }))+ const dataDir = mkdtempSync(join(tmpdir(), 'swarm-unconfirmed-'))+ onTestFinished(() => rmSync(dataDir, { recursive: true, force: true }))+ ;(f.core as { dataDir: string }).dataDir = dataDir+ await f.machine.tick()+ expect(JSON.parse(readFileSync(swarmUnconfirmedFile(dataDir, 'host'), 'utf8')).launches)+ .toEqual([{ startId: 'start', path: startPath, harnessId: 'launched', creationId: 'creation' }])+ f.machine.stop()+ const restarted = new ContributedMachines(f.core, 'host', f.deps as never)+ fail(); f.advance(); await restarted.tick(); await settle()+ expect(closeMember).toHaveBeenCalledWith('launched', 'creation')+ expect(JSON.parse(readFileSync(swarmUnconfirmedFile(dataDir, 'host'), 'utf8')).launches).toEqual([])+ restarted.stop()+ })+it('never stops one that joined, one its receipt does not name, or one whose start is still pending', async () => {const joined = failedLater(() => ({ harnessId: 'launched' }))await joined.f.machine.tick(); joined.fail(); joined.f.advance(); await joined.f.machine.tick(); await settle()diff --git a/cli/src/superTabs/machines.ts b/cli/src/superTabs/machines.tsindex 69060fd9f..d3d392bbe 100644--- a/cli/src/superTabs/machines.ts+++ b/cli/src/superTabs/machines.ts@@ -80,6 +80,19 @@ function writeWorktrees(file: string, worktrees: SwarmWorktree[]) {writeFileSync(`${file}.next`, JSON.stringify({ version: 1, worktrees }), { mode: 0o600, flush: true })renameSync(`${file}.next`, file)}+/** The starts this machine launched whose engines have not recorded their sessions yet (ContributedMachines `abandoned`),+ * kept across a restart: in memory only, a daemon restarted between the launch and the Swarm failing the start would+ * forget the agent it launched, and it would stay up with no Swarm agent, as ten did on Mac Auto (2026-10-29). */+export const swarmUnconfirmedFile = (dataDir: string, machineId: string) => join(dataDir, 'super-tabs', `swarm-unconfirmed-${machineId}.json`)+type SavedLaunch = { startId: string; path: string; harnessId: string; creationId: string }+function readUnconfirmed(file: string): SavedLaunch[] {+ let saved: unknown+ try { saved = JSON.parse(readFileSync(file, 'utf8')) } catch { return [] }+ const rows = object(saved).launches+ return (Array.isArray(rows) ? rows.map(object) : []).filter(l => [l.startId, l.harnessId, l.creationId].every(identifier)+ && typeof l.path === 'string' && l.path.startsWith('/api/')) as unknown as SavedLaunch[]+}+const within = (parent: string, path: string) => {const rel = relative(resolve(parent), resolve(path))return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))@@ -364,6 +377,7 @@ export class ContributedMachines {for (const id of this.waiting.keys()) if (!pendingIds.has(id)) this.waiting.delete(id)for (const id of this.refusedSince.keys()) if (!pendingIds.has(id)) this.refusedSince.delete(id)for (const id of this.preparing) if (!pendingIds.has(id)) this.preparing.delete(id)+ this.loadUnconfirmed()for (const [id, launch] of this.unconfirmed) if (!pendingIds.has(id) && !launch.checking) void this.abandoned(id, launch)for (const tab of this.published.keys()) if (!pools.some(row => row.tabId === tab)) this.published.delete(tab)for (const tab of this.lastSent.keys()) if (!pools.some(row => row.tabId === tab)) this.lastSent.delete(tab)@@ -588,8 +602,8 @@ export class ContributedMachines {else this.preparing.delete(String(start.id))// Launched, its engine yet to record its session: if the Swarm fails this start meanwhile, [abandoned] stops it.if (result.error === 'START_PENDING' && identifier(result.harnessId) && identifier(result.creationId)) {- this.unconfirmed.set(String(start.id), { path, harnessId: result.harnessId, creationId: result.creationId, tries: 0, checking: false })- } else this.unconfirmed.delete(String(start.id))+ this.remember(String(start.id), { path, harnessId: result.harnessId, creationId: result.creationId, tries: 0, checking: false })+ } else this.forget(String(start.id))if (!refused) this.refusedSince.delete(start.id)if (result.ok === true && identifier(result.harnessId)) {this.waiting.delete(start.id)@@ -615,6 +629,36 @@ export class ContributedMachines {}} finally { local?.close() }}+ private unconfirmedLoaded = false+ /** The launches an earlier run of this daemon kept ([swarmUnconfirmedFile]), once, before the first pass looks at them. */+ private loadUnconfirmed(): void {+ if (this.unconfirmedLoaded) return+ this.unconfirmedLoaded = true+ for (const launch of readUnconfirmed(swarmUnconfirmedFile(this.core.dataDir, this.machineId))) {+ if (!this.unconfirmed.has(launch.startId)) {+ this.unconfirmed.set(launch.startId, { path: launch.path, harnessId: launch.harnessId, creationId: launch.creationId, tries: 0, checking: false })+ }+ }+ }+ private remember(startId: string, launch: Unconfirmed): void {+ const known = this.unconfirmed.get(startId)+ this.unconfirmed.set(startId, launch)+ if (!known || known.harnessId !== launch.harnessId || known.creationId !== launch.creationId) this.saveUnconfirmed()+ }+ private forget(startId: string): void {+ if (this.unconfirmed.delete(startId)) this.saveUnconfirmed()+ }+ /** Written whole on each change; a write that fails leaves the launches in memory, as before. */+ private saveUnconfirmed(): void {+ const file = swarmUnconfirmedFile(this.core.dataDir, this.machineId)+ const launches: SavedLaunch[] = [...this.unconfirmed].map(([startId, l]) => ({ startId, path: l.path, harnessId: l.harnessId, creationId: l.creationId }))+ try {+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 })+ writeFileSync(`${file}.next`, JSON.stringify({ version: 1, launches }), { mode: 0o600 })+ renameSync(`${file}.next`, file)+ } catch (error) { this.log(`Could not keep the starts awaiting their sessions: ${error instanceof Error ? error.message : String(error)}`) }+ }+/*** A start this host launched, its engine never recording its session, that the backend no longer lists as pending: when* the backend says it failed (its machine did not start it within 3 minutes, say) and joined no agent, the agent this@@ -627,20 +671,20 @@ export class ContributedMachines {launch.checking = truetry {const status = object(await this.deps.backend(this.core, 'GET', launch.path))- if (identifier(status.harnessId) || !status.error) { this.unconfirmed.delete(startId); return }+ if (identifier(status.harnessId) || !status.error) { this.forget(startId); return }const close = this.core.agents.closeMember- if (!close) { this.unconfirmed.delete(startId); return }+ if (!close) { this.forget(startId); return }const closed = await close(launch.harnessId, launch.creationId)if ('closed' in closed && closed.closed) {- this.unconfirmed.delete(startId)+ this.forget(startId)this.log(`Stopped the agent a failed start launched (start ${startId}, session ${launch.harnessId.slice(0, 8)}): ${String(status.error)}`)return}// Not this start's own agent, as its receipt says: nothing here to stop.- if ('error' in closed && closed.error === 'NOT_A_MEMBER') { this.unconfirmed.delete(startId); return }+ if ('error' in closed && closed.error === 'NOT_A_MEMBER') { this.forget(startId); return }throw new Error(`${'error' in closed ? closed.error : 'unknown'}${'detail' in closed && closed.detail ? `: ${closed.detail}` : ''}`)} catch (error) {- if (++launch.tries >= ABANDONED_TRIES) this.unconfirmed.delete(startId)+ if (++launch.tries >= ABANDONED_TRIES) this.forget(startId)this.log(`Could not stop the agent a failed start launched (start ${startId}): ${error instanceof Error ? error.message : String(error)}`)} finally { launch.checking = false }}