An open-source, faster Devin alternative
TypeScript
default to merged single-disk creation (was gated behind an env flag), and make the worker-image build derive default-merged.ext4 correctly (truncate before resize2fs) and fail loudly if it isn't a valid ~20GB ext4 so a bad base can't brick the fleet.
Brian Reardonec5664e3d1de
diff --git a/deploy/ec2/build-rootfs-docker.sh b/deploy/ec2/build-rootfs-docker.shindex 21cd8932..ffe8abd3 100755--- a/deploy/ec2/build-rootfs-docker.sh+++ b/deploy/ec2/build-rootfs-docker.sh@@ -339,6 +339,25 @@ make_ext4() {log "Done: $IMAGES_DIR/${outname}.ext4 ($(du -h "$IMAGES_DIR/${outname}.ext4" | cut -f1))"}+# assert_merged_base FILE MIN_MB — fail the build unless FILE is a valid ext4+# whose FILESYSTEM (not just the file) is at least ~MIN_MB. Catches a resize2fs+# that silently left the merged base at the 4GB split size. Since merged-create+# is the default, a bad merged base bricks every worker's golden build — so this+# is fatal on purpose.+assert_merged_base() {+ local f="$1" min_mb="$2" blocks bsize fs_mb+ [ -f "$f" ] || { err "merged base $f missing after derivation"; exit 1; }+ dumpe2fs -h "$f" >/dev/null 2>&1 || { err "merged base $f is not a valid ext4"; exit 1; }+ blocks=$(dumpe2fs -h "$f" 2>/dev/null | awk -F: '/Block count/{gsub(/ /,"",$2);print $2}')+ bsize=$(dumpe2fs -h "$f" 2>/dev/null | awk -F: '/Block size/{gsub(/ /,"",$2);print $2}')+ fs_mb=$(( blocks * bsize / 1024 / 1024 ))+ if [ "$fs_mb" -lt $(( min_mb * 95 / 100 )) ]; then+ err "merged base $f filesystem is ${fs_mb}MB, expected ~${min_mb}MB — resize2fs failed"+ exit 1+ fi+ log "merged base verified: ${fs_mb}MB ext4"+}+ROOTFS_MIN_MB="${ROOTFS_MIN_MB:-4096}"# Primary base for this build's configured layout.@@ -348,18 +367,24 @@ make_ext4 "$IMAGE_NAME" "$EXT4_SIZE_MB" "$ROOTFS_MIN_MB"# default-merged.ext4 so one worker image carries both bases (enabling merged-# create is then a pure OPENSANDBOX_GOLDEN_DISK_LAYOUT=merged flip). The two are# byte-identical content; the merged one is just grown to 20GB. Derive it from-# the split base (cp + resize2fs) rather than a fresh mkfs so it can be-# reproduced from a CACHED default.ext4 with no rootfs tar — the Packer worker--# image build applies the exact same derivation on a rootfs-cache hit. Skipped-# for the merged build itself, non-default templates, or EMIT_MERGED_VARIANT=0.+# the split base (cp, grow the file, resize2fs the ext4) rather than a fresh+# mkfs so it can be reproduced from a CACHED default.ext4 with no rootfs tar —+# the Packer worker-image build applies the exact same derivation on a rootfs-+# cache hit. Merged-create is the DEFAULT, so a missing/wrong-sized merged base+# would brick every worker's golden build — assert_merged_base fails the build+# loudly rather than shipping a bad image. Skipped for the merged build itself,+# non-default templates, or EMIT_MERGED_VARIANT=0.if [ "$IMAGE_NAME" = "default" ] && [ "$DISK_LAYOUT" != "merged" ] && [ "${EMIT_MERGED_VARIANT:-1}" = "1" ]; thenMERGED_SIZE_MB="${MERGED_SIZE_MB:-20480}"+ MERGED_PATH="$IMAGES_DIR/default-merged.ext4"log "Deriving companion merged base default-merged.ext4 (${MERGED_SIZE_MB}MB) from ${IMAGE_NAME}.ext4..."- cp --reflink=auto "$IMAGES_DIR/${IMAGE_NAME}.ext4" "$IMAGES_DIR/default-merged.ext4" 2>/dev/null \- || cp "$IMAGES_DIR/${IMAGE_NAME}.ext4" "$IMAGES_DIR/default-merged.ext4"- e2fsck -fy "$IMAGES_DIR/default-merged.ext4" >/dev/null 2>&1 || true- resize2fs "$IMAGES_DIR/default-merged.ext4" "${MERGED_SIZE_MB}M" 2>/dev/null || log "resize2fs merged failed (non-fatal)"- log "Done: $IMAGES_DIR/default-merged.ext4 ($(du -h "$IMAGES_DIR/default-merged.ext4" | cut -f1))"+ cp --reflink=auto "$IMAGES_DIR/${IMAGE_NAME}.ext4" "$MERGED_PATH" 2>/dev/null \+ || cp "$IMAGES_DIR/${IMAGE_NAME}.ext4" "$MERGED_PATH"+ truncate -s "${MERGED_SIZE_MB}M" "$MERGED_PATH" # grow the file before growing the fs+ e2fsck -fy "$MERGED_PATH" >/dev/null 2>&1 || true # resize2fs needs a clean fs+ resize2fs "$MERGED_PATH" "${MERGED_SIZE_MB}M" # grow the ext4 to fill (fatal via set -e)+ assert_merged_base "$MERGED_PATH" "$MERGED_SIZE_MB"+ log "Done: $MERGED_PATH ($(du -h "$MERGED_PATH" | cut -f1))"fi# Clean up Docker imagediff --git a/deploy/packer/worker-ami.pkr.hcl b/deploy/packer/worker-ami.pkr.hclindex 629320ba..a1b35996 100644--- a/deploy/packer/worker-ami.pkr.hcl+++ b/deploy/packer/worker-ami.pkr.hcl@@ -358,14 +358,24 @@ build {# Ensure the 20GB merged base exists before staging. build-rootfs-docker.sh# emits it on a cache MISS, but on a cache HIT the Docker build is skipped,- # so derive it here from the (cached) default.ext4 — identical content grown- # to 20GB, the exact same cp+resize2fs derivation the build script uses.+ # so derive it here from the (cached) default.ext4 — identical content, the+ # file grown to 20GB then the ext4 grown to fill it (same derivation the+ # build script uses)."if [ ! -f /data/firecracker/images/default-merged.ext4 ]; then"," echo 'Deriving default-merged.ext4 from default.ext4 (rootfs-cache hit)'"," cp --reflink=auto /data/firecracker/images/default.ext4 /data/firecracker/images/default-merged.ext4 2>/dev/null || cp /data/firecracker/images/default.ext4 /data/firecracker/images/default-merged.ext4",+ " truncate -s 20480M /data/firecracker/images/default-merged.ext4"," e2fsck -fy /data/firecracker/images/default-merged.ext4 >/dev/null 2>&1 || true",- " resize2fs /data/firecracker/images/default-merged.ext4 20480M || echo 'resize2fs merged failed (non-fatal)'",+ " resize2fs /data/firecracker/images/default-merged.ext4 20480M || { echo 'FATAL: resize2fs merged failed'; exit 1; }","fi",+ # Fatal check (covers both the cache-miss build output and the cache-hit+ # derivation): merged-create is the default, so a missing/undersized merged+ # base bricks every worker's golden build. Verify the FILESYSTEM is ~20GB.+ "MB=/data/firecracker/images/default-merged.ext4",+ "[ -f \"$MB\" ] || { echo 'FATAL: default-merged.ext4 missing'; exit 1; }",+ "FS_MB=$(( $(dumpe2fs -h \"$MB\" 2>/dev/null | awk -F: '/Block count/{gsub(/ /,\"\",$2);print $2}') * $(dumpe2fs -h \"$MB\" 2>/dev/null | awk -F: '/Block size/{gsub(/ /,\"\",$2);print $2}') / 1048576 ))",+ "[ \"$FS_MB\" -ge 19000 ] || { echo \"FATAL: default-merged.ext4 fs is $${FS_MB}MB, expected ~20480MB\"; exit 1; }",+ "echo \"default-merged.ext4 verified: $${FS_MB}MB\"",# Save rootfs to /opt (survives NVMe mount overlay on /data)"mkdir -p /opt/opensandbox/images",diff --git a/internal/config/config.go b/internal/config/config.goindex 224c2004..545f927c 100644--- a/internal/config/config.go+++ b/internal/config/config.go@@ -105,15 +105,16 @@ type Config struct {QEMUBin string // Path to qemu-system binary (default: "qemu-system-x86_64")// GoldenDiskLayout selects the block topology this worker builds its golden- // with — "" / "split" (default) = legacy two-disk (rootfs + workspace),- // "merged" = single 20GB disk (OS + /home/sandbox). Controls the layout of- // freshly CREATED sandboxes only; forks/wakes follow each snapshot's recorded- // layout, and a dual-mode worker still HOSTS the other layout via migrate-in.- // Defaults to split so deploying the merged-capable binary is behaviour-- // neutral (no merged boxes appear at deploy). Flip to merged only AFTER the- // whole fleet runs this binary AND ships the ~20GB base image (see- // build-rootfs-docker.sh DISK_LAYOUT=merged) — set- // OPENSANDBOX_GOLDEN_DISK_LAYOUT=merged to enable merged-create.+ // with — "merged" (default) = single 20GB disk (OS + /home/sandbox), "split"+ // = legacy two-disk (rootfs + workspace). Controls the layout of freshly+ // CREATED sandboxes only; forks/wakes follow each snapshot's recorded layout,+ // and a dual-mode worker still HOSTS the other layout via migrate-in.+ // Defaults to merged so a single rolling replace onto this build produces+ // merged boxes with no extra config. Safe because the worker image build+ // guarantees a valid ~20GB default-merged.ext4 (build-rootfs-docker.sh /+ // worker-ami.pkr.hcl assert it, fatal), and a worker missing it locally+ // falls back to the global-blob copy. Set OPENSANDBOX_GOLDEN_DISK_LAYOUT=split+ // to keep a worker (or the whole fleet) on the legacy two-disk layout.GoldenDiskLayout string// AWS EC2 compute pool (server mode only — for auto-scaling worker machines)@@ -364,7 +365,7 @@ func Load() (*Config, error) {ImagesDir: os.Getenv("OPENSANDBOX_IMAGES_DIR"), // default derived from DataDirQEMUBin: envOrDefault("OPENSANDBOX_QEMU_BIN", "qemu-system-x86_64"),- GoldenDiskLayout: os.Getenv("OPENSANDBOX_GOLDEN_DISK_LAYOUT"), // "" ⇒ split; set "merged" to enable merged-create (see field doc)+ GoldenDiskLayout: envOrDefault("OPENSANDBOX_GOLDEN_DISK_LAYOUT", "merged"), // default merged; set "split" to override (see field doc)EC2AMI: os.Getenv("OPENSANDBOX_EC2_AMI"),EC2InstanceType: envOrDefault("OPENSANDBOX_EC2_INSTANCE_TYPE", "c7gd.metal"),