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 Local models: an owner's computer that cannot set up grid no longer undoes another's ready

bitcoinbuilderbf77fd7ca934
diff --git a/cli/src/superTabs/swarmGrids.spec.ts b/cli/src/superTabs/swarmGrids.spec.ts
index 407ec6eec..e75297c2e 100644
--- a/cli/src/superTabs/swarmGrids.spec.ts
+++ b/cli/src/superTabs/swarmGrids.spec.ts
@@ -78,6 +78,28 @@ describe('the owner\'s Swarm grids', () => {
f.later(); await f.grids.tick()
expect(f.request).toHaveBeenCalledTimes(2)
})
+ it('leaves a grid another of the owner\'s computers keeps ready alone, when this one cannot set grid up', async () => {
+ const failed = { ready: false, error: 'Grid could not be set up on this computer. Try again.' }
+ const f = fixture([row({ ready: true })], async () => failed)
+ await f.grids.tick()
+ expect(f.request).toHaveBeenCalledOnce()
+ expect(f.posts()).toEqual([])
+ // Not asked again each minute while the other computer keeps it ready.
+ f.later(); await f.grids.tick()
+ expect(f.request).toHaveBeenCalledOnce()
+ // Once the Swarm shows it failed (the other computer could not either), this one tries and says so.
+ f.backend.mockImplementation((async (_c: unknown, method: string) => method === 'GET' ? [row({ ready: false })] : {}) as never)
+ f.later(); await f.grids.tick()
+ expect(f.posts()).toEqual([['/api/super-tabs/tab1/commands', { operationId: 'grid-id1', command: { type: 'localModels.status', grid: GRID, ...failed } }]])
+ })
+ it('still reports a failure on a grid it kept ready itself', async () => {
+ const f = fixture([row()])
+ await f.grids.tick()
+ f.request.mockResolvedValueOnce({ ready: false, error: 'grid is down' })
+ f.backend.mockImplementation((async (_c: unknown, method: string) => method === 'GET' ? [row({ ready: true, members: ['[email protected]'] })] : {}) as never)
+ f.later(); await f.grids.tick()
+ expect(f.posts()[1]![1]).toMatchObject({ command: { ready: false, error: 'grid is down' } })
+ })
it('does not ask grid again about a refusal only the person can change, until the Swarm\'s people change', async () => {
const f = fixture([row()], async () => ({ ready: false, error: 'Free plan allows one network', final: true }))
await f.grids.tick()
diff --git a/cli/src/superTabs/swarmGrids.ts b/cli/src/superTabs/swarmGrids.ts
index 726fc7e3e..2890031c3 100644
--- a/cli/src/superTabs/swarmGrids.ts
+++ b/cli/src/superTabs/swarmGrids.ts
@@ -53,8 +53,9 @@ export class SwarmGrids {
const signature = JSON.stringify([row.grid, members])
const last = this.synced.get(String(row.tabId))
// A final refusal is left alone while the Swarm still shows it; turning the add-on off and on clears what the
- // Swarm shows, even between two passes, and that asks again.
- if (last?.signature === signature && (last.ready ? row.ready === true : last.final && row.ready === false)) continue
+ // Swarm shows, even between two passes, and that asks again. A grid ready is left alone too when this computer
+ // could not make it: another of the owner's computers keeps it.
+ if (last?.signature === signature && (row.ready === true || (last.final && row.ready === false))) continue
local ??= await this.deps.open({ dataDir: this.core.dataDir, port: this.core.daemon.port, machineId: this.machineId })
const result = object(await local.request('grid_swarm_sync', { grid: row.grid, members }, 180_000)
.catch((error: unknown) => ({ ready: false, error: error instanceof Error ? error.message : 'The grid could not be reached.' })))
@@ -63,6 +64,10 @@ export class SwarmGrids {
// A refusal only the person can change (grid's plan limit) is not asked again every minute: only once the
// Swarm's people change, or the owner turns the add-on off and on.
this.synced.set(String(row.tabId), { signature, ready, final: result.final === true })
+ // Every computer signed in as the owner keeps the owner's grids. One that cannot (grid not set up on it) must not
+ // undo another's ready: each would answer the other every minute, and the Swarm flip between ready and failed. One
+ // that kept the grid ready itself still reports its failure.
+ if (!ready && row.ready === true && !last?.ready) continue
await this.deps.backend(this.core, 'POST', `/api/super-tabs/${row.tabId}/commands`, { operationId: `grid-${this.deps.newId()}`,
command: { type: 'localModels.status', grid: row.grid, ready, ...(error ? { error } : {}) } })
}