diff --git a/agent-queue/agent-queue.sh b/agent-queue/agent-queue.sh index 62ef308..bd84c4f 100755 --- a/agent-queue/agent-queue.sh +++ b/agent-queue/agent-queue.sh @@ -448,7 +448,13 @@ caps_match() { resolve_engine() { local f=$1 eng cls prefers eng=$(fm_get "$f" engine "") - if [[ -n "$eng" ]]; then printf '%s' "$eng"; return 0; fi + if [[ -n "$eng" ]]; then + # Mirror the engine-class path: only honor an explicit engine when its binary + # is actually available; otherwise emit "" (the no-engine signal) so the caller + # marks the job no_engine instead of trying to run a missing binary and crashing. + if engine_available "$eng"; then printf '%s' "$eng"; else printf '%s' ""; fi + return 0 + fi cls=$(fm_eff "$f" engine-class "") # inherit engine-class from the job's profile if [[ -z "$cls" ]]; then printf '%s' "$DEFAULT_ENGINE"; return 0; fi local class_engines; class_engines=$(engine_class_engines "$cls") @@ -686,6 +692,28 @@ _fleet_pr_prepare() { echo "$dir" } +# _cache_prune — conservatively GC cached repo checkouts under the clone cache +# ($STATE/repos, the same base _fleet_pr_prepare uses) that have not been ACCESSED +# in AQ_FLEET_CACHE_TTL_DAYS days (default 14). Set the var to 0 to disable pruning +# entirely (prior behavior). Best-effort: never fails the run loop, and never runs +# rm against an empty/unset base path. +_cache_prune() { + local ttl="${AQ_FLEET_CACHE_TTL_DAYS:-14}" + [[ "$ttl" =~ ^[0-9]+$ ]] || return 0 + [[ "$ttl" -eq 0 ]] && return 0 + local reposdir="${AQ_FLEET_REPOS_DIR:-$STATE/repos}" + # Guard: refuse to operate unless both the state root and the repos dir are + # non-empty and the repos dir actually exists (never rm an unset/empty path). + [[ -n "$STATE" && -n "$reposdir" && -d "$reposdir" ]] || return 0 + local before after pruned + before=$(find "$reposdir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l | tr -d ' ') + find "$reposdir" -mindepth 1 -maxdepth 1 -type d -atime +"$ttl" -exec rm -rf {} + 2>/dev/null || true + after=$(find "$reposdir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l | tr -d ' ') + pruned=$(( before - after )) + [[ "$pruned" -gt 0 ]] && log "cache: pruned $pruned stale checkout(s)" + return 0 +} + # Commit the agent's work in