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.

Swarm: set its models up on creation, in the background

bitcoinbuilder1b3fd1495bf6
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.ts
index 8d484fa0d..5e223a75a 100644
--- a/backend/src/superTabs/commands.test.ts
+++ b/backend/src/superTabs/commands.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { applyCommand, commandSchema, PAIR_CHAIN_LIMIT, withoutCredentials, type Command, type CommandContext } from './commands.js'
+import { applyCommand, commandSchema, PAIR_CHAIN_LIMIT, swarmGridName, withoutCredentials, type Command, type CommandContext } from './commands.js'
import { CREDENTIAL_MARKER, type CredentialKind } from './credentials.js'
import { hostLocalGrid, machineSlots, removalPreview, swarmGridRow } from './machines.js'
import { activeWork, agentRole, createSuperTab, visibleState, type Actor, type AgentConfiguration } from './model.js'
@@ -2039,9 +2039,15 @@ describe('the Local models add-on', () => {
requirements: { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false } })
const grant = { contribution: { machineOwnerId: 'host-owner', contributorId: 'owner' } }
- it('is off until the owner turns it on, mints one grid name, and keeps it when turned off', () => {
+ it('is on in a new Swarm, its grid named, so the owner\'s computer sets it up in the background', () => {
const f = fixture()
- expect(f.state.localModels).toBeUndefined()
+ expect(f.state.localModels).toEqual({ grid: swarmGridName('tab'), enabled: true })
+ expect(swarmGridRow('tab', f.state)).toMatchObject({ grid: swarmGridName('tab'), enabled: true, ready: null })
+ })
+
+ it('is off in a Swarm from before until the owner turns it on, mints one grid name, and keeps it when turned off', () => {
+ const f = fixture()
+ delete f.state.localModels
f.invite()
expect(() => f.run({ type: 'localModels.set', enabled: true }, peer)).toThrow(expect.objectContaining({ code: 'OWNER_REQUIRED' }))
const on = f.run({ type: 'localModels.set', enabled: true })
@@ -2054,6 +2060,7 @@ describe('the Local models add-on', () => {
it('gives the owner\'s computer the grid and the people who may act, and a host the grid only while it is on', () => {
const f = fixture()
+ delete f.state.localModels
expect(swarmGridRow('tab', f.state)).toBeNull()
expect(hostLocalGrid(f.state)).toEqual({})
f.invite()
@@ -2066,6 +2073,7 @@ describe('the Local models add-on', () => {
expect(hostLocalGrid(f.state)).toEqual({})
// A viewer may not act in the Swarm, so is no member of its grid.
const viewing = fixture()
+ delete viewing.state.localModels
viewing.invite('viewer')
viewing.run({ type: 'localModels.set', enabled: true })
expect(swarmGridRow('tab', viewing.state)!.members).toEqual([])
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 71cf7b4be..bccbe2843 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -1,10 +1,9 @@
-import { createHash } from 'node:crypto'
import { admitMachineStart, expireRemoval, expireRemovals, failTeamWork, machineContribution, machineOffline, ownedMachine, requireTeamWork, teamWorkCheck, type ContributedMachine } from './machines.js'
import { assignAgentDisplayNames } from './agentNames.js'
import { z } from 'zod'
import {
activeWork, actorKey, agent, agentRole, author, conversation, crossProjectActive, fail, isLeads, person, stableId, syncLeads, numberConversations, nextConversationNumber, renderWorkTask,
- finishWorker, requireWorkerDecisions, reviewing, AGENT_ONLY,
+ finishWorker, requireWorkerDecisions, reviewing, swarmGridName, AGENT_ONLY,
type Actor, type Agent, type Author, type CommandEffects, type Conversation, type SuperTabState,
} from './model.js'
import { routeRecordSchema, routeTitle, startedAs, type RouteCandidate, type RouteDecision, type RouteFinal, type RouteOverride } from './routeRecord.js'
@@ -1543,11 +1542,7 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
}
/** A contribution owns capacity independently of membership. Reuse invalidates every prior stop proof. */
-/** The Swarm's grid name: `swarm-` and 12 hex of sha256(tab id). Derived so it is reproducible when supported; the
- * stored value is authoritative and never renamed. */
-export function swarmGridName(tabId: string): string {
- return `swarm-${createHash('sha256').update(tabId).digest('hex').slice(0, 12)}`
-}
+export { swarmGridName } from './model.js'
function reserveHarnessSlot(state: SuperTabState, machineId: string, harnessId: string, generation: string) {
const observation = state.machines?.find(m => m.machineId === machineId)?.observation
diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.ts
index 691ff6945..1dda84825 100644
--- a/backend/src/superTabs/model.ts
+++ b/backend/src/superTabs/model.ts
@@ -365,6 +365,12 @@ export function author(state: SuperTabState, actor: Actor, write = false): Autho
return { kind: 'agent', id: member.id, name: member.name, displayName: agentDisplayName(state.agents, member.id), membershipGeneration: member.membershipGeneration }
}
+/** The Swarm's grid name: `swarm-` and 12 hex of sha256(tab id). Derived so it is reproducible when supported; the
+ * stored value is authoritative and never renamed. */
+export function swarmGridName(tabId: string): string {
+ return `swarm-${createHash('sha256').update(tabId).digest('hex').slice(0, 12)}`
+}
+
export function createSuperTab(id: string, name: string, owner: { id: string; email: string }, environment: string, visibility?: ProjectVisibility): SuperTabState {
const state: SuperTabState = {
version: 1, id, name, ownerId: owner.id, environment, paused: false,
@@ -374,6 +380,10 @@ export function createSuperTab(id: string, name: string, owner: { id: string; em
}
// A new Swarm's first project starts in Default; only a project from before skill modes reads as Harness orchestration.
state.projects = [{ ...projectsOf(state)[0]!, ...(visibility ? { visibility } : {}), skillMode: 'default' }]
+ // Its models are on from the start (owner, 2026-10-24): the owner's computer makes the Swarm's grid in the background
+ // (CLI `superTabs/swarmGrids.ts`) and reports how it went. Fire and forget: a grid that could not be made leaves the
+ // Swarm as it is, and the owner's first share or run in Manage models sets the models up then.
+ state.localModels = { grid: swarmGridName(id), enabled: true }
syncLeads(state)
return state
}
diff --git a/desktop/lib/models/swarm_models_target.dart b/desktop/lib/models/swarm_models_target.dart
index e1bef45df..c46b917dc 100644
--- a/desktop/lib/models/swarm_models_target.dart
+++ b/desktop/lib/models/swarm_models_target.dart
@@ -20,8 +20,13 @@ class SwarmModelsTarget extends ChangeNotifier {
this.onSetUp,
this.setupNote,
this.setupError,
+ this.setupPending = false,
});
+ /// Turned on and not yet answered: the owner's computer is setting the models up in the background (a new Swarm's
+ /// are, from its creation). A share or run still sets them up at once if it has not finished.
+ final bool setupPending;
+
/// Whether the Swarm's models are set up, its grid made. Until they are, nothing is shared or run for it: the owner's
/// first share or run sets them up first ([whenSetUp]), and anyone else waits for the owner (2026-10-24: a list of
/// actions that could not be taken until a separate Set up read as broken).
diff --git a/desktop/lib/state/swarm_search.dart b/desktop/lib/state/swarm_search.dart
index 7108c66e7..b84c5ecdc 100644
--- a/desktop/lib/state/swarm_search.dart
+++ b/desktop/lib/state/swarm_search.dart
@@ -491,7 +491,11 @@ class SwarmSearchController extends ChangeNotifier {
command: action.command,
run: run == null || !swarm.canSetUp || swarm.settingUp
? null
- : () => swarm.whenSetUp(run),
+ : () async {
+ final error = await swarm.whenSetUp(run);
+ // A set up that failed is said in the preview, once; what the share or run itself answered is said here.
+ return swarm.setupNeeded ? null : error;
+ },
);
}
diff --git a/desktop/lib/super_tabs/local_models.dart b/desktop/lib/super_tabs/local_models.dart
index 3fe842e3c..e80da1516 100644
--- a/desktop/lib/super_tabs/local_models.dart
+++ b/desktop/lib/super_tabs/local_models.dart
@@ -15,6 +15,7 @@ import '../widgets/desktop_chrome.dart';
import '../widgets/key_hints.dart';
import '../widgets/swarm_resource_preview.dart';
import '../widgets/swarm_switcher.dart';
+import '../ws/ws_conn.dart';
import 'controller.dart';
import 'dialog_scope.dart';
import 'model.dart';
@@ -97,6 +98,12 @@ class _SwarmModelsWindowState extends State<_SwarmModelsWindow> {
Map<String, dynamic> answer;
try {
answer = await app.swarmGridSync(machineId, grid, members);
+ } on WsRequestFailure catch (failure) {
+ // Grid's own answer, refused: its words, not "unreachable" (2026-10-24: a plan's network limit read as this
+ // computer could not be reached).
+ answer = failure.payload.isNotEmpty
+ ? {...failure.payload, 'ready': false}
+ : {'ready': false, 'error': failure.detail ?? failure.code};
} catch (_) {
answer = {
'ready': false,
@@ -276,6 +283,7 @@ class _SwarmModelsWindowState extends State<_SwarmModelsWindow> {
? 'The Swarm owner is setting up its models.'
: 'The Swarm owner has not set up models yet.',
setupError: _settingUp ? null : failed,
+ setupPending: on && local?.ready == null,
),
),
] else
@@ -300,6 +308,7 @@ class _SwarmModelsPicker extends StatefulWidget {
this.onSetUp,
this.setupNote,
this.setupError,
+ this.setupPending = false,
});
final AppNotifier app;
@@ -309,6 +318,7 @@ class _SwarmModelsPicker extends StatefulWidget {
final Future<({String? grid, String? error})> Function()? onSetUp;
final String? setupNote;
final String? setupError;
+ final bool setupPending;
@override
State<_SwarmModelsPicker> createState() => _SwarmModelsPickerState();
@@ -339,6 +349,7 @@ class _SwarmModelsPickerState extends State<_SwarmModelsPicker> {
onSetUp: widget.onSetUp,
setupNote: widget.setupNote,
setupError: widget.setupError,
+ setupPending: widget.setupPending,
);
unawaited(_target.refresh());
// `adding`/`offersCreate`: the APIs section ends in Add API connection, as ⌘I's does.
diff --git a/desktop/lib/widgets/swarm_resource_preview.dart b/desktop/lib/widgets/swarm_resource_preview.dart
index cb9f3ecdb..4e6bae754 100644
--- a/desktop/lib/widgets/swarm_resource_preview.dart
+++ b/desktop/lib/widgets/swarm_resource_preview.dart
@@ -1464,6 +1464,9 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
key: const ValueKey('swarm-model-setup-note'),
swarm.settingUp
? 'Setting up this Swarm\'s models… The first time can take a few minutes.'
+ : swarm.canSetUp && swarm.setupPending
+ ? 'This Swarm\'s models are being set up in the background. If that has not finished, your first '
+ 'share or run finishes it.'
: swarm.canSetUp
? 'This Swarm\'s models are not set up yet. Your first share or run sets them up: it connects this '
'computer to the Swarm with your Harness account, and everyone in the Swarm can then use them.'