#!/bin/sh # Poll an arena submission and its run every 5 minutes (up to 12 h). Prints a line whenever the submission state, # run state or evaluation state changes; exits once the run is terminal and its evaluation is done or failed, # or the submission is rejected. Usage: sh scripts/watch_run.sh cd "$(dirname "$0")/.." || exit 1 BASE=https://openenvarena-arena.hf.space/api/openenv SUB=$1; OUT=reports/watch-$SUB; mkdir -p "$OUT"; prev="" for i in $(seq 1 144); do TOKEN=$(cat "$HOME/.config/hf-arena/token") printf 'Authorization: Bearer %s\n' "$TOKEN" | curl -sS -H @- "$BASE/submissions/$SUB" -o "$OUT/submission.json" 2>/dev/null RUN=$(python3 -I -c "import json,sys;r=(json.load(open(sys.argv[1])).get('run') or {});print(r.get('run_id') or '')" "$OUT/submission.json" 2>/dev/null) [ -n "$RUN" ] && printf 'Authorization: Bearer %s\n' "$TOKEN" | curl -sS -H @- "$BASE/runs/$RUN" -o "$OUT/run.json" 2>/dev/null unset TOKEN line=$(python3 -I - "$OUT/submission.json" "$OUT/run.json" "$RUN" <<'PY' import json, sys s = json.load(open(sys.argv[1])) r = json.load(open(sys.argv[2])) if sys.argv[3] else {} e = r.get("evaluation") or {} parts = [f"submission={s.get('state')}", f"run={r.get('state')}", f"error={r.get('error_code')}", f"eval={e.get('state')}"] if e.get("state") == "done": parts.append(f"solved={e.get('solved')}/{e.get('total')}") print(" ".join(parts)) PY ) if [ "$line" != "$prev" ]; then echo "$(date '+%m-%d %H:%M') $line"; prev=$line; fi case "$line" in *submission=rejected*|*eval=done*|*eval=failed*|*run=failed*|*run=cancelled*) exit 0 ;; esac sleep 300 done echo "run watcher: 12 h limit reached; last: $prev"