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
fix(swarm): no hourly cap on routing a Super Tab's tasks (#1815)
0xken15dcaa477b4ef5
diff --git a/backend/src/superTabs/commands.test.ts b/backend/src/superTabs/commands.test.tsindex 73928808a..23596ac59 100644--- a/backend/src/superTabs/commands.test.ts+++ b/backend/src/superTabs/commands.test.ts@@ -590,7 +590,7 @@ function routed() {describe('route.record and route.override', () => {it('records a lead decision as a route message with its id', () => {const f = routed()- const effects = f.run({ type: 'route.record', conversationId: 'lead', decision: record() } as Command, f.leadActor, { recentRoutes: 0 })+ const effects = f.run({ type: 'route.record', conversationId: 'lead', decision: record() } as Command, f.leadActor, {})expect(effects.result.routeDecisionId).toBeTruthy()expect(effects.routeDecisions).toEqual([{ op: 'create', id: effects.result.routeDecisionId, conversationId: 'lead', record: expect.objectContaining({ pick: 'c0' }) }])expect(effects.messages[0]).toMatchObject({ text: 'Routed to Title c0 — Jev 82% · "Schema change."',@@ -599,7 +599,7 @@ describe('route.record and route.override', () => {})it('keeps the context Jev was given with the record, bounded, and still takes a record without it', () => {const f = routed()- const run = (decision: unknown) => f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, f.leadActor, { recentRoutes: 0 })+ const run = (decision: unknown) => f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, f.leadActor, {})expect(run(record({ context: { chars: 9000, missing: ['messages', 'activity'] } })).routeDecisions[0]).toMatchObject({ record: { context: { chars: 9000, missing: ['messages', 'activity'] } } })expect(run(record()).routeDecisions[0]).toMatchObject({ record: { pick: 'c0' } })for (const context of [{ chars: -1, missing: [] }, { chars: 1.5, missing: [] }, { chars: 40_000, missing: [] }, { chars: 10 },@@ -610,7 +610,7 @@ describe('route.record and route.override', () => {})it('keeps the size and each candidate\'s quota fit, and still takes a record without them', () => {const f = routed()- const run = (decision: unknown) => f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, f.leadActor, { recentRoutes: 0 })+ const run = (decision: unknown) => f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, f.leadActor, {})const fit = { status: 'short', coverage: -0.2, effectiveCost: 1.5, expiring: 0, spend: { '5-hour': 45, weekly: 6 }, account: 'remote-1:codex' }const sized = (size: unknown, patch: Record<string, unknown> = {}) => record({ assessment: { difficulty: 'high', risk: 'low', why: 'Schema change.', size },candidates: [candidate('c0', { fit: { ...fit, ...patch } }), candidate('c1', { model: 'sonnet', quality: 2, cost: 2, fit: { status: 'unknown', coverage: null, effectiveCost: 2, expiring: 0, spend: {} } })] })@@ -626,9 +626,9 @@ describe('route.record and route.override', () => {const f = routed()const route = (decision: unknown, actor: Actor, context: Partial<CommandContext>) =>f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, actor, context)- expect(() => route(record({ pick: 'c5' }), f.leadActor, { recentRoutes: 0 })).toThrow()- expect(() => route(record(), f.workerActor, { recentRoutes: 0 })).toThrow('coordinating lead')- expect(() => route(record(), f.leadActor, { recentRoutes: 30 })).toThrow('30 tasks')+ expect(() => route(record({ pick: 'c5' }), f.leadActor, {})).toThrow()+ expect(() => route(record(), f.workerActor, {})).toThrow('coordinating lead')+ expect(() => route(record(), f.leadActor, {})).not.toThrow()})it('lets a writer change an open decision with a reason and tells the lead', () => {const f = routed()@@ -708,7 +708,7 @@ describe('decisions linked to work', () => {it('gives the policy-order row the Lead’s reason and why the order decided', () => {const f = routed()const order = (patch: Record<string, unknown>) => f.run({ type: 'route.record', conversationId: 'lead', decision: record({ via: 'order', p: null, ...patch }) } as Command,- f.leadActor, { recentRoutes: 0 }).messages[0]!+ f.leadActor, {}).messages[0]!expect(order({ fallback: 'unavailable', why: 'Jev unavailable (BUSY); first in the policy order.' })).toMatchObject({text: 'Routed to Title c0 — by policy order · "Schema change."', source: { why: 'Schema change.', fallback: 'unavailable' } })expect(order({ fallback: 'unsure' }).source).toMatchObject({ fallback: 'unsure' })@@ -1332,7 +1332,7 @@ describe('the owner\'s rules', () => {})it('refuses a recorded pick that breaks a hard rule, but not a ruled-out candidate that was not picked', () => {const f = routed()- const route = (decision: unknown) => f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, f.leadActor, { recentRoutes: 0 })+ const route = (decision: unknown) => f.run({ type: 'route.record', conversationId: 'lead', decision } as Command, f.leadActor, {})f.run(set({ kind: 'forbidModel', model: 'sonnet' }, 'No Sonnet.'))expect(route(record()).result.routeDecisionId).toBeTruthy()expect(() => route(record({ pick: 'c1' }))).toThrow('The owner\'s rule "No Sonnet." rules out Claude sonnet.')@@ -1398,7 +1398,7 @@ describe('the owner\'s rules in a Swarm of projects', () => {const f = projects(), app = projectIdOf(f, f.app)f.run(forbid(app, 'sonnet')); f.run(forbid(app, 'test-model'))expect(f.state.rules!.map(r => r.projectId)).toEqual([app, app])- const route = (conversationId: string, actor: Actor) => f.run({ type: 'route.record', conversationId, decision: record({ pick: 'c1' }) } as Command, actor, { recentRoutes: 0 })+ const route = (conversationId: string, actor: Actor) => f.run({ type: 'route.record', conversationId, decision: record({ pick: 'c1' }) } as Command, actor, {})expect(route(f.site, f.siteLead).result.routeDecisionId).toBeTruthy()expect(() => route(f.app, f.lead)).toThrow('The owner\'s rule "No sonnet." rules out Claude sonnet.')const siteWorker = f.add('site-worker', 'owner', f.site)diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 76eb55952..c5bc93960 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -235,7 +235,6 @@ export interface CommandContext {/** The files `message.send` names, each checked by the store: uploaded by this actor to this conversation, and unused. */attachments?: Attachment[]/** Route decisions this tab recorded in the last hour, counted by the store. */- recentRoutes?: number/** The decision a command names, read from SuperTabRouteDecision by the store. */routeDecision?: RouteDecision/** Starts on the machine being contributed that the store found abandoned: never contributed, never dispatched,@@ -1494,7 +1493,6 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma// Only the pick is checked, so an older CLI that still lists a ruled-out candidate records an allowed pick.ruled(member ? agentTarget(state, member) : chosen, command.conversationId, `${who} routed to ${chosen.title}`)requireWorkerDecisions(state, actor, open(state, command.conversationId), chosen.kind === 'member' ? chosen.agentId : undefined)- if ((context.recentRoutes ?? 0) >= 30) fail('RATE_LIMITED', 'This Super Tab routed 30 tasks in the last hour. Wait before routing again.', 429)const via = decision.via === 'jev' ? `Jev ${Math.round((decision.p ?? 0) * 100)}%`: decision.via === 'only' ? 'only candidate' : 'by policy order'effects.routeDecisions.push({ op: 'create', id: operationId, conversationId: command.conversationId, record: decision })diff --git a/backend/src/superTabs/routeDecisions.ts b/backend/src/superTabs/routeDecisions.tsindex d009867dd..c27e7f534 100644--- a/backend/src/superTabs/routeDecisions.ts+++ b/backend/src/superTabs/routeDecisions.ts@@ -17,10 +17,6 @@ export const decisionOf = (row: SuperTabRouteDecision): RouteDecision => ({/** The decision with the times the log shows: when it was recorded and when its outcome was. */export const timedDecisionOf = (row: SuperTabRouteDecision) => ({ ...decisionOf(row), createdAt: row.createdAt, outcomeAt: row.outcomeAt })-export async function recentRoutes(tx: Tx, tabId: string, now: number): Promise<number> {- return tx.superTabRouteDecision.count({ where: { tabId, createdAt: { gte: new Date(now - 60 * 60_000) } } })-}-export async function readDecision(tx: Tx, tabId: string, id: string): Promise<RouteDecision | undefined> {const row = await tx.superTabRouteDecision.findFirst({ where: { id, tabId } })return row ? decisionOf(row) : undefineddiff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 80d4ffb83..ef5a339be 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -31,7 +31,7 @@ import { agentDisplayName } from './agentNames.js'import { endedHolds, HOLDING, type WorkHold } from '../github/holds.js'import { accrueLent } from './leaderboard/lent.js'import { mayDrive, TERMINAL_ANSWER_MS, TERMINAL_EXPIRY_MS, TERMINAL_PICKUP_MS, type TerminalEffect } from './terminal.js'-import { closeAssignment, closeUnassignedStart, readDecision, recentRoutes, timedDecisionOf, writeRouteEffects } from './routeDecisions.js'+import { closeAssignment, closeUnassignedStart, readDecision, timedDecisionOf, writeRouteEffects } from './routeDecisions.js'import { listMentions, markDone, mentionsWaiting, readMention, resolveByReply, writeMentions } from './mentions.js'import { answerable, listDecisions, readAskedDecision, recordAnswer, waitingInProject, writeDecisions } from './decisions.js'import { DEFAULT_ROUTING_POLICY, effectivePolicy, routingPolicySchema, type RoutingPolicy } from './routingPolicy.js'@@ -740,7 +740,6 @@ export class SuperTabStore {if (command.type === 'mention.done') context.mention = await readMention(tx, tabId, command.mentionId)if (command.type === 'decision.answer') context.decision = await readAskedDecision(tx, tabId, command.decisionId)if (command.type === 'message.send' && command.attachmentIds?.length) context.attachments = await this.sendable(tx, tabId, actor, command)- if (command.type === 'route.record') context.recentRoutes = await recentRoutes(tx, tabId, context.now)if (TEAM_WORK_COMMANDS.has(command.type)) {context.teamMachines = await this.teamMachines(tx, original)if (this.hooks.teamAccountsIdle) context.teamAccountsIdle = truediff --git a/backend/src/superTabs/teamRouting.test.ts b/backend/src/superTabs/teamRouting.test.tsindex 286654ada..cdeced0df 100644--- a/backend/src/superTabs/teamRouting.test.ts+++ b/backend/src/superTabs/teamRouting.test.ts@@ -266,7 +266,7 @@ describe('routing a teammate\'s work', () => {const f = routed()const effects = f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'mate-team'), candidate('c1', 'mate-mac'),candidate('c2', 'mate-mac', { kind: 'member', agentId: f.personal, title: 'personal on mate-mac' }), candidate('c3', 'owner-mac')]) } as Command,- f.leadActor, { recentRoutes: 0 })+ f.leadActor, {})expect(effects.routeDecisions[0]).toMatchObject({ op: 'create', record: {candidates: [{ id: 'c0' }, { id: 'c3' }],excluded: [@@ -283,7 +283,7 @@ describe('routing a teammate\'s work', () => {observation: reading('team', PASSED, NOW, NOW - 30 * MINUTE) })f.machine('mate-team').observation = reading('team', FAILED)const effects = f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'owner-mac'), candidate('c1', 'mate-team'),- candidate('c2', 'mate-stale')]) } as Command, f.leadActor, { recentRoutes: 0 })+ candidate('c2', 'mate-stale')]) } as Command, f.leadActor, {})expect((effects.routeDecisions[0] as { record: { excluded: { reason: string }[] } }).record.excluded.map(e => e.reason)).toEqual(['The Harness Team account on MacBook Pro · Team is not private (gitconfig: it could read its owner\'s ~/.gitconfig), so it runs only its owner\'s projects.','The privacy check on Mini · Team last passed 30 minutes ago, so it runs only its owner\'s projects until it passes again.',@@ -294,7 +294,7 @@ describe('routing a teammate\'s work', () => {it('refuses a pick that cannot take it, so no decision names it', () => {const f = routed()expect(refusal(() => f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'mate-mac'), candidate('c1', 'mate-team')]) } as Command,- f.leadActor, { recentRoutes: 0 }))).toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED',+ f.leadActor, {}))).toMatchObject({ code: 'TEAM_ACCOUNT_REQUIRED',message: 'MacBook Pro has no Harness Team account yet, so it runs only its owner\'s projects. Route again.' })})@@ -312,7 +312,7 @@ describe('routing a teammate\'s work', () => {it('keeps a person\'s own project routing as it was', () => {const f = routed()- const effects = f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'owner-mac')]) } as Command, f.leadActor, { recentRoutes: 0 })+ const effects = f.run({ type: 'route.record', conversationId: f.group, decision: record([candidate('c0', 'owner-mac')]) } as Command, f.leadActor, {})expect(effects.routeDecisions[0]).toMatchObject({ record: { candidates: [{ id: 'c0' }], excluded: [{ title: 'Owner Mac · claude' }] } })})})@@ -494,7 +494,7 @@ describe('one machine: a Mac and its Harness Team account', () => {title: 'Builder on MacBook Pro', label: 'Codex' }const effects = f.run({ type: 'route.record', conversationId: group, decision: { assessment: { difficulty: 'medium', risk: 'low', why: 'A small change.' },candidates: [candidate], excluded: [], floor: 2, notes: false, pick: 'c0', via: 'order', p: null, belowFloor: false, why: 'Policy order.' } } as Command,- leadActor, { recentRoutes: 0 })+ leadActor, {})const recorded = effects.routeDecisions[0] as unknown as { id: string; record: RouteDecision['record'] }expect(recorded.record.candidates).toEqual([expect.objectContaining({ id: 'c0' })])const decision = { id: recorded.id, conversationId: group, record: recorded.record, final: null, override: null, assignmentId: null, outcome: null } as unknown as RouteDecision