Multiplayer agent harness for work.
Remove artificial swarm setting maximums (#2141)
Joshua France1ecb06c5dd1a
diff --git a/docs/swarms.md b/docs/swarms.mdindex 16d955b7c..dd6d1285d 100644--- a/docs/swarms.md+++ b/docs/swarms.md@@ -218,22 +218,22 @@ Resume, and Stop; and Pause all, Resume all, and Stop all (with a confirm), whicapply this action to the root's direct children so it cascades. The striprefreshes every few seconds only while workers are active and the tab is visible.-## Defaults and safety bounds--| Setting | Default | Maximum |-| ------------------------------------------------ | -------------------- | ----------- |-| `agents` (root and failed reservations included) | 32 | 256 |-| `depth` below root | 4 | 8 |-| `spawnRequests` | 32 | 64 |-| `messages` including initial work | 128 | 256 |-| `notifications` including initial work | 256 | 1,024 |-| `contextBytes` / `textBytes` | 8,192 each | 16,384 each |-| `lifetimeMs` from first spawn | 3,600,000 | 86,400,000 |-| `turnMs` per notification | 600,000 (10 minutes) | 3,600,000 |-| `waitMs` per read | 10,000 | 30,000 |+## Defaults++| Setting | Default |+| ------------------------------------------------ | -------------------- |+| `agents` (root and failed reservations included) | 32 |+| `depth` below root | 4 |+| `spawnRequests` | 32 |+| `messages` including initial work | 128 |+| `notifications` including initial work | 256 |+| `contextBytes` / `textBytes` | 8,192 each |+| `lifetimeMs` from first spawn | 3,600,000 |+| `turnMs` per notification | 600,000 (10 minutes) |+| `waitMs` per read | 10,000 |The root and at least one worker require `agents >= 2`. All other settings accept-positive integers up to their maximum. Read requests can still use `waitMs:0`.+any positive integer; `turnMs` is limited only by the 2,147,483,647 ms timer ceiling. Read requests can still use `waitMs:0`.Per-swarm budgets are reserved atomically with the messages and members consumingthem. Both the orchestrator and independent worker cancellation honor the storedturn deadline; existing organization-wide limits can shorten it. Internal reconciliation limits, the 32-message read page, anddiff --git a/src/swarms/swarm-settings.ts b/src/swarms/swarm-settings.tsindex 17440768c..5d387924b 100644--- a/src/swarms/swarm-settings.ts+++ b/src/swarms/swarm-settings.ts@@ -13,18 +13,7 @@ export const SWARM_DEFAULTS = {export type SwarmSettings = typeof SWARM_DEFAULTS;-export const SWARM_MAXIMUMS: Readonly<SwarmSettings> = {- agents: 256,- depth: 8,- messages: 256,- notifications: 1_024,- spawnRequests: 64,- contextBytes: 16_384,- textBytes: 16_384,- waitMs: 30_000,- turnMs: 3_600_000,- lifetimeMs: 86_400_000,-};+const MAX_TIMER_MS = 2_147_483_647;export function resolveSwarmSettings(input: unknown = {}, defaults: SwarmSettings = SWARM_DEFAULTS): SwarmSettings {if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("invalid swarm settings");@@ -34,7 +23,7 @@ export function resolveSwarmSettings(input: unknown = {}, defaults: SwarmSettingconst settings = { ...defaults, ...input };for (const key of Object.keys(SWARM_DEFAULTS) as Array<keyof SwarmSettings>) {const value = settings[key];- if (!Number.isSafeInteger(value) || value < 1 || value > SWARM_MAXIMUMS[key])+ if (!Number.isSafeInteger(value) || value < 1 || (key === "turnMs" && value > MAX_TIMER_MS))throw new Error(`invalid swarm setting: ${key}`);}if (settings.agents < 2) throw new Error("swarm settings must allow the root and a worker");diff --git a/test/swarm-settings.test.ts b/test/swarm-settings.test.tsindex 714c36f4f..8fddbaf8a 100644--- a/test/swarm-settings.test.ts+++ b/test/swarm-settings.test.ts@@ -2,7 +2,7 @@ import { test } from "node:test";import assert from "node:assert/strict";import { loadConfig } from "../src/config.ts";import { createSwarmService } from "../src/swarms/swarm-service.ts";-import { resolveSwarmSettings, SWARM_DEFAULTS, SWARM_MAXIMUMS } from "../src/swarms/swarm-settings.ts";+import { resolveSwarmSettings, SWARM_DEFAULTS } from "../src/swarms/swarm-settings.ts";import { processRun } from "../src/runs/worker.ts";import type { Orchestrator } from "../src/core/orchestrator.ts";import { swarmFixture } from "./support/swarm-fixture.ts";@@ -17,9 +17,12 @@ test("backend defaults validate every setting and preserve unspecified defaults"for (const settings of ["null", "[]", '"wrong"', '{"surprise":1}', '{"turnMs":0}', "{"])assert.throws(() => loadConfig({ SWARM_DEFAULTS: settings }));for (const key of Object.keys(SWARM_DEFAULTS) as Array<keyof typeof SWARM_DEFAULTS>) {- for (const value of [0, -1, 1.5, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1, SWARM_MAXIMUMS[key] + 1])+ for (const value of [0, -1, 1.5, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1])assert.throws(() => resolveSwarmSettings({ [key]: value }), new RegExp(key));}+ assert.throws(() => resolveSwarmSettings({ turnMs: 2_147_483_648 }), /turnMs/);+ const large = { agents: 10_000, depth: 100, messages: 100_000, lifetimeMs: 30 * 86_400_000, turnMs: 2_147_483_647 };+ assert.deepEqual(resolveSwarmSettings(large), { ...SWARM_DEFAULTS, ...large });});test("resolved defaults, initial overrides, children, and restarted services share one immutable settings contract", async () => {