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.

Let work.cancel close a task whose worker was removed (#1552)

0xken1573d2d3527b30
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.ts
index 051d8a0a5..796c92c00 100644
--- a/backend/src/superTabs/commands.test.ts
+++ b/backend/src/superTabs/commands.test.ts
@@ -850,10 +850,21 @@ describe('cancelling work', () => {
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()
+ it('closes a task whose worker was removed, tells nobody, and ignores a retry', () => {
+ const { f, group, worker, leadActor, cancel } = active()
+ f.run({ type: 'agent.remove', agentId: worker })
+ expect(f.state.conversations.find(c => c.id === group)!.assignment!.status).toBe('reconciling')
+ const effects = f.run(cancel, leadActor)
+ expect(f.state.conversations.find(c => c.id === group)!.assignment).toMatchObject({ status: 'cancelled', result: 'Duplicate of another task' })
+ expect(effects.messages).toHaveLength(1)
+ expect(effects.messages[0]).toMatchObject({ recipients: [], text: 'The Lead cancelled this task: Duplicate of another task.' })
+ expect(f.run(cancel, leadActor).messages).toHaveLength(0)
+ })
+ it('still refuses a worker or collaborator cancelling a removed worker’s task', () => {
+ const { f, worker, workerActor, cancel } = active()
f.run({ type: 'agent.remove', agentId: worker })
- expect(() => f.run(cancel)).toThrow('left the Super Tab')
+ expect(() => f.run(cancel, workerActor)).toThrow()
+ expect(() => f.run(cancel, peer)).toThrow('Lead')
})
it('refuses work that already finished', () => {
const { f, group, leadActor, assignmentId, cancel } = active()
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index fd8f18ecb..15e258d12 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -819,11 +819,13 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
// 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.')
+ // A removed worker (reconciling) can never confirm a stop, so this is the only way to close its task; nobody is left to tell.
+ const gone = assignment.status === 'reconciling'
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])
+ message(group.id, `${isLead ? 'The Lead' : 'The tab owner'} cancelled this task: ${command.reason.replace(/[.\s]+$/, '')}.${gone ? '' : ' Stop working on it.'}`,
+ gone ? [] : [assignment.agentId])
break
}
case 'work.check': {