An open-source, faster Devin alternative
TypeScript
AMI dual-write goldens to Tigris + two-pass rclone with correct storage class
Brian Reardon76a88729e95e
diff --git a/.github/workflows/build-worker-ami.yml b/.github/workflows/build-worker-ami.ymlindex 53a3920e..d9aee66d 100644--- a/.github/workflows/build-worker-ami.yml+++ b/.github/workflows/build-worker-ami.yml@@ -139,6 +139,10 @@ jobs:-var "base_archive_account=${{ secrets.AZURE_STORAGE_ACCOUNT }}" \-var "base_archive_key=${{ secrets.AZURE_STORAGE_KEY }}" \-var "prev_golden_version=${{ steps.prev-golden.outputs.prev }}" \+ -var "tigris_endpoint=${{ secrets.TIGRIS_ENDPOINT }}" \+ -var "tigris_access_key_id=${{ secrets.TIGRIS_ACCESS_KEY_ID }}" \+ -var "tigris_secret_access_key=${{ secrets.TIGRIS_SECRET_ACCESS_KEY }}" \+ -var "tigris_goldens_bucket=${{ secrets.TIGRIS_GOLDENS_BUCKET }}" \deploy/packer/worker-ami.pkr.hcl | tee /tmp/packer-output.txt# Use the gallery image ID (NVMe-compatible for v7 VMs)diff --git a/deploy/packer/worker-ami.pkr.hcl b/deploy/packer/worker-ami.pkr.hclindex 52126a4e..e8e269ba 100644--- a/deploy/packer/worker-ami.pkr.hcl+++ b/deploy/packer/worker-ami.pkr.hcl@@ -115,6 +115,44 @@ variable "prev_golden_version" {description = "Previous AMI's golden version. When set, Packer downloads bases/{prev}/default.ext4 from blob storage and bakes it into the AMI at /opt/opensandbox/images/bases/{prev}/default.ext4 so forks of checkpoints pinned to the previous golden don't need a runtime blob download."}+# Tigris dual-write: during the Azure→Tigris migration window, the AMI bake+# uploads each new golden to BOTH Azure (via the legacy Python step) AND+# Tigris (via opensandbox-worker golden-upload). Leave these empty to skip+# the Tigris upload — falls back to Azure-only behavior. Drop the Python+# Azure upload entirely once the cutover is complete (Phase 5+).++variable "tigris_endpoint" {+ type = string+ default = ""+ description = "Tigris (or any S3-compat) endpoint for the goldens dual-write. Empty skips."+}++variable "tigris_access_key_id" {+ type = string+ default = ""+ sensitive = true+ description = "Tigris access key. Paired with tigris_endpoint."+}++variable "tigris_secret_access_key" {+ type = string+ default = ""+ sensitive = true+ description = "Tigris secret key. Paired with tigris_endpoint."+}++variable "tigris_goldens_bucket" {+ type = string+ default = ""+ description = "Tigris bucket where goldens land (e.g. opencomputer-prod). Empty skips."+}++variable "tigris_region" {+ type = string+ default = "auto"+ description = "Tigris region. 'auto' works for Tigris/R2; AWS would need a real region."+}+# ---------------------------------------------------------------------# Source: Ubuntu 24.04 x86_64 on Azure# ---------------------------------------------------------------------@@ -394,6 +432,33 @@ build {]}+ # 4b'. Dual-write the new golden to Tigris via the worker's golden-upload+ # subcommand. Runs only when tigris_endpoint + creds + bucket are set.+ # Uses the same blobstore.S3 backend the worker uses at runtime — no+ # separate Tigris client code in the AMI bake. Skips cleanly (exit 0)+ # when any required var is unset, so this step is safe to leave in+ # the pipeline once we drop the Azure upload entirely (Phase 5+).+ provisioner "shell" {+ execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E bash '{{ .Path }}'"+ environment_vars = [+ "OPENSANDBOX_GLOBAL_BLOB_ENDPOINT=${var.tigris_endpoint}",+ "OPENSANDBOX_GLOBAL_BLOB_REGION=${var.tigris_region}",+ "OPENSANDBOX_GLOBAL_BLOB_ACCESS_KEY_ID=${var.tigris_access_key_id}",+ "OPENSANDBOX_GLOBAL_BLOB_SECRET_ACCESS_KEY=${var.tigris_secret_access_key}",+ "OPENSANDBOX_GLOBAL_BLOB_USE_PATH_STYLE=true",+ "OPENSANDBOX_GLOBAL_BLOB_GOLDENS_BUCKET=${var.tigris_goldens_bucket}",+ "OPENSANDBOX_GLOBAL_BLOB_NAME=tigris",+ ]+ inline = [+ "if [ -z \"$OPENSANDBOX_GLOBAL_BLOB_ENDPOINT\" ] || [ -z \"$OPENSANDBOX_GLOBAL_BLOB_ACCESS_KEY_ID\" ] || [ -z \"$OPENSANDBOX_GLOBAL_BLOB_GOLDENS_BUCKET\" ]; then",+ " echo 'Tigris dual-write: env vars not set, skipping'",+ " exit 0",+ "fi",+ "echo 'Tigris dual-write: uploading /opt/opensandbox/images/default.ext4 via golden-upload subcommand'",+ "/usr/local/bin/opensandbox-worker golden-upload /opt/opensandbox/images/default.ext4",+ ]+ }+# 4c. Bake previous golden's default.ext4 into the AMI under# /opt/opensandbox/images/bases/{prev}/default.ext4. At first boot the# Azure custom-data script copies /opt/opensandbox/images/bases/* todiff --git a/docs/blobstore-tigris-cutover.md b/docs/blobstore-tigris-cutover.mdindex c5335927..c68f1f74 100644--- a/docs/blobstore-tigris-cutover.md+++ b/docs/blobstore-tigris-cutover.md@@ -16,7 +16,8 @@ the soak window.| Data | Old backend | Cutover mechanism ||---|---|---|| Checkpoints / hibernation archives / templates | Azure Blob | rclone bulk copy + FallbackStore in migration mode |-| Goldens (`bases/<version>/default.ext4`) | Azure Blob | same |+| Goldens — existing (`bases/<old-versions>/default.ext4`) | Azure Blob | rclone bulk copy (they live in the same container as checkpoints) |+| Goldens — new ones produced by future AMI bakes | Azure Blob | **AMI bake dual-writes to both Azure and Tigris** until Phase 5 || pg-backups / pg-wal | Azure Blob | Out of scope (managed by separate path) |All worker-managed paths flow through `internal/blobstore.Store`, so a@@ -57,20 +58,37 @@ required for binary or system-level changes.`opencomputer-prod`, fallback uses Azure container `checkpoints`,configured via `OPENSANDBOX_S3_FALLBACK_BUCKET`-## Phase 1 — Ship the new binary (one AMI bake)--**Goal**: get the new code into the worker pool. No behavior change yet-(`OPENSANDBOX_S3_FALLBACK_*` unset means workers log "no fallback" and-behave identically to before).--1. Merge the PR.-2. CI builds a new worker AMI (`.github/workflows/build-worker-ami.yml`)- and bumps KV `worker-image-version`.-3. Scaler does its normal rolling-replace.-4. Verify all workers report the new version via `GET /api/workers`.-5. Smoke test: create / hibernate / wake. Behavior identical.+## Phase 1 — Ship the new binary + start dual-writing goldens++**Goal**: get the new code into the worker pool AND start uploading each+new AMI's golden to Tigris in parallel with Azure. No worker behavior+change yet (`OPENSANDBOX_S3_FALLBACK_*` unset means workers log "no+fallback" and behave identically to before).++1. Before merging: stash Tigris creds in GitHub Actions secrets used by+ `build-worker-ami.yml`:+ - `TIGRIS_ENDPOINT` = `https://t3.storage.dev`+ - `TIGRIS_ACCESS_KEY_ID` = `tid_...`+ - `TIGRIS_SECRET_ACCESS_KEY` = `tsec_...`+ - `TIGRIS_GOLDENS_BUCKET` = `opencomputer-prod`+2. Merge the PR.+3. CI builds a new worker AMI. The bake now performs **two** golden+ uploads:+ - Existing Python step → Azure container `checkpoints` (unchanged)+ - New step → Tigris bucket `opencomputer-prod` via+ `opensandbox-worker golden-upload` (skips silently if Tigris secrets+ aren't set, so this is safe on dev/PR branches that don't have them)+4. CI bumps KV `worker-image-version`. Scaler does rolling-replace.+5. Verify all workers report the new version via `GET /api/workers`.+6. Smoke test: create / hibernate / wake. Behavior identical.+7. Verify the new golden landed in Tigris:+ ```+ tigris ls "opencomputer-prod/bases/$(<the hash from packer output>)/"+ ```+ Should show `default.ext4` at the expected size.-**Rollback**: bump KV `worker-image-version` back. Scaler rolls back.+**Rollback**: bump KV `worker-image-version` back. Scaler rolls back. The+Tigris-uploaded golden stays in Tigris as a no-op (no reader yet).## Phase 2 — Bulk rclone Azure → Tigris@@ -161,13 +179,19 @@ Monitor:If fallback hit rate stays elevated, run another delta rclone sync towarm cold keys into Tigris proactively.-## Phase 5 — Disable fallback (commit to Tigris)+## Phase 5 — Disable fallback + drop Azure golden upload (commit to Tigris)1. Edit `server.env`: remove the `OPENSANDBOX_S3_FALLBACK_*` block and`OPENSANDBOX_BLOB_MIGRATION_MODE`.2. Restart CP.3. Cycle workers (same options as Phase 3 step 4).4. Verify log: `checkpoint store: tigris primary (no fallback)`.+5. **Remove the Python Azure-upload step from `deploy/packer/worker-ami.pkr.hcl`.**+ At this point Tigris is the authoritative store and Azure shouldn't+ receive new writes. The Tigris-upload step stays.+6. Optionally also remove the "download previous golden from Azure" step+ and replace with a Tigris fetch (or accept the runtime fetch cost for+ forks of stale-pinned checkpoints, which should be rare).**Rollback past this point** is harder. Re-adding the fallback re-enablesthe safety net, but any keys written to Tigris during the no-fallbackdiff --git a/scripts/rclone-azure-to-tigris.sh b/scripts/rclone-azure-to-tigris.shindex 7f97caab..70aeaddb 100755--- a/scripts/rclone-azure-to-tigris.sh+++ b/scripts/rclone-azure-to-tigris.sh@@ -1,13 +1,12 @@#!/usr/bin/env bash# rclone-azure-to-tigris.sh#-# One-shot copy of the prod checkpoints container from Azure Blob to Tigris.-# Run with --dry-run first to confirm the planned transfer.+# Copies worker-managed object storage from Azure Blob to Tigris.+# Idempotent; safe to re-run for delta syncs.## Required env vars:# AZURE_STORAGE_ACCOUNT e.g. occkpt3ccf3c31-# AZURE_STORAGE_KEY az storage account keys list -g opencomputer-prod \-# -n occkpt3ccf3c31 --query "[0].value" -o tsv+# AZURE_STORAGE_KEY az storage account keys list -g <rg> -n <account> --query "[0].value" -o tsv# TIGRIS_ACCESS_KEY_ID# TIGRIS_SECRET_ACCESS_KEY#@@ -16,10 +15,33 @@# TIGRIS_BUCKET default: opencomputer-prod# TIGRIS_ENDPOINT default: https://t3.storage.dev#-# Use rclone copy (not sync) — never deletes from destination. Safe to re-run;-# subsequent runs only transfer keys that changed (delta sync).+# ---------------------------------------------------------------------------+# Why two passes (don't simplify this without understanding):#-# Best run from a VM in eastus2 (same region as source storage account).+# The legacy Azure backend stripped a leading "<container>/" from keys on+# write (internal/storage/blob_azure.go's normalizeKey). So a key like+# "checkpoints/sb-xxx/123.tar.zst" passed by the worker was stored at Azure+# blob name "sb-xxx/123.tar.zst" (no checkpoints/ prefix).+#+# The new S3-compat backend (internal/blobstore/s3.go) does NOT strip.+# Workers calling Get(bucket="opencomputer-prod", key="checkpoints/sb-xxx/...")+# expect Tigris to have it at exactly that key.+#+# So sandbox archives in Azure ("sb-XXXX/...") must be re-prefixed with+# "checkpoints/" when copying to Tigris. Other prefixes (bases/, migrations/,+# templates/) were never stripped — their keys never started with+# "checkpoints/" — so they stay at their current paths.+#+# Skipped on purpose: deploy/, db-backups/, rootfs-cache/ — no worker+# code reads these (build artifacts / out-of-band backups).+# ---------------------------------------------------------------------------+#+# Required rclone flags:+# --s3-storage-class STANDARD Tigris rejects Azure's "Hot"/"Cool" tier+# names — without this every PUT fails with+# 400 InvalidStorageClass.+# --metadata=false Skip Azure-specific metadata that doesn't+# translate and isn't needed by our code.set -euo pipefail@@ -44,31 +66,69 @@ export RCLONE_CONFIG_TIGRIS_ACCESS_KEY_ID="$TIGRIS_ACCESS_KEY_ID"export RCLONE_CONFIG_TIGRIS_SECRET_ACCESS_KEY="$TIGRIS_SECRET_ACCESS_KEY"export RCLONE_CONFIG_TIGRIS_FORCE_PATH_STYLE=true-LOGFILE="${LOGFILE:-rclone-az-to-tigris-$(date +%Y%m%d-%H%M%S).log}"+TIMESTAMP="$(date +%Y%m%d-%H%M%S)"+LOG_SB="${LOG_SB:-rclone-az-to-tigris-sb-${TIMESTAMP}.log}"+LOG_REST="${LOG_REST:-rclone-az-to-tigris-rest-${TIMESTAMP}.log}"++# Shared flags. --s3-storage-class STANDARD + --metadata=false are required+# for Tigris compatibility; the rest is throughput tuning.+#+# Memory sizing: rclone holds (transfers × multi-thread-streams ×+# upload-concurrency × chunk-size) bytes in flight as a worst case. The+# settings below cap at ~4 GB resident on the bastion, fitting D4s_v3+# (16 GB) comfortably. An earlier tuning with transfers=16, streams=8,+# concurrency=4, chunk=64M OOM-killed rclone on Pass 2's 4 GB golden files.+# If you upsize the bastion to D8s_v3 (32 GB) or larger you can crank these+# back up.+COMMON_FLAGS=(+ --s3-storage-class STANDARD+ --metadata=false+ --transfers 8+ --checkers 32+ --multi-thread-streams 4+ --multi-thread-cutoff 512M+ --s3-chunk-size 32M+ --s3-upload-concurrency 2+ --progress+ --stats 30s+ --stats-one-line+ --log-level INFO+)++echo "==> $(date) Pass 1: sb-* sandbox archives → tigris:${TIGRIS_BUCKET}/checkpoints/"+echo " log: $LOG_SB"+echo " extra args: $*"++# Pass 1: relocate sb-* archives under the "checkpoints/" prefix so the+# new worker code's HibernationKey() ("checkpoints/sb-xxx/...") finds them.+rclone copy \+ "az:$SRC_CONTAINER" \+ "tigris:$TIGRIS_BUCKET/checkpoints" \+ --include "sb-*/**" \+ --log-file "$LOG_SB" \+ "${COMMON_FLAGS[@]}" \+ "$@"-echo "==> $(date) rclone copy az:$SRC_CONTAINER -> tigris:$TIGRIS_BUCKET"-echo " log: $LOGFILE"-echo " args: $*"+echo "==> $(date) Pass 2: bases/, migrations/, templates/ → tigris:${TIGRIS_BUCKET}/ (unchanged paths)"+echo " log: $LOG_REST"-# --transfers 16: parallel file transfers-# --checkers 32: parallel existence checks-# --multi-thread-streams 8 with cutoff 256M: parallelize large goldens (4GB)-# --s3-chunk-size 64M: fewer S3 ops per big file-# --progress + --stats: live visibility+# Pass 2: copy other worker-managed prefixes verbatim. These already match+# what the new code expects (no prefix transform needed).rclone copy \"az:$SRC_CONTAINER" \"tigris:$TIGRIS_BUCKET" \- --transfers 16 \- --checkers 32 \- --multi-thread-streams 8 \- --multi-thread-cutoff 256M \- --s3-chunk-size 64M \- --s3-upload-concurrency 4 \- --progress \- --stats 30s \- --stats-one-line \- --log-level INFO \- --log-file "$LOGFILE" \+ --include "bases/**" \+ --include "migrations/**" \+ --include "templates/**" \+ --log-file "$LOG_REST" \+ "${COMMON_FLAGS[@]}" \"$@"-echo "==> $(date) done"+echo "==> $(date) done. logs: $LOG_SB, $LOG_REST"+echo ""+echo "Parity check:"+echo " rclone size az:$SRC_CONTAINER --include 'sb-*/**'"+echo " rclone size tigris:$TIGRIS_BUCKET/checkpoints"+echo ""+echo " rclone size az:$SRC_CONTAINER --include 'bases/**' --include 'migrations/**' --include 'templates/**'"+echo " rclone size tigris:$TIGRIS_BUCKET --include 'bases/**' --include 'migrations/**' --include 'templates/**'"