Multiplayer agent harness for work.
fix(superserve): increase default sandbox resources (#1415)
Pavitra Bhalla5a5cb51260b1
diff --git a/docs/superserve.md b/docs/superserve.mdindex b7b35b1fb..dc4d9f767 100644--- a/docs/superserve.md+++ b/docs/superserve.md@@ -41,6 +41,15 @@ database requirements apply.For local development, export the key and template and run`npm run dev-instance -- --sandbox superserve`.+## Sandbox capacity++Sandboxes inherit CPU, memory, and disk capacity from their template. The agent+template builder defaults to 8 vCPUs, 16384 MiB (16 GiB) memory, and 32768 MiB+(32 GiB) disk. Override these with `--vcpu`, `--memory-mib`, and `--disk-mib` at+build time; there are no runtime resource-size settings. Existing sandboxes are+not resized by updating QM or rebuilding a template. Follow the [capacity rollout steps](../superserve/templates/README.md#increase-sandbox-capacity)+to build and verify a new template, preserve resident work, and replace sandboxes.+## Settings| Variable | Default | Purpose |diff --git a/superserve/templates/README.md b/superserve/templates/README.mdindex 2b4c6cf20..78809d5f2 100644--- a/superserve/templates/README.md+++ b/superserve/templates/README.md@@ -19,8 +19,11 @@ to `SUPERSERVE_HOME_DIR` (default `/root`) and uses `<home>/workspace`.Deployment tools and skills are installed during provisioning. The optionalbrowser engine is not included.-The default Superserve sandbox has 2 vCPUs, 2048 MiB memory, and 8192 MiB disk. Override these with-`--vcpu`, `--memory-mib`, and `--disk-mib` when building.+The default Superserve sandbox has 8 vCPUs, 16384 MiB (16 GiB) memory, and+32768 MiB (32 GiB) disk. The disk includes the OS and toolchain as well as workspace files,+dependencies, package caches, and build output. Override these with `--vcpu`,+`--memory-mib`, and `--disk-mib` when building. CPU, memory, and disk capacity are set+on the template, not at sandbox creation.## Build@@ -44,6 +47,32 @@ Rebuilding under the same name does not update existing sandboxes. Changing`SUPERSERVE_TEMPLATE` to a different name replaces them and deletes their residentfiles. Export needed files first; see [updates and retention](../../docs/superserve.md#updates-and-retention).+## Increase sandbox capacity++Existing templates and sandboxes keep their original capacity when these defaults+change. Passing `--vcpu`, `--memory-mib`, or `--disk-mib` with an already-ready+template name also reuses that template without resizing it.++To roll out larger sandboxes:++1. Pause ongoing jobs, commit and push source changes to Git, and export other+ needed resident files before replacing sandboxes.+2. Build under a new template name, for example:+ `node superserve/templates/qm-agent.ts --release 0.1.0-8cpu-16ram-32disk --vcpu 8 --memory-mib 16384 --disk-mib 32768 --wait`.+3. Verify it with+ `node superserve/templates/verify-qm-agent.ts --template qm-agent-0.1.0-8cpu-16ram-32disk`.+4. Set `SUPERSERVE_TEMPLATE=qm-agent-0.1.0-8cpu-16ram-32disk` on core and deploy. This replaces+ existing scope sandboxes on use and deletes their old resident files; it does+ not resize them in place. Restore exported work into the new sandboxes.+5. Check `nproc`, `free -h`, and `df -h /root/workspace` in a new sandbox, then+ rerun representative builds and full typechecking before resuming heavy jobs.++Use your deployment's release tag in place of `0.1.0`. A distinct suffix keeps the+old template available during verification. `--force` rebuilds a same-name+template but does not upgrade existing sandboxes. Confirm the requested shape is supported and allow+for the increased CPU, memory, and storage in provider quotas and costs before+rollout.+## Verify```shdiff --git a/superserve/templates/qm-agent.ts b/superserve/templates/qm-agent.tsindex cb1d79a6d..498792439 100644--- a/superserve/templates/qm-agent.ts+++ b/superserve/templates/qm-agent.ts@@ -23,9 +23,9 @@ const NODE_SHA256_X64 = "55aa7153f9d88f28d765fcdad5ae6945b5c0f98a36881703817e4c4const AGENT_VENV = "/opt/agent-venv";const BASE_IMAGE = "ubuntu:24.04";-const DEFAULT_VCPU = 2;-const DEFAULT_MEMORY_MIB = 2048;-const DEFAULT_DISK_MIB = 8192;+const DEFAULT_VCPU = 8;+const DEFAULT_MEMORY_MIB = 16384;+const DEFAULT_DISK_MIB = 32768;const APT_PACKAGES = ["bash",diff --git a/test/superserve-template.test.ts b/test/superserve-template.test.tsnew file mode 100644index 000000000..6b840f3f7--- /dev/null+++ b/test/superserve-template.test.ts@@ -0,0 +1,99 @@+import assert from "node:assert/strict";+import { execFile } from "node:child_process";+import { once } from "node:events";+import { createServer } from "node:http";+import { test, type TestContext } from "node:test";+import { promisify } from "node:util";++const TEMPLATE = {+ id: "test-template",+ name: "qm-agent-test",+ team_id: "test-team",+ status: "ready",+ vcpu: 2,+ memory_mib: 2048,+ disk_mib: 8192,+ created_at: "2026-01-01T00:00:00Z",+};++async function builder(t: TestContext, existing = false) {+ const requests: { method: string; path: string; body: Record<string, unknown> }[] = [];+ const server = createServer(async (req, res) => {+ let body = "";+ for await (const chunk of req) body += chunk;+ const path = new URL(req.url!, "http://localhost").pathname;+ requests.push({ method: req.method!, path, body: body ? JSON.parse(body) : {} });+ res.setHeader("content-type", "application/json");+ if (req.method === "GET" && path === "/templates") {+ res.end(JSON.stringify(existing ? [TEMPLATE] : []));+ } else if (req.method === "GET" && path === `/templates/${TEMPLATE.id}`) {+ res.end(JSON.stringify(TEMPLATE));+ } else if (req.method === "POST" && path === "/templates") {+ res.end(JSON.stringify({ ...TEMPLATE, status: "pending", build_id: "test-build" }));+ } else {+ res.statusCode = 400;+ res.end(JSON.stringify({ error: { message: "Unexpected request" } }));+ }+ });+ server.listen(0, "127.0.0.1");+ await once(server, "listening");+ t.after(() => new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve()))));+ const address = server.address();+ assert.ok(address && typeof address === "object");+ return {+ requests,+ run: (...args: string[]) =>+ promisify(execFile)(process.execPath, ["superserve/templates/qm-agent.ts", "--release", "test", ...args], {+ cwd: new URL("../", import.meta.url),+ env: {+ ...process.env,+ SUPERSERVE_API_KEY: "test-api-key",+ SUPERSERVE_BASE_URL: `http://127.0.0.1:${address.port}`,+ },+ timeout: 10_000,+ }),+ };+}++test("agent template defaults to 8 vCPUs, 16 GiB memory, and 32 GiB disk", async (t) => {+ const b = await builder(t);+ await b.run();+ const creates = b.requests.filter((r) => r.method === "POST");+ assert.equal(creates.length, 1);+ assert.equal(creates[0]!.body.disk_mib, 32768);+ assert.equal(creates[0]!.body.vcpu, 8);+ assert.equal(creates[0]!.body.memory_mib, 16384);+});++for (const { flag, field, values } of [+ { flag: "vcpu", field: "vcpu", values: [2, 16] },+ { flag: "memory-mib", field: "memory_mib", values: [2048, 32768] },+ { flag: "disk-mib", field: "disk_mib", values: [8192, 65536] },+]) {+ for (const value of values) {+ test(`agent template honors --${flag} ${value}`, async (t) => {+ const b = await builder(t);+ await b.run(`--${flag}`, String(value));+ const creates = b.requests.filter((r) => r.method === "POST");+ assert.equal(creates.length, 1);+ const { vcpu, memory_mib, disk_mib } = creates[0]!.body;+ assert.deepEqual({ vcpu, memory_mib, disk_mib }, { vcpu: 8, memory_mib: 16384, disk_mib: 32768, [field]: value });+ });+ }++ for (const value of ["0", "-1", "1.5", "invalid"]) {+ test(`agent template rejects --${flag}=${value} before contacting the API`, async (t) => {+ const b = await builder(t);+ await assert.rejects(b.run(`--${flag}=${value}`), new RegExp(`--${flag} must be a positive integer`));+ assert.deepEqual(b.requests, []);+ });+ }+}++test("a ready template is reused without resizing or deleting it", async (t) => {+ const b = await builder(t, true);+ const result = await b.run("--vcpu", "8", "--memory-mib", "16384", "--disk-mib", "32768");+ assert.match(result.stdout, /already ready/);+ assert.match(result.stdout, /shape=2vcpu\/2048MiB\/8192MiB/);+ assert.ok(b.requests.every((r) => r.method === "GET"));+});