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 failed start for a task that needs a machine or device waits and reports, never moves (#1847)

0xken15ce6bfd667511
diff --git a/cli/src/lib/swarmSkills.spec.ts b/cli/src/lib/swarmSkills.spec.ts
index 103599366..4e9aafa38 100644
--- a/cli/src/lib/swarmSkills.spec.ts
+++ b/cli/src/lib/swarmSkills.spec.ts
@@ -74,7 +74,7 @@ describe('built-in Swarm skills', () => {
const requestsLast = `\n${requests.trimEnd()}\n`
const twoHours = '- A Builder or Reviewer that has been down for 2 hours (machine offline, session gone or stopped): cancel its task with the reason, route it, and assign it to another agent with what the first one left (branch, last revision, last report).\n'
// A failed start is never left (the round-device group, 2026-10-27; superTabs/start.ts): the Lead's alone, in both modes.
- const failedStart = '- A failed start is retried elsewhere or reported, never left: when one fails, resume it; it starts once on the route\'s next machine, or tells the group and its requester.\n'
+ const failedStart = '- A failed start is retried elsewhere or reported, never left: when one fails, resume it; it starts once on the route\'s next machine, or tells the group and its requester. A task that requires a machine or device never moves: when its route says it waits, keep it queued and route it again once that machine can take it.\n'
it.each([
['lead', 'b9254e4bb5c633a73e1b87e6ca6690915e1c3a7bb55db0d3d093e6710dd719db'],
['dev', 'e78ce31a71f169d8956a2acd46e8bb43b79bd654b80b0fe3c33dbced9d2c3c75'],
diff --git a/cli/src/lib/swarmSkills.ts b/cli/src/lib/swarmSkills.ts
index f7809d7ee..663f28cd9 100644
--- a/cli/src/lib/swarmSkills.ts
+++ b/cli/src/lib/swarmSkills.ts
@@ -99,7 +99,7 @@ For large work, post the group plan and get the owner's ok before assigning; onc
- Match strength to work: mechanical → cheaper; integration and judgment → standard; design or subtle risk → strongest. A review is at least as strong as the build. Don't go below the standard tier for Reviewers, or for Builders working from prose; the cheapest models take more turns and end up costing more.
- Reuse an idle agent before starting a new one. Start only on the Swarm's listed machines, from the branch the work builds on.
- Local models: when the Swarm serves one (a member's model, a shared API, a model shared with a member), the route may pick it for low-difficulty, well-specified work; it costs no subscription. Set "local":true in the route only when a person asks for a local model. When a person names a model, set "model" to their words ("deepseek 4.1 flash"): the route then offers that model alone. Start the pick with the gridModel and gridName the route gives, never a model or effort.
-- A failed start is retried elsewhere or reported, never left: when one fails, resume it; it starts once on the route's next machine, or tells the group and its requester.
+- A failed start is retried elsewhere or reported, never left: when one fails, resume it; it starts once on the route's next machine, or tells the group and its requester. A task that requires a machine or device never moves: when its route says it waits, keep it queued and route it again once that machine can take it.
- The brief is all a Builder gets. Never pass your chat history; put everything needed in the brief.
- Before assigning, look at other projects' active work; if your task touches the same code, say so in the Leads conversation and agree an order first.
@@ -387,7 +387,7 @@ Keep each Builder's list a few tasks deep; do the easy, self-contained parts fir
- Route each group; reuse an idle agent before starting one; start only on the Swarm's machines.
- With 3 or more groups waiting, run plan first: it places them all at once on the best machines and models. Then route each group in the plan's order and start the plan's pick, with overrideReason "scheduler plan" when the route picks otherwise. If plan cannot run here, route as usual.
- Local models: the route may pick one for low-difficulty, well-specified work; set "local":true only when a person asks for one, set "model" to a model a person names, and start it with the route's gridModel and gridName.
-- A failed start is retried elsewhere or reported, never left: when one fails, resume it; it starts once on the route's next machine, or tells the group and its requester.
+- A failed start is retried elsewhere or reported, never left: when one fails, resume it; it starts once on the route's next machine, or tells the group and its requester. A task that requires a machine or device never moves: when its route says it waits, keep it queued and route it again once that machine can take it.
- The brief is all a Builder gets; never rely on chat history.
- Before assigning, look at other projects' active work; if your task touches the same code, say so in the Leads conversation and agree an order first.
diff --git a/cli/src/superTabs/start.spec.ts b/cli/src/superTabs/start.spec.ts
index d8bfafb03..19752e402 100644
--- a/cli/src/superTabs/start.spec.ts
+++ b/cli/src/superTabs/start.spec.ts
@@ -897,8 +897,8 @@ describe('a Lead\'s start that fails before its agent exists', () => {
const decision = (candidates: ReturnType<typeof candidate>[], override: unknown = null) => ({ id: 'decision-1', conversationId: 'group', outcome: 'failed', final: null, override,
record: { assessment: { difficulty: 'medium', risk: 'low', why: 'Queued Lead routing.', size: 'medium' }, candidates, excluded: [],
floor: 2, notes: false, pick: candidates[0]!.id, via: 'order', p: null, belowFloor: false, why: 'Policy order.' } })
- const swarm = (rules: unknown[] = []) => ({
- conversations: [{ id: 'group', projectId: 'project', leadId: 'lead', requesterId: 'person-1' }],
+ const swarm = (rules: unknown[] = [], requires?: unknown) => ({
+ conversations: [{ id: 'group', projectId: 'project', leadId: 'lead', requesterId: 'person-1', ...(requires ? { task: { goal: 'Check the round.', requires } } : {}) }],
projects: [{ id: 'project', ownerId: 'owner-1', repository: { machineId: 'repo-mac', cwd: '/repo' } }],
machines: [{ machineId: 'mac-one', name: 'Mac One', scope: 'swarm', cwd: '/one/swarm' }, { machineId: 'mac-two', name: 'Mac Two', scope: 'swarm', cwd: '/two/swarm/' }],
rules,
@@ -906,6 +906,8 @@ describe('a Lead\'s start that fails before its agent exists', () => {
const TOKEN = 'The Harness GitHub App token is not in the form GitHub gives.'
/** A backend with contributed machines whose hosts fail a start in preparation, as the round-device group saw. */
function backend(options: { candidates?: ReturnType<typeof candidate>[]; rules?: unknown[]; fails?: string[]; override?: unknown
+ /** The group's task requirement, as the Lead reads it (backend model.ts TaskRequirement). */
+ requires?: unknown
/** What happens to the retry's start: the backend refuses it, or its reply is lost after or before the backend recorded it. */
retry?: 'refused' | 'lost' | 'lostUnrecorded'
/** Machines off the contributed list: the Lead's own start launches there, and this one refuses for its owner's sharing. */
@@ -924,7 +926,7 @@ describe('a Lead\'s start that fails before its agent exists', () => {
return { ok: true, value: structuredClone(start) }
}
if (payload.action === 'routeDecision') return { ok: true, value: decision(options.candidates ?? [candidate('c0', 'mac-one'), candidate('c1', 'mac-one', 'member'), candidate('c2', 'mac-two')], options.override) }
- if (payload.action === 'status') return { ok: true, value: { state: swarm(options.rules) } }
+ if (payload.action === 'status') return { ok: true, value: { state: swarm(options.rules, options.requires) } }
const cmd = payload.command as Record<string, unknown>
commands.push({ operationId: payload.operationId, ...cmd })
if (cmd.type === 'agent.start') {
@@ -1076,6 +1078,43 @@ describe('a Lead\'s start that fails before its agent exists', () => {
expect(b.of('agent.start')).toHaveLength(1)
})
+ const STAYS = 'Builder could not start. This task needs a particular machine or device, so it was not moved to another machine. It has no worker until a machine that has what it needs can start it.'
+ it('keeps a task that requires its machine or device where it is, and tells the group and its requester', async () => {
+ // As each Lead reads it: a machine it sees, one it does not (only counted), a device.
+ for (const requires of [{ machines: ['mac-one'] }, { machines: [], unseenMachines: 1 }, { devices: ['/dev/cu.round'] }]) {
+ const b = backend({ requires })
+ expect(await b.lead(b.first)).toMatchObject({ error: 'START_BLOCKED', startId: 'first-start', detail: expect.stringContaining(TOKEN) })
+ expect(b.of('route.record')).toEqual([])
+ expect(b.of('agent.start')).toHaveLength(1)
+ expect(b.of('message.send')).toMatchObject([{ conversationId: 'group', mentions: ['person-1'], recipientIds: [], text: STAYS }])
+ // A group reader may not see the machine (backend model.ts withSeenRequirement): the post names none, nor the raw error.
+ for (const hidden of ['mac-one', 'Mac One', TOKEN, 'token']) expect(String(b.of('message.send')[0]!.text)).not.toContain(hidden)
+ }
+ })
+ it('reports the requirement when the backend refuses the new pick for it', async () => {
+ // The requirement was set after the Lead read the group: the backend holds the pick to it.
+ const b = backend()
+ const answer = b.scoped.getMockImplementation()!
+ b.scoped.mockImplementation(async payload => (payload.command as Record<string, unknown> | undefined)?.type === 'route.record'
+ ? { error: 'REQUIREMENT_UNMET', detail: 'This task runs only on the machine it requires, and this is another machine.' } : answer(payload))
+ expect(await b.lead(b.first)).toMatchObject({ error: 'START_BLOCKED', startId: 'first-start' })
+ expect(b.of('agent.start')).toHaveLength(1)
+ expect(b.of('message.send')).toMatchObject([{ text: STAYS }])
+ })
+ it('reports the requirement when the backend refuses the retry\'s start for it', async () => {
+ const b = backend()
+ const answer = b.scoped.getMockImplementation()!
+ b.scoped.mockImplementation(async payload => {
+ const command = payload.command as Record<string, unknown> | undefined
+ if (command?.type !== 'agent.start' || payload.operationId === 'first-start') return answer(payload)
+ b.commands.push({ operationId: payload.operationId, ...command })
+ return { error: 'REQUIREMENT_UNMET', detail: 'This task needs /dev/cu.round.' }
+ })
+ expect(await b.lead(b.first)).toMatchObject({ error: 'START_BLOCKED', startId: 'first-start' })
+ expect(b.of('agent.start')).toHaveLength(2)
+ expect(b.of('message.send')).toMatchObject([{ text: STAYS }])
+ })
+
it('a rule of another project does not hold the task back', async () => {
const b = backend({ rules: [{ id: 'rule-2', projectId: 'other', rule: { kind: 'requiresMachine', machineId: 'mac-one' } }] })
expect(await b.lead(b.first)).toMatchObject({ ok: true, queued: true })
diff --git a/cli/src/superTabs/start.ts b/cli/src/superTabs/start.ts
index 75b66a1f9..ea3aaac75 100644
--- a/cli/src/superTabs/start.ts
+++ b/cli/src/superTabs/start.ts
@@ -121,8 +121,8 @@ async function watchQueued(queued: Json, scoped: ScopedRequest, pause: (ms: numb
return queued
}
-/** Hard rules this client reads before it moves a task. A rule of any other kind may bind the task to its machine (a
- * machine or device requirement added later), so the task then stays where it is and is reported instead. */
+/** Hard rules this client reads before it moves a task. A rule of any other kind may bind the task to its machine, so the
+ * task then stays where it is and is reported instead. */
const KNOWN_RULES = new Set(['forbidModel', 'machines', 'minEffort', 'preferEngine', 'preferIdle'])
const RETRY = /^retry-[0-9a-f]{24}$/
/** Answers that are not the request's own (routeCommand.ts): the backend may still have recorded it. */
@@ -143,16 +143,27 @@ async function startElsewhere(input: Json, failed: Json, scoped: ScopedRequest,
const machines = Array.isArray(state.machines) ? state.machines.map(object) : []
const project = (Array.isArray(state.projects) ? state.projects.map(object) : []).find(p => p.id === group?.projectId)
const machineName = (id: unknown) => text(machines.find(m => m.machineId === id)?.name) ?? 'its machine'
- const blocked = async (on: Json): Promise<Json> => {
+ const blocked = async (on: Json, required = false): Promise<Json> => {
const requester = identifier(group?.requesterId) ? [group.requesterId] : []
- // People read why in the failure row the backend wrote; this one says only what it means, never the raw error.
+ // People read why in the failure row the backend wrote; this one says only what it means, never the raw error. A task's
+ // requirement names no machine at all: the one it failed on is a required one, which a reader may not see (backend
+ // model.ts TaskRequirement; review of #1847).
requireSuccess(await scoped({ action: 'command', operationId: derived('start-blocked', String(on.id)), command: { type: 'message.send',
conversationId: request.conversationId, replyTo: null, recipientIds: [], ...(requester.length ? { mentions: requester } : {}),
- text: `${String(request.name)} could not start on ${machineName(object(on.request).machineId)}, and no other machine allowed for this task could take it. `
- + 'This task has no worker until that machine is fixed or another one is added.' } }))
- return { error: 'START_BLOCKED', startId: on.id, detail: `${String(on.error)} No other machine allowed for this task could start it; the group was told.` }
+ text: required
+ ? `${String(request.name)} could not start. This task needs a particular machine or device, so it was not moved to another machine. `
+ + 'It has no worker until a machine that has what it needs can start it.'
+ : `${String(request.name)} could not start on ${machineName(object(on.request).machineId)}, and no other machine allowed for this task could take it. `
+ + 'This task has no worker until that machine is fixed or another one is added.' } }))
+ return { error: 'START_BLOCKED', startId: on.id, detail: `${String(on.error)} ${required
+ ? 'This task requires its machine or device, so it was not moved; the group was told.'
+ : 'No other machine allowed for this task could start it; the group was told.'}` }
}
if (RETRY.test(startId)) return blocked(failed)
+ // A task that requires its machines or devices waits for them (#1829): a Lead who cannot see a required machine reads only
+ // how many there are, and no machine reports its devices, so nothing tells this client another machine could do it.
+ const requires = object(object(group?.task).requires)
+ if (Array.isArray(requires.machines) || (number(requires.unseenMachines) ?? 0) > 0 || (Array.isArray(requires.devices) && requires.devices.length)) return blocked(failed, true)
const rules = (Array.isArray(state.rules) ? state.rules.map(object) : []).filter(r => !r.projectId || r.projectId === group?.projectId)
if (rules.some(r => !KNOWN_RULES.has(String(object(r.rule).kind)))) return blocked(failed)
const decision = object(requireSuccess(await scoped({ action: 'routeDecision', decisionId: failed.routeDecisionId })))
@@ -184,9 +195,10 @@ async function startElsewhere(input: Json, failed: Json, scoped: ScopedRequest,
excluded: [...all.filter(c => failedOn.has(String(c.machineId))).map(c => ({ title: c.title, reason })),
...(Array.isArray(record.excluded) ? record.excluded : [])].slice(0, 200),
pick: pick.id, via: 'order', fallback: undefined, p: null, belowFloor: false, why } } })
- // The backend refuses a pick that breaks a hard rule or cannot take a teammate's work: then nothing else may run it.
+ // The backend refuses a pick that breaks a hard rule, the task's requirement set since it was read, or cannot take a
+ // teammate's work: then nothing else may run it.
const routeDecisionId = rerouted.ok === true ? object(object(rerouted.value).result).routeDecisionId : null
- if (!identifier(routeDecisionId)) return blocked(failed)
+ if (!identifier(routeDecisionId)) return blocked(failed, rerouted.error === 'REQUIREMENT_UNMET')
// What named the failed machine's own setup stays with it; the pick says what runs on the new one.
const { permissionMode: _mode, model: _model, effort: _effort, gridModel: _grid, gridName: _name, codexHome: _home, ...kept } = request
const retryId = derived('retry', startId), retryRequest = { ...kept, machineId: pick.machineId, engine: pick.engine, cwd: folder(pick.machineId),
@@ -199,6 +211,7 @@ async function startElsewhere(input: Json, failed: Json, scoped: ScopedRequest,
// A lost reply may follow a recorded start: its own receipt, read again, says which. Only a backend that answered with
// a refusal and holds no such start refused it.
const code = object(error).code, receipt = await scoped({ action: 'startStatus', startId: retryId }).catch((): Json => ({}))
+ if (receipt.ok !== true && receipt.error === 'NOT_FOUND' && code === 'REQUIREMENT_UNMET') return blocked(failed, true)
if (receipt.ok !== true) return receipt.error === 'NOT_FOUND' && typeof code === 'string' && !TRANSPORT.has(code) ? refused((error as Error).message) : uncertain
try { retry = await startOnce({ action: 'resume', tabId: input.tabId, startId: retryId }, scoped, where, open) } catch { return uncertain }
}