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.

Backend: a Swarm stays readable while a release rolls out (#1651)

0xken15ea7f41fbded8
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.ts
index 64cadc668..5a7335c76 100644
--- a/backend/integration/superTabs.test.ts
+++ b/backend/integration/superTabs.test.ts
@@ -2436,3 +2436,41 @@ describe('Leads conversation', () => {
expect((await store.deliveries(host, tab, docsLead)).filter(d => d.conversationId === leads)).toHaveLength(1)
})
})
+
+describe('a Swarm written by a later release', () => {
+ it('keeps conversation kinds and fields it does not know unchanged through its own reads and writes', async () => {
+ // Like production Swarms, no project is named 'lead', so a conversation without a project belongs to none.
+ const tab = (await store.create(owner, randomUUID(), 'Rollout')).id
+ await run(tab, { type: 'project.create', name: 'Pilot', visibility: 'public', brief: '' })
+ await run(tab, { type: 'project.delete', projectId: 'lead' })
+ type Stored = Record<string, unknown> & { conversations: Array<Record<string, unknown>>; parkedConversations?: Array<Record<string, unknown>> }
+ const stored = (await db.superTab.findUniqueOrThrow({ where: { id: tab } })).state as unknown as Stored
+ const later = { id: 'later', kind: 'later-kind', title: 'From a later release', leadId: null, agentIds: [], archived: false, brief: '',
+ checks: [], assignment: null, lastMessageSequence: 0, laterField: { nested: [1] } }
+ const chat = stored.conversations.find(c => c.kind !== 'leads')!
+ stored.laterField = { kept: true }
+ chat.laterField = 'kept'
+ stored.conversations.push(later)
+ await db.superTab.update({ where: { id: tab }, data: { state: stored as never } })
+
+ expect((await store.read(owner, tab)).state.conversations.map(c => c.id)).toEqual([chat.id, stored.leadsConversationId])
+ await run(tab, { type: 'message.send', conversationId: chat.id as string, text: 'Still writable', replyTo: null, recipientIds: [] })
+ expect((await store.messages(owner, tab, chat.id as string, {})).messages.map(m => m.text)).toEqual(['Still writable'])
+ await expect(store.messages(owner, tab, 'later', {})).rejects.toMatchObject({ code: 'NOT_FOUND' })
+ const written = (await db.superTab.findUniqueOrThrow({ where: { id: tab } })).state as unknown as Stored
+ expect(written.laterField).toEqual({ kept: true })
+ expect(written.conversations.find(c => c.id === chat.id)!.laterField).toBe('kept')
+ // A later release, which knows the kind, puts it back from here.
+ expect(written.parkedConversations).toEqual([later])
+ })
+
+ it('never gives a new conversation the number of a conversation it set aside', async () => {
+ const tab = (await store.create(owner, randomUUID(), 'Rollout numbers')).id
+ const stored = (await db.superTab.findUniqueOrThrow({ where: { id: tab } })).state as unknown as { conversations: Array<Record<string, unknown>> }
+ stored.conversations.push({ id: 'later', kind: 'later-kind', number: 7, title: 'From a later release', leadId: null, agentIds: [],
+ archived: false, brief: '', checks: [], assignment: null, lastMessageSequence: 0 })
+ await db.superTab.update({ where: { id: tab }, data: { state: stored as never } })
+ const created = String((await run(tab, { type: 'conversation.create', title: 'New work', brief: '', checks: [] })).result.conversationId)
+ expect((await store.read(owner, tab)).state.conversations.find(c => c.id === created)!.number).toBe(8)
+ })
+})
diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.ts
index 7b274a247..724c53c60 100644
--- a/backend/src/superTabs/model.ts
+++ b/backend/src/superTabs/model.ts
@@ -186,6 +186,8 @@ export interface SuperTabState {
releasedHarnesses?: Array<{ machineId: string; harnessId: string }>
/** Sessions of removed agents their host closes, listed to that host until it says they closed (agent.sessionClosed). */
closingSessions?: Array<{ agentId: string; machineId: string; harnessId: string; machineOwnerId: string }>
+ /** Conversations of a kind a later release added, set aside unchanged by a release that does not know it (parkLaterConversations). */
+ parkedConversations?: Conversation[]
}
export interface OtherProjectWork {
conversationId: string
@@ -281,6 +283,18 @@ export function conversation(state: SuperTabState, id: string): Conversation {
export const isLeads = (group: Conversation): boolean => group.kind === 'leads'
+const KNOWN_KINDS: Record<NonNullable<Conversation['kind']>, true> = { leads: true }
+/** During a rolling deploy the previous release reads what the next one wrote. A conversation kind it does not know
+ * belongs to no project it can check, so it waits here unchanged, and the release that knows it puts it back. */
+export function parkLaterConversations(state: SuperTabState): void {
+ const all = [...state.conversations, ...state.parkedConversations ?? []]
+ const known = (c: Conversation) => c.kind == null || Object.hasOwn(KNOWN_KINDS, c.kind)
+ state.conversations = all.filter(known)
+ const parked = all.filter(c => !known(c))
+ if (parked.length) state.parkedConversations = parked
+ else delete state.parkedConversations
+}
+
/** Work a Lead of another project should know about: assigned and moving, not finished, stuck or archived. */
export const crossProjectActive = (group: Conversation): boolean => !group.archived && !isLeads(group)
&& ['working', 'review', 'needs_human'].includes(group.assignment?.status ?? '')
@@ -316,7 +330,7 @@ export function numberConversations(state: SuperTabState): void {
}
}
export function nextConversationNumber(state: SuperTabState): number {
- return Math.max(state.retiredConversationNumber ?? 0, 0, ...state.conversations.map(c => c.number ?? 0)) + 1
+ return Math.max(state.retiredConversationNumber ?? 0, 0, ...[...state.conversations, ...state.parkedConversations ?? []].map(c => c.number ?? 0)) + 1
}
export function author(state: SuperTabState, actor: Actor, write = false): Author {
if (actor.kind === 'person') {
@@ -368,6 +382,7 @@ export function visibleState(state: SuperTabState, actor: Actor, now = Date.now(
delete visible.overlapAlerts
// Only that machine's host roster lists them (store.ts hostTabs); a removed private agent's session is not every member's.
delete visible.closingSessions
+ delete visible.parkedConversations
numberConversations(visible)
delete visible.retiredConversationNumber
placeRules(visible)
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index a28e0cea7..505dd27e2 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -16,7 +16,7 @@ import { noteProjectReports, projectUpdateRequest } from './projectUpdates.js'
import { revokeNativeContexts, SuperTabNativeStore } from './native.js'
import {
activeWork, actorKey, agent, appendPullRequestUrls, author, conversation, createSuperTab, fail, person, stableId, visibleState, finishWorker,
- SuperTabError, isLeads, syncLeads, type Actor, type Agent, type Assignment, type Author, type MessageDraft, type SuperTabState,
+ SuperTabError, isLeads, parkLaterConversations, syncLeads, type Actor, type Agent, type Assignment, type Author, type MessageDraft, type SuperTabState,
} from './model.js'
import { holdNoticeText, type HoldReason } from './holdNotice.js'
import { mayDrive, TERMINAL_ANSWER_MS, TERMINAL_EXPIRY_MS, TERMINAL_PICKUP_MS, type TerminalEffect } from './terminal.js'
@@ -34,6 +34,7 @@ const hash = (value: unknown): string => createHash('sha256').update(JSON.string
const stateOf = (row: SuperTab): SuperTabState => {
const state = row.state as unknown as SuperTabState
if (state.version !== 1) fail('UPDATE_REQUIRED', 'Update Harness to open this Super Tab.', 409)
+ parkLaterConversations(state)
syncLeads(state)
return state
}