From 06d293fbd54187f50a2f88234e6b43e725801b62 Mon Sep 17 00:00:00 2001 From: didericis Date: Tue, 21 Jul 2026 21:24:35 -0400 Subject: [PATCH] fix(firecracker): remove per-bottle run dir on teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each Firecracker bottle created its run dir (holding an ~1G rootfs.ext4) but never removed it — launch teardown only terminated the VM. Every run leaked its rootfs, filling the CI runner's disk (187 stale sandbox-tester dirs / 141G in one incident). Register a run-dir rmtree callback on the ExitStack before the vm.terminate callback so, LIFO, the VM is gone before its rootfs is removed. ignore_errors keeps teardown resilient. Co-Authored-By: Claude Opus 4.8 --- bot_bottle/backend/firecracker/launch.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bot_bottle/backend/firecracker/launch.py b/bot_bottle/backend/firecracker/launch.py index a5efc00..3859b75 100644 --- a/bot_bottle/backend/firecracker/launch.py +++ b/bot_bottle/backend/firecracker/launch.py @@ -26,6 +26,7 @@ from __future__ import annotations import dataclasses import os +import shutil from contextlib import ExitStack, contextmanager from pathlib import Path from typing import Callable, Generator @@ -167,6 +168,10 @@ def launch( # Step 6: build the per-bottle rootfs + SSH key, then boot. run_dir = util.cache_dir() / "run" / plan.slug run_dir.mkdir(parents=True, exist_ok=True) + # Remove the run dir on teardown so the per-bottle rootfs.ext4 (~1G) + # doesn't leak. Registered before vm.terminate below so it runs *after* + # it (ExitStack is LIFO): the VM is gone before we rm its rootfs. + stack.callback(lambda: shutil.rmtree(run_dir, ignore_errors=True)) rootfs = run_dir / "rootfs.ext4" util.build_rootfs_ext4(agent_base, rootfs) private_key, pubkey = util.generate_keypair(run_dir)