Skip to content

feat(sandbox): node-level uploader that fills the shared golden store - #5843

Merged
nicacioliveira merged 2 commits into
mainfrom
feat/sandbox-golden-uploader
Aug 10, 2026
Merged

nicacioliveira merged 2 commits into
mainfrom
feat/sandbox-golden-uploader

Conversation

@nicacioliveira

@nicacioliveira nicacioliveira commented Aug 7, 2026 •

Copy link
Copy Markdown

Stacked on #5824 — that PR adds the L2 restore; this one adds the publish. Base is its branch, so the diff here is only this change and GitHub will retarget to main when #5824 merges.

Neither is useful alone: #5824 restores from a store nothing fills, and this fills a store nothing reads. Merge both or neither.

The gap this closes

A sandbox pod's L2 mount is read-only by design, so nothing a tenant boots can publish. The store is therefore permanently empty, and #5824's restore always misses. This is the missing half.

Why a DaemonSet and not a sidecar

Writing a store shared across nodes needs write access, and a sandbox runs untrusted code — a package manager installs cached content as-is, so a tenant able to write it could poison another node's boot. The tenant's write path stops at its own node's hostPath, which is already the accepted trust domain there (depsCache's own comment: "Do NOT widen to a shared cache without making it read-only to tenant pods"). This carries goldens the rest of the way.

