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
Let the Lead cancel an active assignment (#1546)
0xken15ba05ebe7ef5e
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex e4f5bee85..051d8a0a5 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -809,6 +809,59 @@ it('allows the contributor to keep a completed worker and refuses another projecexpect(() => f.run({ type: 'agent.release', agentId: worker, decision: 'stop' }, { kind: 'agent', agentId: otherLead, machineOwnerId: 'host-owner' })).toThrow()})+describe('cancelling work', () => {+ function active() {+ const f = fixture(); f.invite()+ const lead = f.add('lead', 'owner', 'lead', true), group = f.group(), worker = f.add('worker', 'owner', group)+ const leadActor: Actor = { kind: 'agent', agentId: lead, machineOwnerId: 'host-owner' }+ const workerActor: Actor = { kind: 'agent', agentId: worker, machineOwnerId: 'host-owner' }+ const assignmentId = f.run({ type: 'work.assign', conversationId: group, agentId: worker }).result.assignmentId as string+ const cancel = { type: 'work.cancel', conversationId: group, assignmentId, reason: 'Duplicate of another task' } as Command+ return { f, group, worker, leadActor, workerActor, assignmentId, cancel }+ }+ it('lets the Lead cancel, tells the worker once, and frees the worker to release', () => {+ const { f, group, worker, leadActor, cancel } = active()+ const effects = f.run(cancel, leadActor)+ const assignment = f.state.conversations.find(c => c.id === group)!.assignment!+ expect(assignment).toMatchObject({ status: 'cancelled', result: 'Duplicate of another task' })+ expect(activeWork(f.state.conversations.find(c => c.id === group)!)).toBe(false)+ expect(effects.messages).toHaveLength(1)+ expect(effects.messages[0]).toMatchObject({ recipients: [worker], text: 'The Lead cancelled this task: Duplicate of another task. Stop working on it.' })+ expect(f.run(cancel, leadActor).messages).toHaveLength(0)+ expect(f.state.agents.find(a => a.id === worker)!.workDecision).toBe('awaiting')+ f.run({ type: 'agent.release', agentId: worker, decision: 'keep' }, leadActor)+ expect(f.state.agents.find(a => a.id === worker)!.workDecision).toBe('keep')+ })+ it('lets the tab owner cancel, and never counts a check as passed', () => {+ const { f, group, cancel } = active()+ f.run(cancel)+ expect(f.state.conversations.find(c => c.id === group)!.checks.every(c => !c.passedBy)).toBe(true)+ })+ it('refuses the worker, a collaborator and another project’s Lead', () => {+ const { f, workerActor, cancel } = active()+ const project = f.run({ type: 'project.create', name: 'Other', visibility: 'public', brief: '' }).result+ const otherLead = f.add('other-lead', 'owner', project.conversationId as string, true)+ expect(() => f.run(cancel, workerActor)).toThrow('Lead')+ expect(() => f.run(cancel, peer)).toThrow('Lead')+ expect(() => f.run(cancel, { kind: 'agent', agentId: otherLead, machineOwnerId: 'host-owner' })).toThrow()+ })+ it('names the owner when the owner cancels and drops a trailing full stop from the reason', () => {+ const { f, cancel } = active()+ const text = f.run({ ...cancel, reason: 'Obsolete.' } as Command).messages[0]!.text+ expect(text).toBe('The tab owner cancelled this task: Obsolete. Stop working on it.')+ })+ it('refuses cancelling work whose worker already left', () => {+ const { f, worker, cancel } = active()+ f.run({ type: 'agent.remove', agentId: worker })+ expect(() => f.run(cancel)).toThrow('left the Super Tab')+ })+ it('refuses work that already finished', () => {+ const { f, group, leadActor, assignmentId, cancel } = active()+ f.run({ type: 'work.status', conversationId: group, assignmentId, status: 'stopped', result: null }, owner, { confirmedStopped: true })+ expect(() => f.run(cancel, leadActor)).toThrow('already ended')+ })+})+it('allows routing directly to the awaiting worker without first keeping it', () => {const f = routed(), group = f.group()const assignmentId = f.run({ type: 'work.assign', conversationId: group, agentId: f.worker }).result.assignmentId as stringdiff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 84c1a4399..fd8f18ecb 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -92,6 +92,7 @@ export const commandSchema = z.discriminatedUnion('type', [z.object({ type: z.literal('work.assign'), conversationId: id, agentId: id, routeDecisionId: id.optional(), overrideReason: reason.optional() }).strict(),z.object({ type: z.literal('work.status'), conversationId: id, assignmentId: id,status: z.enum(['working', 'needs_human', 'blocked', 'review', 'done', 'stopped']), result: text.nullable() }).strict(),+ z.object({ type: z.literal('work.cancel'), conversationId: id, assignmentId: id, reason }).strict(),z.object({ type: z.literal('route.record'), conversationId: id, decision: routeRecordSchema }).strict(),z.object({ type: z.literal('route.override'), decisionId: id, candidateId: z.string().regex(/^c\d{1,2}$/), reason }).strict(),z.object({ type: z.literal('route.modelResult'), decisionId: id, startId: id, model: z.string().min(1).max(200), effort: z.string().min(1).max(80) }).strict(),@@ -806,6 +807,25 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma}break}+ case 'work.cancel': {+ const group = open(state, command.conversationId)+ const assignment = group.assignment+ if (!assignment || assignment.id !== command.assignmentId) fail('STALE_ASSIGNMENT', 'This is no longer the active assignment.')+ const project = groupProject(state, group)+ const isLead = actor.kind === 'agent' && conversation(state, project.leadConversationId).leadId === actor.agentId+ if (!isLead && !(actor.kind === 'person' && actor.userId === state.ownerId)) {+ fail('FORBIDDEN', 'Only this project’s Lead or the tab owner can cancel work.', 403)+ }+ // A retry after the cancel keeps the first reason and tells the worker once.+ if (assignment.status === 'cancelled') break+ if (!activeWork(group)) fail('ATTEMPT_CLOSED', 'This attempt has already ended.')+ if (assignment.status === 'reconciling') fail('RECONCILING', 'This worker left the Super Tab. Reconcile the assignment instead of cancelling it.')+ assignment.status = 'cancelled'+ assignment.result = command.reason+ finishWorker(state, assignment.agentId)+ message(group.id, `${isLead ? 'The Lead' : 'The tab owner'} cancelled this task: ${command.reason.replace(/[.\s]+$/, '')}. Stop working on it.`, [assignment.agentId])+ break+ }case 'work.check': {const group = open(state, command.conversationId)if (!group.assignment || group.assignment.id !== command.assignmentId) fail('STALE_ASSIGNMENT', 'This is no longer the active assignment.')diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.tsindex 6b1f7b90d..0da552c3b 100644--- a/backend/src/superTabs/model.ts+++ b/backend/src/superTabs/model.ts@@ -67,7 +67,7 @@ export interface AgentStart {}/** `needs_human`: the agent needs a person's decision (its result is the question). `blocked`: it cannot go on (its result* says why). Both stay active work; the machine running the agent alerts its Harness Pro (cli/src/superTabs/attention.ts). */-export type WorkStatus = 'planned' | 'working' | 'needs_human' | 'blocked' | 'review' | 'done' | 'stopped' | 'reconciling'+export type WorkStatus = 'planned' | 'working' | 'needs_human' | 'blocked' | 'review' | 'done' | 'stopped' | 'cancelled' | 'reconciling'export interface Check {id: stringdescription: string@@ -175,7 +175,7 @@ export function fail(code: string, message: string, status = 409): never { throwexport const stableId = (...parts: string[]): string => createHash('sha256').update(JSON.stringify(parts)).digest('hex').slice(0, 24)export const actorKey = (actor: Actor): string => actor.kind === 'person' ? `person:${actor.userId}` : `agent:${actor.agentId}`export const activeWork = (group: Conversation): boolean => !!group.assignment &&- !['done', 'stopped'].includes(group.assignment.status)+ !['done', 'stopped', 'cancelled'].includes(group.assignment.status)/** Old states derive pending decisions from their closed assignments; new states persist them on the worker. */export function awaitingWorkers(state: SuperTabState, projectId: string): Agent[] {diff --git a/backend/src/superTabs/routeDecisions.ts b/backend/src/superTabs/routeDecisions.tsindex bec4ecc17..c633cfc9c 100644--- a/backend/src/superTabs/routeDecisions.ts+++ b/backend/src/superTabs/routeDecisions.ts@@ -46,7 +46,7 @@ export async function writeRouteEffects(tx: Tx, tabId: string, effects: RouteDec}}-export async function closeAssignment(tx: Tx, tabId: string, assignmentId: string, outcome: 'done' | 'stopped', now: number): Promise<void> {+export async function closeAssignment(tx: Tx, tabId: string, assignmentId: string, outcome: 'done' | 'stopped' | 'cancelled', now: number): Promise<void> {// The Lead must stop an assignment before handing the task to the candidate a person chose. That stop is// the handover, not the end of the decision: keep it open so the next start or assignment links to it.if (outcome === 'stopped') {diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 7e2faa05c..fb05c6c98 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -480,6 +480,9 @@ export class SuperTabStore {revision, state: json(effects.state), ...indexes(effects.state),} })await writeRouteEffects(tx, tabId, effects.routeDecisions, context.now)+ if (command.type === 'work.cancel') {+ await closeAssignment(tx, tabId, command.assignmentId, 'cancelled', context.now)+ }if (command.type === 'work.status' && (command.status === 'done' || command.status === 'stopped')) {await closeAssignment(tx, tabId, command.assignmentId, command.status, context.now)}diff --git a/cli/src/lib/swarmSkills.ts b/cli/src/lib/swarmSkills.tsindex b171cc576..643b10243 100644--- a/cli/src/lib/swarmSkills.ts+++ b/cli/src/lib/swarmSkills.ts@@ -24,7 +24,7 @@ description: Use when coordinating a Harness Swarm project as its Lead or Produc2. Split only after the task giver or project owner clearly approves the description. Others' opinions and a vague “ok” do not replace that approval. A small, clear request (a question or one-spot fix) can be done immediately; say what you did. If told “just do it”, skip questions and state important choices.3. Give numbered options, mark one default, and set a deadline. When it passes, record and use that default for choices already authorized. A deadline never supplies the approval required above.4. Discuss → approved description → groups → route → assign. Every group carries goal, changes, constraints, owned code and acceptance checks. Multi-part work or work taking about 15 minutes or more goes to Swarm agents in groups. Coordinate it; your own subagents only read and look things up.-5. When a worker finishes, decide reuse, keep, or stop; prefer stop unless more work is coming soon. Never leave a worker idle without an explicit decision. Check workers silent too long and reassign work stalled too long. Report on-screen trust, sign-in or permission questions in chat immediately, naming the machine owner who can answer.+5. When a worker finishes, decide reuse, keep, or stop; prefer stop unless more work is coming soon. Never leave a worker idle without an explicit decision. If an active task is a duplicate, obsolete or the wrong task, cancel it with work.cancel and a reason instead of waiting; the worker is told to stop, then decide what to do with it. Check workers silent too long and reassign work stalled too long. Report on-screen trust, sign-in or permission questions in chat immediately, naming the machine owner who can answer.6. Summarize long threads once and record important decisions once. Keep the project chat informed of progress, blockers and next steps.`,dev: `---diff --git a/cli/src/superTabs/host.spec.ts b/cli/src/superTabs/host.spec.tsindex c6475aaad..032b22ec5 100644--- a/cli/src/superTabs/host.spec.ts+++ b/cli/src/superTabs/host.spec.ts@@ -522,6 +522,25 @@ it('stops a requested worker once, confirms removal, and releases retention on texpect(acknowledgements).toBe(1)})+it('closes the session of a worker whose assignment the Lead cancelled', async () => {+ const t = setup(), host = t.open()+ vi.mocked(t.core.agents.byAgent).mockReturnValue({ agentId: 'harness', sessionId: 'native', registeredAt: 0, startedBy: 'agent' } as never)+ let closed = false, removed = false+ const target = { id: 'agent', harnessId: 'harness', machineId: 'machine-1', workDecision: 'stop', startedSession: { creationId: 'super-original-creation', sessionId: 'native', createdAt: new Date(0).toISOString() } }+ t.core.agents.stopped = async () => closed+ t.core.agents.closeSwarm = async () => { closed = true; return { closed: true } }+ t.core.account.backend = async (method, path, body) => {+ if ((body as any)?.command?.type === 'agent.stopLease') return { status: 200, body: { data: { result: { expiresAt: Date.now() + 3_600_000, durationMs: 120_000 } } } }+ if (path.includes('/hosts/')) return { status: 200, body: { data: removed ? [] : [{ tabId: 'tab', agent: target, stopRequested: true }] } }+ if (method === 'GET') return { status: 200, body: { data: { state: { agents: [target], conversations: [{ id: 'g', assignment: { id: 'a', agentId: 'agent', status: 'cancelled' } }] } } } }+ removed = true+ return { status: 200, body: { data: {} } }+ }+ await host.tick()+ await vi.waitFor(() => expect(removed).toBe(true))+ expect(closed).toBe(true)+})+it.each(['active', 'foreign', 'changed', 'missing', 'refused', 'unconfirmed', 'unsupported'])('withholds closure or acknowledgement when stop safety is %s', async kind => {const t = setup(), host = t.open()vi.mocked(t.core.agents.byAgent).mockReturnValue({ agentId: 'harness', sessionId: 'native', registeredAt: 0, startedBy: 'agent' } as never)diff --git a/cli/src/superTabs/host.ts b/cli/src/superTabs/host.tsindex 93e606306..d9d5964fc 100644--- a/cli/src/superTabs/host.ts+++ b/cli/src/superTabs/host.ts@@ -17,7 +17,7 @@ export class SuperTabHostError extends Error {constructor(readonly code: string, message: string, readonly status = 503) { super(message) }}export { identifier, object } from './wire.js'-import { identifier, object } from './wire.js'+import { ENDED_WORK, identifier, object } from './wire.js'/** The core signs each request. Neither the service nor its journal holds an account credential. */export async function backend(core: CoreApi, method: string, path: string, body?: unknown): Promise<unknown> {@@ -242,7 +242,7 @@ export class SuperTabHost {if (!Array.isArray(current.conversations) || current.conversations.map(object).some(c => {if (c.leadId === agent.id) return trueconst work = object(c.assignment)- return work.agentId === agent.id && !['done', 'stopped'].includes(String(work.status))+ return work.agentId === agent.id && !ENDED_WORK.includes(String(work.status))})) return// A refusal no retry can change is told to the Lead once: until 2026-10-22 it went only to this machine's log,// and a stopped worker stayed open with no one told why.diff --git a/cli/src/superTabs/routeCommand.ts b/cli/src/superTabs/routeCommand.tsindex 0beb43a97..764fe9202 100644--- a/cli/src/superTabs/routeCommand.ts+++ b/cli/src/superTabs/routeCommand.ts@@ -5,7 +5,7 @@ import { randomUUID } from 'node:crypto'import { openDaemon, type Daemon, type Where } from '../agentClient/daemon.js'import { startRequirements } from './capacity.js'import { inspectCapacity, type ScopedRequest } from './start.js'-import { object, within } from './wire.js'+import { ENDED_WORK, object, within } from './wire.js'import { choose, contextSize, decide, jevQuestion, parseAssessment, quotaOf2, rateFor, recordOf, repoMatch, type Assessment, type Attempt, type Commitment, type MemberFrame, type Policy, type Probe, type TaskFolder } from './route.js'import { stat } from 'node:fs/promises'import { describeScmProject } from '../scm/scmProjects.js'@@ -22,7 +22,7 @@ const NO_PROJECT_FOLDER = 'This machine does not have the project folder. Add itconst OFFLINE = 'Machine is offline or unreachable.'const UNKNOWN_QUOTA: Probe['quota'] = { known: false, leftPercent: null, resetsAt: null }const UNKNOWN_LOAD: NonNullable<Probe['load']> = { agents: null, freeMemoryBytes: null, hasFolder: null }-const active = (assignment: unknown) => { const a = object(assignment); return !!a.id && !['done', 'stopped'].includes(String(a.status)) }+const active = (assignment: unknown) => { const a = object(assignment); return !!a.id && !ENDED_WORK.includes(String(a.status)) }const list = (value: unknown) => Array.isArray(value) ? value.map(object) : []/** The Lead's machine, for the task's folder; replaced in tests. */interface FolderReader { describe: typeof describeScmProject; isDirectory: (path: string) => Promise<boolean> }@@ -61,7 +61,7 @@ function endedWork(conversations: Json[], agents: Json[], decisions: Json[] | nuconst nameOf = (id: unknown) => text(agents.find(a => a.id === id)?.name)const ended: Ended[] = [...(decisions ?? [])].reverse().flatMap(d => {const final = object(d.final)- return typeof d.assignmentId === 'string' && ['done', 'stopped'].includes(String(d.outcome)) && final.kind+ return typeof d.assignmentId === 'string' && ENDED_WORK.includes(String(d.outcome)) && final.kind? [{ assignmentId: d.assignmentId, groupId: String(d.conversationId), group: titleOf(d.conversationId), outcome: String(d.outcome),agentId: final.kind === 'member' ? String(final.agentId) : null,agent: final.kind === 'member' ? nameOf(final.agentId) ?? 'An agent' : `New agent (${String(final.engine)} ${String(final.model)})` }]diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.tsindex a51e1d2b8..70eaed11d 100644--- a/cli/src/superTabs/service.spec.ts+++ b/cli/src/superTabs/service.spec.ts@@ -502,6 +502,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.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 neverdiff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex c63f5aaeb..15a39dd8f 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -31,6 +31,7 @@ const HELP = {{ type: 'conversation.create', title: 'Outcome', task: { goal: 'An independently assignable result', changes: 'What changes', constraints: 'What must stay true', owns: ['Paths or code areas'] }, checks: [{ description: 'Observable acceptance evidence', 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: 'agent.release', agentId: 'AGENT', decision: 'keep|stop' },{ type: 'work.assign', conversationId: 'GROUP', agentId: 'AGENT', routeDecisionId: 'DECISION' },{ type: 'work.status', conversationId: 'GROUP', assignmentId: 'ATTEMPT', status: 'working', result: null },diff --git a/cli/src/superTabs/wire.ts b/cli/src/superTabs/wire.tsindex 80f7421f3..0975ae915 100644--- a/cli/src/superTabs/wire.ts+++ b/cli/src/superTabs/wire.ts@@ -6,3 +6,5 @@ export async function within<T>(read: Promise<T>, ms = 3000): Promise<T | null>let timer: NodeJS.Timeout | undefinedtry { return await Promise.race([read, new Promise<null>(resolve => { timer = setTimeout(resolve, ms, null) })]) } catch { return null } finally { clearTimeout(timer) }}+/** Assignment statuses (and route outcomes) that mean the work is over; the backend's `activeWork` lists the same ones. */+export const ENDED_WORK = ['done', 'stopped', 'cancelled']diff --git a/desktop/lib/super_tabs/view.dart b/desktop/lib/super_tabs/view.dartindex a840fa053..a046a123a 100644--- a/desktop/lib/super_tabs/view.dart+++ b/desktop/lib/super_tabs/view.dart@@ -875,6 +875,7 @@ class _SuperTabViewState extends State<SuperTabView>const ['done','stopped',+ 'cancelled',].contains(group.assignment!['status'])? () => _groupAction('archive', group): null,diff --git a/desktop/test/super_tab_chat_test.dart b/desktop/test/super_tab_chat_test.dartindex 33f2b4331..b39ceea3f 100644--- a/desktop/test/super_tab_chat_test.dart+++ b/desktop/test/super_tab_chat_test.dart@@ -21,6 +21,8 @@ void main() {expect(superTabWorkStatusLabel('blocked'), 'stuck');expect(superTabWorkStatusLabel('needs_human'), 'needs human');expect(superTabWorkStatusLabel('reconciling'), 'reconciling');+ expect(superTabWorkStatusLabel('cancelled'), 'cancelled');+ expect(superTabWorkWaits('cancelled'), isFalse);});Future<SuperTabController> show(