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.

Route: every engine on every machine, each row with its weekly quota (#2723)

0xken1592bf71270c9c
diff --git a/backend/src/superTabs/instructions.test.ts b/backend/src/superTabs/instructions.test.ts
index f21180cf1..75267cb15 100644
--- a/backend/src/superTabs/instructions.test.ts
+++ b/backend/src/superTabs/instructions.test.ts
@@ -120,6 +120,13 @@ describe('the built-in template', () => {
const routing = INSTRUCTIONS_TEMPLATE.slice(INSTRUCTIONS_TEMPLATE.indexOf('## Routing')).replace(/\n +/g, ' ')
expect(routing).toContain('- When no other account has weekly quota left, the PM\'s account takes work as any other account does.')
})
+ it('says the route lists every engine on every machine with its weekly quota, which the PM orders by itself', () => {
+ // Ken, 2026-11-03: the route's rows now carry each account's quota, and no account is cut from them.
+ const routing = INSTRUCTIONS_TEMPLATE.slice(INSTRUCTIONS_TEMPLATE.indexOf('## Routing')).replace(/\n +/g, ' ')
+ expect(routing).toContain('- The route lists the best new agent and the best idle agent of every engine on every machine, each with its quota: '
+ + 'fits or short, weekly quota left and reset time. Its order does not rank by quota: the PM applies this order itself.')
+ expect(routing).not.toContain('The route\'s lines show')
+ })
})
describe('role names', () => {
diff --git a/backend/src/superTabs/instructionsTemplate.ts b/backend/src/superTabs/instructionsTemplate.ts
index 736f42cc8..46cda6172 100644
--- a/backend/src/superTabs/instructionsTemplate.ts
+++ b/backend/src/superTabs/instructionsTemplate.ts
@@ -99,9 +99,10 @@ export const TEMPLATE_ROUTING = `## Routing
work that follows straight on from what the agent just did.
5. Between equals, the machine with fewer agents working. Then price.
- When no other account has weekly quota left, the PM's account takes work as any other account does.
-- The route's lines show each account's weekly quota left and reset time, but its order does not rank by them: the PM
- applies this order itself. Picking against it needs a reason in the route's override: urgency, context, or a machine
- the work needs. "Idle" is not a reason.
+- The route lists the best new agent and the best idle agent of every engine on every machine, each with its quota:
+ fits or short, weekly quota left and reset time. Its order does not rank by quota: the PM applies this order itself.
+ Picking against it needs a reason in the route's override: urgency, context, or a machine the work needs. "Idle" is
+ not a reason.
- An agent whose account runs out of weekly quota mid-task, or whose account is the PM's and falls below its line,
hands its pushed branch to an agent on another account.
- Urgent work (production down, security) ignores quota.`
diff --git a/backend/src/superTabs/routeRecord.test.ts b/backend/src/superTabs/routeRecord.test.ts
new file mode 100644
index 000000000..e975b71d3
--- /dev/null
+++ b/backend/src/superTabs/routeRecord.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest'
+import { routeRecordSchema } from './routeRecord.js'
+
+const candidate = (i: number) => ({ id: `c${i}`, kind: 'new', machineId: `m${i}`, engine: 'claude', model: 'opus', effort: 'high', quality: 3, cost: 3,
+ title: `New agent · Claude opus high · m${i}`, label: `New agent · Claude opus high · m${i}` })
+const record = (count: number) => ({ assessment: { difficulty: 'medium', risk: 'low', why: 'Endpoint.' },
+ candidates: Array.from({ length: count }, (_, i) => candidate(i)), excluded: [], floor: 1, notes: false, pick: 'c0', via: 'order', p: null,
+ belowFloor: false, why: 'First by strength, then price and quota fit.' })
+
+describe('route.record', () => {
+ // The route shows every engine on every machine (Ken, 2026-11-03): a Swarm of a dozen Macs with two engines, a new agent and an
+ // idle member on each, is 48 rows, and the agent choosing may pick any of them by its id.
+ it('keeps up to 64 candidates, and refuses more', () => {
+ expect(routeRecordSchema.safeParse(record(64)).success).toBe(true)
+ expect(routeRecordSchema.safeParse(record(65)).success).toBe(false)
+ })
+})
diff --git a/backend/src/superTabs/routeRecord.ts b/backend/src/superTabs/routeRecord.ts
index 2c44563eb..fdb0eb75c 100644
--- a/backend/src/superTabs/routeRecord.ts
+++ b/backend/src/superTabs/routeRecord.ts
@@ -44,7 +44,9 @@ export const routeRecordSchema = z.object({
kind: z.string().regex(/^[a-z][a-z0-9-]{0,39}$/).optional(),
/** A person asked for a local model, or named one (cli superTabs/route.ts Assessment), kept with the decision. */
local: z.literal(true).optional(), model: z.string().trim().min(1).max(200).optional() }).strict(),
- candidates: z.array(routeCandidateSchema).min(1).max(12),
+ /** Every engine on every machine, a new agent and an idle member each (cli superTabs/route.ts RECORD_MAX, Ken 2026-11-03); 12
+ * before, when the route showed one row a machine. */
+ candidates: z.array(routeCandidateSchema).min(1).max(64),
excluded: z.array(z.object({ title: z.string().trim().min(1).max(160), reason: z.string().trim().min(1).max(500) }).strict()).max(200),
floor: z.number().int().min(1).max(3),
notes: z.boolean(),
diff --git a/cli/src/superTabs/__snapshots__/route.answers.json b/cli/src/superTabs/__snapshots__/route.answers.json
index 5b2f7faf2..8db128353 100644
--- a/cli/src/superTabs/__snapshots__/route.answers.json
+++ b/cli/src/superTabs/__snapshots__/route.answers.json
@@ -2084,6 +2084,144 @@
"id": "c11",
"title": "New agent · Claude sonnet medium · m08",
"label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (62% left, resets in 3h); weekly 4% of 90% · m08 · new · quota 5-hour 62% left (resets in 3h), weekly 90% left (resets in 5 days)"
+ },
+ {
+ "kind": "new",
+ "machineId": "m10",
+ "machineName": "m10",
+ "engine": "claude",
+ "model": "sonnet",
+ "effort": "medium",
+ "quality": 2,
+ "cost": 2,
+ "quota": {
+ "known": true,
+ "leftPercent": 70,
+ "resetsAt": null,
+ "windows": [
+ {
+ "name": "5-hour",
+ "leftPercent": 70,
+ "resetsAt": 1010800000
+ },
+ {
+ "name": "weekly",
+ "leftPercent": 90,
+ "resetsAt": 1432000000
+ }
+ ],
+ "account": "acct10"
+ },
+ "activity": "new",
+ "known": true,
+ "refusals": [],
+ "notes": [],
+ "fit": {
+ "status": "fits",
+ "coverage": 2.33,
+ "effectiveCost": 2,
+ "expiring": 0,
+ "spend": {
+ "5-hour": 30,
+ "weekly": 4
+ },
+ "account": "acct10"
+ },
+ "id": "c12",
+ "title": "New agent · Claude sonnet medium · m10",
+ "label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (70% left, resets in 3h); weekly 4% of 90% · m10 · new · quota 5-hour 70% left (resets in 3h), weekly 90% left (resets in 5 days)"
+ },
+ {
+ "kind": "new",
+ "machineId": "m12",
+ "machineName": "m12",
+ "engine": "claude",
+ "model": "sonnet",
+ "effort": "medium",
+ "quality": 2,
+ "cost": 2,
+ "quota": {
+ "known": true,
+ "leftPercent": 78,
+ "resetsAt": null,
+ "windows": [
+ {
+ "name": "5-hour",
+ "leftPercent": 78,
+ "resetsAt": 1010800000
+ },
+ {
+ "name": "weekly",
+ "leftPercent": 90,
+ "resetsAt": 1432000000
+ }
+ ],
+ "account": "acct12"
+ },
+ "activity": "new",
+ "known": true,
+ "refusals": [],
+ "notes": [],
+ "fit": {
+ "status": "fits",
+ "coverage": 2.6,
+ "effectiveCost": 2,
+ "expiring": 0,
+ "spend": {
+ "5-hour": 30,
+ "weekly": 4
+ },
+ "account": "acct12"
+ },
+ "id": "c13",
+ "title": "New agent · Claude sonnet medium · m12",
+ "label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (78% left, resets in 3h); weekly 4% of 90% · m12 · new · quota 5-hour 78% left (resets in 3h), weekly 90% left (resets in 5 days)"
+ },
+ {
+ "kind": "new",
+ "machineId": "m14",
+ "machineName": "m14",
+ "engine": "claude",
+ "model": "sonnet",
+ "effort": "medium",
+ "quality": 2,
+ "cost": 2,
+ "quota": {
+ "known": true,
+ "leftPercent": 86,
+ "resetsAt": null,
+ "windows": [
+ {
+ "name": "5-hour",
+ "leftPercent": 86,
+ "resetsAt": 1010800000
+ },
+ {
+ "name": "weekly",
+ "leftPercent": 90,
+ "resetsAt": 1432000000
+ }
+ ],
+ "account": "acct14"
+ },
+ "activity": "new",
+ "known": true,
+ "refusals": [],
+ "notes": [],
+ "fit": {
+ "status": "fits",
+ "coverage": 2.87,
+ "effectiveCost": 2,
+ "expiring": 0,
+ "spend": {
+ "5-hour": 30,
+ "weekly": 4
+ },
+ "account": "acct14"
+ },
+ "id": "c14",
+ "title": "New agent · Claude sonnet medium · m14",
+ "label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (86% left, resets in 3h); weekly 4% of 90% · m14 · new · quota 5-hour 86% left (resets in 3h), weekly 90% left (resets in 5 days)"
}
],
"excluded": [],
@@ -2424,6 +2562,75 @@
},
"account": "acct8"
}
+ },
+ {
+ "id": "c12",
+ "kind": "new",
+ "machineId": "m10",
+ "engine": "claude",
+ "model": "sonnet",
+ "effort": "medium",
+ "quality": 2,
+ "cost": 2,
+ "title": "New agent · Claude sonnet medium · m10",
+ "label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (70% left, resets in 3h); weekly 4% of 90% · m10 · new · quota 5-hour 70% left (resets in 3h), weekly 90% left (resets in 5 days)",
+ "fit": {
+ "status": "fits",
+ "coverage": 2.33,
+ "effectiveCost": 2,
+ "expiring": 0,
+ "spend": {
+ "5-hour": 30,
+ "weekly": 4
+ },
+ "account": "acct10"
+ }
+ },
+ {
+ "id": "c13",
+ "kind": "new",
+ "machineId": "m12",
+ "engine": "claude",
+ "model": "sonnet",
+ "effort": "medium",
+ "quality": 2,
+ "cost": 2,
+ "title": "New agent · Claude sonnet medium · m12",
+ "label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (78% left, resets in 3h); weekly 4% of 90% · m12 · new · quota 5-hour 78% left (resets in 3h), weekly 90% left (resets in 5 days)",
+ "fit": {
+ "status": "fits",
+ "coverage": 2.6,
+ "effectiveCost": 2,
+ "expiring": 0,
+ "spend": {
+ "5-hour": 30,
+ "weekly": 4
+ },
+ "account": "acct12"
+ }
+ },
+ {
+ "id": "c14",
+ "kind": "new",
+ "machineId": "m14",
+ "engine": "claude",
+ "model": "sonnet",
+ "effort": "medium",
+ "quality": 2,
+ "cost": 2,
+ "title": "New agent · Claude sonnet medium · m14",
+ "label": "New agent · Claude sonnet medium · strength 2, cost 2 · fits: needs about 30% of the 5-hour window (86% left, resets in 3h); weekly 4% of 90% · m14 · new · quota 5-hour 86% left (resets in 3h), weekly 90% left (resets in 5 days)",
+ "fit": {
+ "status": "fits",
+ "coverage": 2.87,
+ "effectiveCost": 2,
+ "expiring": 0,
+ "spend": {
+ "5-hour": 30,
+ "weekly": 4
+ },
+ "account": "acct14"
+ }
}
],
"excluded": [],
diff --git a/cli/src/superTabs/route.spec.ts b/cli/src/superTabs/route.spec.ts
index 29109c69c..919a72a8f 100644
--- a/cli/src/superTabs/route.spec.ts
+++ b/cli/src/superTabs/route.spec.ts
@@ -171,10 +171,12 @@ describe('choose', () => {
expect(short.shown.map(s => [s.machineName, s.fit.status])).toEqual([['mac', 'unknown'], ['remote-1', 'short']])
expect(short.short).toBeUndefined()
})
- it('shows at most 12 candidates', () => {
+ // Every account the coordinator may pick by the project's order is in front of it: the route used to cut the list at 12, one
+ // row a machine, and a Claude account with 99% left on a machine whose cheaper Codex was used up never showed (Ken, 2026-11-03).
+ it('shows a row for every machine and engine, past 12, and fills up to 12 by rank', () => {
const r = choose(Array.from({ length: 20 }, (_, i) => probe({ machineId: `m${i}`, machineName: `box-${String(i).padStart(2, '0')}` })), policy, a())
if ('error' in r) throw new Error('unexpected')
- expect(r.shown).toHaveLength(12)
+ expect(r.shown).toHaveLength(20)
})
})
@@ -262,14 +264,31 @@ describe('strength, fit and effective cost', () => {
expect(spent.shown[0].fit).toMatchObject({ status: 'short', effectiveCost: 2 })
expect(spent.short).toBe('No candidate is expected to cover this task; its weekly quota is expected to run out partway and resets in 7 days.')
})
- it('a Codex account that has only a weekly window is read in full; a Claude one missing its 5-hour window is not', () => {
+ // A 5-hour window is never what runs out (Ken, 2026-11-03), and a Team account's Claude, whose 5-hour window its host does not
+ // relay, read as unknown and fell behind every Codex that fit.
+ it('reads an account with a weekly window in full on either engine, with or without its 5-hour window', () => {
const CODEX = { engine: 'codex', model: 'default', effort: 'default', quality: 2, cost: 2 } as const
const weekly = quotaOf2({ known: true, windows: [{ usedPercent: 19, resetsAt: (NOW + 6 * D) / 1000, name: 'weekly' }] })
const r = route([on(CODEX, 'codex', weekly), on(SONNET, 'claude', windows([90, 3 * H], [80, 5 * D]))], { difficulty: 'low' })
expect(r.shown.map(s => [s.engine, s.fit.status])).toEqual([['claude', 'fits'], ['codex', 'fits']])
expect(r.excluded).toEqual([])
const half = route([on(SONNET, 'half', weekly), on(SONNET, 'claude', windows([90, 3 * H], [80, 5 * D]))], { difficulty: 'low' })
- expect(half.shown.map(s => [s.machineName, s.fit.status])).toEqual([['claude', 'fits'], ['half', 'unknown']])
+ expect(half.shown.map(s => [s.machineName, s.fit.status])).toEqual([['claude', 'fits'], ['half', 'fits']])
+ // A weekly window with no room is short; with no weekly reading the fit is not known.
+ expect(route([on(SONNET, 'a', windows([90, 3 * H], [1, 5 * D]))], {}).shown[0].fit.status).toBe('short')
+ expect(route([on(SONNET, 'a', windows([90, 3 * H], null))], {}).shown[0].fit.status).toBe('unknown')
+ })
+ it('keeps a row for each engine of every machine, though a cheaper engine there is used up', () => {
+ const boxes = Array.from({ length: 14 }, (_, i) => `box-${String(i).padStart(2, '0')}`)
+ const r = route(boxes.flatMap(b => [on(CODEX, b, windows(null, [0, 5 * D], `${b}-x`)), on(OPUS, b, windows(null, [99, D], `${b}-c`))]), { difficulty: 'high' })
+ expect(r.shown).toHaveLength(28)
+ for (const b of boxes) expect(r.shown.filter(s => s.machineName === b).map(s => [s.engine, s.fit.status]).sort()).toEqual([['claude', 'fits'], ['codex', 'short']])
+ })
+ it('shows at most 64 rows, what the backend keeps of a decision, the best-ranked first', () => {
+ const boxes = Array.from({ length: 40 }, (_, i) => `box-${String(i).padStart(2, '0')}`)
+ const r = route(boxes.flatMap(b => [on(CODEX, b, windows(null, [50, 5 * D], `${b}-x`)), on(OPUS, b, windows(null, [99, D], `${b}-c`))]), { difficulty: 'high' })
+ expect(r.shown).toHaveLength(64)
+ expect(r.shown.at(-1)!.id).toBe('c63')
})
it('an engine on an API key is metered: it fits with no window, beside a subscription machine', () => {
const metered = quotaOf2({ known: true, windows: [] })
@@ -291,17 +310,18 @@ describe('strength, fit and effective cost', () => {
expect(r.shown.map(s => s.machineName)).toEqual([...Array(11).fill('a'), 'z'])
expect(r.shown.map(s => s.id)).toEqual(Array.from({ length: 12 }, (_, i) => `c${i}`))
})
- it('with more machines than rows shown, keeps the best rows of the best-ranked machines', () => {
+ it('with more machines than rows shown, shows a new agent and a member of every one', () => {
const many = Array.from({ length: 14 }, (_, i) => on(SONNET, `m${String(i).padStart(2, '0')}`, windows([90 - i, 3 * H], [80, 5 * D], `A${i}`)))
const r = route([...many, ...many.map(p => ({ ...p, kind: 'member' as const, agentId: p.machineId, name: 'Extra' }))], { difficulty: 'low' })
- expect(new Set(r.shown.map(s => s.machineName)).size).toBe(12)
+ expect(new Set(r.shown.map(s => s.machineName)).size).toBe(14)
+ expect(r.shown).toHaveLength(28)
})
it('orders the short by title at equal strength and price, and says when no reset is known', () => {
const r = route([on(SONNET, 'b', windows([20, null], [80, null], 'B')), on(SONNET, 'a', windows([20, null], [80, null], 'A')), on(SONNET, 'c', windows([25, null], [80, null], 'C'))], {})
expect(picks(r)).toEqual(['sonnet on a', 'sonnet on b', 'sonnet on c'])
expect(r.short).toBe('No candidate is expected to cover this task; its 5-hour quota is expected to run out partway.')
expect(r.shown[2].label).toContain('short: needs about 30% of the 5-hour window (25% left); weekly 4% of 80%')
- expect(route([on(SONNET, 'a', windows(null, [80, null]))], {}).shown[0].label).toContain('unknown: 5-hour window unknown; weekly 4% of 80%')
+ expect(route([on(SONNET, 'a', windows(null, [80, null]))], {}).shown[0].label).toContain('fits: 5-hour window unknown; weekly 4% of 80%')
})
})
diff --git a/cli/src/superTabs/route.ts b/cli/src/superTabs/route.ts
index 6187e65fb..7a8207953 100644
--- a/cli/src/superTabs/route.ts
+++ b/cli/src/superTabs/route.ts
@@ -185,6 +185,10 @@ export const SIZES: Record<Size, { minutes: number; spend: Record<Window, number
}
const WINDOWS: Window[] = ['5-hour', 'weekly']
const MAX_SHOWN = 12
+/** The most rows a decision keeps (backend superTabs/routeRecord.ts), past [MAX_SHOWN] only for every engine on every machine; a
+ * backend from before them keeps [MAX_SHOWN] (routeCommand.ts routeTask). */
+export const RECORD_MAX = 64
+export const OLD_RECORD_MAX = MAX_SHOWN
const ENGINE = { claude: 'Claude', codex: 'Codex' } as const
const ENGINES = Object.keys(ENGINE)
const cut = (text: string, max: number) => text.length <= max ? text : `${text.slice(0, max - 1)}…`
@@ -434,12 +438,12 @@ function sizeUp(p: Probe, a: Assessment, now: number, open: Commitment[]): Sized
return [{ name, usable: w.leftPercent - committed(name), resetsIn,
needed: resetsIn !== null && resetsIn < runMs ? spend[name] * resetsIn / runMs : spend[name] }]
})
- // Every account has a weekly window; a Codex account may have no 5-hour one at all, reporting its weekly alone (2026-10-24),
- // and that reading is complete.
- const complete = windows.length === WINDOWS.length || (p.engine === 'codex' && windows.length === 1 && windows[0]!.name === 'weekly')
- const status = windows.some(w => w.usable < w.needed) ? 'short' : complete ? 'fits' : 'unknown'
- const tight = windows.length ? windows.reduce((x, y) => y.usable / y.needed < x.usable / x.needed ? y : x) : null
+ // A weekly reading is complete on either engine: the 5-hour window is never what runs out (Ken, 2026-11-03), and a Team
+ // account's Claude, whose host relays no 5-hour window, read as unknown and ranked behind every Codex that fit. A 5-hour
+ // window that is read still counts when it is short.
const five = windows.find(w => w.name === '5-hour'), week = windows.find(w => w.name === 'weekly')
+ const status = windows.some(w => w.usable < w.needed) ? 'short' : week ? 'fits' : 'unknown'
+ const tight = windows.length ? windows.reduce((x, y) => y.usable / y.needed < x.usable / x.needed ? y : x) : null
// A 5-hour window that resets before the task ends, or soon after, loses what is left of it: spending it costs nothing.
const expiring = five && five.resetsIn !== null && five.resetsIn <= runMs + 3_600_000 ? Math.min(1, Math.max(0, five.usable) / five.needed) : 0
let effectiveCost = p.cost * (1 - expiring)
@@ -470,16 +474,31 @@ function compare(x: Probe & Sized & { rank: Ranked }, y: Probe & Sized & { rank:
|| titleOf(x).localeCompare(titleOf(y))
}
-/** The rows shown: each machine's best row first (the best-ranked machines, if there are more than the limit), then the rest by rank,
- * all in rank order, so the agent choosing can always choose another machine. */
-function withEveryMachine<T extends { machineId: string }>(ranked: T[]): T[] {
- const firsts = new Set<T>(), seen = new Set<string>()
- for (const p of ranked) if (!seen.has(p.machineId)) { seen.add(p.machineId); firsts.add(p) }
- const keep = new Set([...firsts].slice(0, MAX_SHOWN))
+/** An engine on a machine, or the machine's local models, as a new agent or an idle member: what the project's order picks
+ * between (an account, then whether to reuse an agent on it). */
+export const slotOf = (p: Pick<Probe, 'machineId' | 'engine' | 'gridModel' | 'kind'>) => `${p.machineId}\0${p.gridModel ? 'grid' : p.engine}\0${p.kind}`
+
+/** The rows shown: the best new agent and the best member of every engine on every machine, up to [RECORD_MAX], then the rest by rank up to the limit, all in rank
+ * order. The agent choosing picks between accounts by the project's order; one row a machine, cut at 12, hid a Claude account with
+ * 99% left behind its machine's used-up Codex (Ken, 2026-11-03). */
+function withEveryAccount<T extends Pick<Probe, 'machineId' | 'engine' | 'gridModel' | 'kind'>>(ranked: T[]): T[] {
+ const keep = new Set<T>(), seen = new Set<string>()
+ for (const p of ranked) if (!seen.has(slotOf(p)) && keep.size < RECORD_MAX) { seen.add(slotOf(p)); keep.add(p) }
for (const p of ranked) if (keep.size < MAX_SHOWN) keep.add(p)
return ranked.filter(p => keep.has(p))
}
+/** What the agent choosing reads of a row's quota: its fit and its weekly window, the one the project's order compares. */
+export function quotaBrief(p: Pick<Probe, 'quota' | 'gridModel'> & { fit: Pick<Fit, 'status'> }, now: number): string {
+ if (p.gridModel) return 'local model, no subscription'
+ if (p.quota.metered) return 'metered'
+ const week = p.quota.windows?.find(w => w.name === 'weekly')
+ const left = week ? week.leftPercent : p.quota.windows?.length ? null : p.quota.leftPercent
+ const resetsAt = week ? week.resetsAt : p.quota.resetsAt
+ if (!p.quota.known || left === null) return `${p.fit.status}: weekly unknown`
+ return `${p.fit.status}: weekly ${Math.round(left)}% left${resetsAt === null ? '' : `, resets in ${resetsIn(resetsAt, now)}`}`
+}
+
/** One unrated new agent per machine of the named model's engine, on that machine's first row of the engine, which carries
* its facts and its quota ([CLAUDE_NAMES]). The person's words are the model's id, in lowercase with no spaces. */
function unratedProbes(probes: Probe[], named: string): Probe[] {
@@ -546,7 +565,7 @@ export function choose(given: Probe[], catalog: Catalog, a: Assessment, now: num
return [{ ...p, notes: [...p.notes, ...reasons], rank }]
}).sort(compare)
if (!ranked.length) return { error: 'NO_CANDIDATE', excluded, ...warned() }
- const shown = withEveryMachine(ranked).map(({ tight, text, rank: _rank, ...p }, i) => ({ ...p, id: `c${i}`, title: titleOf(p), label: labelOf({ ...p, tight, text }, now) }))
+ const shown = withEveryAccount(ranked).map(({ tight, text, rank: _rank, ...p }, i) => ({ ...p, id: `c${i}`, title: titleOf(p), label: labelOf({ ...p, tight, text }, now) }))
const first = ranked[0]!
return { shown, excluded, floor: 1, belowFloor: false, ...(first.fit.status === 'short' ? { short: shortOf(first, ranked) } : {}),
...(adjusted ? { adjusted: true as const } : {}), ...warned() }
diff --git a/cli/src/superTabs/routeCommand.spec.ts b/cli/src/superTabs/routeCommand.spec.ts
index d67562ff3..095208456 100644
--- a/cli/src/superTabs/routeCommand.spec.ts
+++ b/cli/src/superTabs/routeCommand.spec.ts
@@ -1406,6 +1406,42 @@ describe('routing contributed capacity', () => {
const answer = await routeTask(input, s, where, opener())
expect(answer).toMatchObject({ ok: true, pick: { machineId: 'm1', engine: 'codex' } })
expect((answer.alternatives as Array<{ machineId: string; engine: string }>).map(x => [x.machineId, x.engine])).toEqual([['m1', 'claude'], ['m2', 'claude'], ['m3', 'claude']])
+ // Each row says its account's weekly quota, which the project's order picks by (Ken, 2026-11-03).
+ expect((answer.pick as { quota: string }).quota).toBe('fits: weekly 80% left, resets in 5 days')
+ expect((answer.alternatives as Array<{ quota: string }>).map(x => x.quota)).toEqual(['fits: weekly 80% left, resets in 5 days', 'metered', 'metered'])
+ })
+ // The coordinator picks by the project's order among accounts, so every account is an alternative, once: a Claude account with
+ // 99% left on a machine whose Codex was used up never reached it (Ken, 2026-11-03).
+ it('offers the best row of every engine on every machine as an alternative, and no second row of an account', async () => {
+ const week = (usedPercent: number) => [{ name: 'weekly', usedPercent, resetsAt: Date.now() + 30 * 3_600_000 }]
+ const box = (machineId: string) => Object.assign({ ...healthy(), machineId, name: `Box ${machineId}`, engines: ['claude', 'codex'] }, {
+ observation: { ...healthy().observation, runningHarnessIds: [], quotas: [{ engine: 'claude', known: true, windows: week(1) }, { engine: 'codex', known: true, windows: week(100) }] } })
+ const enabled = { ...floorPolicy, models: floorPolicy.models.map(m => ({ ...m, enabled: true })) }
+ const s = scoped({ context: { ok: true, value: { agentId: 'lead', tab: { state: { id: 'tab', agents: [], conversations: conversations(), machines: ['m1', 'm2', 'm3'].map(box) } },
+ policy: { policy: enabled, warnings: [] }, machines: [] } } })
+ const answer = await routeTask(input, s, where, opener())
+ const rows = [answer.pick, ...answer.alternatives as unknown[]] as Array<{ machineId: string; engine: string; quota: string }>
+ expect(rows.map(x => `${x.machineId} ${x.engine}`).sort()).toEqual(['m1 claude', 'm1 codex', 'm2 claude', 'm2 codex', 'm3 claude', 'm3 codex'])
+ expect(rows.find(x => x.engine === 'claude')!.quota).toBe('fits: weekly 99% left, resets in 30h')
+ expect(rows.find(x => x.engine === 'codex')!.quota).toBe('short: weekly 0% left, resets in 30h')
+ })
+ // A backend from before 2026-11-03 keeps 12 candidates of a decision: the route records the first 12 and offers only those, as the
+ // agent choosing assigns by a recorded candidate.
+ it('records and offers the first 12 rows when the backend keeps no more', async () => {
+ const week = [{ name: 'weekly', usedPercent: 10, resetsAt: Date.now() + 30 * 3_600_000 }]
+ const box = (machineId: string) => Object.assign({ ...healthy(), machineId, name: `Box ${machineId}`, engines: ['claude', 'codex'] }, {
+ observation: { ...healthy().observation, runningHarnessIds: [], quotas: [{ engine: 'claude', known: true, windows: week }, { engine: 'codex', known: true, windows: week }] } })
+ const enabled = { ...floorPolicy, models: floorPolicy.models.map(m => ({ ...m, enabled: true })) }
+ const base = scoped({ context: { ok: true, value: { agentId: 'lead', tab: { state: { id: 'tab', agents: [], conversations: conversations(),
+ machines: Array.from({ length: 8 }, (_, i) => box(`m${i}`)) } }, policy: { policy: enabled, warnings: [] }, machines: [] } } })
+ const s = vi.fn(async (payload: Record<string, any>) => payload.action === 'command' && payload.command.decision.candidates.length > 12
+ ? { error: 'VALIDATION_ERROR', detail: 'command.decision.candidates: Too big' } : base(payload))
+ const answer = await routeTask(input, s as never, where, opener())
+ expect(answer).toMatchObject({ ok: true, routeDecisionId: 'd1' })
+ const sent = s.mock.calls.filter(c => c[0].action === 'command').map(c => c[0].command.decision.candidates.length)
+ expect(sent).toEqual([16, 12])
+ const recordedIds = new Set(s.mock.calls.filter(c => c[0].action === 'command').at(-1)![0].command.decision.candidates.map((c: { id: string }) => c.id))
+ for (const row of [answer.pick, ...answer.alternatives as unknown[]] as Array<{ id: string }>) expect(recordedIds.has(row.id)).toBe(true)
})
it('leaves out a machine that cannot take a teammate\'s project, with the backend\'s reason, and keeps its owner\'s own work there', async () => {
const reason = 'Contributed laptop has no Harness Team account yet, so it runs only its owner\'s projects.'
diff --git a/cli/src/superTabs/routeCommand.ts b/cli/src/superTabs/routeCommand.ts
index 7fafc65be..164d0ec83 100644
--- a/cli/src/superTabs/routeCommand.ts
+++ b/cli/src/superTabs/routeCommand.ts
@@ -7,7 +7,7 @@ import { openDaemon, type Daemon, type Where } from '../agentClient/daemon.js'
import { RELAYED_QUOTA, requiredToolReason, startRequirements, USED_UP_WINDOW } from './capacity.js'
import { inspectCapacity, type ScopedRequest } from './start.js'
import { ENDED_WORK, object, within } from './wire.js'
-import { accountOf, API_BUILDERS, catalogFrom, catalogRow, choose, decide, gridStrength, parseAssessment, quotaOf2, recordOf, repoMatch, repositoryKey, type Assessment, type Catalog, type CatalogModel, type RecordShape, type Commitment, type Excluded, type HeldModel, type MemberFrame, type Probe, type TaskFolder } from './route.js'
+import { accountOf, API_BUILDERS, catalogFrom, catalogRow, choose, decide, gridStrength, parseAssessment, OLD_RECORD_MAX, quotaBrief, quotaOf2, slotOf, recordOf, repoMatch, repositoryKey, type Assessment, type Catalog, type CatalogModel, type RecordShape, type Commitment, type Excluded, type HeldModel, type MemberFrame, type Probe, type TaskFolder } from './route.js'
import { makePlugins, ROUTE_PLUGIN_MAKERS, type PluginMaker } from './routePlugins.js'
import { CI_HOLD_OPENING, CI_RETRY_MINUTES, MACHINE_FIT_MAKER } from './machineFit.js'
import { stat } from 'node:fs/promises'
@@ -348,7 +348,8 @@ export async function routeTask(input: { tabId: string; conversationId: string;
.map(d => ({ account: d.account, spend: object(d.spend), size: d.size, createdAt: Date.parse(String(d.createdAt)) }) as Commitment)
// A model a host now offline served is left out with that reason, and a person naming it gets no stand-in (route.ts choose).
const offline = offlineModels(state)
- const choice = choose(probes, catalog, assessment, Date.now(), working, heldLocalModels(state), offline, made.plugins)
+ const now = Date.now()
+ const choice = choose(probes, catalog, assessment, now, working, heldLocalModels(state), offline, made.plugins)
const skipped = [...made.warnings, ...(choice.warnings ?? [])]
choice.excluded.push(...offline, ...(catalog.models.length ? [] : [{ title: 'New agents', reason: CATALOG_UNREADABLE }]))
// The task stays in the agent's queue rather than going where it cannot be done.
@@ -360,9 +361,13 @@ export async function routeTask(input: { tabId: string; conversationId: string;
...ciHeld ? { waiting: true, retryAfterMinutes: CI_RETRY_MINUTES, detail: ciHeld.reason.slice(MACHINE_FIT_MAKER.name.length + 2) } : {} }
const verdict = decide(choice)
const operationId = `route-${newId()}`
+ // The rows recorded are the rows offered: the agent choosing assigns by a recorded candidate.
+ let offered = choice.shown
const record = (shape: RecordShape) => scoped({ action: 'command', operationId,
- command: { type: 'route.record', conversationId: input.conversationId, decision: recordOf(choice, verdict, assessment, shape) } })
+ command: { type: 'route.record', conversationId: input.conversationId, decision: recordOf({ ...choice, shown: offered }, verdict, assessment, shape) } })
let recorded = await record('current')
+ // A backend from before every engine on every machine was shown keeps 12 candidates (Ken, 2026-11-03): the best 12 go.
+ if (recorded.error === 'VALIDATION_ERROR' && offered.length > OLD_RECORD_MAX) { offered = offered.slice(0, OLD_RECORD_MAX); recorded = await record('current') }
// A backend from before kinds, or before phase 1, refuses the new fields as invalid; the decision is still worth keeping in
// the shape it knows. A task with no kind has nothing to leave out at the first step.
if (recorded.error === 'VALIDATION_ERROR' && assessment.kind) recorded = await record('unkinded')
@@ -373,12 +378,12 @@ export async function routeTask(input: { tabId: string; conversationId: string;
// What the agent choosing reads of a candidate: where it runs, and what the route knows of it beside the ranking.
const publicOf = (s: typeof verdict.pick) => ({ id: s.id, kind: s.kind, ...(s.agentId ? { agentId: s.agentId } : {}), machineId: s.machineId,
engine: s.engine, model: s.model, effort: s.effort, title: s.title, ...(s.gridModel ? { gridModel: s.gridModel, gridName: s.gridName } : {}),
- ...(s.unrated ? { unrated: true } : {}), ...(s.notes.length ? { notes: s.notes } : {}) })
+ ...(s.unrated ? { unrated: true } : {}), quota: quotaBrief(s, now), ...(s.notes.length ? { notes: s.notes } : {}) })
return {
ok: true, ...(typeof routeDecisionId === 'string' ? { routeDecisionId } : { unrecorded: true }),
...(instructions ? { instructions } : { instructionsUnreadable: true }),
pick: publicOf(verdict.pick), via: verdict.via, p: verdict.p, why: verdict.why,
- alternatives: alternativesTo(verdict.pick, choice.shown).map(publicOf),
+ alternatives: alternativesTo(verdict.pick, offered).map(publicOf),
leftOut: leftOut(choice.excluded, choice.shown),
warnings: [...(Array.isArray(effective.warnings) ? effective.warnings : []), ...(value.machinesUnreadable === true ? [MACHINES_UNREADABLE] : []),
...(catalog.models.length ? [] : [CATALOG_UNREADABLE]),
@@ -414,9 +419,12 @@ export function leftOut(excluded: Excluded[], shown: Array<{ machineName: string
const MAX_LEFT_OUT = 20, MAX_REASONS = 4
/** The next two rows, and the best row of every other machine, so the agent choosing can take another machine. */
-function alternativesTo<T extends { id: string; machineId: string }>(pick: T, shown: T[]): T[] {
- const seen = new Set([pick.machineId])
- return shown.filter(s => s.id !== pick.id).filter((s, i) => { const best = !seen.has(s.machineId); seen.add(s.machineId); return i < 2 || best })
+/** The best new agent and the best member of every engine on every machine, in rank order, the pick's own left out: the project's
+ * order picks between accounts, then whether to reuse an agent there, so each is in front of the agent choosing once (Ken,
+ * 2026-11-03). */
+function alternativesTo<T extends { id: string } & Parameters<typeof slotOf>[0]>(pick: T, shown: T[]): T[] {
+ const seen = new Set([slotOf(pick)])
+ return shown.filter(s => { const best = !seen.has(slotOf(s)); seen.add(slotOf(s)); return best })
}
/** A reading this old says nothing is served (backend `MACHINE_FRESH_MS`). */
diff --git a/cli/src/superTabs/windowPull.spec.ts b/cli/src/superTabs/windowPull.spec.ts
index d34025b53..22b83068e 100644
--- a/cli/src/superTabs/windowPull.spec.ts
+++ b/cli/src/superTabs/windowPull.spec.ts
@@ -100,20 +100,23 @@ describe('the window pull leaves alone', () => {
expect(choice.shown.every(s => !noteOf(s))).toBe(true)
expect(choice.shown[0]!.machineId).toBe('alpha')
})
- it('a candidate whose fit is not known to cover the task: a 5-hour window that could not be read (review of f97c022)', () => {
- // Opus with only its weekly window read: the fit is unknown, and half off would put it above a Codex that fits.
- const unread = { ...opusMember('zulu', windows(null, [60, 12 * H], 'acct-soon')), kind: 'new' as const, agentId: undefined, name: undefined }
+ it('a candidate whose fit is not known to cover the task: a weekly window that could not be read (review of f97c022)', () => {
+ // Opus with only its 5-hour window read: the fit is unknown, and half off would put it above a Codex that fits.
+ const unread = { ...opusMember('zulu', windows([90, 12 * H], null, 'acct-soon')), kind: 'new' as const, agentId: undefined, name: undefined }
const choice = route([codex('alpha', FRESH), unread], [pull])
expect(choice.shown.find(s => s.machineId === 'zulu')!.fit.status).toBe('unknown')
expect(choice.shown[0]!.machineId).toBe('alpha')
expect(choice.shown.every(s => !noteOf(s))).toBe(true)
none(unread, { status: 'unknown' })
})
- it('but pulls a Codex account that reports its weekly window alone, a complete reading that fits', () => {
+ it('but pulls an account that reports its weekly window alone, Codex or Claude, a complete reading that fits', () => {
const weeklyOnly = codex('zulu', windows(null, [60, 12 * H], 'acct-soon'))
const choice = route([codex('alpha', FRESH), weeklyOnly], [pull])
expect(choice.shown[0]).toMatchObject({ machineId: 'zulu', fit: { status: 'fits' } })
expect(noteOf(choice.shown[0]!)).toBeDefined()
+ // A Team account's Claude, whose host relays no 5-hour window (Ken, 2026-11-03).
+ const claude = { ...opusMember('zulu', windows(null, [60, 12 * H], 'acct-soon')), kind: 'new' as const, agentId: undefined, name: undefined }
+ expect(route([codex('alpha', FRESH), claude], [pull]).shown.find(s => s.machineId === 'zulu')!.fit.status).toBe('fits')
})
it('a reading that says nothing of a weekly window about to reset', () => {
none(codex('zulu', { known: false, leftPercent: null, resetsAt: null, account: 'acct-soon' }))
diff --git a/cli/src/superTabs/windowPull.ts b/cli/src/superTabs/windowPull.ts
index c75788d7b..c644d9be6 100644
--- a/cli/src/superTabs/windowPull.ts
+++ b/cli/src/superTabs/windowPull.ts
@@ -55,10 +55,10 @@ const round = (n: number) => Math.round(n * 100) / 100
const inTime = (ms: number) => ms < 3_600_000 ? `${Math.max(1, Math.round(ms / 60_000))}m` : `${Math.round(ms / 3_600_000)}h`
/** The pull's word on one candidate: its price less up to half ([MAX_DISCOUNT]), by the part of the task its account's weekly
- * window would otherwise leave unused. Only on a candidate whose quota is known to carry the task (fit `fits`; a Codex
- * reading of its weekly window alone is complete, route.ts sizeUp): one that would run out partway trades wasted weekly
- * quota for a stalled task, and one whose 5-hour window could not be read (`unknown`) would, since price ranks before fit,
- * beat an account known to fit on half a reading (review of f97c022). The reason names the window, never the account or
+ * window would otherwise leave unused. Only on a candidate whose quota is known to carry the task (fit `fits`; a reading
+ * of its weekly window alone is complete on either engine, route.ts sizeUp): one that would run out partway trades wasted
+ * weekly quota for a stalled task, and one whose weekly window could not be read (`unknown`) would, since price ranks before
+ * fit, beat an account known to fit on half a reading (review of f97c022). The reason names the window, never the account or
* the machine a reading was relayed from, since every reader of the route log sees it. */
export function windowPullAdjust(p: Readonly<Probe & { fit: Fit }>, now: number, held: readonly Commitment[]): Adjustment | null {
if (p.fit.status !== 'fits' || p.fit.spend.weekly <= 0 || p.fit.effectiveCost <= 0) return null