sidecar DaemonSet
sandbox PodSpec +1 container in every pod untouched
packing density (just tuned in terraform#91) reduced unaffected
can degrade the health probe yes no
writable mount lives in the tenant's pod once per node, in infrastructure
compression CPU competes with the user's dev server capped (50m/500m), nobody waits on it

Asserted against the rendered output, not just intended: the SandboxTemplate never references the writable claim, and the DaemonSet mounts the hostPath readOnly: true.

Keyed by org — this is what makes fleet-wide publishing acceptable

A repo hash is derived from the clone URL, so two orgs cloning the same public template land on one key. Node-locally that is a single trust domain; fleet-wide it would let one org's tree restore into another's sandbox.

The daemon is the only process holding both facts at once — the org from Studio's config push, and the golden it writes — so it records them together beside the tree. A golden without a readable org is skipped rather than uploaded under an unscoped key: an archive whose owner is unknown must not exist.

orgId already reached buildConfigPayload via EnsureOptions.tenant; it was simply never put on the wire. Getting the key right now matters because adding the org later would change every key and invalidate the whole store.

What it uploads is not configurable, and cannot be

Sandboxes are multi-tenant and run third-party code, so the set of (repo, lockfile) pairs is not knowable ahead of time. There is no list to curate and no image to pre-bake — measured: 18 distinct repos in a 41-event sample over 30 days, long tail, no concentration to exploit. It forwards what a real boot produced and the daemon already judged healthy enough to publish node-locally, and nothing else.

Cost

One PUT per (org, repo, lockfile) across the whole fleet — an existing key is a HEAD and a skip. At ~300 MB/archive and ~200 lockfiles that is single-digit dollars a month in S3, and $0 transfer via the VPC Gateway Endpoint. The real cost is compression CPU on the sandbox NodePool, which is why the limit is low and sweeps are sequential.

Shape

Same binary as the daemon, via a golden-uploader subcommand — the archive format lives in internal/setup, which Go's internal/ rule keeps unimportable from outside the module, and reusing the sandbox image means no second artifact to build or keep in lockstep. It is not the daemon: no HTTP server, no lifecycle, no tenant.

Chart 0.12.0, goldenUploader.enabled default off.

Testing

Real files, real tar/zstd, no mocks. 26 tests pass in internal/setup; go build, go vet, gofmt clean; helm lint clean; bun run fmt clean.

test why
uploads keyed by org the archive lands under the org prefix, not a bare repo hash
skips without provenance an archive with an unknown owner must not exist
steady-state sweep recompresses nothing; mtime unchanged
restores on a cold root the uploaded archive is actually readable by #5824's restore
two orgs, one repo separate archives; neither overwrites the other
in-flight publish a golden dir with no node_modules is skipped, so no partial tree ships
.vite excluded pod-local churn does not travel
both no-op paths missing cache root, missing remote root

Inverted the build-config-payload test that asserted an operator-only payload, since the org is now sent too. Fixed splitGoldenLockDir to return empty strings alongside ok=false — a test caught it handing back a half-parsed key.

Chart render verified across: uploader off (nothing), on (DaemonSet + writable PV/PVC, distinct from the tenant's), dynamic path without pvcName (fails with the reason), dynamic path with it (renders, no PV).

Not validated on a real pod. Per the repo norm, "done" is a tailed pod showing an L2 hit; that needs both PRs deployed and goldenUploader.enabled on, which is a deco-apps-cd change after these land.


Summary by cubic

Adds a node-level golden-uploader DaemonSet that moves dependency goldens from each node’s L1 cache to a shared L2 store. Keys are per‑org to prevent cross‑org restores; orgId now reaches the daemon and is written beside each golden. Helm chart bumped to 0.13.0 (uploader off by default).

  • New Features

    • Node-scoped uploader (same image, golden-uploader subcommand) reads a read‑only hostPath and writes to a writable shared store; sequential sweeps with low CPU limits.
    • Shared archive paths: org → repo → <pm>-<lock>.tar.zst; existing archives are skipped; remote restore/publish require orgId.
    • Daemon writes .golden-meta.json (orgId/cloneUrl/pm); uploader skips goldens without a readable org.
    • Helm 0.13.0: DaemonSet plus a writable PV/PVC and validations; placement matches sandbox pods; default disabled.
  • Migration

    • Enable with goldenUploader.enabled: true and ensure depsCache.enabled and depsCache.remote.enabled are true.
    • Provide a writable L2 view via depsCache.remote.volume.attributes (chart‑provisioned PV/PVC) or set goldenUploader.pvcName to an existing claim.
    • If using a dynamic depsCache.remote.storageClassName, you must set goldenUploader.pvcName (the StorageClass cannot express the read‑only/read‑write split).

Written for commit ce88414. Summary will update on new commits.

Review in cubic

@nicacioliveira
nicacioliveira force-pushed the feat/sandbox-l2-golden-in-go-daemon branch from ee30d0f to 2f539d6 Compare August 7, 2026 21:36
@nicacioliveira
nicacioliveira force-pushed the feat/sandbox-golden-uploader branch from 8d1d643 to 9b3929f Compare August 7, 2026 21:36
@nicacioliveira

Copy link
Copy Markdown
Author

Rebased on current main (both branches were 86 commits behind) and added the piece that was missing to actually ship:

packages/sandbox/package.json 1.44.6 → 1.45.0. The release-studio-sandbox workflow reads that version as the image tag and skips the entire build when the tag already exists in GHCR (1.44.6 is published). Merging without the bump would have published chart 0.13.0 while reusing the old image — so the DaemonSet would have shipped against a binary with no golden-uploader subcommand and exited on every sandbox node. Worse than not merging.

Also in the rebase:

  • chart version 0.12.0 → 0.13.0: main had already used 0.12.0 and 0.12.1 for tenantPools and the warm-pool updateStrategy pin, and is at 0.12.10 now.
  • fixed my own shortcut: the "omits orgId when there is no tenant" test stubbed repo with as never, and buildConfigPayload has since started reading repo.userName.trim(). Replaced the cast with a real fixture — that cast is exactly what CLAUDE.md warns about, and the rebase is what exposed it.

Re-verified from scratch after the rebase, not from cache: go build, go vet, go clean -testcache && go test ./internal/setup/ (26 pass), helm lint, bun test build-config-payload (7 pass), bun run fmt clean.

Base automatically changed from feat/sandbox-l2-golden-in-go-daemon to main August 10, 2026 13:00
Nicacio Oliveira and others added 2 commits August 10, 2026 10:32
The golden's path carries only a repo hash, derived from the clone URL. That is
enough node-locally, where the cache is one trust domain, but not for a store
shared across nodes: two organizations cloning the same public template land on
the same key, so an archive published by one would restore into the other's
sandbox.

The daemon is the only process holding both facts — the org from Studio's config
push and the golden it writes — so it records them together. A golden with no
readable org is ineligible for the shared tier, which is the safe default.

orgId already reached buildConfigPayload via EnsureOptions.tenant; it was simply
never put on the wire. Inverted the test that asserted the operator-only payload,
since the org is now sent too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Nothing publishes to the L2 store today, so it is permanently empty: a sandbox
pod's mount is read-only by design. This adds the missing half — a DaemonSet
that carries goldens from a node's L1 hostPath into the shared store.

WHY NOT A SIDECAR IN THE SANDBOX POD. Writing a store shared across nodes needs
write access, and a sandbox runs untrusted code: a package manager installs
cached content as-is, so a tenant able to write it could poison another node's
boot. The tenant's write path therefore stops at its own node's hostPath, which
is already the accepted trust domain there. What that buys over a sidecar:

- the sandbox PodSpec is untouched — no per-pod request, no effect on how many
  sandboxes pack onto a node (which #91 just tuned), and nothing new that can
  degrade the health probe Studio tears the pod down on.
- the writable mount exists once per node in infrastructure, not inside every
  tenant's pod.
- CPU is capped (50m/500m) without competing with a user's dev server. The
  compression is the expensive part and no boot waits on it.

Asserted in the rendered output: the SandboxTemplate never references the
writable claim, and the DaemonSet mounts the hostPath read-only.

KEYED BY ORG, which is what makes fleet-wide publishing acceptable. A repo hash
comes from the clone URL, so two orgs cloning the same public template collide
on one key — node-locally that is a single trust domain, fleet-wide it would let
one org's tree restore into another's sandbox. The daemon stamps the org beside
each golden and a golden without one is SKIPPED rather than uploaded under an
unscoped key, so an archive with an unknown owner cannot exist.

WHAT IT UPLOADS is not configurable, and cannot be. Sandboxes are multi-tenant
and run third-party code, so the set of (repo, lockfile) pairs is unknowable
ahead of time — there is no list to curate and no image to pre-bake. It forwards
what a real boot produced and the daemon already judged healthy enough to
publish node-locally.

Same binary as the daemon, via a `golden-uploader` subcommand: the archive
format lives in internal/setup, which Go's internal rule keeps unimportable from
outside the module, and reusing the sandbox image means no second artifact to
build or keep in lockstep. It is not the daemon — no HTTP server, no lifecycle,
no tenant.

Cost, for the record: one PUT per (org, repo, lockfile) across the whole fleet,
because an existing key is a HEAD and a skip. Everything after that is
compression CPU, which is why the limit is low and the sweep is sequential.

Tests use real files and real tar/zstd: upload keyed by org, skip without
provenance, steady-state sweep that recompresses nothing, an archive that
actually restores on a cold root, two orgs on one repo getting separate
archives, in-flight publishes skipped, and both no-op paths. 26 tests pass in
internal/setup.

Chart 0.12.0, default off. Requires depsCache.enabled + depsCache.remote.enabled
and a writable volume source; the dynamic storageClassName path must supply
goldenUploader.pvcName, since a StorageClass cannot express the
read-only/read-write split this relies on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@nicacioliveira
nicacioliveira force-pushed the feat/sandbox-golden-uploader branch from 9b3929f to ce88414 Compare August 10, 2026 13:35
@nicacioliveira
nicacioliveira merged commit 41c9037 into main Aug 10, 2026
27 checks passed
@nicacioliveira
nicacioliveira deleted the feat/sandbox-golden-uploader branch August 10, 2026 13:44
decocms Bot pushed a commit that referenced this pull request Aug 10, 2026
PR: #5843 feat(sandbox): node-level uploader that fills the shared golden store
Bump type: minor

- @decocms/sandbox (packages/sandbox/package.json): 1.45.0 -> 1.46.0
- deploy/helm/sandbox-env (chart 0.13.1) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.46.0

Deploy-Scope: both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants