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.

Swarm: deleting a project removes its agents (#1495)

0xken153aa5bf75c8b8
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.ts
index 5ebfa058c..e85d64c8e 100644
--- a/backend/integration/superTabs.test.ts
+++ b/backend/integration/superTabs.test.ts
@@ -152,8 +152,6 @@ describe('deleting abandoned swarm projects', () => {
const agentId = String((await run(tab, { type: 'agent.add', conversationId, machineId: 'test-host', harnessId,
name: 'Private lead', configuration: config, lead: true })).result.agentId)
const context = await store.native.open(owner, tab, { operationId: randomUUID(), conversationId, agentId })
- await expect(run(tab, { type: 'project.delete', projectId })).rejects.toMatchObject({ code: 'PROJECT_HAS_AGENTS' })
- await run(tab, { type: 'agent.remove', agentId })
await run(tab, { type: 'project.delete', projectId })
await expect(store.native.read(host, tab, context.contextId)).rejects.toMatchObject({ code: 'NATIVE_CONTEXT_REVOKED' })
expect(await store.mayObserve(owner, tab, 'test-host', harnessId, host.sub)).toBe(false)
@@ -168,12 +166,12 @@ describe('deleting abandoned swarm projects', () => {
run(tab, { type: 'project.delete', projectId }),
run(tab, { type: 'agent.add', conversationId, machineId: 'test-host', harnessId: randomUUID(), name: 'Lead', configuration: config, lead: true }),
])
- expect(results.filter(r => r.status === 'fulfilled')).toHaveLength(1)
- expect(results.filter(r => r.status === 'rejected')).toHaveLength(1)
+ // Whichever runs first, the delete wins and takes a lead that arrived before it.
+ expect(results[0].status).toBe('fulfilled')
const state = (await store.read(owner, tab)).state
- const exists = state.projects!.some(p => p.id === projectId)
- expect(state.agents.some(a => a.projectId === projectId)).toBe(exists)
- expect(state.conversations.some(c => c.id === conversationId)).toBe(exists)
+ expect(state.projects!.some(p => p.id === projectId)).toBe(false)
+ expect(state.agents.some(a => a.projectId === projectId)).toBe(false)
+ expect(state.conversations.some(c => c.id === conversationId)).toBe(false)
})
})
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 7006c411f..b2753c9f8 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -263,9 +263,14 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
project.name = command.name
break
}
- case 'project.delete':
+ case 'project.delete': {
+ // Its owner confirmed a permanent delete; nothing in Desktop removes agents one by one, so the project takes its
+ // own agents with it. Their machines release the native sessions as they would for any removed agent.
+ const project = manageProject(state, actor, command.projectId)
+ for (const target of state.agents.filter(a => agentProjectId(state, a) === project.id)) removeAgent(target)
deleteProject(state, actor, command.projectId)
break
+ }
case 'project.sharing': {
const project = manageProject(state, actor, command.projectId)
project.members = projectMembers(state, command.memberIds)
diff --git a/backend/src/superTabs/projects.test.ts b/backend/src/superTabs/projects.test.ts
index c8075207a..d1143db28 100644
--- a/backend/src/superTabs/projects.test.ts
+++ b/backend/src/superTabs/projects.test.ts
@@ -164,13 +164,12 @@ describe('projects inside an invite-only swarm', () => {
expect(f.state.name).toBe('Lead renamed')
})
- it('refuses any project agent, even after it leaves every workgroup', () => {
- const f = setup(), p = f.project(), agentId = f.add(p.conversationId, 'idle')
+ it('removes only its own agents, even one that left every workgroup', () => {
+ const f = setup(), p = f.project(), agentId = f.add(p.conversationId, 'idle'), otherId = f.add('lead', 'other')
f.run({ type: 'conversation.agent', conversationId: p.conversationId, agentId, present: false, lead: false })
- expect(() => f.run({ type: 'project.delete', projectId: p.projectId })).toThrow('Stop and remove')
- f.run({ type: 'agent.remove', agentId })
f.run({ type: 'project.delete', projectId: p.projectId })
expect(projectsOf(f.state).map(p => p.id)).toEqual(['lead'])
+ expect(f.state.agents.map(a => a.id)).toEqual([otherId])
})
it.each(['queued', 'dispatched', 'settling'] as const)('refuses %s starts and removes only settled project history', phase => {
diff --git a/backend/src/superTabs/projects.ts b/backend/src/superTabs/projects.ts
index 7e9692271..0aa6c6df8 100644
--- a/backend/src/superTabs/projects.ts
+++ b/backend/src/superTabs/projects.ts
@@ -97,15 +97,12 @@ export function manageProject(state: SuperTabState, actor: Actor, projectId: str
return projectOf(state, projectId)
}
-/** Removes coordination only. Native sessions and pending starts must be
- * reconciled first; their terminal-history privacy bindings remain permanent. */
+/** Removes coordination only; the command removes the project's agents first.
+ * Pending starts must be reconciled first; terminal-history privacy bindings remain permanent. */
export function deleteProject(state: SuperTabState, actor: Actor, projectId: string): void {
const project = manageProject(state, actor, projectId)
const groups = state.conversations.filter(c => groupProject(state, c).id === project.id)
const groupIds = new Set(groups.map(c => c.id))
- if (state.agents.some(a => agentProjectId(state, a) === project.id)) {
- fail('PROJECT_HAS_AGENTS', 'Stop and remove this project’s agents before deleting it.')
- }
if (state.starts?.some(s => groupIds.has(s.request.conversationId) && !s.error &&
(!s.harnessId || s.poolGeneration && !s.poolSettled))) {
fail('STARTS_PENDING', 'Resolve this project’s pending agent starts before deleting it.')
diff --git a/desktop/test/super_tab_project_delete_test.dart b/desktop/test/super_tab_project_delete_test.dart
index 022c59058..09b69e627 100644
--- a/desktop/test/super_tab_project_delete_test.dart
+++ b/desktop/test/super_tab_project_delete_test.dart
@@ -133,10 +133,6 @@ void main() {
);
for (final (code, message) in [
- (
- 'PROJECT_HAS_AGENTS',
- 'Stop and remove this project’s agents before deleting it.',
- ),
(
'STARTS_PENDING',
'Resolve this project’s pending agent starts before deleting it.',