Secure, Fast, and Extensible Sandbox runtime for AI agents.
feat(fsb-env): prune stale artifact sets before the artifact-heavy verifies
高然324497701adb
diff --git a/scripts/fast-sandbox-env/lib.sh b/scripts/fast-sandbox-env/lib.shindex 901136ca4..8100b60e4 100644--- a/scripts/fast-sandbox-env/lib.sh+++ b/scripts/fast-sandbox-env/lib.sh@@ -504,5 +504,67 @@ require_template_id() {|| die "no template id at $WORK/template-id (run 'integration.sh up' first)"}+# --- artifact-store hygiene ---------------------------------------------------------++# Prune stale artifact sets from the test S3 (RustFS). Every pause publishes+# an instance-private checkpoint set (multi-GiB: rootfs + vmstate + memory)+# and crashed runs leave stale template sets, so the artifact-heavy verifies+# prune before they start — while no sandbox exists that could still restore+# from one. The baseline golden template survives: its published set (the+# manifest_ref directory) and every image index that points INTO it are+# kept; everything else under the store prefix goes. Best-effort by design:+# a failed delete is logged and pruned-skip never fails a verify (hygiene,+# not a functional gate).+prune_artifact_store() {+ local manifest_ref protected_digest entry key seg mref removed=0 kept=0+ local -a stale_sets=() stale_indexes=()+ local -A seen=()+ [[ -n "${TEMPLATE_ID:-}" ]] || { log "artifact prune: no template id; skipping"; return 0; }+ manifest_ref="$(osb_api template get "$TEMPLATE_ID" -o json 2>/dev/null | jq -r '.status.manifest_ref // empty')"+ [[ "$manifest_ref" == "s3://$RUSTFS_BUCKET/publish/"* ]] \+ || { log "artifact prune: template manifest_ref unavailable; skipping"; return 0; }+ protected_digest="${manifest_ref#s3://$RUSTFS_BUCKET/publish/}"+ protected_digest="${protected_digest%%/*}"+ log "artifact prune: protecting template set publish/$protected_digest/ (and the indexes pointing into it)"+ while IFS= read -r key; do+ key="${key#/}"; key="${key#chain/$RUSTFS_BUCKET/}"; key="${key#publish/}"+ [[ "$key" == *"/"* ]] || continue+ seg="${key%%/*}"+ if [[ "$seg" == "$protected_digest" ]]; then+ kept=$((kept + 1))+ elif [[ "$seg" == "index" ]]; then+ entry="${key#index/}"+ [[ -n "$entry" ]] || continue+ mref="$(rc cat "chain/$RUSTFS_BUCKET/publish/index/$entry" 2>/dev/null | jq -r '.manifestRef // empty' 2>/dev/null)"+ if [[ "$mref" == "s3://$RUSTFS_BUCKET/publish/$protected_digest/"* ]]; then+ kept=$((kept + 1))+ elif [[ -z "${seen[$entry]:-}" ]]; then+ seen[$entry]=1+ stale_indexes+=("$entry")+ fi+ elif [[ -z "${seen[$seg]:-}" ]]; then+ seen[$seg]=1+ stale_sets+=("$seg")+ fi+ done < <(rc ls --recursive "chain/$RUSTFS_BUCKET/publish/" 2>/dev/null | awk '{print $NF}')+ for seg in "${stale_sets[@]:-}"; do+ [[ -n "$seg" ]] || continue+ if rc rm --recursive --force "chain/$RUSTFS_BUCKET/publish/$seg" >/dev/null 2>&1; then+ removed=$((removed + 1))+ else+ log "artifact prune: failed to remove publish/$seg/ (continuing)"+ fi+ done+ for entry in "${stale_indexes[@]:-}"; do+ [[ -n "$entry" ]] || continue+ if rc rm --force "chain/$RUSTFS_BUCKET/publish/index/$entry" >/dev/null 2>&1; then+ removed=$((removed + 1))+ else+ log "artifact prune: failed to remove publish/index/$entry (continuing)"+ fi+ done+ log "artifact prune: removed ${#stale_sets[@]} stale set(s) + ${#stale_indexes[@]} stale index(es) ($removed delete call(s), baseline kept: $kept object(s))"+}+# Workspace directories must exist before any log()/stage call.mkdir -p "$WORK" "$LOGS_DIR" "$GEN_DIR"diff --git a/scripts/fast-sandbox-env/verify/idle-pause.sh b/scripts/fast-sandbox-env/verify/idle-pause.shindex 02805da70..f28e050c0 100755--- a/scripts/fast-sandbox-env/verify/idle-pause.sh+++ b/scripts/fast-sandbox-env/verify/idle-pause.sh@@ -45,6 +45,10 @@# arrive within a 300s budget).# 5. Cleanup: kill the sandbox and wait until GET 404s.#+# Housekeeping: the artifact store is pruned at entry — stale checkpoint /+# template sets are removed, the baseline golden template set and the+# indexes pointing into it are preserved.+## Runs as part of `integration.sh up` (the entry chains every verify# script) or standalone against a live stack from `env.sh up`.source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib.sh"@@ -101,6 +105,9 @@ idle_pause_verify() {local created t0 t1 code ilocal x=30local rounds="${IDLE_PAUSE_ROUNDS:-3}"+ # Every auto-pause round publishes a checkpoint set: drop stale ones+ # from earlier runs before this verify adds its own.+ prune_artifact_store[[ "$rounds" =~ ^[1-9][0-9]*$ ]] || die "IDLE_PAUSE_ROUNDS must be a positive integer (got $rounds)"log "verify (idle-pause): creating an opted-in sandbox (idleTimeoutSeconds=$x, rounds=$rounds) via the lifecycle API"t0="$(now_ms)"diff --git a/scripts/fast-sandbox-env/verify/pause-resume.sh b/scripts/fast-sandbox-env/verify/pause-resume.shindex 17e8055e2..85e994b95 100755--- a/scripts/fast-sandbox-env/verify/pause-resume.sh+++ b/scripts/fast-sandbox-env/verify/pause-resume.sh@@ -60,6 +60,10 @@# than the first bundle's.# 8. Cleanup: kill the sandbox and wait until GET 404s.#+# Housekeeping: the artifact store is pruned at entry — stale checkpoint /+# template sets are removed, the baseline golden template set and the+# indexes pointing into it are preserved.+## Runs as part of `integration.sh up` (the entry chains every verify# script) or standalone against a live stack from `env.sh up`.@@ -114,6 +118,9 @@ pause_resume_verify() {# PUT a new rule set -> pause again -> the NEW checkpoint bundle must# carry the UPDATED policy (new rule present, replaced rule gone).local created t0 t1 t2 t3 t4 rev1 rev2 sandbox_uid policy_file+ # Every pause publishes a multi-GiB checkpoint set: drop stale ones from+ # earlier runs before this verify adds its own (baseline template kept).+ prune_artifact_storepolicy_file="$GEN_DIR/pause-policy.json"jq -n '{defaultAction: "deny", egress: [{action: "allow", target: "example.com"}, {action: "allow", target: "*.opensandbox.ai"}]}' \> "$policy_file"diff --git a/scripts/fast-sandbox-env/verify/snapshot.sh b/scripts/fast-sandbox-env/verify/snapshot.shindex fe44ad2c2..7d47d2198 100755--- a/scripts/fast-sandbox-env/verify/snapshot.sh+++ b/scripts/fast-sandbox-env/verify/snapshot.sh@@ -43,6 +43,10 @@# The snapshot ids are shared through SNAPSHOT_ID / SNAPSHOT_ID2 /# SNAPSHOT_EXTRA.#+# Housekeeping: the artifact store is pruned at entry — stale checkpoint /+# template sets are removed, the baseline golden template set and the+# indexes pointing into it are preserved.+## Runs as part of `integration.sh up` (the entry chains every verify# script) or standalone against a live stack from `env.sh up`.@@ -77,6 +81,9 @@ snapshot_verify() {# to Ready, restore a NEW sandbox from the snapshotId and boot it. Also# covers re-entry fencing, source-sandbox survival, and a repeat snapshot.local created out source_id snapshot_id snapshot_id2 restore_id reentry_out reentry_code+ # Snapshot sets are multi-GiB: drop stale ones from earlier runs before+ # this verify adds its own (baseline template kept).+ prune_artifact_storelocal t0 t1 t2 t3 t4t0="$(now_ms)"log "verify (snapshot): creating the source sandbox via the opensandbox CLI (templateId=$TEMPLATE_ID)"diff --git a/scripts/fast-sandbox-env/verify/vault.sh b/scripts/fast-sandbox-env/verify/vault.shindex 349668f4c..525852312 100755--- a/scripts/fast-sandbox-env/verify/vault.sh+++ b/scripts/fast-sandbox-env/verify/vault.sh@@ -41,6 +41,10 @@# revision 1.# 7. Cleanup: kill the sandbox and wait until GET 404s.#+# Housekeeping: the artifact store is pruned at entry — stale checkpoint /+# template sets are removed, the baseline golden template set and the+# indexes pointing into it are preserved.+## Runs as part of `integration.sh up` (the entry chains every verify# script) or standalone against a live stack from `env.sh up`.@@ -77,6 +81,9 @@ vault_revision_is() { # <expected-revision>vault_lifecycle_verify() {local created vault_body ack rev sandbox_uid+ # The pause here publishes a checkpoint set (vault + policy bundles):+ # drop stale ones from earlier runs before this verify adds its own.+ prune_artifact_storelog "verify (vault): creating a sandbox via the opensandbox CLI (templateId=$TEMPLATE_ID)"# The policy rides the create: a policy-less create produces no egress# binding at all, so the subject would never register.