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: invitations land on a remaining project once the original is deleted (#1524)

0xken1557ac03b7590b
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.ts
index 9718266dd..af28a6e9d 100644
--- a/backend/integration/superTabs.test.ts
+++ b/backend/integration/superTabs.test.ts
@@ -113,7 +113,8 @@ describe('deleting abandoned swarm projects', () => {
const state = (await store.read(owner, tab)).state
expect(state.projects!.map(p => p.id)).toEqual(['lead'])
expect(state.conversations.map(c => c.id)).toEqual(['lead'])
- expect(state.invitations).toEqual([])
+ // An invitation is to the Swarm: it moves to the project that is left rather than disappearing.
+ expect(state.invitations.map(i => [i.email, i.conversationId])).toEqual([['[email protected]', 'lead']])
for (const id of [conversationId, group]) {
await expect(store.messages(owner, tab, id, {})).rejects.toMatchObject({ code: 'NOT_FOUND' })
await expect(store.attempts(owner, tab, id)).rejects.toMatchObject({ code: 'NOT_FOUND' })
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index 872e16885..fc4a6c78a 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -8,7 +8,7 @@ import {
import { routeRecordSchema, routeTitle, startedAs, type RouteCandidate, type RouteDecision, type RouteFinal, type RouteOverride } from './routeRecord.js'
import { routingOverrideSchema } from './routingPolicy.js'
import { MAX_ATTACHMENTS, type Attachment } from './attachments.js'
-import { agentProjectId, deleteProject, groupProject, manageProject, mutableProjects, projectMembers, projectOf, readAgent, readConversation, readProject, sameProject } from './projects.js'
+import { agentProjectId, deleteProject, groupProject, inviteLanding, manageProject, mutableProjects, projectMembers, projectOf, readAgent, readConversation, readProject, sameProject } from './projects.js'
const id = z.string().min(1).max(160).regex(/^[A-Za-z0-9_-]+$/)
const title = z.string().trim().min(1).max(160)
@@ -120,7 +120,8 @@ export function authorizeCommandAccess(state: SuperTabState, actor: Actor, comma
if (command.type === 'invite.accept') return
const leaving = command.type === 'member.remove' && actor.kind === 'person' && command.userId === actor.userId
author(state, actor, !leaving)
- if ('conversationId' in command) readConversation(state, actor, command.conversationId)
+ // An invitation's group is only where the person lands, and invite.create replaces a deleted one (inviteLanding).
+ if ('conversationId' in command && command.type !== 'invite.create') readConversation(state, actor, command.conversationId)
if ('projectId' in command && command.projectId) readProject(state, actor, command.projectId)
if ('agentId' in command) readAgent(state, actor, command.agentId)
if (command.type === 'agent.start') readConversation(state, actor, command.request.conversationId)
@@ -527,11 +528,11 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma
}
case 'invite.create': {
owner(state, actor)
- conversation(state, command.conversationId)
+ const landing = inviteLanding(state, command.conversationId) ?? fail('NO_PROJECT', 'Create a project before inviting people.')
const email = command.email.trim().toLowerCase()
if (state.people.some(p => p.email === email)) fail('ALREADY_MEMBER', 'This person is already in the Super Tab.')
state.invitations = state.invitations.filter(i => i.email !== email)
- state.invitations.push({ id: operationId, email, role: command.role, conversationId: command.conversationId,
+ state.invitations.push({ id: operationId, email, role: command.role, conversationId: landing,
expiresAt: context.now + 7 * 86_400_000 })
result.inviteId = operationId
break
diff --git a/backend/src/superTabs/projects.test.ts b/backend/src/superTabs/projects.test.ts
index d1143db28..5f340e157 100644
--- a/backend/src/superTabs/projects.test.ts
+++ b/backend/src/superTabs/projects.test.ts
@@ -164,6 +164,21 @@ describe('projects inside an invite-only swarm', () => {
expect(f.state.name).toBe('Lead renamed')
})
+ it('invites to a remaining public project once the original Lead group is deleted, and keeps pending invitations', () => {
+ const f = setup(), hidden = f.project('private'), open = f.project('public')
+ f.run({ type: 'invite.create', email: '[email protected]', role: 'viewer', conversationId: 'lead' })
+ f.run({ type: 'project.delete', projectId: 'lead' })
+ // Desktop still asks for the original 'lead' group; on 2026-10-22 that refused every invitation.
+ f.run({ type: 'invite.create', email: '[email protected]', role: 'collaborator', conversationId: 'lead' })
+ expect(f.state.invitations.map(i => [i.email, i.conversationId])).toEqual([
+ ['[email protected]', open.conversationId], ['[email protected]', open.conversationId]])
+ f.run({ type: 'project.delete', projectId: open.projectId })
+ expect(f.state.invitations.map(i => i.conversationId)).toEqual([hidden.conversationId, hidden.conversationId])
+ f.run({ type: 'project.delete', projectId: hidden.projectId })
+ expect(f.state.invitations).toEqual([])
+ expect(() => f.run({ type: 'invite.create', email: '[email protected]', role: 'viewer', conversationId: 'lead' })).toThrow('Create a project')
+ })
+
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 })
diff --git a/backend/src/superTabs/projects.ts b/backend/src/superTabs/projects.ts
index 0aa6c6df8..6a5280b85 100644
--- a/backend/src/superTabs/projects.ts
+++ b/backend/src/superTabs/projects.ts
@@ -112,13 +112,24 @@ export function deleteProject(state: SuperTabState, actor: Actor, projectId: str
state.projects = state.projects!.filter(p => p.id !== project.id)
state.conversations = state.conversations.filter(c => !groupIds.has(c.id))
state.starts = state.starts?.filter(s => !groupIds.has(s.request.conversationId))
- state.invitations = state.invitations.filter(i => !groupIds.has(i.conversationId))
+ // A pending invitation is to the Swarm, not to this project: it lands somewhere that is left instead.
+ const landing = inviteLanding(state)
+ state.invitations = state.invitations.flatMap(i => !groupIds.has(i.conversationId) ? [i] : landing ? [{ ...i, conversationId: landing }] : [])
if (project.id === 'lead') {
delete state.project
state.machines = state.machines?.filter(m => m.scope === 'swarm')
}
}
+/** Where an invited person lands: the asked-for group while it exists, else a remaining project's Lead
+ * conversation, public first. Desktop asks for the original 'lead' group, which is gone once its project is
+ * deleted; on 2026-10-22 that refused every invitation with "This conversation is unavailable". */
+export function inviteLanding(state: SuperTabState, preferred?: string): string | null {
+ if (preferred && state.conversations.some(c => c.id === preferred)) return preferred
+ const projects = projectsOf(state).filter(p => state.conversations.some(c => c.id === p.leadConversationId))
+ return (projects.find(p => p.visibility === 'public') ?? projects[0])?.leadConversationId ?? null
+}
+
/** Capture current swarm membership so leaving and rejoining does not restore
* an old private-project invitation. */
export function projectMembers(state: SuperTabState, ids: string[]) {