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
fix(swarm): an agent can name its task as "current", and a stale id is answered with the right one
bitcoinbuilder1ff22968f6d0
diff --git a/cli/src/superTabs/assignmentIds.spec.ts b/cli/src/superTabs/assignmentIds.spec.tsnew file mode 100644index 000000000..19bb151a3--- /dev/null+++ b/cli/src/superTabs/assignmentIds.spec.ts@@ -0,0 +1,42 @@+import { describe, expect, it } from 'vitest'+import { currentAssignment, staleAssignmentHint, wantsCurrent, withCurrentAssignment } from './assignmentIds.js'++const state = { conversations: [{ id: 'g1', assignment: { id: '58c2d5f2bdc100771bc57de7', agentId: 'builder' } }, { id: 'g2' }] }++describe('assignment ids', () => {+ it('reads the group\'s active assignment', () => {+ expect(currentAssignment(state, 'g1')).toEqual({ id: '58c2d5f2bdc100771bc57de7', agentId: 'builder' })+ expect(currentAssignment(state, 'g2')).toBeNull()+ expect(currentAssignment(null, 'g1')).toBeNull()+ })++ it('fills "current" or a missing id with the assignment the agent holds', () => {+ for (const assignmentId of ['current', undefined, null, '']) {+ expect(withCurrentAssignment({ type: 'work.status', conversationId: 'g1', assignmentId, status: 'done' }, state, 'builder'))+ .toMatchObject({ assignmentId: '58c2d5f2bdc100771bc57de7', status: 'done' })+ }+ })++ it('never reports on another agent\'s task, but lets the Lead cancel it by "current"', () => {+ const status = { type: 'work.status', conversationId: 'g1', assignmentId: 'current', status: 'done' }+ expect(withCurrentAssignment(status, state, 'lead')).toBe(status)+ expect(withCurrentAssignment({ type: 'work.cancel', conversationId: 'g1', assignmentId: 'current' }, state, 'lead'))+ .toMatchObject({ assignmentId: '58c2d5f2bdc100771bc57de7' })+ })++ it('leaves an explicit id, another command, or a group with no task as sent', () => {+ const named = { type: 'work.status', conversationId: 'g1', assignmentId: '9887f5667a24ace0b589b7ff' }+ expect(wantsCurrent(named)).toBe(false)+ expect(withCurrentAssignment(named, state, 'builder')).toBe(named)+ expect(wantsCurrent({ type: 'message.send', conversationId: 'g1' })).toBe(false)+ const none = { type: 'work.status', conversationId: 'g2', assignmentId: 'current' }+ expect(withCurrentAssignment(none, state, 'builder')).toBe(none)+ })++ it('names the id to use when a stale one is refused', () => {+ const stale = { type: 'work.status', conversationId: 'g1', assignmentId: '9887f5667a24ace0b589b7ff' }+ expect(staleAssignmentHint(stale, state, 'builder')).toContain('"assignmentId": "58c2d5f2bdc100771bc57de7"')+ expect(staleAssignmentHint(stale, state, 'other')).toMatch(/another agent's/)+ expect(staleAssignmentHint({ ...stale, conversationId: 'g2' }, state, 'builder')).toMatch(/no active assignment/)+ })+})diff --git a/cli/src/superTabs/assignmentIds.ts b/cli/src/superTabs/assignmentIds.tsnew file mode 100644index 000000000..8021ce9da--- /dev/null+++ b/cli/src/superTabs/assignmentIds.ts@@ -0,0 +1,45 @@+/**+ * The assignment a Swarm command names, filled in for the agent when it says `current`, and named in the refusal when it+ * names a stale one.+ *+ * A Codex Builder on gpt-6-luna (Mac Auto, task #13, 2026-10-29) did its task, then could not record it done: it sent its+ * start id and then a made-up id as `assignmentId`, the backend refused both ("STALE_ASSIGNMENT: This is no longer the+ * active assignment.") without saying which one is, and the task stayed open until the Lead cancelled it. An agent may now+ * write `current` (or leave it out), and a stale id is answered with the one to use.+ */+type Json = Record<string, unknown>+const object = (value: unknown): Json => value && typeof value === 'object' && !Array.isArray(value) ? value as Json : {}++/** The commands that name an assignment, and those an agent sends only for its own task. */+export const ASSIGNMENT_COMMANDS: ReadonlySet<string> = new Set(['work.status', 'work.check', 'work.cancel', 'work.resume'])+const OWN_TASK: ReadonlySet<string> = new Set(['work.status', 'work.check'])+const CURRENT = 'current'++/** The group's active assignment in a Swarm's state (its old shape, as the daemon reassembles it), or null. */+export function currentAssignment(state: unknown, conversationId: unknown): { id: string; agentId: string } | null {+ const conversations = object(state).conversations+ const group = (Array.isArray(conversations) ? conversations.map(object) : []).find(c => c.id === conversationId)+ const assignment = object(group?.assignment)+ return typeof assignment.id === 'string' && typeof assignment.agentId === 'string' ? { id: assignment.id, agentId: assignment.agentId } : null+}++/** Whether [command] asks for its group's current assignment: `current`, or no id at all. */+export const wantsCurrent = (command: Json) => ASSIGNMENT_COMMANDS.has(String(command.type))+ && (command.assignmentId === undefined || command.assignmentId === null || command.assignmentId === '' || command.assignmentId === CURRENT)++/** [command] with `current` replaced by the group's assignment: for a status or check, only the one this agent holds.+ * Unchanged when there is none, so the backend refuses it as it would have. */+export function withCurrentAssignment(command: Json, state: unknown, agentId: string): Json {+ if (!wantsCurrent(command)) return command+ const current = currentAssignment(state, command.conversationId)+ if (!current || (OWN_TASK.has(String(command.type)) && current.agentId !== agentId)) return command+ return { ...command, assignmentId: current.id }+}++/** What a stale-assignment refusal adds, so the agent can send it again right: the id to use, or why there is none. */+export function staleAssignmentHint(command: Json, state: unknown, agentId: string): string {+ const current = currentAssignment(state, command.conversationId)+ if (!current) return 'This group has no active assignment now.'+ if (OWN_TASK.has(String(command.type)) && current.agentId !== agentId) return 'This group\'s active assignment is another agent\'s, not yours.'+ return `This group's active assignment is ${current.id}: send it again with "assignmentId": "${current.id}" (or "current").`+}diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.tsindex 6a57c8655..f44b9a1ab 100644--- a/cli/src/superTabs/service.spec.ts+++ b/cli/src/superTabs/service.spec.ts@@ -757,7 +757,7 @@ it('documents finished worker decisions and explains an older backend without reconst t = setup()const help = (await t.ask({ action: 'help' }, owner)).help as { commands: unknown[]; release: string }expect(help.commands).toContainEqual({ type: 'agent.release', agentId: 'AGENT', decision: 'keep|stop' })- expect(help.commands).toContainEqual(expect.objectContaining({ type: 'work.cancel', assignmentId: 'ATTEMPT' }))+ expect(help.commands).toContainEqual(expect.objectContaining({ type: 'work.cancel', assignmentId: 'current' }))expect(help.release).toContain('prefer stop')t.call.mockImplementation(async (...args: unknown[]) => args[0] === 'POST'? { status: 400, body: { success: false, error: { code: 'VALIDATION_ERROR', message: 'Invalid request' } } } as never@@ -1253,6 +1253,42 @@ describe('a Buddy\'s status', () => {})})+// Swarm group #13, 2026-10-29: a Codex Builder on gpt-6-luna sent its start id, then a made-up one, as assignmentId; both were+// refused as stale without the right id, and its finished task stayed open until the Lead cancelled it.+describe('the assignment a command names', () => {+ const live = '58c2d5f2bdc100771bc57de7'+ const withTask = (t: ReturnType<typeof setup>, holder: string) => {+ const state = { agents: [t.agent], conversations: [{ id: 'g1', agentIds: [t.agentId], assignment: { id: live, agentId: holder, status: 'working' } }] }+ const answer = t.call.getMockImplementation()!+ t.call.mockImplementation(async (method, path, body) => method === 'GET' && !path.includes('/hosts/')+ ? { status: 200, body: { success: true, data: swarmData(t.agent, path, state) } } : answer(method, path, body))+ }+ const posted = (t: ReturnType<typeof setup>) => t.call.mock.calls.filter(c => c[0] === 'POST').map(c => (c[2] as { command: Record<string, unknown> }).command)+ const status = (assignmentId?: string) => ({ type: 'work.status', conversationId: 'g1', ...(assignmentId === undefined ? {} : { assignmentId }), status: 'review', result: 'PR #1' })++ it('sends "current", or no id, as the task the agent holds', async () => {+ const t = setup(); withTask(t, t.agentId)+ expect(await t.ask({ action: 'command', tabId: 'tab', agentId: t.agentId, operationId: 'a', command: status('current') }, owner)).toMatchObject({ ok: true })+ expect(await t.ask({ action: 'command', tabId: 'tab', agentId: t.agentId, operationId: 'b', command: status() }, owner)).toMatchObject({ ok: true })+ expect(posted(t)).toEqual([{ ...status(), assignmentId: live }, { ...status(), assignmentId: live }])+ })++ it('answers a stale id with the one to use', async () => {+ const t = setup(); withTask(t, t.agentId)+ const answer = t.call.getMockImplementation()!+ t.call.mockImplementation(async (method, path, body) => method === 'POST'+ ? { status: 409, body: { success: false, error: { code: 'STALE_ASSIGNMENT', message: 'This is no longer the active assignment.' } } } : answer(method, path, body))+ expect(await t.ask({ action: 'command', tabId: 'tab', agentId: t.agentId, operationId: 'c', command: status('9887f5667a24ace0b589b7ff') }, owner)).toMatchObject({+ error: 'STALE_ASSIGNMENT', detail: `This is no longer the active assignment. This group's active assignment is ${live}: send it again with "assignmentId": "${live}" (or "current").` })+ })++ it('never fills in another agent\'s task for a status', async () => {+ const t = setup(); withTask(t, 'someone-else')+ await t.ask({ action: 'command', tabId: 'tab', agentId: t.agentId, operationId: 'd', command: status('current') }, owner)+ expect(posted(t)).toEqual([status('current')])+ })+})+// Review of #2106: an attempt ends with every token its session used, read as it finishes, not the last machine report's.describe('finishing your own work', () => {const opus = { 'claude-opus-5-5': { input: 7000, output: 1200, cacheRead: 0, cacheWrite: 0 } }diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex a900e8219..b3e2b2481 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -4,6 +4,7 @@ import { readAuthSession } from '../lib/authSession.js'import { createHash } from 'node:crypto'import type { CoreApi, ServiceRequests, SuperTabsPort } from '../core/api.js'import { validModelTokens } from '../lib/agentUsageWire.js'+import { ASSIGNMENT_COMMANDS, staleAssignmentHint, wantsCurrent, withCurrentAssignment } from './assignmentIds.js'import { backend, swarmRoleFor, hostJournalFile, identifier, object, SuperTabHost, SuperTabHostError, type SuperTabHostOptions, type SwarmSources } from './host.js'import { HostFeed } from './hostFeed.js'import { SwarmReads, type SwarmRead } from './swarmReads.js'@@ -85,7 +86,7 @@ const HELP = {{ type: 'conversation.create', title: 'Review: Outcome', reviewOf: 'GROUP', task: { goal: 'An independent verdict on the Builder\'s revision', changes: 'None: read only', constraints: 'The reviewed group\'s constraints', owns: ['The reviewed group\'s owned code, read only'] }, checks: [{ description: 'Verdict with the reviewed revision', independent: false }] },{ type: 'conversation.agent', conversationId: 'GROUP', agentId: 'AGENT', present: true, lead: false },{ type: 'work.define', conversationId: 'GROUP', task: { goal: 'What to deliver', changes: 'What changes', constraints: 'What must stay true', owns: ['Paths or code areas'] }, checks: [{ description: 'Observable acceptance evidence', independent: false }] },- { type: 'work.cancel', conversationId: 'GROUP', assignmentId: 'ATTEMPT', reason: 'Lead or tab owner only: why the task is cancelled, in one short sentence' },+ { type: 'work.cancel', conversationId: 'GROUP', assignmentId: 'current', reason: 'Lead or tab owner only: why the task is cancelled, in one short sentence' },{ type: 'conversation.merged', conversationId: 'GROUP', pullRequestUrl: 'https://github.com/OWNER/REPOSITORY/pull/NUMBER', mergedAt: 'Optional ISO time of a merge recorded later' },{ type: 'agent.release', agentId: 'AGENT', decision: 'keep|stop' },{ type: 'rule.set', rule: { kind: 'forbidModel', model: 'haiku' }, text: 'The owner\'s words: No Haiku.', askedIn: { conversationId: 'GROUP', messageId: 'OWNER_MESSAGE' } },@@ -97,15 +98,15 @@ const HELP = {{ type: 'rule.remove', ruleId: 'RULE', askedIn: { conversationId: 'GROUP', messageId: 'OWNER_MESSAGE' } },{ type: 'machine.engineResume', machineId: 'MACHINE', engine: 'codex', askedIn: { conversationId: 'GROUP', messageId: 'OWNER_MESSAGE' } },{ type: 'work.assign', conversationId: 'GROUP', agentId: 'AGENT', routeDecisionId: 'DECISION' },- { type: 'work.status', conversationId: 'GROUP', assignmentId: 'ATTEMPT', status: 'working', result: null },+ { type: 'work.status', conversationId: 'GROUP', assignmentId: 'current', status: 'working', result: null },// Both reach the Lead and alert the Harness Pro on the machine running the agent until the status moves on.- { type: 'work.status', conversationId: 'GROUP', assignmentId: 'ATTEMPT', status: 'needs_human', result: 'The decision you need from a person, asked as one short question' },+ { type: 'work.status', conversationId: 'GROUP', assignmentId: 'current', status: 'needs_human', result: 'The decision you need from a person, asked as one short question' },// The same, opened as a decision for one person in the conversation (decisions in help).- { type: 'work.status', conversationId: 'GROUP', assignmentId: 'ATTEMPT', status: 'needs_human', result: 'The question, in one sentence',+ { type: 'work.status', conversationId: 'GROUP', assignmentId: 'current', status: 'needs_human', result: 'The question, in one sentence',ask: { personId: 'PERSON', options: ['Option A', 'Option B'], recommended: 0, unblocks: 'What the answer unblocks' } },- { type: 'work.status', conversationId: 'GROUP', assignmentId: 'ATTEMPT', status: 'blocked', result: 'Why you are stuck and what would unblock you, in one or two sentences' },- { type: 'work.check', conversationId: 'GROUP', assignmentId: 'ATTEMPT', checkId: 'CHECK', passed: true, evidence: 'Exact test command, revision and observed result' },- { type: 'work.status', conversationId: 'GROUP', assignmentId: 'ATTEMPT', status: 'done', result: 'Exact revision, evidence and deliverable links' },+ { type: 'work.status', conversationId: 'GROUP', assignmentId: 'current', status: 'blocked', result: 'Why you are stuck and what would unblock you, in one or two sentences' },+ { type: 'work.check', conversationId: 'GROUP', assignmentId: 'current', checkId: 'CHECK', passed: true, evidence: 'Exact test command, revision and observed result' },+ { type: 'work.status', conversationId: 'GROUP', assignmentId: 'current', status: 'done', result: 'Exact revision, evidence and deliverable links' },],}@@ -596,11 +597,19 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =} catch { return { ok: true, value: page } }}if (payload.action === 'command' && identifier(payload.operationId) && payload.command && typeof payload.command === 'object' && !Array.isArray(payload.command)) {- const command = await finishingWith(core, await mentionCommand(taskCommand(object(payload.command)), async () => (await swarm()).state), String(agent.harnessId))+ const asked = object(payload.command)+ // `current` (or no id) names the group's active assignment for the agent (superTabs/assignmentIds.ts).+ const filled = wantsCurrent(asked) ? withCurrentAssignment(asked, (await swarm()).state, agentId) : asked+ const command = await finishingWith(core, await mentionCommand(taskCommand(filled), async () => (await swarm()).state), String(agent.harnessId))const send = (command: Record<string, unknown>) => backend(core, 'POST', `${path}/commands`,{ operationId: payload.operationId, command, asAgentId: agentId })let value: unknowntry { value = await send(command) } catch (error) {+ // A stale id gets the one to use, so the agent can send it again right.+ if (error instanceof SuperTabHostError && error.code === 'STALE_ASSIGNMENT' && ASSIGNMENT_COMMANDS.has(String(command.type))) {+ const hint = await swarm().then(read => staleAssignmentHint(command, read.state, agentId), () => '')+ throw new SuperTabHostError(error.code, `${error.message}${hint ? ` ${hint}` : ''}`, error.status)+ }// A backend from before cost records refuses the totals; the status itself still goes.if (command.tokens && error instanceof SuperTabHostError && error.status === 400 && error.code === 'VALIDATION_ERROR' && /"tokens"|'tokens'/.test(error.message)) {const { tokens: _tokens, ...status } = command