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.

fix(swarm): a PM or Buddy start is no longer refused on one busy CPU reading (#2398)

0xken158e9460330d46
diff --git a/backend/src/superTabs/buddies.test.ts b/backend/src/superTabs/buddies.test.ts
index 3b108a335..93b19dbce 100644
--- a/backend/src/superTabs/buddies.test.ts
+++ b/backend/src/superTabs/buddies.test.ts
@@ -291,6 +291,12 @@ describe('adding a Buddy', () => {
worktree: true, name: 'peer\'s Buddy', buddyOf: { personId: 'peer', generation: 'first' } })
expect(start.request.role).toBeUndefined()
})
+ it('asks its machine for memory and disk, never for a CPU reading under 100%: one busy sample must not refuse it (Diego, 10-30)', () => {
+ const f = fresh()
+ const added = addBuddy(f, peer, f.app.projectId, 'peer-mac')
+ const start = f.state.starts!.find(s => s.id === added.result.startId)!
+ expect(start.request.requirements).toEqual({ memoryBytes: 2 * 1024 ** 3, diskBytes: 1024 ** 3, maxCpuPercent: 100, tools: ['git'], devices: [], quotaRequired: false })
+ })
it('makes the started agent a Buddy in its owner\'s chat, and says it is ready there', () => {
const f = fresh()
diff --git a/backend/src/superTabs/buddies.ts b/backend/src/superTabs/buddies.ts
index e2dc87bc2..3cf1fc4ee 100644
--- a/backend/src/superTabs/buddies.ts
+++ b/backend/src/superTabs/buddies.ts
@@ -131,8 +131,9 @@ export function chosenBuddyName(state: SuperTabState, chat: Conversation, owner:
return { name: chat.title, notice: `${was} is taken now; your Buddy starts as ${chat.title}. Rename it from the ⋮ menu.` }
}
-/** What a Buddy asks of its machine: it reads and talks, so the usual agent's share with git to read the project. */
-export const BUDDY_REQUIREMENTS: AgentStartRequest['requirements'] = { memoryBytes: 2 * 1024 ** 3, diskBytes: 1024 ** 3, maxCpuPercent: 85,
+/** What a Buddy asks of its machine: it reads and talks, so the usual agent's share with git to read the project. CPU use is one
+ * momentary sample, so it is not capped, as a routed Builder's start (Diego, 10-30). */
+export const BUDDY_REQUIREMENTS: AgentStartRequest['requirements'] = { memoryBytes: 2 * 1024 ** 3, diskBytes: 1024 ** 3, maxCpuPercent: 100,
tools: ['git'], devices: [], quotaRequired: false }
/** The line a Buddy's chat shows once its session joined. */
diff --git a/backend/src/superTabs/leadStart.test.ts b/backend/src/superTabs/leadStart.test.ts
index 72476b39a..05a079d14 100644
--- a/backend/src/superTabs/leadStart.test.ts
+++ b/backend/src/superTabs/leadStart.test.ts
@@ -66,6 +66,8 @@ describe('starting a project\'s Product Manager on a Swarm machine', () => {
request: expect.objectContaining({ conversationId: f.app.conversationId, machineId: 'owner-mac', engine: 'claude', model: 'opus', effort: 'high',
cwd: `/swarm/${f.app.projectId}`, worktree: true, leadFor: { projectId: f.app.projectId, personId: 'owner', generation: expect.any(String) } }) })])
expect(started.result).toMatchObject({ machineId: 'owner-mac' })
+ // Memory and disk gate it; CPU is one momentary sample, so a busy machine admits it as it does a routed Builder (Diego, 10-30).
+ expect(f.state.starts![0]!.request.requirements).toEqual({ memoryBytes: 2 * 1024 ** 3, diskBytes: 1024 ** 3, maxCpuPercent: 100, tools: ['git'], devices: [], quotaRequired: false })
expect(f.project().lead).toMatchObject({ status: 'starting', machineId: 'owner-mac', machineName: 'Owner Mac', startId: started.result.startId })
// The repository it clones, recorded for the project.
expect(f.project().repository).toEqual({ machineId: 'owner-mac', cwd: `/swarm/${f.app.projectId}`, repositoryUrl: REPO })
diff --git a/backend/src/superTabs/leadStart.ts b/backend/src/superTabs/leadStart.ts
index a84bc04ab..63722a409 100644
--- a/backend/src/superTabs/leadStart.ts
+++ b/backend/src/superTabs/leadStart.ts
@@ -13,7 +13,8 @@ import { failureNotice, publicReason } from './startFailure.js'
/** What a host reports it can launch: a Product Manager. A host from before it is never given one. */
export const LEAD_CAPABILITY = 'leadStart'
export const LEAD_NAME = 'Product Manager'
-export const LEAD_REQUIREMENTS: AgentStartRequest['requirements'] = { memoryBytes: 2 * 1024 ** 3, diskBytes: 1024 ** 3, maxCpuPercent: 85,
+/** Memory and disk gate it; CPU use is one momentary sample, so it is not capped, as a routed Builder's start (Diego, 10-30). */
+export const LEAD_REQUIREMENTS: AgentStartRequest['requirements'] = { memoryBytes: 2 * 1024 ** 3, diskBytes: 1024 ** 3, maxCpuPercent: 100,
tools: ['git'], devices: [], quotaRequired: false }
/** Where the project's Product Manager is: starting on the machine its person named, started, or failed with the reason. */
diff --git a/cli/src/superTabs/capacity.spec.ts b/cli/src/superTabs/capacity.spec.ts
index 2d7acb28f..8cac25097 100644
--- a/cli/src/superTabs/capacity.spec.ts
+++ b/cli/src/superTabs/capacity.spec.ts
@@ -1,5 +1,5 @@
import { expect, it, vi } from 'vitest'
-import { admission, quotaOf, quotaUnknownReason, readCapabilities } from './capacity.js'
+import { admission, quotaOf, quotaUnknownReason, readCapabilities, START_REQUIREMENTS, startRequirements } from './capacity.js'
const requirements = { memoryBytes: 100, diskBytes: 200, maxCpuPercent: 80, tools: ['git'], devices: ['/dev/test'], quotaRequired: false }
it('uses the destination filesystem and reports missing tools/devices without executing commands', async () => {
const deps = { resources: vi.fn(async () => ({ cpuPercent: 25, memoryTotalBytes: 1000, memoryUsedBytes: 300 })),
@@ -86,3 +86,20 @@ it('says why an allowance is unknown, for each way its reading fails', () => {
// A readable allowance has no reason.
expect(quotaUnknownReason(reply({ outcome: 'answered', httpStatus: 200, body: { five_hour: { utilization: 5 } } }), 'claude', false)).toBeNull()
})
+it('admits a Product Manager, Buddy or template start on a busy CPU, as a routed Builder start, while memory, disk and pressure still refuse (Diego, 10-30)', () => {
+ const GiB = 1024 ** 3
+ // What the backend sends for a PM and a Buddy (leadStart.ts LEAD_REQUIREMENTS, buddies.ts BUDDY_REQUIREMENTS).
+ const pmOrBuddy = { memoryBytes: 2 * GiB, diskBytes: GiB, maxCpuPercent: 100, tools: ['git'], devices: [], quotaRequired: false }
+ const busy = { resources: { cpuPercent: 91.4, memoryTotalBytes: 32 * GiB, memoryUsedBytes: 16 * GiB, projectDiskFreeBytes: 100 * GiB }, tools: { git: true }, devices: {} }
+ for (const wanted of [pmOrBuddy, START_REQUIREMENTS, startRequirements({ tools: [], devices: [] })]) {
+ expect(admission(busy, { installed: true }, quotaOf({}, 'claude', false), wanted)).toMatchObject({ allowed: true, reasons: [] })
+ // An unknown CPU reading does not refuse either; memory, disk and critical pressure still do.
+ expect(admission({ ...busy, resources: { ...busy.resources, cpuPercent: null } }, { installed: true }, quotaOf({}, 'claude', false), wanted).allowed).toBe(true)
+ expect(admission({ ...busy, resources: { ...busy.resources, memoryUsedBytes: 31 * GiB } }, { installed: true }, quotaOf({}, 'claude', false), wanted).reasons)
+ .toEqual([expect.stringMatching(/memory/i)])
+ expect(admission({ ...busy, resources: { ...busy.resources, projectDiskFreeBytes: 1 } }, { installed: true }, quotaOf({}, 'claude', false), wanted).reasons)
+ .toEqual([expect.stringMatching(/Project disk space/)])
+ expect(admission({ ...busy, resources: { ...busy.resources, memoryPressure: 'critical' } }, { installed: true }, quotaOf({}, 'claude', false), wanted).reasons)
+ .toEqual(['The machine reports critical memory pressure.'])
+ }
+})
diff --git a/cli/src/superTabs/capacity.ts b/cli/src/superTabs/capacity.ts
index ca5e6227a..343bea4d4 100644
--- a/cli/src/superTabs/capacity.ts
+++ b/cli/src/superTabs/capacity.ts
@@ -12,12 +12,12 @@ export interface Requirements {
memoryBytes: number; diskBytes: number; maxCpuPercent: number
tools: string[]; devices: string[]; quotaRequired: boolean
}
-/** What `start` asks of a machine when the Lead has no reason to ask for more: the help's template. */
-export const START_REQUIREMENTS: Requirements = { memoryBytes: 2147483648, diskBytes: 10737418240, maxCpuPercent: 85, tools: ['git'], devices: [], quotaRequired: false }
+/** What `start` asks of a machine when the Lead has no reason to ask for more: the help's template. CPU use is only a momentary
+ * reading: a busy machine would refuse every start (seen in the route e2e at 98.7%), so no cap; memory, disk and pressure gate it. */
+export const START_REQUIREMENTS: Requirements = { memoryBytes: 2147483648, diskBytes: 10737418240, maxCpuPercent: 100, tools: ['git'], devices: [], quotaRequired: false }
/** The same plus what the task needs. The route admits a pick on exactly this, so the start it suggests is admitted too. */
export const startRequirements = (needs: { tools: string[]; devices: string[] }): Requirements =>
- // CPU use is only a momentary reading: a busy machine would refuse every candidate (seen in the route e2e at 98.7%), so the route does not cap it.
- ({ ...START_REQUIREMENTS, maxCpuPercent: 100, tools: [...new Set([...START_REQUIREMENTS.tools, ...needs.tools])], devices: needs.devices })
+ ({ ...START_REQUIREMENTS, tools: [...new Set([...START_REQUIREMENTS.tools, ...needs.tools])], devices: needs.devices })
/** A missing result is a completed check; an absent value or failed check is only unverified. */
export function requiredToolReason(tool: string, reported: unknown, failure?: unknown): string | null {
diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.ts
index 54dfecfb8..55b195b48 100644
--- a/cli/src/superTabs/service.spec.ts
+++ b/cli/src/superTabs/service.spec.ts
@@ -449,6 +449,8 @@ it('tells the Lead which branch a started agent works from, and how to choose an
expect(help.start).toContain('default branch, fetched first')
expect(help.start).toContain('branchRef')
expect(help.startRequest).toMatchObject({ worktree: true, branchRef: 'refs/remotes/origin/BASE_BRANCH' })
+ // The template asks for memory and disk, not a CPU reading: one busy sample would refuse a start the route admits.
+ expect(help.startRequest.requirements).toMatchObject({ memoryBytes: 2147483648, diskBytes: 10737418240, maxCpuPercent: 100 })
expect(help.start).toContain('role "reviewer"')
expect(help.start).toContain('reviewOf')
})