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 Mac's Team account stops using up the 32 machines, and refused commands are logged (#2900)
0xken154f5f7425c177
diff --git a/backend/integration/superTabCommandLoads.test.ts b/backend/integration/superTabCommandLoads.test.tsindex 0ed82f981..5fac70dbe 100644--- a/backend/integration/superTabCommandLoads.test.ts+++ b/backend/integration/superTabCommandLoads.test.ts@@ -3,16 +3,18 @@ import { execFile } from 'node:child_process'import { promisify } from 'node:util'import { join } from 'node:path'import { tmpdir } from 'node:os'-import { afterAll, beforeAll, describe, expect, it } from 'vitest'+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'import { MongoMemoryReplSet } from 'mongodb-memory-server-core'import { PrismaClient, type Prisma } from '@prisma/client'import type { AuthUser } from '../src/lib/ssoAuth.js'import { SuperTabStore } from '../src/superTabs/store.js'import type { Command } from '../src/superTabs/commands.js'+import { logger } from '../src/utils/logger.js'import type { Conversation } from '../src/superTabs/model.js'// Ken's prod DB profile, 2026-11-02: a command naming the PM read every group the PM was ever in, 1,628 of them and growing with// every task, up to 1.66 s a read. Those that write its groups need them; those that only ask about it do not.+const REFUSED = 'Swarm command refused'let replica: MongoMemoryReplSetlet db: PrismaClientconst owner: AuthUser = { sub: '220000000000000000000001', email: '[email protected]', autonomousEnv: 'prod', role: 'user' }@@ -68,6 +70,23 @@ async function groupsRead(run: () => Promise<unknown>): Promise<number> {const FEW = 100+describe('a refused command in the log', () => {+ const secret = 'do-not-log-this'+ it('writes one line, its code and type and no values; one that passes writes none (Ken, 2026-11-04)', async () => {+ const { execute } = await swarm()+ const said = vi.spyOn(logger, 'warn').mockImplementation(() => {})+ try {+ await execute({ type: 'conversation.create', title: secret, brief: secret, checks: [] })+ expect(said.mock.calls.filter(([line]) => line === REFUSED)).toEqual([])+ await expect(execute({ type: 'conversation.rename', conversationId: secret, title: secret })).rejects.toMatchObject({ code: 'NOT_FOUND' })+ expect(said.mock.calls.filter(([line]) => line === REFUSED)).toEqual([[REFUSED, { code: 'NOT_FOUND', type: 'conversation.rename' }]])+ expect(JSON.stringify(said.mock.calls)).not.toContain(secret)+ } finally {+ said.mockRestore()+ }+ })+})+describe('a command naming the coordinator', () => {it('agent.alert reads none of its 1,000 dormant groups, and its row still lands', async () => {const f = await swarm(1000)diff --git a/backend/src/superTabs/buddyMachines.test.ts b/backend/src/superTabs/buddyMachines.test.tsindex e2587a737..e0db4e249 100644--- a/backend/src/superTabs/buddyMachines.test.ts+++ b/backend/src/superTabs/buddyMachines.test.ts@@ -336,6 +336,20 @@ describe('a Buddy-only machine after its reviews', () => {expect(rows.roster.find(r => 'agent' in r && r.agent.id === lead)).toMatchObject({ joinSwarm: true })})+ it('follows the Swarm\'s limit on machines, where Team accounts\' entries do not count', () => {+ const fill = (f: Swarm, entries: number, team: number) => {+ f.state.machines!.push(...Array.from({ length: entries - f.state.machines!.length }, (_, i) => ({ ...f.state.machines![0]!, machineId: `other-${i}`,+ ...i < team ? { hostMachineId: 'owner-mac' } : {} })))+ }+ const room = setup()+ fill(room, 32, 15)+ addOwn(room, room.app.projectId)+ expect(buddyOnly(room)).toBeDefined()+ const full = setup()+ fill(full, 32, 0)+ expect(() => addOwn(full, full.app.projectId)).toThrow('This Swarm is at its limit of 32 machines. One has to be removed before another can be added.')+ })+it('never lets a Mac\'s Team account join through it (review 2)', () => {const f = setup()addOwn(f, f.app.projectId)diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex df6e48306..a8a644eb8 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -1,6 +1,6 @@import { applyPushOrigin, failPushUnknown, failTeamWritten, hasStep, mainAccountMembers, markTeamWritten, requireNameable, requireTeamWrittenAccount, requireTeamWrittenMachine, TEAM_WRITTEN_REASON, TEAM_WRITTEN_STOP, teamWrittenTask } from './teamWritten.js'import type { PushOrigin } from '../github/pushOrigin.js'-import { admitMachineStart, defaultProfileId, storedProfileId, BUDDY_WINDOWS_REFUSAL, buddyHomeFolder, buddyProjectsOn, SWARM_BUDDY_CAPABILITY, cleanupOverdue, dropIdleBuddyMachines, NOT_SWARM_MACHINE, downSince, expireRemoval, expireRemovals, failTeamWork, removalEnded, machineContribution, machineOffline, machineSlots, contributedEngines, ownedMachine, productManagerOn, projectFolder, projectsOnMachine, requireTeamWork, teamMachineFor, teamAccountPool, teamPoolsOf, teamStartRequest, teamWorkCheck, type ContributedMachine } from './machines.js'+import { admitMachineStart, defaultProfileId, storedProfileId, BUDDY_WINDOWS_REFUSAL, buddyHomeFolder, buddyProjectsOn, SWARM_BUDDY_CAPABILITY, cleanupOverdue, dropIdleBuddyMachines, machinesFull, MACHINES_FULL_MESSAGE, NOT_SWARM_MACHINE, downSince, expireRemoval, expireRemovals, failTeamWork, removalEnded, machineContribution, machineOffline, machineSlots, contributedEngines, ownedMachine, productManagerOn, projectFolder, projectsOnMachine, requireTeamWork, teamMachineFor, teamAccountPool, teamPoolsOf, teamStartRequest, teamWorkCheck, type ContributedMachine } from './machines.js'import { agentDisplayName, assignAgentDisplayNames } from './agentNames.js'import { keepUsernames, setUsername, swarmUsernames, usernameOf } from './usernames.js'import { setName, writtenNameOf } from './personNames.js'@@ -1356,7 +1356,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,if (state.machineCleanups?.some(c => c.machineId === machineId)) {fail('MACHINE_CLEANING', 'This machine is still cleaning up after your last Buddy there. Try again in a minute.')}- if ((state.machines?.length ?? 0) >= 32) fail('MACHINES_FULL', 'This Swarm cannot take another machine.')+ if (machinesFull(state)) fail('MACHINES_FULL', MACHINES_FULL_MESSAGE)const pool: ContributedMachine = { machineId, name: setup.name, cwd: setup.cwd, scope: 'swarm', engines: [...new Set(setup.engines)],maxAgents: 1, contributorId: me.id, membershipGeneration: me.generation, generation: operationId, paused: false, buddyOnly: true };(state.machines ??= []).push(pool)@@ -1784,7 +1784,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,if (!state.removedMachines.length) delete state.removedMachines}if (cleaning) fail('MACHINE_CLEANING', 'This machine is still cleaning up after its removal. Add it again once that finishes.')- if (!state.machines.some(m => m.machineId === command.machineId) && state.machines.length >= 32) fail('MACHINES_FULL', 'A Super Tab can have up to 32 contributed machines.')+ if (!state.machines.some(m => m.machineId === command.machineId) && machinesFull(state, !!context.contribution?.hostMachineId)) fail('MACHINES_FULL', MACHINES_FULL_MESSAGE)// Before a machine was contributed, a Lead's start on it that never dispatched was left pending for good (12 on Ken's// Mac that day) and refused every contribution. Those finish as failed; a dispatched or recent start still blocks.const abandoned = (state.starts ?? []).filter(s => context.abandonedStartIds?.includes(s.id))diff --git a/backend/src/superTabs/machineCap.test.ts b/backend/src/superTabs/machineCap.test.tsnew file mode 100644index 000000000..c9521ce4e--- /dev/null+++ b/backend/src/superTabs/machineCap.test.ts@@ -0,0 +1,44 @@+// A new collaborator could not add their Mac to a Swarm holding 32 machines, 15 of them Team accounts' (Ken, 2026-11-04).+import { describe, expect, it } from 'vitest'+import { applyCommand, type Command, type CommandContext } from './commands.js'+import { createSuperTab, type Actor } from './model.js'++const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }+const own = { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }+const FULL = 'This Swarm is at its limit of 32 machines. One has to be removed before another can be added.'++/** A Swarm of [entries] machines, [team] of them Harness Team accounts' entries. */+function swarm(entries: number, team = 0) {+ const state = createSuperTab('swarm', 'Team', { id: 'owner', email: owner.email }, 'test')+ state.machines = Array.from({ length: entries }, (_, i) => ({ machineId: `m${i}`, name: `Mac ${i}`, contributorId: 'owner', membershipGeneration: 'g', generation: 'g0',+ cwd: '/swarm', scope: 'swarm' as const, engines: ['claude'], maxAgents: 2, paused: false, ...i < team ? { hostMachineId: `m${team}` } : {} }))+ return state+}+const contribute = (state: ReturnType<typeof swarm>, machineId: string, context: Partial<CommandContext> = {}) =>+ applyCommand(state, owner, { type: 'machine.contribute', machineId, name: 'New', cwd: '/swarm', scope: 'swarm', engines: ['claude'], maxAgents: 2 } as Command,+ { operationId: 'op', now: 1000, contribution: own, ...context }).state++describe('how many machines a Swarm holds', () => {+ it('takes a new machine with 32 entries, 15 of them Team accounts\'', () => {+ expect(contribute(swarm(32, 15), 'new').machines).toHaveLength(33)+ })++ it('refuses the next at 32 real machines, and says so in words a person can act on', () => {+ expect(() => contribute(swarm(32), 'new')).toThrow(FULL)+ expect(() => contribute(swarm(47, 15), 'new')).toThrow(expect.objectContaining({ code: 'MACHINES_FULL' }))+ })++ it('lets a Mac\'s Team account join at 32 real machines: it is the same Mac', () => {+ expect(contribute(swarm(32), 'team', { contribution: { ...own, hostMachineId: 'm0' } }).machines).toHaveLength(33)+ })++ it('holds Team accounts\' entries too, at one for each of the 32', () => {+ const team = { contribution: { ...own, hostMachineId: 'm40' } }+ expect(contribute(swarm(63, 31), 'team', team).machines).toHaveLength(64)+ expect(() => contribute(swarm(64, 32), 'team', team)).toThrow(FULL)+ })++ it('still saves the settings of a machine already in it at the limit', () => {+ expect(contribute(swarm(32), 'm5').machines).toHaveLength(32)+ })+})diff --git a/backend/src/superTabs/machines.ts b/backend/src/superTabs/machines.tsindex cd17866cd..fbc63e225 100644--- a/backend/src/superTabs/machines.ts+++ b/backend/src/superTabs/machines.ts@@ -549,6 +549,14 @@ export function recordAgentPresence(state: SuperTabState, machineId: string, run/** Harness cannot yet tell a Buddy's window from another agent's on Windows (security review of #2093). */export const BUDDY_WINDOWS_REFUSAL = 'A Buddy cannot run on a Windows machine yet. Pick one of your Macs or Linux machines.'export const NOT_SWARM_MACHINE = 'This machine is not one of the Swarm\'s machines.'+/** Real machines only: a Mac's Harness Team account is that same Mac (Ken, 2026-11-04). It stays 32 until a machine's reading+ * stops re-reading every machine; #2900 has what grows with the count. */+const MAX_MACHINES = 32+export const MACHINES_FULL_MESSAGE = `This Swarm is at its limit of ${MAX_MACHINES} machines. One has to be removed before another can be added.`+/** Whether [state] can take another machine, or with [team] another Team account's entry: one for each machine at most. */+export const machinesFull = (state: SuperTabState, team = false): boolean => team+ ? (state.machines?.length ?? 0) >= 2 * MAX_MACHINES+ : (state.machines ?? []).filter(m => !m.hostMachineId).length >= MAX_MACHINES/** A Buddy-only machine with no Buddy left on it, running or starting, leaves: its host deletes the Swarm's folders there as* for a removed machine, and no chat hears of it, since none ever saw it (Lead, 10-29). Run after every command (commands.ts)diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex adc8bbbb9..28ab1b623 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -1313,6 +1313,8 @@ export class SuperTabStore {if (input.command?.type === 'message.send' && input.command.newSession && done.result.startId) logger.info('Buddy session started', { tabId, startId: done.result.startId })return done} catch (error) {+ // Its code and type alone, no values: a Swarm refusing a machine went unseen (MACHINES_FULL, Ken, 2026-11-04).+ if (error instanceof SuperTabError && input.command?.type) logger.warn('Swarm command refused', { code: error.code, type: input.command.type })if (input.command?.type === 'message.send' && input.command.newSession && error instanceof SuperTabError) logger.info('Buddy session refused', { tabId, code: error.code })// A refusal for a bot's push rolled its mark back. The mark stays, so a post or a join that reads no GitHub is refused next (review 1 of #2559).const pushedOn = input.command && 'conversationId' in input.command ? input.command.conversationId : undefineddiff --git a/desktop/test/super_tab_add_computers_test.dart b/desktop/test/super_tab_add_computers_test.dartindex 64251fa13..d70e0804d 100644--- a/desktop/test/super_tab_add_computers_test.dart+++ b/desktop/test/super_tab_add_computers_test.dart@@ -296,6 +296,23 @@ void main() {},);+ testWidgets('a Swarm at its limit fails the row and says why', (+ tester,+ ) async {+ final (:f, :c) = await swarm((_) {});+ await openBox(tester, c, f.app);+ const full =+ 'This Swarm is at its limit of 32 machines. One has to be rem'+ 'oved before another can be added.';+ f.connection.server.refuseContributions['m'] = full;+ await tester.tap(find.text('Add 1'));+ await settle(tester);++ expect(inRow('m', 'failed'), findsOneWidget);+ expect(find.byTooltip(full), findsOneWidget);+ await close(tester, f, c);+ });+testWidgets('a computer that fails keeps its reason and its tick, and the others are still added',(tester) async {diff --git a/desktop/test/swarm_join_machine_test.dart b/desktop/test/swarm_join_machine_test.dartindex 8405bf274..a8de4dce6 100644--- a/desktop/test/swarm_join_machine_test.dart+++ b/desktop/test/swarm_join_machine_test.dart@@ -209,13 +209,16 @@ void main() {daemon = _Daemon();server.refuse = {'code': 'MACHINES_FULL',- 'message': 'A Super Tab can have up to 32 contributed machines.',+ 'message':+ 'This Swarm is at its limit of 32 machines. One has to be rem'+ 'oved before another can be added.',};final refused = await attempt();expect(refused?.added, isFalse);expect(refused?.problem,- 'A Super Tab can have up to 32 contributed machines.',+ 'This Swarm is at its limit of 32 machines. One has to be rem'+ 'oved before another can be added.',);expect(daemon.woken, isEmpty);});@@ -474,4 +477,27 @@ void noteTests() {expect(find.byKey(const Key('swarm-joined-machine-remove')), findsNothing);c.dispose();});++ testWidgets('a Swarm at its limit says so after joining', (tester) async {+ final c = await mount(+ tester,+ const SwarmJoinedMachine(+ tabId: 'tab',+ swarmName: 'Pilot',+ machineId: 'mate-mac',+ machineName: 'MacBook Air',+ problem:+ 'This Swarm is at its limit of 32 machines. One has to be rem'+ 'oved before another can be added.',+ ),+ );+ expect(+ find.text(+ 'This Mac was not added to Pilot. This Swarm is at its limit of 32 machin'+ 'es. One has to be removed before another can be added.',+ ),+ findsOneWidget,+ );+ c.dispose();+ });}diff --git a/docs/design/2026-10-26-swarm-state-parts.md b/docs/design/2026-10-26-swarm-state-parts.mdindex df7023a5e..c9f660b9a 100644--- a/docs/design/2026-10-26-swarm-state-parts.md+++ b/docs/design/2026-10-26-swarm-state-parts.md@@ -1128,7 +1128,7 @@ The items as raised:wanted.- The PM channel UI builds on (a)–(f).-**Q4. Swarm-wide limits serialize on the head.** Pending starts ≤ 32 (`commands.ts:1034`), machines ≤ 32, projects+**Q4. Swarm-wide limits serialize on the head.** Pending starts ≤ 32 (`commands.ts:1034`), machines ≤ 32 (Team accounts' entries apart), projects≤ 100 and rules ≤ 50 are guarded by touching or writing `H`. So two `agent.start` calls in one Swarm conflict andone retries. **Recommendation:** accept. Starts are rare, and the limit stays exact.diff --git a/docs/plans/2026-11-04-machine-cap-team-entries-plan.md b/docs/plans/2026-11-04-machine-cap-team-entries-plan.mdnew file mode 100644index 000000000..642aaed55--- /dev/null+++ b/docs/plans/2026-11-04-machine-cap-team-entries-plan.md@@ -0,0 +1,67 @@+# Machine cap and refusal log Implementation Plan++> **For agentic workers:** Follow the project Engineer workflow: plan first in a draft PR; implement task by task with a committed failing test before its code; no per-task review, one independent review on the pull request.++**Goal:** A Mac's Harness Team account stops using up a Swarm's 32 machines, every refused command leaves one log line, and a person whose Mac is refused is told why.++**Architecture:** One helper in `machines.ts` answers whether a Swarm is full, for both places that add a machine. `SuperTabStore.execute`, the one way into a command, logs each refusal. Desktop already shows the server's message, so it only gains tests naming this refusal.++**Tech Stack:** TypeScript, Vitest, MongoDB in the integration suite; Flutter/Dart Desktop tests.++**Spec:** Task #2610 (Ken, 2026-11-04): the openharness Swarm holds 32 entries, 15 of them Team entries, and refuses a new collaborator's Mac. Ken first decided on a cap of 128, then replaced it: for now only Team entries leave the count, and the cap stays 32 real machines until the read-cost fixes ship (host readings read only what changed, the heartbeat out of the machine part).++## Design++- **Growth:** an entry goes with `machine.remove`. Limit per Swarm: 32 real machines. A Team entry is refused once the Swarm holds 64 entries, so Team entries stay bounded even for one whose Mac is not in the Swarm.+- **Concurrency:** unchanged: the head guards the count.+- **Read cost:** no new read. The count is over `state.machines`, already loaded. At most 64 entries, up from 32: the numbers are in the pull request.+- **Scale:** first warning: the new `MACHINES_FULL` log line.+- **Compatibility:** old clients show the server's message and list more entries.+- **Migration + rollback:** nothing stored changes. Rolled back, a Swarm above 32 entries refuses new machines until it is below again.+- **Audience:** the server decides, as before.+- **Identity:** the same contributor checks as before.+- **Failure:** today's silent refusal becomes a log line, with the code and command type only.+- **Platforms:** backend. Desktop on macOS, Linux and Windows reads the same message.++## Global Constraints++- Failing test before its code, each in its own commit.+- A refusal's log line holds its code and command type, and no ids or text.+- Visible copy says Swarm and machine (`docs/naming-system.md`), never Super Tab.+- No Desktop screen changes: the check shows they already say why.+- Swarm code stays out of `cli/src/core`.++## Review Focus++- A Team entry joining at 32 real machines; a real machine refused at 32; Buddy-only entries still counted; saving an entry already in the Swarm at the limit still works.+- The refusal log: one line per refused command, no values, no line for a command that succeeds.+- The 64-entry bound for Team entries.++## Task 1: Count only real machines++**Files:** `backend/src/superTabs/machines.ts`, `backend/src/superTabs/commands.ts`, `backend/src/superTabs/machineCap.test.ts`, `backend/src/superTabs/buddyMachines.test.ts`, `docs/design/2026-10-26-swarm-state-parts.md`.++**Interfaces:** `machinesFull(state, team?): boolean`, `MACHINES_FULL_MESSAGE`.++- [ ] Write failing tests: 32 entries, 15 of them Team, take a new machine; 32 real machines refuse with the new message; a Team entry joins at 32 real machines and is refused at 64 entries; saving an entry already there works; a Buddy-only machine follows the same limit.+- [ ] Run them, watch them fail, commit.+- [ ] Add the helper, use it in `machine.contribute` and `addBuddyMachine`.+- [ ] Run the tests of what changed, commit.++## Task 2: Log every refused command++**Files:** `backend/src/superTabs/store.ts`, `backend/integration/superTabCommandLoads.test.ts`.++**Interfaces:** the log line `Swarm command refused` with `{ code, type }`.++- [ ] Write failing test: a refused command writes one line with its code and type and nothing else; a command that succeeds writes none.+- [ ] Run it, watch it fail, commit.+- [ ] Log in `SuperTabStore.execute`'s catch.+- [ ] Run the test and commit.++## Task 3: Desktop says why++**Files:** `desktop/test/swarm_join_machine_test.dart`, `desktop/test/super_tab_add_computers_test.dart`.++- [ ] Add tests with this refusal: the note after joining says it, and Add machine's row shows `failed` with it as the reason.+- [ ] Run them. They pass on today's code: they guard the check, they do not change behavior. Commit.