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
Deliver a Lead's message to the assigned worker (#1549) (#1553)
Jacob Pham55845480ca63
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 796c92c00..66bd2f6ae 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { applyCommand, commandSchema, type Command, type CommandContext } from './commands.js'+import { applyCommand, commandSchema, PAIR_CHAIN_LIMIT, type Command, type CommandContext } from './commands.js'import { machineSlots } from './machines.js'import { activeWork, createSuperTab, visibleState, type Actor, type AgentConfiguration } from './model.js'import type { RouteDecision } from './routeRecord.js'@@ -234,11 +234,103 @@ describe('Super Tab collaboration policy', () => {expect(post(as(worker))).toEqual([lead])expect(post(as(worker), [other])).toEqual([other])expect(post(as(other))).toEqual([])- expect(post(as(lead))).toEqual([])+ expect(post(as(lead))).toEqual([worker])f.run({ type: 'work.status', conversationId: group, assignmentId: f.state.conversations[1]!.assignment!.id, status: 'blocked', result: 'Stuck.' }, as(worker))expect(post(as(worker))).toEqual([lead])})+ describe('a Lead\'s message to the assigned worker (#1549)', () => {+ const setup = () => {+ const f = fixture()+ const lead = f.add('lead', 'owner', 'lead', true)+ const group = f.group(), worker = f.add('worker', 'owner', group), other = f.add('other', 'owner', group)+ const as = (agentId: string): Actor => ({ kind: 'agent', agentId, machineOwnerId: 'host-owner' })+ const history: { author: { kind: 'agent' | 'person'; id: string }; recipients: string[]; id: string }[] = []+ const post = (agentId: string, recipientIds: string[] = [], replyTo: string | null = null) => {+ const reply = history.find(m => m.id === replyTo)+ const sent = f.run({ type: 'message.send', conversationId: group, text: 'Update.', replyTo, recipientIds }, as(agentId), {+ recent: history.slice().reverse().slice(0, PAIR_CHAIN_LIMIT).map(m => ({ author: m.author as never, recipients: m.recipients })),+ ...(reply ? { reply: { id: reply.id, conversationId: group, author: reply.author as never } } : {}),+ }).messages[0]!+ history.push({ author: { kind: 'agent', id: agentId }, recipients: sent.recipients, id: sent.id })+ return sent+ }+ const assign = (assigner: 'lead' | 'person') => {+ const sent = f.run({ type: 'work.assign', conversationId: group, agentId: worker }, assigner === 'lead' ? as(lead) : owner).messages[0]!+ history.push({ author: { kind: assigner === 'lead' ? 'agent' : 'person', id: assigner === 'lead' ? lead : 'owner' }, recipients: sent.recipients, id: sent.id })+ return sent+ }+ return { f, lead, group, worker, other, as, post, assign, history }+ }++ it('reaches the assigned worker for a plain post, only while the work is active', () => {+ const { f, lead, group, worker, post } = setup()+ expect(post(lead).recipients).toEqual([])+ f.run({ type: 'work.assign', conversationId: group, agentId: worker })+ expect(post(lead).recipients).toEqual([worker])+ f.run({ type: 'work.cancel', conversationId: group, assignmentId: f.state.conversations[1]!.assignment!.id, reason: 'Duplicate of another task' })+ expect(post(lead).recipients).toEqual([])+ })++ it('reaches the assigned worker for a reply to the worker\'s message', () => {+ const { f, lead, group, worker, post } = setup()+ f.run({ type: 'work.assign', conversationId: group, agentId: worker })+ const report = post(worker)+ expect(report.recipients).toEqual([lead])+ expect(post(lead, [], report.id).recipients).toEqual([worker])+ })++ it('lets explicit recipients win and leaves other members, replies to others and person routing alone', () => {+ const { f, lead, group, worker, other, as, post, history } = setup()+ f.run({ type: 'work.assign', conversationId: group, agentId: worker })+ expect(post(lead, [other]).recipients).toEqual([other])+ const aside = post(other)+ expect(aside.recipients).toEqual([])+ expect(post(lead, [], aside.id).recipients).toEqual([])+ const personMessage = f.run({ type: 'message.send', conversationId: group, text: 'Status?', replyTo: null, recipientIds: [] }).messages[0]!+ history.push({ author: { kind: 'person', id: 'owner' }, recipients: personMessage.recipients, id: personMessage.id })+ expect(personMessage.recipients).toEqual([lead])+ const reply = f.run({ type: 'message.send', conversationId: group, text: 'Ask the worker', replyTo: personMessage.id, recipientIds: [] }, as(lead), {+ reply: { id: personMessage.id, conversationId: group, author: personMessage.author },+ }).messages[0]!+ expect(reply.recipients).toEqual([])+ })++ it('delivers the Lead\'s approval of the worker\'s plan after the Lead\'s own brief (#1549)', () => {+ for (const assigner of ['lead', 'person'] as const) {+ const { lead, worker, post, assign } = setup()+ expect(assign(assigner).recipients).toEqual([worker])+ const plan = post(worker)+ expect(plan.recipients).toEqual([lead])+ expect(post(lead).recipients).toEqual([worker])+ expect(post(worker, [], plan.id).recipients).toEqual([lead])+ expect(post(lead, [], plan.id).recipients).toEqual([worker])+ }+ })++ it('stops an unattended Lead and worker loop, and a person message or explicit recipients start a new one', () => {+ const { f, lead, group, worker, post, assign, history } = setup()+ assign('lead')+ const hops: string[][] = []+ let speaker = worker+ // Each agent answers every message it receives, the worst case for a loop.+ for (let turn = 0; turn < 50; turn++) {+ const sent = post(speaker)+ hops.push(sent.recipients)+ const next = sent.recipients[0]+ if (!next) break+ speaker = next+ }+ expect(hops.slice(0, -1).every(recipients => recipients.length === 1)).toBe(true)+ expect(hops.at(-1)).toEqual([])+ expect(hops).toHaveLength(PAIR_CHAIN_LIMIT)+ expect(post(lead, [worker]).recipients).toEqual([worker])+ const person = f.run({ type: 'message.send', conversationId: group, text: 'Carry on.', replyTo: null, recipientIds: [worker] }).messages[0]!+ history.push({ author: { kind: 'person', id: 'owner' }, recipients: person.recipients, id: person.id })+ expect(post(lead).recipients).toEqual([worker])+ })+ })+it('lets a viewer read and leave, but not send, assign, attach or invite', () => {const f = fixture()f.invite('viewer')diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 15e258d12..05082176a 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -108,6 +108,8 @@ export interface CommandContext {contribution?: { machineOwnerId: string; contributorId: string; hostGrant?: string | null }/** Loaded from this tab and conversation by the store. */reply?: { id: string; conversationId: string; author: Author }+ /** The newest messages of this conversation before the one being sent, newest first, loaded by the store for `message.send`. */+ recent?: { author: Author; recipients: string[] }[]/** A host's receipt, not an elapsed lease, proves that an assignment stopped. */confirmedStopped?: boolean/** An uncertain receipt and its original message, read transactionally. */@@ -120,6 +122,21 @@ export interface CommandContext {routeDecision?: RouteDecision}+/** Messages in a row between the Lead and its worker after which the Lead's message is no longer delivered automatically. */+export const PAIR_CHAIN_LIMIT = 6++/** A Lead's automatic delivery to the assigned worker answers the worker's post. Worker posts reach the Lead automatically, so+ * without a bound the two agents would keep answering each other. Count the messages in a row between the pair, newest first,+ * until one is anyone else's or is not addressed to the other (a person's message, a notice, a message to someone else). A normal+ * exchange (brief, plan, approval, report) stays well under the limit; an unattended loop stops at it. Explicit recipients still+ * deliver, so the Lead can always continue on purpose. */+function leadWorkerBounced(recent: CommandContext['recent'] = [], leadId: string, workerId: string): boolean {+ const sentToPartner = (m: NonNullable<CommandContext['recent']>[number]) => m.author.kind === 'agent'+ && (m.author.id === leadId ? m.recipients.includes(workerId) : m.author.id === workerId && m.recipients.includes(leadId))+ const run = recent.findIndex(m => !sentToPartner(m))+ return (run < 0 ? recent.length : run) >= PAIR_CHAIN_LIMIT+}+function controls(state: SuperTabState, actor: Actor, conversationId = 'lead'): void {const group = readConversation(state, actor, conversationId)if (actor.kind === 'agent' && group.leadId !== actor.agentId) {@@ -647,10 +664,16 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Commaconst replyAgent = context.reply?.author.kind === 'agent' ? context.reply.author.id : null// An assigned worker's own post in its group reaches the Lead. Workers reported results as plain posts, which went to no// one: the Lead heard only at the next scheduled consolidation, and the owner saw no summary of finished work for up to- // 19 minutes (2026-10-21/22). Only the worker's posts are routed, never the Lead's back, so agents cannot loop.- const worker = actor.kind === 'agent' && activeWork(group) && group.assignment?.agentId === actor.agentId+ // 19 minutes (2026-10-21/22). The Lead's message reaches the worker the same way (#1549), except for a reply to someone+ // else and a message that would continue an automatic round trip (leadWorkerBounced), so agents cannot loop.+ const assigned = activeWork(group) ? group.assignment!.agentId : null+ const leadToWorker = actor.kind === 'agent' && actor.agentId === group.leadId && assigned && assigned !== group.leadId+ && group.agentIds.includes(assigned) && (!context.reply || replyAgent === assigned)+ && !leadWorkerBounced(context.recent, group.leadId, assigned) ? assigned : null+ const workerToLead = actor.kind === 'agent' && activeWork(group) && group.assignment?.agentId === actor.agentId&& group.leadId && group.leadId !== actor.agentId && group.agentIds.includes(group.leadId) ? group.leadId : null- const automatic = actor.kind === 'person' ? (replyAgent && group.agentIds.includes(replyAgent) ? replyAgent : group.leadId) : worker+ const agentRecipient = leadToWorker ?? workerToLead+ const automatic = actor.kind === 'person' ? (replyAgent && group.agentIds.includes(replyAgent) ? replyAgent : group.leadId) : agentRecipientconst recipients = [...new Set(command.recipientIds.length ? command.recipientIds : automatic ? [automatic] : [])]for (const id of recipients) {agent(state, id)diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex fb05c6c98..7269144c1 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -5,7 +5,7 @@ import type { AuthUser } from '../lib/ssoAuth.js'import { machineAlive } from '../lib/prisma.js'import { machineShareGrant, sharedVia } from '../lib/machineSharePolicy.js'import { machineBillingAllowsDataPlane } from '../lib/billingState.js'-import { applyCommand, authorizeCommandAccess, operationSchema, postable, type Command, type CommandContext } from './commands.js'+import { applyCommand, authorizeCommandAccess, operationSchema, PAIR_CHAIN_LIMIT, postable, type Command, type CommandContext } from './commands.js'import { attachmentMime, attachmentName, AttachmentTooLarge, checkedType, MAX_ATTACHMENT_BYTES, objectKeyFor, publicUrl, type Attachment, type Attachments } from './attachments.js'import { randomBytes } from 'node:crypto'import type { Readable } from 'node:stream'@@ -384,6 +384,11 @@ export class SuperTabStore {const reply = await tx.superTabMessage.findFirst({ where: { id: command.replyTo, tabId, conversationId: command.conversationId } })if (reply) context.reply = { id: reply.id, conversationId: reply.conversationId, author: reply.author as unknown as Author }}+ if (command.type === 'message.send' && actor.kind === 'agent') {+ const recent = await tx.superTabMessage.findMany({ where: { tabId, conversationId: command.conversationId },+ orderBy: { sequence: 'desc' }, take: PAIR_CHAIN_LIMIT, select: { author: true, recipientIds: true } })+ context.recent = recent.map(m => ({ author: m.author as unknown as Author, recipients: m.recipientIds }))+ }if (command.type === 'work.status' && command.status === 'stopped') {const proof = await tx.superTabStopReceipt.findUnique({ where: { tabId_assignmentId: { tabId, assignmentId: command.assignmentId } } })const execution = conversation(original, command.conversationId).assignment?.execution