|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Tear down orphaned benchmark infrastructure after a killed `vero harbor run`. |
| 3 | +# |
| 4 | +# Killing the outer harbor process orphans everything below it: the docker |
| 5 | +# compose topology (daemon-owned, survives its creator) and any in-flight |
| 6 | +# Modal sandboxes (server-side, default 24h timeout). This removes both. |
| 7 | +# Scope is strictly ours: `task__*` compose containers locally, and sandboxes |
| 8 | +# in the dedicated `harness-engineering-bench` Modal app. |
| 9 | +# |
| 10 | +# Usage: bash scripts/cleanup_orphans.sh [--dry-run] |
| 11 | +# Requires MODAL_TOKEN_ID/MODAL_TOKEN_SECRET in the environment (or a dotenv |
| 12 | +# sourced beforehand); skips Modal cleanup if they are absent. |
| 13 | +set -euo pipefail |
| 14 | + |
| 15 | +dry_run=false |
| 16 | +[ "${1:-}" = "--dry-run" ] && dry_run=true |
| 17 | + |
| 18 | +containers=$(docker ps --format '{{.Names}}' | grep -i '^task__' || true) |
| 19 | +if [ -n "$containers" ]; then |
| 20 | + echo "orphaned containers:"; echo "$containers" |
| 21 | + if ! $dry_run; then |
| 22 | + echo "$containers" | xargs docker rm -f |
| 23 | + fi |
| 24 | +else |
| 25 | + echo "no orphaned task__* containers" |
| 26 | +fi |
| 27 | + |
| 28 | +if [ -z "${MODAL_TOKEN_ID:-}" ]; then |
| 29 | + echo "MODAL_TOKEN_ID not set; skipping Modal sandbox cleanup" |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | + |
| 33 | +uv run --quiet --python 3.12 --with modal python - "$dry_run" <<'PY' |
| 34 | +import sys |
| 35 | +import modal |
| 36 | +
|
| 37 | +dry_run = sys.argv[1] == "true" |
| 38 | +try: |
| 39 | + app = modal.App.lookup("harness-engineering-bench", create_if_missing=False) |
| 40 | +except Exception as error: |
| 41 | + print(f"no harness-engineering-bench app: {error}") |
| 42 | + raise SystemExit(0) |
| 43 | +count = 0 |
| 44 | +for sandbox in modal.Sandbox.list(app_id=app.app_id): |
| 45 | + print(("would terminate" if dry_run else "terminating"), sandbox.object_id) |
| 46 | + if not dry_run: |
| 47 | + sandbox.terminate() |
| 48 | + count += 1 |
| 49 | +print(f"{count} running sandbox(es) in harness-engineering-bench") |
| 50 | +PY |
0 commit comments