From 530a58c77b6a11d5823731395e9af58173133a15 Mon Sep 17 00:00:00 2001 From: Satya Patel <14907857+saddlepaddle@users.noreply.github.com> Date: Tue, 17 Nov 2026 03:09:35 +0000 Subject: [PATCH 1/4] feat(sandbox): ship OpenCode and Pi on the agents drive only Pinned upstream GitHub releases (opencode 1.19.5, pi 1.5.2), sha256 checked against the release digest. Their asset rows have no dest, so assets.tsv, sync-assets and the image skip them; the agent-tools builder fetches them from the bucket by sha. The login profile turns off their update checks. superset-boot: the dangling-link check used find -print | grep -q under pipefail, so with two or more dangling links find got SIGPIPE and the restore never ran. Add -quit, and delete links that have no image copy. --- docs/cloud-sandbox-mismatches.md | 11 +++- packages/sandbox/README.md | 8 ++- packages/sandbox/bundle/assets.json | 14 ++++ .../bundle/rootfs/etc/profile.d/superset.sh | 7 +- .../bundle/rootfs/usr/local/bin/superset-boot | 4 +- packages/sandbox/src/agent-tools.test.ts | 31 +++++++-- packages/sandbox/src/agent-tools.ts | 4 +- packages/sandbox/src/assets/produce.ts | 65 ++++++++++++++++++- packages/sandbox/src/boot-twice.ts | 20 ++++-- packages/sandbox/src/manifest.test.ts | 24 +++++++ packages/sandbox/src/manifest.ts | 27 ++++++-- 11 files changed, 190 insertions(+), 25 deletions(-) diff --git a/docs/cloud-sandbox-mismatches.md b/docs/cloud-sandbox-mismatches.md index 644e4a0f857..988674e3af3 100644 --- a/docs/cloud-sandbox-mismatches.md +++ b/docs/cloud-sandbox-mismatches.md @@ -930,7 +930,16 @@ sandbox gets one only from `Sandbox.create`, `Sandbox.fork` or and `wakeSandbox` both pass it. A drive lives in one region and mounts only in that region. A session without the mount leaves links in `/usr/local/bin` that point nowhere; `superset-boot` re-runs `install-agent-clis` to put the -image's agents back. +image's agents back. OpenCode and Pi exist only on the drive, so for them it +deletes the link instead. + +**An agent on the drive cannot update itself.** On a machine someone owns, +OpenCode and Pi update in place, beside their binary. On a box they run from +a read-only mount and are pinned by the bundle. `/etc/profile.d/superset.sh` +turns off their update checks (`OPENCODE_DISABLE_AUTOUPDATE`, +`PI_SKIP_VERSION_CHECK`), the same way `DISABLE_AUTOUPDATER` does for +Claude. They keep their state under `~/.local/share/opencode`, +`~/.config/opencode` and `~/.pi/agent`, as they do on a laptop. **A read-only snapshot mount taken while a writer holds the drive is corrupt.** Measured 2026-11-17: a box that mounted the snapshot while the builder still diff --git a/packages/sandbox/README.md b/packages/sandbox/README.md index 2fdb4b2c7ea..9cd3ca1090f 100644 --- a/packages/sandbox/README.md +++ b/packages/sandbox/README.md @@ -22,6 +22,11 @@ checklist is `plans/20260913-sandbox-implementation-checklist.md`. `sync-assets` does not fetch them again, and fetches them again only when the step has to re-run. A file the box runs in place (`claude`, `superset`) is never discarded. +- **An agent only the agents drive carries** (`opencode`, `pi`) is a row + with no `dest`. `assets.tsv` leaves it out, so neither the image nor a + boot fetches it; `bun run build --publish` still mirrors it to the bucket, + and `bun run agent-tools` fetches it from there by sha. A step cannot + declare such a row. - **Something the box has to execute to configure itself** is a step: `bundle/steps/.sh`, registered in `bundle/steps.json` with the assets it consumes, the rootfs files it reads (`inputs`) and the steps it must @@ -47,7 +52,7 @@ The rule of thumb: if you can answer "where is it on the box", put it there. | `bun run image` | Builds the image: OS, apt lists, vendor tools, the `ubuntu` user, then installs the bundle at its sha and runs every pass once, so a fresh box finds every hash sidecar and step marker matching. A push logs Docker into the registry itself with a credential minted from `VERCEL_SANDBOX_TOKEN`, so there is no login to renew. `--local` builds `superset-sandbox:local` for the boot-twice test; `--dry` prints the Dockerfile. | | boot (`superset-boot`) | On the box, as root, run by the control plane on every create and wake, after it has written `sandbox.conf`, with the host secret in its env: clears `/run/superset`, installs the pinned bundle if the hash differs, runs the three passes (each a hash compare), starts host-service as `ubuntu` with the secret from the boot env, writes `resources.env`, starts `superset-memguard` (ranks every process for the OOM killer and reaps the largest before the kernel has to), then the desktop and the checkout. Once host-service answers, the environment has been pushed and the checkout is in, the runner asks host-service to run the repo's `start` hook with that environment. | | `bun run release` | Rewrites the host-service and CLI assets from this checkout and the claude, codex and Chrome rows to their latest upstream release, publishes the bundle, pushes the image under a candidate tag `release-` (unless `--skip-image`), builds the internal golden from it with the environment's `setup` hook, probes a fork of it (`src/environments/probe.ts`) including a stop and wake, and only after the probe passes moves `latest` to the candidate and writes the environment rows. Every image environment resolves `superset-hostsvc` to `latest`, so a failed release changes no box. | -| `bun run agent-tools --bundle ` | Writes that bundle's agent CLIs to `agent-tools--`, a drive boxes mount read-only at `/opt/agents` when their organization has the `sandbox-agent-tools-drive` flag. A drive is written once and never again; it starts as a fork of the region's newest earlier drive, so only changed agents are fetched, and an agent that fails its download or `--version` check keeps the earlier drive's version or is left out. `bun run release` does this for every region with an environment, six at a time, before it records the bundle, and afterwards deletes the drives no environment names. | +| `bun run agent-tools --bundle ` | Writes that bundle's agent CLIs to `agent-tools--`, a drive boxes mount read-only at `/opt/agents` when their organization has the `sandbox-agent-tools-drive` flag. A drive is written once and never again; it starts as a fork of the region's newest earlier drive, so only changed agents are fetched, and an agent that fails its download or `--version` check keeps the earlier drive's version or is left out. The drive carries claude, codex and pdev (also in the image) and opencode and pi (only on the drive). `bun run release` does this for every region with an environment, six at a time, before it records the bundle, and afterwards deletes the drives no environment names. | | `bun run src/real-sandbox.ts` | The Sandbox workflow dispatched with `real-sandbox`: one real sandbox from the registry image on this checkout's bundle, the same probe, a stop and a wake. | | Sandbox workflow, `production-release` | `bun run release --production` from `main` on a CI runner: the image, the internal golden and production's environment rows. Runs on a merge that touches the bundle and every night; a failed merge or nightly run opens an issue, or comments on the open one. | @@ -83,6 +88,7 @@ image or a boot writes is paid for in every snapshot. - A step: `sha256(script + declared asset shas + declared input hashes + versions of steps it follows + salt)`. - The bundle: the sha256 of its tarball; the one pointer the box holds, written into `/etc/superset/sandbox.conf` by the control plane. - host-service, the CLI, claude, codex and Chrome move at release time, so their committed rows are only the floor a pull request's boot test uses. The other rows move only when someone runs `bun run assets`. + That includes opencode and pi: `bun run assets opencode ` and `bun run assets pi ` pin an upstream GitHub release and check its published sha256. The release does not follow their latest on purpose: a person bumps them after trying the new version. ## The runner in the image runs first diff --git a/packages/sandbox/bundle/assets.json b/packages/sandbox/bundle/assets.json index 177dce60011..4ec89e3808b 100644 --- a/packages/sandbox/bundle/assets.json +++ b/packages/sandbox/bundle/assets.json @@ -166,6 +166,13 @@ "version": "1.29.0+bfc1ec72a", "node": 24 }, + "opencode": { + "sha256": "588310a336fa3b9df36b3f0225b26f679d453efaad0cf3d66c3651ef3ec1647a", + "suffix": ".tar.gz", + "mode": "0644", + "source": "https://github.com/anomalyco/opencode/releases/download/v1.19.5/opencode-linux-x64.tar.gz", + "version": "1.19.5" + }, "pdev": { "sha256": "5a51852a4de0a40e20c0137b873f83e1b26255b4c5d01b6b0a2f608e152d8535", "suffix": ".tar.gz", @@ -174,6 +181,13 @@ "source": "https://github.com/ParadevAI/pdev/releases/download/v0.2.5/pdev-0.2.5-linux-x64.tar.gz", "version": "0.2.5" }, + "pi": { + "sha256": "811c6f2c9e7aaee252b5404252e556fb713aa209c1f7f924226aa77d4ef70cb5", + "suffix": ".tar.gz", + "mode": "0644", + "source": "https://github.com/earendil-works/pi/releases/download/v1.5.2/pi-linux-x64.tar.gz", + "version": "1.5.2" + }, "wallpaper-0": { "sha256": "497a4edb230a58ea385c8b63fe8135e47554cb4a5169de3f6bbae293a1f5435a", "suffix": ".jpg", diff --git a/packages/sandbox/bundle/rootfs/etc/profile.d/superset.sh b/packages/sandbox/bundle/rootfs/etc/profile.d/superset.sh index a2e27de7f73..6eae7dfec23 100644 --- a/packages/sandbox/bundle/rootfs/etc/profile.d/superset.sh +++ b/packages/sandbox/bundle/rootfs/etc/profile.d/superset.sh @@ -10,6 +10,7 @@ export DISPLAY="${DISPLAY:-${SUPERSET_DISPLAY:-:1}}" # The box's memory ceiling and CPUs, written by superset-boot from the cgroup. [ -r "${SUPERSET_RUN_DIR:-/run/superset}/resources.env" ] && . "${SUPERSET_RUN_DIR:-/run/superset}/resources.env" case ":$PATH:" in *":/usr/local/go/bin:"*) ;; *) export PATH="$PATH:/usr/local/go/bin" ;; esac -# The agent CLIs are pinned by the bundle (install-agent-clis); a self-update -# would drift from the pin and only prints a warning every session. -export DISABLE_AUTOUPDATER=1 +# The agent CLIs are pinned by the bundle (install-agent-clis) or run from the +# read-only agents drive; a self-update would drift from the pin and only +# prints a warning every session. +export DISABLE_AUTOUPDATER=1 OPENCODE_DISABLE_AUTOUPDATE=1 PI_SKIP_VERSION_CHECK=1 diff --git a/packages/sandbox/bundle/rootfs/usr/local/bin/superset-boot b/packages/sandbox/bundle/rootfs/usr/local/bin/superset-boot index 6dd3e6e2bfd..78d57a589e6 100755 --- a/packages/sandbox/bundle/rootfs/usr/local/bin/superset-boot +++ b/packages/sandbox/bundle/rootfs/usr/local/bin/superset-boot @@ -124,9 +124,11 @@ stamp "steps.start"; "$BUNDLE/setup" run-steps >> "$SUPERSET_BOOT_LOG" 2>&1; sta link_agents() { local dir="${SUPERSET_AGENTS_DIR:-/opt/agents}" linked=0 name sha bin target local manifest="${dir}/manifest.json" - if find /usr/local/bin -maxdepth 1 -lname "${dir}/*" ! -exec test -e {} \; -print | grep -q .; then + if find /usr/local/bin -maxdepth 1 -lname "${dir}/*" ! -exec test -e {} \; -print -quit | grep -q .; then SUPERSET_BUNDLE_DIR="$BUNDLE" bash "$BUNDLE/steps/install-agent-clis.sh" >> "$SUPERSET_BOOT_LOG" 2>&1 || stamp "agents.restore.failed" + # What is still dangling has no image copy to restore: opencode, pi. + find /usr/local/bin -maxdepth 1 -lname "${dir}/*" ! -exec test -e {} \; -delete fi if ! jq -e 'type == "array"' "$manifest" > /dev/null 2>&1; then stamp "agents.unavailable no manifest at ${dir}" diff --git a/packages/sandbox/src/agent-tools.test.ts b/packages/sandbox/src/agent-tools.test.ts index 7dac023edce..c8db13b598d 100644 --- a/packages/sandbox/src/agent-tools.test.ts +++ b/packages/sandbox/src/agent-tools.test.ts @@ -21,7 +21,7 @@ import { publishAgentToolsDrives, renderBuilderScript, } from "./agent-tools"; -import { type Assets, sha256 } from "./manifest"; +import { type Assets, loadAssets, sha256 } from "./manifest"; const sha = (c: string) => c.repeat(64); const BUNDLE = "0123456789abcdef".repeat(4); @@ -35,6 +35,8 @@ const agentAssets: Assets = { codex: row(sha("b"), ".tar.gz"), pdev: row(sha("c"), ".tar.gz"), chrome: row(sha("d"), ".deb"), + opencode: { sha256: sha("e"), suffix: ".tar.gz", mode: "0644" }, + pi: { sha256: sha("f"), suffix: ".tar.gz", mode: "0644" }, }; describe("agent-tools manifest", () => { @@ -44,10 +46,29 @@ describe("agent-tools manifest", () => { { name: "claude", sha: sha("a"), bin: "claude" }, { name: "codex", sha: sha("b"), bin: "bin/codex" }, { name: "pdev", sha: sha("c"), bin: "pdev/pdev" }, + { name: "opencode", sha: sha("e"), bin: "opencode" }, + { name: "pi", sha: sha("f"), bin: "pi/pi" }, ]); expect(parseAgentToolsManifest(JSON.stringify(manifest))).toEqual(manifest); }); + test("the committed bundle has a row for every agent, and opencode and pi only on the drive", () => { + const assets = loadAssets( + join(import.meta.dir, "..", "bundle", "assets.json"), + ); + expect(agentToolsManifest(assets).map((entry) => entry.name)).toEqual([ + "claude", + "codex", + "pdev", + "opencode", + "pi", + ]); + for (const name of ["opencode", "pi"]) { + expect(assets[name]?.dest).toBeUndefined(); + expect(assets[name]?.source).toStartWith("https://github.com/"); + } + }); + test("a missing or bad manifest reads as empty", () => { expect(parseAgentToolsManifest(null)).toEqual([]); expect(parseAgentToolsManifest("{not json")).toEqual([]); @@ -142,11 +163,9 @@ describe("publishAgentToolsDrive", () => { expect(result.drive).toBe(drive); expect(result.outcome).toBe("published"); expect(result.forkedFrom).toBeUndefined(); - expect(result.agents.map((agent) => agent.outcome)).toEqual([ - "written", - "written", - "written", - ]); + expect(result.agents.map((agent) => agent.outcome)).toEqual( + Array(5).fill("written"), + ); expect(calls).toEqual([`create ${drive}`, `write ${drive}`]); expect(agentLine(scripts[drive], "claude")).toEndWith("'' '' '--version'"); }); diff --git a/packages/sandbox/src/agent-tools.ts b/packages/sandbox/src/agent-tools.ts index 1c422daa7c8..2d94e54cdc6 100644 --- a/packages/sandbox/src/agent-tools.ts +++ b/packages/sandbox/src/agent-tools.ts @@ -41,6 +41,8 @@ export const AGENT_TOOLS: readonly AgentTool[] = [ { name: "claude", bin: "claude" }, { name: "codex", bin: "bin/codex" }, { name: "pdev", bin: "pdev/pdev" }, + { name: "opencode", bin: "opencode" }, + { name: "pi", bin: "pi/pi" }, ]; export interface AgentTool { @@ -411,7 +413,7 @@ export function describeAgentToolsPublish( ] : agent.outcome === "dropped" ? [ - `::warning::agent-tools: ${drive}: ${agent.name} left out; its boxes keep the image's ${agent.name}`, + `::warning::agent-tools: ${drive}: ${agent.name} left out; its boxes keep the image's ${agent.name}, if the image has one`, ] : [], ), diff --git a/packages/sandbox/src/assets/produce.ts b/packages/sandbox/src/assets/produce.ts index e1b319795aa..63cdb59caff 100644 --- a/packages/sandbox/src/assets/produce.ts +++ b/packages/sandbox/src/assets/produce.ts @@ -8,6 +8,8 @@ * bun run assets host-service the runtime tarball from this checkout * bun run assets claude [version] Claude Code's native binary (default: latest) * bun run assets codex [version] Codex's standalone package (default: latest) + * bun run assets opencode [version] OpenCode's linux-x64 release, drive only + * bun run assets pi [version] Pi's linux-x64 release, drive only * bun run assets all * * Each producer writes its files to .cache/assets/, then @@ -60,7 +62,9 @@ function rewriteRows(rows: Record): void { ); writeFileSync(ASSETS_JSON, `${JSON.stringify(sorted, null, "\t")}\n`); for (const [name, row] of Object.entries(rows)) - console.log(`${name}: ${assetObjectKey(row)} -> ${row.dest}`); + console.log( + `${name}: ${assetObjectKey(row)} -> ${row.dest ?? "agent-tools drive only"}`, + ); } async function fetchBytes(url: string): Promise { @@ -538,6 +542,63 @@ async function pdev(version?: string): Promise { }); } +/** + * An agent that boxes get only from the agent-tools drive: the row has no + * `dest`, so neither the image nor a boot fetches it. + */ +async function driveOnlyAgent(args: { + name: string; + repo: string; + asset: string; + version?: string; +}): Promise { + const tag = args.version ? `tags/v${args.version}` : "latest"; + const release = JSON.parse( + await fetchText( + `https://api.github.com/repos/${args.repo}/releases/${tag}`, + ), + ) as { + tag_name: string; + assets: { name: string; digest: string; browser_download_url: string }[]; + }; + const pinned = release.tag_name.replace(/^v/, ""); + const asset = release.assets.find((a) => a.name === args.asset); + if (!asset) throw new Error(`${args.name} ${pinned}: no ${args.asset}`); + const { sha256: hash } = cache( + await fetchBytes(asset.browser_download_url), + ".tar.gz", + ); + if (`sha256:${hash}` !== asset.digest) + throw new Error( + `${args.name} ${pinned}: sha256 ${hash}, release ${asset.digest}`, + ); + rewriteRows({ + [args.name]: { + sha256: hash, + suffix: ".tar.gz", + mode: "0644", + source: asset.browser_download_url, + version: pinned, + }, + }); +} + +const opencode = (version?: string) => + driveOnlyAgent({ + name: "opencode", + repo: "anomalyco/opencode", + asset: "opencode-linux-x64.tar.gz", + version, + }); + +const pi = (version?: string) => + driveOnlyAgent({ + name: "pi", + repo: "earendil-works/pi", + asset: "pi-linux-x64.tar.gz", + version, + }); + export const producers: Record< string, (version?: string) => Promise | void @@ -552,6 +613,8 @@ export const producers: Record< claude, codex, pdev, + opencode, + pi, }; if (import.meta.main) { diff --git a/packages/sandbox/src/boot-twice.ts b/packages/sandbox/src/boot-twice.ts index 97f3f54d857..e715c0d1c0a 100644 --- a/packages/sandbox/src/boot-twice.ts +++ b/packages/sandbox/src/boot-twice.ts @@ -358,14 +358,20 @@ try { const stubSha = "f".repeat(64); stop(); exec( - `: > ${SANDBOX_PATHS.bootLog}; mkdir -p ${SANDBOX_PATHS.agents}/claude/${stubSha} && printf '#!/bin/sh\\necho drive-claude\\n' > ${SANDBOX_PATHS.agents}/claude/${stubSha}/claude && chmod 755 ${SANDBOX_PATHS.agents}/claude/${stubSha}/claude && printf '%s' '${JSON.stringify([{ name: "claude", sha: stubSha, bin: "claude" }])}' > ${SANDBOX_PATHS.agents}/manifest.json`, + `: > ${SANDBOX_PATHS.bootLog}; for name in claude pi; do mkdir -p ${SANDBOX_PATHS.agents}/$name/${stubSha} && printf '#!/bin/sh\\necho drive-%s\\n' $name > ${SANDBOX_PATHS.agents}/$name/${stubSha}/$name && chmod 755 ${SANDBOX_PATHS.agents}/$name/${stubSha}/$name; done && printf '%s' '${JSON.stringify( + [ + { name: "claude", sha: stubSha, bin: "claude" }, + { name: "pi", sha: stubSha, bin: "pi" }, + ], + )}' > ${SANDBOX_PATHS.agents}/manifest.json`, ); boot(3); const logDrive = exec(`cat ${SANDBOX_PATHS.bootLog}`); expect( - "drive: listed agent linked", - /agents\.linked 1/.test(logDrive) && - /drive-claude/.test(exec("claude", { check: false, user: "ubuntu" })), + "drive: listed agents linked", + /agents\.linked 2/.test(logDrive) && + /drive-claude/.test(exec("claude", { check: false, user: "ubuntu" })) && + /drive-pi/.test(exec("pi", { check: false, user: "ubuntu" })), logDrive.match(/agents\..*/)?.[0], ); stop(); @@ -391,6 +397,12 @@ try { ), exec("readlink -f /usr/local/bin/claude", { check: false }).trim(), ); + expect( + "no drive: a drive-only agent's link is gone", + exec("test -L /usr/local/bin/pi && echo dangling", { + check: false, + }).trim() === "", + ); // Third boot, with host-service deliberately broken: the box must stay // alive, the desktop must still come up, and the log must say so. diff --git a/packages/sandbox/src/manifest.test.ts b/packages/sandbox/src/manifest.test.ts index 3880d324f74..07fc01a226d 100644 --- a/packages/sandbox/src/manifest.test.ts +++ b/packages/sandbox/src/manifest.test.ts @@ -140,6 +140,22 @@ describe("deriveStepVersions", () => { expect(build({ salt: "x" })[1]?.version).not.toBe(build({})[1]?.version); }); + test("refuses a step that consumes a drive-only row", () => { + const f = fixture(); + expect(() => + deriveStepVersions({ + steps: [ + { name: "one", assets: ["agent"], after: [], inputs: [], salt: "" }, + ], + assets: { + agent: { sha256: "d".repeat(64), suffix: ".tar.gz", mode: "0644" }, + }, + tools: walkRootfs(f.rootfs), + stepsDir: f.steps, + }), + ).toThrow(/drive-only/); + }); + test("refuses unknown assets, missing inputs and forward references", () => { const f = fixture(); const tools = walkRootfs(f.rootfs); @@ -227,6 +243,14 @@ describe("renderAssetsTsv", () => { ); }); + test("a drive-only row has no line, so no box fetches it", () => { + const tsv = renderAssetsTsv({ + ...assets, + agent: { sha256: "d".repeat(64), suffix: ".tar.gz", mode: "0644" }, + }); + expect(tsv).toBe(renderAssetsTsv(assets)); + }); + test("refuses a discard that is not the step's asset, or one two steps claim", () => { expect(() => discardingSteps([step("one", ["tool"], ["thing"])])).toThrow( /not one of its assets/, diff --git a/packages/sandbox/src/manifest.ts b/packages/sandbox/src/manifest.ts index b0ef395fa7c..82c599748f6 100644 --- a/packages/sandbox/src/manifest.ts +++ b/packages/sandbox/src/manifest.ts @@ -18,8 +18,11 @@ const assetSchema = z.object({ * Empty for an executable, which has none. */ suffix: z.string().regex(/^(\.[a-z0-9.]+)?$/), - /** Absolute path on the box. Archives are staged under the media dir. */ - dest: z.string().startsWith("/"), + /** + * Absolute path on the box. Archives are staged under the media dir. + * Absent for a drive-only row: no box fetches it, only the agent-tools drive. + */ + dest: z.string().startsWith("/").optional(), mode: z .string() .regex(/^0[0-7]{3}$/) @@ -123,17 +126,23 @@ export function discardingSteps(steps: Step[]): Map { return owners; } -/** The fifth column names the step that discards the row, empty for a row that stays. */ +/** + * The fifth column names the step that discards the row, empty for a row that + * stays. A drive-only row has no line: no box fetches it. + */ export function renderAssetsTsv(assets: Assets, steps: Step[] = []): string { const owners = discardingSteps(steps); - return Object.entries(assets) - .map(([key, a]) => - [a.mode, a.sha256, a.suffix, b64(a.dest), owners.get(key) ?? ""].join( + const rows = Object.entries(assets).flatMap(([key, a]) => + a.dest ? [{ key, ...a, dest: a.dest }] : [], + ); + return rows + .map((a) => + [a.mode, a.sha256, a.suffix, b64(a.dest), owners.get(a.key) ?? ""].join( "\t", ), ) .join("\n") - .concat(Object.keys(assets).length ? "\n" : ""); + .concat(rows.length ? "\n" : ""); } export interface DerivedStep extends Step { @@ -162,6 +171,10 @@ export function deriveStepVersions(args: { const asset = args.assets[key]; if (!asset) throw new Error(`step ${step.name} declares unknown asset ${key}`); + if (!asset.dest) + throw new Error( + `step ${step.name} declares ${key}, which is drive-only and never on the box`, + ); parts.push(`asset:${key}:${asset.sha256}`); } for (const input of step.inputs) { From 50ae7faad78a9c13547443bd985a1e844cbe5a6d Mon Sep 17 00:00:00 2001 From: Satya Patel <14907857+saddlepaddle@users.noreply.github.com> Date: Tue, 17 Nov 2026 03:16:35 +0000 Subject: [PATCH 2/4] feat(sandbox): move opencode and pi in the release, past a 3-day cooldown The release now bumps opencode and pi like claude and codex, but takes the highest stable vX.Y.Z GitHub release whose asset has been unchanged for AGENT_RELEASE_COOLDOWN_MS. A missing or mismatched GitHub digest refuses the bump and keeps the committed pin. Pin opencode at 2.3.0: GitHub's 'latest' for that repo still points at 1.19.5. --- packages/sandbox/README.md | 7 +- packages/sandbox/bundle/assets.json | 6 +- packages/sandbox/src/assets/produce.test.ts | 73 ++++++++++++++ packages/sandbox/src/assets/produce.ts | 101 +++++++++++++++---- packages/sandbox/src/environments/release.ts | 5 +- 5 files changed, 163 insertions(+), 29 deletions(-) create mode 100644 packages/sandbox/src/assets/produce.test.ts diff --git a/packages/sandbox/README.md b/packages/sandbox/README.md index 9cd3ca1090f..a96385fe728 100644 --- a/packages/sandbox/README.md +++ b/packages/sandbox/README.md @@ -51,7 +51,7 @@ The rule of thumb: if you can answer "where is it on the box", put it there. | `bun run build --publish` | Also uploads the bundle and any asset the bucket lacks, from the local cache or else its row's `source`, checked against the row's sha256. Refuses to publish a bundle that references an asset the bucket does not have. | | `bun run image` | Builds the image: OS, apt lists, vendor tools, the `ubuntu` user, then installs the bundle at its sha and runs every pass once, so a fresh box finds every hash sidecar and step marker matching. A push logs Docker into the registry itself with a credential minted from `VERCEL_SANDBOX_TOKEN`, so there is no login to renew. `--local` builds `superset-sandbox:local` for the boot-twice test; `--dry` prints the Dockerfile. | | boot (`superset-boot`) | On the box, as root, run by the control plane on every create and wake, after it has written `sandbox.conf`, with the host secret in its env: clears `/run/superset`, installs the pinned bundle if the hash differs, runs the three passes (each a hash compare), starts host-service as `ubuntu` with the secret from the boot env, writes `resources.env`, starts `superset-memguard` (ranks every process for the OOM killer and reaps the largest before the kernel has to), then the desktop and the checkout. Once host-service answers, the environment has been pushed and the checkout is in, the runner asks host-service to run the repo's `start` hook with that environment. | -| `bun run release` | Rewrites the host-service and CLI assets from this checkout and the claude, codex and Chrome rows to their latest upstream release, publishes the bundle, pushes the image under a candidate tag `release-` (unless `--skip-image`), builds the internal golden from it with the environment's `setup` hook, probes a fork of it (`src/environments/probe.ts`) including a stop and wake, and only after the probe passes moves `latest` to the candidate and writes the environment rows. Every image environment resolves `superset-hostsvc` to `latest`, so a failed release changes no box. | +| `bun run release` | Rewrites the host-service and CLI assets from this checkout, the claude, codex and Chrome rows to their latest upstream release and the opencode and pi rows to their newest release past the cooldown (see Versioning), publishes the bundle, pushes the image under a candidate tag `release-` (unless `--skip-image`), builds the internal golden from it with the environment's `setup` hook, probes a fork of it (`src/environments/probe.ts`) including a stop and wake, and only after the probe passes moves `latest` to the candidate and writes the environment rows. Every image environment resolves `superset-hostsvc` to `latest`, so a failed release changes no box. | | `bun run agent-tools --bundle ` | Writes that bundle's agent CLIs to `agent-tools--`, a drive boxes mount read-only at `/opt/agents` when their organization has the `sandbox-agent-tools-drive` flag. A drive is written once and never again; it starts as a fork of the region's newest earlier drive, so only changed agents are fetched, and an agent that fails its download or `--version` check keeps the earlier drive's version or is left out. The drive carries claude, codex and pdev (also in the image) and opencode and pi (only on the drive). `bun run release` does this for every region with an environment, six at a time, before it records the bundle, and afterwards deletes the drives no environment names. | | `bun run src/real-sandbox.ts` | The Sandbox workflow dispatched with `real-sandbox`: one real sandbox from the registry image on this checkout's bundle, the same probe, a stop and a wake. | | Sandbox workflow, `production-release` | `bun run release --production` from `main` on a CI runner: the image, the internal golden and production's environment rows. Runs on a merge that touches the bundle and every night; a failed merge or nightly run opens an issue, or comments on the open one. | @@ -87,8 +87,9 @@ image or a boot writes is paid for in every snapshot. - An asset: its sha256, same sidecar rule; it is also the object's name in the bucket. - A step: `sha256(script + declared asset shas + declared input hashes + versions of steps it follows + salt)`. - The bundle: the sha256 of its tarball; the one pointer the box holds, written into `/etc/superset/sandbox.conf` by the control plane. -- host-service, the CLI, claude, codex and Chrome move at release time, so their committed rows are only the floor a pull request's boot test uses. The other rows move only when someone runs `bun run assets`. - That includes opencode and pi: `bun run assets opencode ` and `bun run assets pi ` pin an upstream GitHub release and check its published sha256. The release does not follow their latest on purpose: a person bumps them after trying the new version. +- host-service, the CLI, claude, codex, Chrome, opencode and pi move at release time, so their committed rows are only the floor a pull request's boot test uses. The other rows move only when someone runs `bun run assets`. +- opencode and pi follow upstream with a cooldown. `bun run assets opencode` (or `pi`), which the release runs, takes the highest stable `vX.Y.Z` GitHub release whose asset has not changed for `AGENT_RELEASE_COOLDOWN_MS` (3 days); drafts and prereleases never count, and an asset replaced on an old release waits out the cooldown again. The bytes must match the sha256 digest GitHub publishes for that asset; a missing or different digest refuses the bump, and the release keeps the committed pin with a `::warning::`. A bump the agent-tools check rejects keeps the earlier drive's version of that agent. `bun run assets opencode ` pins a version by hand, without the cooldown but with the digest check. + The cooldown is what protects boxes from a compromised upstream release: it gives a compromised or broken release time to be found and pulled before boxes get it. Upstream's own minimum release age (`minimumReleaseAge` in OpenCode's `bunfig.toml`, `min-release-age` in Pi's `.npmrc`) covers only the dependencies they install, not the binaries they publish. claude, codex and Chrome do not have a cooldown yet. ## The runner in the image runs first diff --git a/packages/sandbox/bundle/assets.json b/packages/sandbox/bundle/assets.json index 4ec89e3808b..f387dc1eca7 100644 --- a/packages/sandbox/bundle/assets.json +++ b/packages/sandbox/bundle/assets.json @@ -167,11 +167,11 @@ "node": 24 }, "opencode": { - "sha256": "588310a336fa3b9df36b3f0225b26f679d453efaad0cf3d66c3651ef3ec1647a", + "sha256": "fc0f81522aceeabac47693d88389efa2bc517ce74c2c38fd6967819fcc6e4d3b", "suffix": ".tar.gz", "mode": "0644", - "source": "https://github.com/anomalyco/opencode/releases/download/v1.19.5/opencode-linux-x64.tar.gz", - "version": "1.19.5" + "source": "https://github.com/anomalyco/opencode/releases/download/v2.3.0/opencode-linux-x64.tar.gz", + "version": "2.3.0" }, "pdev": { "sha256": "5a51852a4de0a40e20c0137b873f83e1b26255b4c5d01b6b0a2f608e152d8535", diff --git a/packages/sandbox/src/assets/produce.test.ts b/packages/sandbox/src/assets/produce.test.ts new file mode 100644 index 00000000000..feed8bde8ff --- /dev/null +++ b/packages/sandbox/src/assets/produce.test.ts @@ -0,0 +1,73 @@ +import { describe, expect, test } from "bun:test"; +import { + AGENT_RELEASE_COOLDOWN_MS, + type GithubRelease, + pickCooledRelease, +} from "./produce"; + +const NOW = Date.parse("2026-11-17T00:00:00Z"); +const DAY = 24 * 60 * 60 * 1000; +const ASSET = "tool-linux-x64.tar.gz"; + +function release( + tag: string, + daysAgo: number, + overrides: Partial & { assetDaysAgo?: number } = {}, +): GithubRelease { + const { assetDaysAgo = daysAgo, ...rest } = overrides; + return { + tag_name: tag, + published_at: new Date(NOW - daysAgo * DAY).toISOString(), + draft: false, + prerelease: false, + assets: [ + { + name: ASSET, + digest: `sha256:${"a".repeat(64)}`, + browser_download_url: `https://example.invalid/${tag}/${ASSET}`, + updated_at: new Date(NOW - assetDaysAgo * DAY).toISOString(), + }, + ], + ...rest, + }; +} + +const pick = (releases: GithubRelease[]) => + pickCooledRelease(releases, ASSET, NOW)?.version; + +describe("pickCooledRelease", () => { + test("takes the highest version past the cooldown, not the newest or the one GitHub marks latest", () => { + expect(AGENT_RELEASE_COOLDOWN_MS).toBe(3 * DAY); + expect( + pick([ + release("v2.3.1", 1), + release("v2.3.0", 4), + release("v1.19.6", 3.5), + release("v2.2.9", 10), + ]), + ).toBe("2.3.0"); + }); + + test("skips drafts, prereleases, other tags and releases without the asset", () => { + expect( + pick([ + release("v3.0.0", 5, { draft: true }), + release("v2.9.0", 5, { prerelease: true }), + release("v2.8.0-rc.1", 5), + release("process-daemon-v9.0.0", 5), + release("v2.7.0", 5, { assets: [] }), + release("v2.6.0", 5), + ]), + ).toBe("2.6.0"); + }); + + test("an asset replaced on an old release waits out the cooldown again", () => { + expect( + pick([release("v2.0.0", 30, { assetDaysAgo: 1 }), release("v1.9.0", 30)]), + ).toBe("1.9.0"); + }); + + test("nothing past the cooldown picks nothing", () => { + expect(pick([release("v1.0.0", 2.9)])).toBeUndefined(); + }); +}); diff --git a/packages/sandbox/src/assets/produce.ts b/packages/sandbox/src/assets/produce.ts index 63cdb59caff..987ab488661 100644 --- a/packages/sandbox/src/assets/produce.ts +++ b/packages/sandbox/src/assets/produce.ts @@ -8,8 +8,8 @@ * bun run assets host-service the runtime tarball from this checkout * bun run assets claude [version] Claude Code's native binary (default: latest) * bun run assets codex [version] Codex's standalone package (default: latest) - * bun run assets opencode [version] OpenCode's linux-x64 release, drive only - * bun run assets pi [version] Pi's linux-x64 release, drive only + * bun run assets opencode [version] OpenCode's linux-x64 release, drive only (default: newest past the cooldown) + * bun run assets pi [version] Pi's linux-x64 release, drive only (default: newest past the cooldown) * bun run assets all * * Each producer writes its files to .cache/assets/, then @@ -542,9 +542,59 @@ async function pdev(version?: string): Promise { }); } +/** How old an upstream release must be before the release moves a drive-only agent to it. */ +export const AGENT_RELEASE_COOLDOWN_MS = 3 * 24 * 60 * 60 * 1000; + +export interface GithubRelease { + tag_name: string; + published_at: string | null; + draft: boolean; + prerelease: boolean; + assets: { + name: string; + digest?: string | null; + browser_download_url: string; + updated_at: string; + }[]; +} + +/** + * The highest stable `vX.Y.Z` release whose asset has been unchanged for the + * cooldown. An asset replaced on an old release counts from its replacement. + */ +export function pickCooledRelease( + releases: readonly GithubRelease[], + assetName: string, + now: number, + cooldownMs = AGENT_RELEASE_COOLDOWN_MS, +): { version: string; asset: GithubRelease["assets"][number] } | undefined { + return releases + .flatMap((release) => { + const asset = release.assets.find((a) => a.name === assetName); + if ( + release.draft || + release.prerelease || + !release.published_at || + !asset || + !/^v\d+\.\d+\.\d+$/.test(release.tag_name) + ) + return []; + const changed = Math.max( + Date.parse(release.published_at), + Date.parse(asset.updated_at), + ); + return changed <= now - cooldownMs + ? [{ version: release.tag_name.slice(1), asset }] + : []; + }) + .sort((a, b) => Bun.semver.order(b.version, a.version))[0]; +} + /** * An agent that boxes get only from the agent-tools drive: the row has no - * `dest`, so neither the image nor a boot fetches it. + * `dest`, so neither the image nor a boot fetches it. Without a version it + * takes the newest release past the cooldown; a version given by hand skips + * the cooldown. Either way the bytes must match GitHub's digest for the asset. */ async function driveOnlyAgent(args: { name: string; @@ -552,33 +602,42 @@ async function driveOnlyAgent(args: { asset: string; version?: string; }): Promise { - const tag = args.version ? `tags/v${args.version}` : "latest"; - const release = JSON.parse( - await fetchText( - `https://api.github.com/repos/${args.repo}/releases/${tag}`, - ), - ) as { - tag_name: string; - assets: { name: string; digest: string; browser_download_url: string }[]; - }; - const pinned = release.tag_name.replace(/^v/, ""); - const asset = release.assets.find((a) => a.name === args.asset); - if (!asset) throw new Error(`${args.name} ${pinned}: no ${args.asset}`); - const { sha256: hash } = cache( - await fetchBytes(asset.browser_download_url), - ".tar.gz", - ); + const api = `https://api.github.com/repos/${args.repo}/releases`; + const picked = args.version + ? { + version: args.version, + asset: ( + JSON.parse( + await fetchText(`${api}/tags/v${args.version}`), + ) as GithubRelease + ).assets.find((a) => a.name === args.asset), + } + : pickCooledRelease( + JSON.parse(await fetchText(`${api}?per_page=100`)) as GithubRelease[], + args.asset, + Date.now(), + ); + if (!picked?.asset) + throw new Error( + `${args.name}: no ${args.asset} ${args.version ? `in v${args.version}` : "in a stable release past the cooldown"}`, + ); + const { version, asset } = picked; + if (!asset.digest?.startsWith("sha256:")) + throw new Error(`${args.name} ${version}: GitHub publishes no digest`); + const bytes = await fetchBytes(asset.browser_download_url); + const hash = sha256(bytes); if (`sha256:${hash}` !== asset.digest) throw new Error( - `${args.name} ${pinned}: sha256 ${hash}, release ${asset.digest}`, + `${args.name} ${version}: sha256 ${hash}, release ${asset.digest}`, ); + cache(bytes, ".tar.gz"); rewriteRows({ [args.name]: { sha256: hash, suffix: ".tar.gz", mode: "0644", source: asset.browser_download_url, - version: pinned, + version, }, }); } diff --git a/packages/sandbox/src/environments/release.ts b/packages/sandbox/src/environments/release.ts index 72836cb16ee..42eb450aa9d 100644 --- a/packages/sandbox/src/environments/release.ts +++ b/packages/sandbox/src/environments/release.ts @@ -5,7 +5,8 @@ * * 1. the host-service runtime asset (this checkout's host-service and * pty-daemon, natives installed for the box), this checkout's CLI, the - * latest claude, codex and Chrome (a fetch that fails keeps the + * latest claude, codex and Chrome, the newest opencode and pi past + * their cooldown (a fetch or digest check that fails keeps the * committed pin) and the bundle, published * 2. the image in Vercel Container Registry under a candidate tag, unless * --skip-image; `latest`, which every image environment resolves to, @@ -60,7 +61,7 @@ process.env.SKIP_ENV_VALIDATION ??= "1"; const SKIP_IMAGE = process.argv.includes("--skip-image"); const KEEP_OLD = process.argv.includes("--keep-old"); const PRODUCTION = process.argv.includes("--production"); -const FOLLOWED_UPSTREAM = ["claude", "codex", "chrome"]; +const FOLLOWED_UPSTREAM = ["claude", "codex", "chrome", "opencode", "pi"]; /** The environment the release rebuilds; without it, the release creates one named INTERNAL_NAME. */ const ENVIRONMENT_ID = process.env.SUPERSET_INTERNAL_ENVIRONMENT_ID; const INTERNAL_NAME = From 72355bcd0a3ee73f0253565f22a8f5ba7542fae4 Mon Sep 17 00:00:00 2001 From: Satya Patel <14907857+saddlepaddle@users.noreply.github.com> Date: Tue, 17 Nov 2026 03:18:28 +0000 Subject: [PATCH 3/4] feat(sandbox): drop the opencode and pi release cooldown The release moves them to the newest stable upstream release, like claude and codex. They still skip drafts and prereleases, take the highest vX.Y.Z rather than GitHub's 'latest' marker, and refuse a bump whose bytes do not match GitHub's digest. --- packages/sandbox/README.md | 5 +- packages/sandbox/src/assets/produce.test.ts | 52 ++++++-------------- packages/sandbox/src/assets/produce.ts | 43 +++++----------- packages/sandbox/src/environments/release.ts | 5 +- 4 files changed, 32 insertions(+), 73 deletions(-) diff --git a/packages/sandbox/README.md b/packages/sandbox/README.md index a96385fe728..7eabd4efbd0 100644 --- a/packages/sandbox/README.md +++ b/packages/sandbox/README.md @@ -51,7 +51,7 @@ The rule of thumb: if you can answer "where is it on the box", put it there. | `bun run build --publish` | Also uploads the bundle and any asset the bucket lacks, from the local cache or else its row's `source`, checked against the row's sha256. Refuses to publish a bundle that references an asset the bucket does not have. | | `bun run image` | Builds the image: OS, apt lists, vendor tools, the `ubuntu` user, then installs the bundle at its sha and runs every pass once, so a fresh box finds every hash sidecar and step marker matching. A push logs Docker into the registry itself with a credential minted from `VERCEL_SANDBOX_TOKEN`, so there is no login to renew. `--local` builds `superset-sandbox:local` for the boot-twice test; `--dry` prints the Dockerfile. | | boot (`superset-boot`) | On the box, as root, run by the control plane on every create and wake, after it has written `sandbox.conf`, with the host secret in its env: clears `/run/superset`, installs the pinned bundle if the hash differs, runs the three passes (each a hash compare), starts host-service as `ubuntu` with the secret from the boot env, writes `resources.env`, starts `superset-memguard` (ranks every process for the OOM killer and reaps the largest before the kernel has to), then the desktop and the checkout. Once host-service answers, the environment has been pushed and the checkout is in, the runner asks host-service to run the repo's `start` hook with that environment. | -| `bun run release` | Rewrites the host-service and CLI assets from this checkout, the claude, codex and Chrome rows to their latest upstream release and the opencode and pi rows to their newest release past the cooldown (see Versioning), publishes the bundle, pushes the image under a candidate tag `release-` (unless `--skip-image`), builds the internal golden from it with the environment's `setup` hook, probes a fork of it (`src/environments/probe.ts`) including a stop and wake, and only after the probe passes moves `latest` to the candidate and writes the environment rows. Every image environment resolves `superset-hostsvc` to `latest`, so a failed release changes no box. | +| `bun run release` | Rewrites the host-service and CLI assets from this checkout and the claude, codex, Chrome, opencode and pi rows to their latest upstream release, publishes the bundle, pushes the image under a candidate tag `release-` (unless `--skip-image`), builds the internal golden from it with the environment's `setup` hook, probes a fork of it (`src/environments/probe.ts`) including a stop and wake, and only after the probe passes moves `latest` to the candidate and writes the environment rows. Every image environment resolves `superset-hostsvc` to `latest`, so a failed release changes no box. | | `bun run agent-tools --bundle ` | Writes that bundle's agent CLIs to `agent-tools--`, a drive boxes mount read-only at `/opt/agents` when their organization has the `sandbox-agent-tools-drive` flag. A drive is written once and never again; it starts as a fork of the region's newest earlier drive, so only changed agents are fetched, and an agent that fails its download or `--version` check keeps the earlier drive's version or is left out. The drive carries claude, codex and pdev (also in the image) and opencode and pi (only on the drive). `bun run release` does this for every region with an environment, six at a time, before it records the bundle, and afterwards deletes the drives no environment names. | | `bun run src/real-sandbox.ts` | The Sandbox workflow dispatched with `real-sandbox`: one real sandbox from the registry image on this checkout's bundle, the same probe, a stop and a wake. | | Sandbox workflow, `production-release` | `bun run release --production` from `main` on a CI runner: the image, the internal golden and production's environment rows. Runs on a merge that touches the bundle and every night; a failed merge or nightly run opens an issue, or comments on the open one. | @@ -88,8 +88,7 @@ image or a boot writes is paid for in every snapshot. - A step: `sha256(script + declared asset shas + declared input hashes + versions of steps it follows + salt)`. - The bundle: the sha256 of its tarball; the one pointer the box holds, written into `/etc/superset/sandbox.conf` by the control plane. - host-service, the CLI, claude, codex, Chrome, opencode and pi move at release time, so their committed rows are only the floor a pull request's boot test uses. The other rows move only when someone runs `bun run assets`. -- opencode and pi follow upstream with a cooldown. `bun run assets opencode` (or `pi`), which the release runs, takes the highest stable `vX.Y.Z` GitHub release whose asset has not changed for `AGENT_RELEASE_COOLDOWN_MS` (3 days); drafts and prereleases never count, and an asset replaced on an old release waits out the cooldown again. The bytes must match the sha256 digest GitHub publishes for that asset; a missing or different digest refuses the bump, and the release keeps the committed pin with a `::warning::`. A bump the agent-tools check rejects keeps the earlier drive's version of that agent. `bun run assets opencode ` pins a version by hand, without the cooldown but with the digest check. - The cooldown is what protects boxes from a compromised upstream release: it gives a compromised or broken release time to be found and pulled before boxes get it. Upstream's own minimum release age (`minimumReleaseAge` in OpenCode's `bunfig.toml`, `min-release-age` in Pi's `.npmrc`) covers only the dependencies they install, not the binaries they publish. claude, codex and Chrome do not have a cooldown yet. +- opencode and pi follow upstream like claude and codex, from GitHub releases. `bun run assets opencode` (or `pi`), which the release runs, takes the highest stable `vX.Y.Z` release that has the linux-x64 tarball, never a draft or prerelease, and not GitHub's `latest` marker, which for OpenCode names an older major line. The bytes must match the sha256 digest GitHub publishes for that asset; a missing or different digest refuses the bump, and the release keeps the committed pin with a `::warning::`. A version the agent-tools check rejects keeps the earlier drive's version of that agent. `bun run assets opencode ` pins a version by hand, with the same digest check. ## The runner in the image runs first diff --git a/packages/sandbox/src/assets/produce.test.ts b/packages/sandbox/src/assets/produce.test.ts index feed8bde8ff..ec2b2a62b64 100644 --- a/packages/sandbox/src/assets/produce.test.ts +++ b/packages/sandbox/src/assets/produce.test.ts @@ -1,23 +1,14 @@ import { describe, expect, test } from "bun:test"; -import { - AGENT_RELEASE_COOLDOWN_MS, - type GithubRelease, - pickCooledRelease, -} from "./produce"; +import { type GithubRelease, pickRelease } from "./produce"; -const NOW = Date.parse("2026-11-17T00:00:00Z"); -const DAY = 24 * 60 * 60 * 1000; const ASSET = "tool-linux-x64.tar.gz"; function release( tag: string, - daysAgo: number, - overrides: Partial & { assetDaysAgo?: number } = {}, + overrides: Partial = {}, ): GithubRelease { - const { assetDaysAgo = daysAgo, ...rest } = overrides; return { tag_name: tag, - published_at: new Date(NOW - daysAgo * DAY).toISOString(), draft: false, prerelease: false, assets: [ @@ -25,49 +16,36 @@ function release( name: ASSET, digest: `sha256:${"a".repeat(64)}`, browser_download_url: `https://example.invalid/${tag}/${ASSET}`, - updated_at: new Date(NOW - assetDaysAgo * DAY).toISOString(), }, ], - ...rest, + ...overrides, }; } const pick = (releases: GithubRelease[]) => - pickCooledRelease(releases, ASSET, NOW)?.version; + pickRelease(releases, ASSET)?.version; -describe("pickCooledRelease", () => { - test("takes the highest version past the cooldown, not the newest or the one GitHub marks latest", () => { - expect(AGENT_RELEASE_COOLDOWN_MS).toBe(3 * DAY); +describe("pickRelease", () => { + test("takes the highest version, not the first listed or an older line's newer patch", () => { expect( - pick([ - release("v2.3.1", 1), - release("v2.3.0", 4), - release("v1.19.6", 3.5), - release("v2.2.9", 10), - ]), + pick([release("v1.19.6"), release("v2.3.0"), release("v2.2.9")]), ).toBe("2.3.0"); }); test("skips drafts, prereleases, other tags and releases without the asset", () => { expect( pick([ - release("v3.0.0", 5, { draft: true }), - release("v2.9.0", 5, { prerelease: true }), - release("v2.8.0-rc.1", 5), - release("process-daemon-v9.0.0", 5), - release("v2.7.0", 5, { assets: [] }), - release("v2.6.0", 5), + release("v3.0.0", { draft: true }), + release("v2.9.0", { prerelease: true }), + release("v2.8.0-rc.1"), + release("process-daemon-v9.0.0"), + release("v2.7.0", { assets: [] }), + release("v2.6.0"), ]), ).toBe("2.6.0"); }); - test("an asset replaced on an old release waits out the cooldown again", () => { - expect( - pick([release("v2.0.0", 30, { assetDaysAgo: 1 }), release("v1.9.0", 30)]), - ).toBe("1.9.0"); - }); - - test("nothing past the cooldown picks nothing", () => { - expect(pick([release("v1.0.0", 2.9)])).toBeUndefined(); + test("no stable release picks nothing", () => { + expect(pick([release("v1.0.0", { prerelease: true })])).toBeUndefined(); }); }); diff --git a/packages/sandbox/src/assets/produce.ts b/packages/sandbox/src/assets/produce.ts index 987ab488661..fc17f99335f 100644 --- a/packages/sandbox/src/assets/produce.ts +++ b/packages/sandbox/src/assets/produce.ts @@ -8,8 +8,8 @@ * bun run assets host-service the runtime tarball from this checkout * bun run assets claude [version] Claude Code's native binary (default: latest) * bun run assets codex [version] Codex's standalone package (default: latest) - * bun run assets opencode [version] OpenCode's linux-x64 release, drive only (default: newest past the cooldown) - * bun run assets pi [version] Pi's linux-x64 release, drive only (default: newest past the cooldown) + * bun run assets opencode [version] OpenCode's linux-x64 release, drive only (default: newest stable) + * bun run assets pi [version] Pi's linux-x64 release, drive only (default: newest stable) * bun run assets all * * Each producer writes its files to .cache/assets/, then @@ -542,48 +542,32 @@ async function pdev(version?: string): Promise { }); } -/** How old an upstream release must be before the release moves a drive-only agent to it. */ -export const AGENT_RELEASE_COOLDOWN_MS = 3 * 24 * 60 * 60 * 1000; - export interface GithubRelease { tag_name: string; - published_at: string | null; draft: boolean; prerelease: boolean; assets: { name: string; digest?: string | null; browser_download_url: string; - updated_at: string; }[]; } /** - * The highest stable `vX.Y.Z` release whose asset has been unchanged for the - * cooldown. An asset replaced on an old release counts from its replacement. + * The highest stable `vX.Y.Z` release that carries the asset. Not GitHub's + * `latest`: OpenCode's still names an older major line. */ -export function pickCooledRelease( +export function pickRelease( releases: readonly GithubRelease[], assetName: string, - now: number, - cooldownMs = AGENT_RELEASE_COOLDOWN_MS, ): { version: string; asset: GithubRelease["assets"][number] } | undefined { return releases .flatMap((release) => { const asset = release.assets.find((a) => a.name === assetName); - if ( - release.draft || - release.prerelease || - !release.published_at || - !asset || - !/^v\d+\.\d+\.\d+$/.test(release.tag_name) - ) - return []; - const changed = Math.max( - Date.parse(release.published_at), - Date.parse(asset.updated_at), - ); - return changed <= now - cooldownMs + return !release.draft && + !release.prerelease && + asset && + /^v\d+\.\d+\.\d+$/.test(release.tag_name) ? [{ version: release.tag_name.slice(1), asset }] : []; }) @@ -593,8 +577,8 @@ export function pickCooledRelease( /** * An agent that boxes get only from the agent-tools drive: the row has no * `dest`, so neither the image nor a boot fetches it. Without a version it - * takes the newest release past the cooldown; a version given by hand skips - * the cooldown. Either way the bytes must match GitHub's digest for the asset. + * takes the newest stable release. The bytes must match GitHub's digest for + * the asset. */ async function driveOnlyAgent(args: { name: string; @@ -612,14 +596,13 @@ async function driveOnlyAgent(args: { ) as GithubRelease ).assets.find((a) => a.name === args.asset), } - : pickCooledRelease( + : pickRelease( JSON.parse(await fetchText(`${api}?per_page=100`)) as GithubRelease[], args.asset, - Date.now(), ); if (!picked?.asset) throw new Error( - `${args.name}: no ${args.asset} ${args.version ? `in v${args.version}` : "in a stable release past the cooldown"}`, + `${args.name}: no ${args.asset} ${args.version ? `in v${args.version}` : "in a stable release"}`, ); const { version, asset } = picked; if (!asset.digest?.startsWith("sha256:")) diff --git a/packages/sandbox/src/environments/release.ts b/packages/sandbox/src/environments/release.ts index 42eb450aa9d..23c65bef6db 100644 --- a/packages/sandbox/src/environments/release.ts +++ b/packages/sandbox/src/environments/release.ts @@ -5,9 +5,8 @@ * * 1. the host-service runtime asset (this checkout's host-service and * pty-daemon, natives installed for the box), this checkout's CLI, the - * latest claude, codex and Chrome, the newest opencode and pi past - * their cooldown (a fetch or digest check that fails keeps the - * committed pin) and the bundle, published + * latest claude, codex, Chrome, opencode and pi (a fetch or digest + * check that fails keeps the committed pin) and the bundle, published * 2. the image in Vercel Container Registry under a candidate tag, unless * --skip-image; `latest`, which every image environment resolves to, * stays on the previous release From 09226d687c81e9c90402829ec36e1677471d6ef5 Mon Sep 17 00:00:00 2001 From: Satya Patel <14907857+saddlepaddle@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:45:11 +0000 Subject: [PATCH 4/4] fix(sandbox): put drive-only pins in the bundle hash A nightly bump of only opencode or pi left the bundle sha, and so the drive name, unchanged, so the release reused the old drive. The pins now go into drive-assets.tsv, which no box reads; assets.tsv and step versions are unchanged. --- packages/sandbox/README.md | 5 +++-- packages/sandbox/src/build.test.ts | 22 ++++++++++++++++++++++ packages/sandbox/src/build.ts | 24 ++++++++++++++++-------- packages/sandbox/src/manifest.ts | 8 ++++++++ 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 packages/sandbox/src/build.test.ts diff --git a/packages/sandbox/README.md b/packages/sandbox/README.md index 7eabd4efbd0..cbb3c63f7d8 100644 --- a/packages/sandbox/README.md +++ b/packages/sandbox/README.md @@ -25,8 +25,9 @@ checklist is `plans/20260913-sandbox-implementation-checklist.md`. - **An agent only the agents drive carries** (`opencode`, `pi`) is a row with no `dest`. `assets.tsv` leaves it out, so neither the image nor a boot fetches it; `bun run build --publish` still mirrors it to the bucket, - and `bun run agent-tools` fetches it from there by sha. A step cannot - declare such a row. + and `bun run agent-tools` fetches it from there by sha. Its pin goes into + the bundle's `drive-assets.tsv`, which no box reads, so a bump alone still + names a new bundle and so a new drive. A step cannot declare such a row. - **Something the box has to execute to configure itself** is a step: `bundle/steps/.sh`, registered in `bundle/steps.json` with the assets it consumes, the rootfs files it reads (`inputs`) and the steps it must diff --git a/packages/sandbox/src/build.test.ts b/packages/sandbox/src/build.test.ts new file mode 100644 index 00000000000..acd0f9bc611 --- /dev/null +++ b/packages/sandbox/src/build.test.ts @@ -0,0 +1,22 @@ +import { afterAll, expect, test } from "bun:test"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { BUNDLE_SRC, buildBundle } from "./build"; +import { loadAssets } from "./manifest"; + +const dist = mkdtempSync(join(tmpdir(), "bundle-")); +afterAll(() => rmSync(dist, { recursive: true, force: true })); + +test("a drive-only pin change names a new bundle and re-runs no step", () => { + const assets = loadAssets(join(BUNDLE_SRC, "assets.json")); + const before = buildBundle(assets, dist); + const opencode = assets.opencode; + if (!opencode) throw new Error("assets.json has no opencode row"); + const after = buildBundle( + { ...assets, opencode: { ...opencode, sha256: "0".repeat(64) } }, + dist, + ); + expect(after.sha256).not.toBe(before.sha256); + expect(after.steps).toEqual(before.steps); +}); diff --git a/packages/sandbox/src/build.ts b/packages/sandbox/src/build.ts index 9e1d61d6ccc..02101fe5be4 100644 --- a/packages/sandbox/src/build.ts +++ b/packages/sandbox/src/build.ts @@ -5,6 +5,7 @@ * setup, steps/, rootfs/ copied * rootfs/etc/superset/contract.sh rendered from @superset/shared/sandbox/contract * tools.tsv, assets.tsv, steps.tsv derived + * drive-assets.tsv the drive-only pins; hashed, never read on the box * dist/bundle.tar.gz the same tree, named by its sha in the bucket * * bun run build.ts build only; prints the bundle sha @@ -36,6 +37,7 @@ import { loadAssets, loadSteps, renderAssetsTsv, + renderDriveAssetsTsv, renderStepsTsv, renderToolsTsv, sha256, @@ -58,8 +60,11 @@ export interface BuiltBundle { steps: DerivedStep[]; } -export function buildBundle(): BuiltBundle { - const staging = join(DIST, "staging"); +export function buildBundle( + assets: Assets = loadAssets(join(BUNDLE_SRC, "assets.json")), + dist = DIST, +): BuiltBundle { + const staging = join(dist, "staging"); rmSync(staging, { recursive: true, force: true }); mkdirSync(staging, { recursive: true }); cpSync(join(BUNDLE_SRC, "setup"), join(staging, "setup")); @@ -75,7 +80,6 @@ export function buildBundle(): BuiltBundle { renderContractShell(), ); - const assets = loadAssets(join(BUNDLE_SRC, "assets.json")); const tools = walkRootfs(join(staging, "rootfs")); const declaredSteps = loadSteps(join(BUNDLE_SRC, "steps.json")); const steps = deriveStepVersions({ @@ -90,19 +94,23 @@ export function buildBundle(): BuiltBundle { renderAssetsTsv(assets, declaredSteps), ); writeFileSync(join(staging, "steps.tsv"), renderStepsTsv(steps)); + writeFileSync( + join(staging, "drive-assets.tsv"), + renderDriveAssetsTsv(assets), + ); // A reproducible tarball, written here rather than by the system tar so the // sha is the tree's on every machine. - const tarball = join(DIST, "bundle.tar.gz"); + const tarball = join(dist, "bundle.tar.gz"); const bytes = tarGzDirectory(staging); writeFileSync(tarball, bytes); const hash = sha256(bytes); - const dir = join(DIST, "bundle", hash); - rmSync(join(DIST, "bundle"), { recursive: true, force: true }); - mkdirSync(join(DIST, "bundle"), { recursive: true }); + const dir = join(dist, "bundle", hash); + rmSync(join(dist, "bundle"), { recursive: true, force: true }); + mkdirSync(join(dist, "bundle"), { recursive: true }); cpSync(staging, dir, { recursive: true }); rmSync(staging, { recursive: true, force: true }); - writeFileSync(join(DIST, "bundle.sha256"), `${hash}\n`); + writeFileSync(join(dist, "bundle.sha256"), `${hash}\n`); return { sha256: hash, dir, tarball, assets, steps }; } diff --git a/packages/sandbox/src/manifest.ts b/packages/sandbox/src/manifest.ts index 82c599748f6..6e84751452b 100644 --- a/packages/sandbox/src/manifest.ts +++ b/packages/sandbox/src/manifest.ts @@ -145,6 +145,14 @@ export function renderAssetsTsv(assets: Assets, steps: Step[] = []): string { .concat(rows.length ? "\n" : ""); } +/** Puts the drive-only pins in the bundle's hash, so a bump names a new drive. No box reads it. */ +export function renderDriveAssetsTsv(assets: Assets): string { + return Object.entries(assets) + .filter(([, a]) => !a.dest) + .map(([key, a]) => `${key}\t${a.sha256}\n`) + .join(""); +} + export interface DerivedStep extends Step { version: string; }