Multiplayer agent harness for work.
sandbox: keep provider instance names within 63 chars (#2115)
Regan Bell9136bde79ea8
diff --git a/src/sandbox/exec-sandbox-base.ts b/src/sandbox/exec-sandbox-base.tsindex 6a88f5b07..e22e6ae55 100644--- a/src/sandbox/exec-sandbox-base.ts+++ b/src/sandbox/exec-sandbox-base.ts@@ -20,12 +20,26 @@ const RO_LAYERS_TAR = ".ro-layers.tar";const RO_LAYERS_MANIFEST = ".ro-layers.manifest";const PREP_TIMEOUT_SEC = 60;+// Provider instance names are DNS-style labels; Sprites rejects anything over 63 chars.+const MAX_SANDBOX_NAME = 63;+const HASH_LEN = 6;+export const sandboxScopeName = (prefix: string, id: string): string => {const cleaned = id.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");- return `${prefix}-${cleaned.slice(0, 40).replace(/-+$/, "") || "scope"}-${shortHash(id)}`;+ const name = `${prefix}-${cleaned.slice(0, 40).replace(/-+$/, "") || "scope"}-${shortHash(id)}`;+ // Names that already fit are kept byte-for-byte so existing computers stay addressable.+ if (name.length <= MAX_SANDBOX_NAME) return name;+ // Over budget (long deployment prefix, or prefix + "-scratch"): shorten the readable parts and+ // hash the full untruncated name so distinct prefixes/ids still map to distinct names.+ const hash = shortHash(name);+ const slugBudget = MAX_SANDBOX_NAME - prefix.length - HASH_LEN - 2;+ const slug = slugBudget > 0 ? cleaned.slice(0, slugBudget).replace(/-+$/, "") : "";+ if (slug) return `${prefix}-${slug}-${hash}`;+ const head = prefix.slice(0, MAX_SANDBOX_NAME - HASH_LEN - 1).replace(/-+$/, "");+ return head ? `${head}-${hash}` : hash;};export interface ExecSandboxBaseDeps {diff --git a/test/sprites-sandbox.test.ts b/test/sprites-sandbox.test.tsindex d481f0b54..340a8e3aa 100644--- a/test/sprites-sandbox.test.ts+++ b/test/sprites-sandbox.test.ts@@ -171,6 +171,28 @@ test("scope name is stable and slugged", () => {assert.match(a, /^qmt-person-tester-[0-9a-f]{6}$/);});+test("scope names fit the 63-char provider limit for long prefixes, scratch included", () => {+ const scope = "person:[email protected]";+ const ids = [scope, "conversation:9f8e7d6c-5b4a-3210-fedc-ba9876543210", "owner:" + scope, ""];+ for (const prefix of ["qm", "qm-long-generic-fleet-tenant-prefix", "x".repeat(70) + "-"]) {+ for (const p of [prefix, `${prefix}-scratch`]) {+ const names = ids.map((id) => sandboxScopeName(p, id));+ for (const n of names) {+ assert.ok(n.length <= 63, `${n} is ${n.length} chars`);+ assert.match(n, /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/);+ }+ assert.equal(new Set(names).size, names.length);+ }+ assert.notEqual(sandboxScopeName(prefix, scope), sandboxScopeName(`${prefix}-scratch`, scope));+ }+ // Names that already fit are unchanged, so existing resident computers keep their identity.+ assert.equal(sandboxScopeName("qmt", "person:tester"), "qmt-person-tester-7b537e");+ assert.match(+ sandboxScopeName("qm-long-generic-fleet-tenant-prefix", "person:tester"),+ /^qm-long-generic-fleet-tenant-prefix-person-tester-[0-9a-f]{6}$/,+ );+});+test("no egress force-through without a proxy url: no policy, no proxy env", async () => {assert.equal(sandbox.profile.egressEnforcement, "none");const h = await sandbox.provision(layers, { egressToken: "ignored" });