1027 lines
49 KiB
Bash
Executable File
1027 lines
49 KiB
Bash
Executable File
#!/bin/bash
|
|
# Fast readiness checks before validate/trial. This is intentionally not a
|
|
# substitute for validate.sh; it catches common local setup problems early.
|
|
#
|
|
# Trials run on the worker's machine, so the profile's resource defaults
|
|
# (CPUS_DEFAULT, MEMORY_MB_DEFAULT, STORAGE_MB_DEFAULT) and, when a task is
|
|
# given, the task's [environment] request are compared with what Docker
|
|
# reports (CPUs, memory, free disk): below the defaults warns, a task above
|
|
# the machine fails. The trial set's size (TRIAL_MIN_SUBSTANTIVE trials at up
|
|
# to the agent budget each) is warned about when it implies a multi-hour run.
|
|
# The Docker daemon is probed for Harbor's egress control: a throwaway
|
|
# container built from Harbor's sidecar image loads a copy of the sidecar's
|
|
# nftables ruleset (the functional signal, which decides) and reads the kernel
|
|
# config for CONFIG_NFT_FIB_INET (Harbor's own check). Rules that load pass;
|
|
# rules that fail to load fail, as the sidecar fails at trial start; rules that
|
|
# load on a daemon whose config says the option is off fail too, because Harbor
|
|
# reads that config first and refuses; a probe that cannot run warns.
|
|
# Harbor must have the Terminus-2 agent, the only trial harness: listed by
|
|
# `harbor run --help` when a Harbor lists its agents there, else importable
|
|
# (harbor.agents.terminus_2) in the interpreter the harbor console script's
|
|
# first line names; FAIL when the import fails, WARN when that cannot be told.
|
|
# The authoring helper, Codex CLI (`codex`), is optional for validate, trial
|
|
# and submit: a codex missing from PATH is a WARN, one below the profile's
|
|
# CODEX_VERSION_FLOOR a FAIL like the other floors, and its .env variables
|
|
# (OPENAI_API_KEY, OPENAI_BASE_URL) missing a WARN naming them.
|
|
# The header names the toolkit version (PROFILE_VERSION) and build (the
|
|
# commit), with ", untagged" when the zip is a smoke cut; the profile name and
|
|
# the release tag stay in .toolkit-manifest and .toolkit-version. Given a
|
|
# task, the README render check and every static
|
|
# check of the profile run on it, the way scripts/validate.sh runs them, so
|
|
# shape problems show before a trial; the section closes with the note that
|
|
# Harbor enforces the offline policy at trial time from task.toml's
|
|
# network_mode values, which preflight only reads.
|
|
#
|
|
# Usage: scripts/preflight.sh [task-path]
|
|
# Example: scripts/preflight.sh tasks/<task-slug>
|
|
|
|
set -uo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
TOOLKIT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "$SCRIPT_DIR/lib/profile.sh"
|
|
source "$SCRIPT_DIR/lib/toml.sh"
|
|
source "$SCRIPT_DIR/lib/trial-lanes.sh"
|
|
source "$SCRIPT_DIR/lib/toolkit-version.sh"
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
FAIL_COUNT=0
|
|
WARN_COUNT=0
|
|
PASS_COUNT=0
|
|
|
|
# What check_docker read from the machine, for check_trial_resources: empty
|
|
# when Docker was not reachable or a value could not be read.
|
|
DOCKER_CPUS_SEEN=""
|
|
DOCKER_MEM_BYTES_SEEN=""
|
|
FREE_KB_SEEN=""
|
|
DOCKER_PS_OK=0
|
|
|
|
# `harbor run --help`, read once by check_harbor_setup_controls and reused by
|
|
# check_harbor_terminus_agent.
|
|
HARBOR_RUN_HELP=""
|
|
# The static checks check_task_static has run on the task, by file name, so
|
|
# the sweep over the profile's checks/ runs none of them twice.
|
|
PREFLIGHT_CHECKS_RUN=""
|
|
|
|
TASK_PATH="${1:-}"
|
|
if [ $# -gt 1 ]; then
|
|
echo "Usage: $0 [task-path]" >&2
|
|
exit 2
|
|
fi
|
|
|
|
pass() {
|
|
PASS_COUNT=$((PASS_COUNT + 1))
|
|
echo -e "${GREEN}PASS${NC} $1"
|
|
}
|
|
|
|
warn() {
|
|
WARN_COUNT=$((WARN_COUNT + 1))
|
|
echo -e "${YELLOW}WARN${NC} $1"
|
|
}
|
|
|
|
fail() {
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
|
echo -e "${RED}FAIL${NC} $1"
|
|
}
|
|
|
|
info() {
|
|
echo -e "${BLUE}INFO${NC} $1"
|
|
}
|
|
|
|
indent_output() {
|
|
sed 's/^/ /'
|
|
}
|
|
|
|
run_with_timeout() {
|
|
local seconds="$1"
|
|
shift
|
|
|
|
if command -v timeout >/dev/null 2>&1; then
|
|
timeout "$seconds" "$@"
|
|
else
|
|
"$@"
|
|
fi
|
|
}
|
|
|
|
load_env() {
|
|
if [ -f "$TOOLKIT_ROOT/.env" ]; then
|
|
local rc=0
|
|
|
|
(set -au; source "$TOOLKIT_ROOT/.env") >/dev/null 2>&1 || rc=$?
|
|
if [ "$rc" -ne 0 ]; then
|
|
fail ".env could not be loaded (exit $rc). Check it for shell syntax errors or unset variable references."
|
|
return
|
|
fi
|
|
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
source "$TOOLKIT_ROOT/.env"
|
|
set +a
|
|
restore_profile_policy_values
|
|
pass "Loaded .env"
|
|
else
|
|
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
|
|
warn ".env not found, but ANTHROPIC_API_KEY is already present in the shell"
|
|
else
|
|
warn ".env not found; copy .env.example to .env and fill in ANTHROPIC_API_KEY"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_required_command() {
|
|
local command_name="$1"
|
|
local purpose="$2"
|
|
local version_args="${3:---version}"
|
|
|
|
if ! command -v "$command_name" >/dev/null 2>&1; then
|
|
fail "$command_name not found ($purpose). Enter the toolkit dev container, then rerun preflight."
|
|
return 1
|
|
fi
|
|
|
|
local version_output
|
|
version_output="$(run_with_timeout 8 "$command_name" $version_args 2>&1 | head -n 1 || true)"
|
|
if [ -n "$version_output" ]; then
|
|
pass "$command_name found: $version_output"
|
|
else
|
|
pass "$command_name found"
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
version_at_least() {
|
|
local found="$1"
|
|
local required="$2"
|
|
local f_major f_minor f_patch r_major r_minor r_patch
|
|
|
|
IFS=. read -r f_major f_minor f_patch _ <<< "$found"
|
|
IFS=. read -r r_major r_minor r_patch _ <<< "$required"
|
|
|
|
for value in "$f_major" "$f_minor" "$f_patch" "$r_major" "$r_minor" "$r_patch"; do
|
|
if ! echo "$value" | grep -Eq '^[0-9]+$'; then
|
|
return 1
|
|
fi
|
|
done
|
|
|
|
if [ "$f_major" -gt "$r_major" ]; then return 0; fi
|
|
if [ "$f_major" -lt "$r_major" ]; then return 1; fi
|
|
if [ "$f_minor" -gt "$r_minor" ]; then return 0; fi
|
|
if [ "$f_minor" -lt "$r_minor" ]; then return 1; fi
|
|
[ "$f_patch" -ge "$r_patch" ]
|
|
}
|
|
|
|
is_positive_number() {
|
|
[[ "$1" =~ ^[0-9]+([.][0-9]+)?$ ]] && awk -v v="$1" 'BEGIN { exit !(v + 0 > 0) }'
|
|
}
|
|
|
|
is_nonnegative_integer() {
|
|
[[ "$1" =~ ^[0-9]+$ ]]
|
|
}
|
|
|
|
check_claude_code_version_floor() {
|
|
local min_version="$CLAUDE_CODE_VERSION_FLOOR"
|
|
local version_output version
|
|
|
|
if ! command -v claude >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
|
|
version_output="$(run_with_timeout 8 claude --version 2>&1 | head -n 1 || true)"
|
|
version="$(printf '%s\n' "$version_output" | grep -Eo '[0-9]+([.][0-9]+){2}' | head -n 1 || true)"
|
|
|
|
if [ -z "$version" ]; then
|
|
warn "Could not parse Claude Code version from: ${version_output:-<empty>}"
|
|
elif version_at_least "$version" "$min_version"; then
|
|
pass "Claude Code version $version meets the floor $min_version (the model defaults this toolkit's reviews, trial analysis and summaries call)"
|
|
else
|
|
fail "Claude Code version $version is older than $min_version, the floor for the model defaults this toolkit's reviews, trial analysis and summaries call (CLAUDE_CODE_VERSION_FLOOR in the profile's profile.env). Rebuild the dev container or run 'claude update', then rerun preflight."
|
|
fi
|
|
}
|
|
|
|
check_codex_version_floor() {
|
|
# The interactive authoring helper: Codex CLI, opened with `codex` on
|
|
# gpt-6.1-sol at high reasoning. `codex --version` prints `codex-cli <x.y.z>`.
|
|
local min_version="$CODEX_VERSION_FLOOR"
|
|
local version_output version
|
|
|
|
if ! command -v codex >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
|
|
version_output="$(run_with_timeout 8 codex --version 2>&1 | head -n 1 || true)"
|
|
version="$(printf '%s\n' "$version_output" | grep -Eo '[0-9]+([.][0-9]+){2}' | head -n 1 || true)"
|
|
|
|
if [ -z "$version" ]; then
|
|
warn "Could not parse Codex version from: ${version_output:-<empty>}"
|
|
elif version_at_least "$version" "$min_version"; then
|
|
pass "Codex version $version meets the floor $min_version (the Codex CLI the codex authoring helper runs on: gpt-6.1-sol at high reasoning)"
|
|
else
|
|
fail "Codex version $version is older than $min_version, the floor for the Codex CLI the codex authoring helper runs on (CODEX_VERSION_FLOOR in the profile's profile.env). Rebuild the dev container, then rerun preflight."
|
|
fi
|
|
}
|
|
|
|
check_harbor_version_floor() {
|
|
local min_version="$HARBOR_VERSION_FLOOR"
|
|
local version_output version
|
|
|
|
if ! command -v harbor >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
|
|
version_output="$(run_with_timeout 8 harbor --version 2>&1 | head -n 1 || true)"
|
|
version="$(printf '%s\n' "$version_output" | grep -Eo '[0-9]+([.][0-9]+){2}' | head -n 1 || true)"
|
|
|
|
if [ -z "$version" ]; then
|
|
warn "Could not parse Harbor version from: ${version_output:-<empty>}"
|
|
elif version_at_least "$version" "$min_version"; then
|
|
pass "Harbor version $version meets the floor $min_version (the release whose trial record and egress-control sidecar this toolkit's scripts read and probe)"
|
|
else
|
|
fail "Harbor version $version is older than $min_version, the Harbor release whose trial record (result.json) and egress-control sidecar this toolkit's scripts read and probe (HARBOR_VERSION_FLOOR in the profile's profile.env). Rebuild the dev container (npx @devcontainers/cli up --remove-existing-container), then rerun preflight."
|
|
fi
|
|
}
|
|
|
|
check_harbor_setup_controls() {
|
|
local help_output
|
|
|
|
if ! command -v harbor >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
|
|
HARBOR_RUN_HELP="$(COLUMNS=220 run_with_timeout 12 harbor run --help 2>&1 || true)"
|
|
help_output="$HARBOR_RUN_HELP"
|
|
if echo "$help_output" | grep -Fq -- "--agent-setup-timeout-multiplier" \
|
|
&& echo "$help_output" | grep -Fq -- "--max-retries" \
|
|
&& echo "$help_output" | grep -Fq -- "--retry-include"; then
|
|
pass "Harbor supports setup-timeout multiplier and setup-timeout retry controls"
|
|
else
|
|
warn "Harbor help did not show setup-timeout controls. Rebuild the dev container before using --agent-setup-timeout-multiplier or --agent-setup-retries."
|
|
fi
|
|
}
|
|
|
|
harbor_python() {
|
|
# The interpreter that runs the harbor console script: uv tool install and
|
|
# pipx write the tool environment's python into the script's first line
|
|
# ("#!/root/.local/share/uv/tools/harbor/bin/python"), and a
|
|
# "#!/usr/bin/env python3" line names one on PATH. Prints nothing when the
|
|
# first line names no python.
|
|
local shim shebang words interp
|
|
shim="$(command -v harbor 2>/dev/null)" || return 0
|
|
shebang="$(head -n 1 "$shim" 2>/dev/null || true)"
|
|
case "$shebang" in
|
|
"#!"*) ;;
|
|
*) return 0 ;;
|
|
esac
|
|
read -r -a words <<< "${shebang#\#!}"
|
|
interp="${words[0]:-}"
|
|
case "$interp" in
|
|
*/env) interp="${words[1]:-}" ;;
|
|
esac
|
|
case "$interp" in
|
|
*python*) ;;
|
|
*) return 0 ;;
|
|
esac
|
|
case "$interp" in
|
|
/*) ;;
|
|
*) interp="$(command -v "$interp" 2>/dev/null || true)" ;;
|
|
esac
|
|
if [ -n "$interp" ] && [ -x "$interp" ]; then
|
|
printf '%s\n' "$interp"
|
|
fi
|
|
}
|
|
|
|
check_harbor_terminus_agent() {
|
|
# Terminus-2 is the only trial harness (scripts/lib/trial-lanes.sh), so
|
|
# Harbor must have it. A Harbor that lists its agents in `harbor run --help`
|
|
# says so there; Harbor 0.22.0 types --agent as text, so the agent's module,
|
|
# harbor.agents.terminus_2 (what Harbor's agent factory loads), is imported
|
|
# in Harbor's own Python instead. No Docker is touched.
|
|
local py
|
|
if ! command -v harbor >/dev/null 2>&1; then
|
|
return
|
|
fi
|
|
if printf '%s\n' "$HARBOR_RUN_HELP" | grep -Fq -- "terminus-2"; then
|
|
pass "Harbor lists the terminus-2 agent (harbor run --help); trials and cheat trials run on it"
|
|
return
|
|
fi
|
|
py="$(harbor_python)"
|
|
if [ -z "$py" ]; then
|
|
warn "Could not tell whether Harbor has the terminus-2 agent: harbor run --help lists no agents and the harbor command's first line names no Python interpreter. Every trial and cheat trial runs on terminus-2; if a trial stops with an unknown agent, rebuild the dev container."
|
|
return
|
|
fi
|
|
if run_with_timeout 20 "$py" -c 'import harbor.agents.terminus_2 as m; m.Terminus2' >/dev/null 2>&1; then
|
|
pass "Harbor has the terminus-2 agent (harbor.agents.terminus_2 imports in $py); trials and cheat trials run on it"
|
|
else
|
|
fail "Harbor's Python ($py) cannot import harbor.agents.terminus_2, the terminus-2 agent every trial and cheat trial runs on. Rebuild the dev container (npx @devcontainers/cli up --remove-existing-container), then rerun preflight."
|
|
fi
|
|
}
|
|
|
|
check_docker() {
|
|
echo ""
|
|
echo "Docker"
|
|
echo "------"
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
fail "docker command not found. Enter the toolkit dev container or fix Docker CLI setup."
|
|
return
|
|
fi
|
|
pass "docker command found"
|
|
|
|
if run_with_timeout 12 docker ps >/dev/null 2>&1; then
|
|
pass "Docker daemon responds to docker ps"
|
|
DOCKER_PS_OK=1
|
|
else
|
|
fail "Docker daemon is unavailable or docker ps hung. Start Docker Desktop / dockerd and confirm docker ps works."
|
|
return
|
|
fi
|
|
|
|
local docker_cpus=""
|
|
local docker_mem_bytes=""
|
|
docker_cpus="$(docker info --format '{{.NCPU}}' 2>/dev/null || true)"
|
|
docker_mem_bytes="$(docker info --format '{{.MemTotal}}' 2>/dev/null || true)"
|
|
|
|
if [ -n "$docker_cpus" ] && [ "$docker_cpus" -gt 0 ] 2>/dev/null; then
|
|
pass "Docker reports $docker_cpus CPU(s)"
|
|
else
|
|
warn "Could not read Docker CPU allocation"
|
|
fi
|
|
|
|
if [ -n "$docker_mem_bytes" ] && [ "$docker_mem_bytes" -gt 0 ] 2>/dev/null; then
|
|
local docker_mem_gb
|
|
docker_mem_gb=$(( (docker_mem_bytes + 1073741823) / 1073741824 ))
|
|
pass "Docker reports about ${docker_mem_gb}GB memory"
|
|
else
|
|
warn "Could not read Docker memory allocation"
|
|
fi
|
|
|
|
local free_kb=""
|
|
local free_gb=0
|
|
free_kb="$(df -Pk "$TOOLKIT_ROOT" 2>/dev/null | awk 'NR == 2 { print $4 }' || true)"
|
|
if [ -n "$free_kb" ] && [ "$free_kb" -gt 0 ] 2>/dev/null; then
|
|
free_gb=$(( free_kb / 1024 / 1024 ))
|
|
if [ "$free_gb" -lt 5 ]; then
|
|
fail "Only ${free_gb}GB free near the toolkit workspace; Docker builds and Harbor jobs may fail. Free disk space before trialing."
|
|
elif [ "$free_gb" -lt 15 ]; then
|
|
warn "Only ${free_gb}GB free near the toolkit workspace. Clean old harbor-jobs/Docker artifacts if trials fail."
|
|
else
|
|
pass "${free_gb}GB free near the toolkit workspace"
|
|
fi
|
|
else
|
|
warn "Could not read free disk space near the toolkit workspace"
|
|
fi
|
|
|
|
DOCKER_CPUS_SEEN="$docker_cpus"
|
|
DOCKER_MEM_BYTES_SEEN="$docker_mem_bytes"
|
|
FREE_KB_SEEN="$free_kb"
|
|
|
|
if [ -n "$docker_cpus" ] && [ "$docker_cpus" -lt 4 ] 2>/dev/null; then
|
|
warn "Docker has fewer than 4 CPUs; use scripts/trial.sh ... --concurrency 1 on this machine."
|
|
elif [ -n "$docker_mem_bytes" ] && [ "$docker_mem_bytes" -lt 12884901888 ] 2>/dev/null; then
|
|
warn "Docker has under 12GB memory; use scripts/trial.sh ... --concurrency 1 if installs or trials stall/OOM."
|
|
else
|
|
pass "Default trial concurrency $TRIAL_CONCURRENCY looks reasonable for the reported Docker resources"
|
|
fi
|
|
}
|
|
|
|
# Trials run on this machine. The profile's *_DEFAULT resource keys are what
|
|
# the scaffold asks for and the task's own [environment] block is what this
|
|
# task asks for; both are compared with what check_docker read. There is no
|
|
# fixed ceiling: below the profile defaults is a warning (the scaffold's task
|
|
# would not fit), a task above the machine is a failure (it cannot be run or
|
|
# calibrated here). The agent budget times the substantive-trial minimum says
|
|
# how long a trial set can take.
|
|
resource_docs_hint() {
|
|
# The profile's docs directory; its README when it has one, else the
|
|
# task-anatomy page (named through a variable so the pre-profiles path
|
|
# guard does not read a literal pre-profiles location here).
|
|
local docs="profiles/$TOOLKIT_PROFILE/docs" anatomy="task-anatomy.md"
|
|
if [ -f "$PROFILE_DOCS_DIR/README.md" ]; then
|
|
echo "see $docs/README.md, the section on budgets and where trials run"
|
|
else
|
|
echo "see $docs/$anatomy on resources and where trials run"
|
|
fi
|
|
}
|
|
|
|
int_part() {
|
|
# int_part <number>: the integer part of a TOML number such as 28800.0
|
|
printf '%s' "$1" | sed 's/\..*$//'
|
|
}
|
|
|
|
check_trial_resources() {
|
|
echo ""
|
|
echo "Trial Resources And Budget"
|
|
echo "--------------------------"
|
|
|
|
local hint docker_mem_mb="" free_mb=""
|
|
hint="$(resource_docs_hint)"
|
|
if [ -n "$DOCKER_MEM_BYTES_SEEN" ]; then
|
|
docker_mem_mb=$(( DOCKER_MEM_BYTES_SEEN / 1048576 ))
|
|
fi
|
|
if [ -n "$FREE_KB_SEEN" ]; then
|
|
free_mb=$(( FREE_KB_SEEN / 1024 ))
|
|
fi
|
|
|
|
# The profile's defaults (what the scaffold's task.toml asks for).
|
|
local cpus_default="${CPUS_DEFAULT:-}" mem_default="${MEMORY_MB_DEFAULT:-}" storage_default="${STORAGE_MB_DEFAULT:-}"
|
|
if [ -z "$cpus_default" ] || [ -z "$mem_default" ] || [ -z "$storage_default" ]; then
|
|
info "Profile $TOOLKIT_PROFILE declares no CPUS_DEFAULT/MEMORY_MB_DEFAULT/STORAGE_MB_DEFAULT; the defaults comparison is skipped"
|
|
elif [ -z "$DOCKER_CPUS_SEEN" ] || [ -z "$docker_mem_mb" ] || [ -z "$free_mb" ]; then
|
|
warn "Could not read Docker's CPUs, memory or the free disk, so the profile defaults ($cpus_default CPUs, $mem_default MB memory, $storage_default MB storage) were not compared with this machine; $hint."
|
|
else
|
|
local below=0
|
|
if [ "$DOCKER_CPUS_SEEN" -lt "$cpus_default" ]; then
|
|
warn "Docker has $DOCKER_CPUS_SEEN CPU(s); the profile's default task asks for $cpus_default (CPUS_DEFAULT). Trials run on this machine on those defaults; $hint."
|
|
below=1
|
|
fi
|
|
if [ "$docker_mem_mb" -lt "$mem_default" ]; then
|
|
warn "Docker has $docker_mem_mb MB of memory; the profile's default task asks for $mem_default MB (MEMORY_MB_DEFAULT). Trials run on this machine on those defaults; $hint."
|
|
below=1
|
|
fi
|
|
if [ "$free_mb" -lt "$storage_default" ]; then
|
|
warn "$free_mb MB free near the toolkit; the profile's default task asks for $storage_default MB of storage (STORAGE_MB_DEFAULT). Trials run on this machine on those defaults; $hint."
|
|
below=1
|
|
fi
|
|
if [ "$below" -eq 0 ]; then
|
|
pass "Docker meets the profile's resource defaults ($cpus_default CPUs, $mem_default MB memory, $storage_default MB storage)"
|
|
fi
|
|
fi
|
|
|
|
# The task's own request, when a task was given.
|
|
local task_toml="" req_cpus="" req_mem="" req_storage="" agent_timeout=""
|
|
if [ -n "$TASK_PATH" ] && [ -f "$TASK_PATH/task.toml" ]; then
|
|
task_toml="$TASK_PATH/task.toml"
|
|
req_cpus="$(int_part "$(toml_path_value "$task_toml" environment.cpus)")"
|
|
req_mem="$(int_part "$(toml_path_value "$task_toml" environment.memory_mb)")"
|
|
req_storage="$(int_part "$(toml_path_value "$task_toml" environment.storage_mb)")"
|
|
agent_timeout="$(int_part "$(toml_path_value "$task_toml" agent.timeout_sec)")"
|
|
fi
|
|
if [ -n "$task_toml" ]; then
|
|
if ! is_nonnegative_integer "$req_cpus" || ! is_nonnegative_integer "$req_mem" || ! is_nonnegative_integer "$req_storage"; then
|
|
warn "$TASK_PATH: could not read [environment] cpus, memory_mb and storage_mb from task.toml (got '${req_cpus:-?}', '${req_mem:-?}', '${req_storage:-?}'), so the task's request was not compared with this machine"
|
|
elif [ -z "$DOCKER_CPUS_SEEN" ] || [ -z "$docker_mem_mb" ] || [ -z "$free_mb" ]; then
|
|
warn "Could not read Docker's CPUs, memory or the free disk, so $TASK_PATH's request ($req_cpus CPUs, $req_mem MB memory, $req_storage MB storage) was not compared with this machine; $hint."
|
|
else
|
|
local above=0
|
|
if [ "$req_cpus" -gt "$DOCKER_CPUS_SEEN" ]; then
|
|
fail "$TASK_PATH asks for $req_cpus CPUs; Docker has $DOCKER_CPUS_SEEN. A task that asks for more than this machine has cannot run or calibrate here: lower [environment] cpus (and [verifier.environment]) or use a bigger machine; $hint."
|
|
above=1
|
|
fi
|
|
if [ "$req_mem" -gt "$docker_mem_mb" ]; then
|
|
fail "$TASK_PATH asks for $req_mem MB of memory; Docker has $docker_mem_mb MB. A task that asks for more than this machine has cannot run or calibrate here: lower [environment] memory_mb (and [verifier.environment]) or use a bigger machine; $hint."
|
|
above=1
|
|
fi
|
|
if [ "$req_storage" -gt "$free_mb" ]; then
|
|
fail "$TASK_PATH asks for $req_storage MB of storage; $free_mb MB are free near the toolkit. A task that asks for more than this machine has cannot run or calibrate here: free disk space or lower [environment] storage_mb (and [verifier.environment]); $hint."
|
|
above=1
|
|
fi
|
|
if [ "$above" -eq 0 ]; then
|
|
pass "$TASK_PATH asks for $req_cpus CPUs, $req_mem MB memory, $req_storage MB storage; Docker can give that"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# The trial set: TRIAL_MIN_SUBSTANTIVE regular trials, then CHEAT_TRIAL_COUNT
|
|
# cheat trials, at up to the agent budget each (the task's [agent]
|
|
# timeout_sec when a task was given, else the profile default),
|
|
# TRIAL_CONCURRENCY at a time.
|
|
local min_trials="${TRIAL_MIN_SUBSTANTIVE:-}" cheat_trials="${CHEAT_TRIAL_COUNT:-}" concurrency="${TRIAL_CONCURRENCY:-}" budget="${agent_timeout:-}"
|
|
if ! is_nonnegative_integer "$budget"; then
|
|
budget="${AGENT_TIMEOUT_SEC_DEFAULT:-}"
|
|
fi
|
|
if is_nonnegative_integer "$min_trials" && is_nonnegative_integer "$budget" && is_nonnegative_integer "$concurrency" && [ "$concurrency" -gt 0 ]; then
|
|
local total_h wall_h batches cheat_note="and the cheat trials come on top"
|
|
total_h=$(( min_trials * budget / 3600 ))
|
|
batches=$(( (min_trials + concurrency - 1) / concurrency ))
|
|
wall_h=$(( batches * budget / 3600 ))
|
|
if is_nonnegative_integer "$cheat_trials"; then
|
|
cheat_note="and the $cheat_trials cheat trials add up to $(( cheat_trials * budget / 3600 )) agent-hours more"
|
|
fi
|
|
if [ $(( min_trials * budget )) -gt 3600 ]; then
|
|
warn "A trial set of $min_trials substantive trials at up to $budget s each is up to $total_h agent-hours (about $wall_h h of wall clock at concurrency $concurrency), $cheat_note; plan for a multi-hour run on this machine; $hint."
|
|
else
|
|
pass "A trial set of $min_trials substantive trials at up to $budget s each fits within an hour (about $wall_h h of wall clock at concurrency $concurrency)"
|
|
fi
|
|
else
|
|
info "TRIAL_MIN_SUBSTANTIVE, TRIAL_CONCURRENCY or the agent budget is not a number; the trial-set budget was not estimated"
|
|
fi
|
|
}
|
|
|
|
# Harbor 0.22.0 enforces no-network and allowlist with an egress-control
|
|
# sidecar: harbor/environments/docker/harbor-docker-egress-control-sidecar,
|
|
# built FROM gogost/gost:3.2.7-nightly.20260602 (Alpine 3.23 with nftables) and
|
|
# run with cap_add NET_ADMIN and NET_RAW (docker-compose-egress-control.yaml).
|
|
# The image's entrypoint is gost itself; Harbor's compose replaces it with the
|
|
# sidecar's entrypoint script, and the probe replaces it with sh (--entrypoint
|
|
# sh), otherwise the probe script reaches gost as arguments and gost exits
|
|
# looking for its config file. Its bin/network-policy loads an nftables
|
|
# ruleset, table inet gost_egress: a
|
|
# nat output chain that redirects TCP to gost and a filter output chain that
|
|
# rejects everything but TCP, both using `fib daddr type local`. Two signals
|
|
# say whether that can work on a Docker daemon, and preflight reads both in one
|
|
# throwaway container built from the sidecar's own base image, so the very nft
|
|
# binary the sidecar uses gives the answer, nothing is installed in the
|
|
# container, and the pull warms the layer Harbor's sidecar build needs anyway:
|
|
#
|
|
# 1. The functional signal, which decides the verdict: with the sidecar's
|
|
# capabilities (--cap-add NET_ADMIN --cap-add NET_RAW; --network none, the
|
|
# probe makes no connections) the container loads a copy of the ruleset
|
|
# under the table name preflight_probe, never a live one, with `nft -f -`
|
|
# and deletes it again. A kernel without the fib expression in inet
|
|
# tables fails the load ("Operation not supported"), which is how the
|
|
# sidecar fails when a trial starts; Docker Desktop before 4.86.0 on Apple
|
|
# Silicon did. A kernel that lists CONFIG_NFT_FIB_INET as a module it
|
|
# cannot load fails here too.
|
|
# 2. The config signal, Harbor's own check: docker.py's
|
|
# _egress_control_kernel_support runs an alpine container that zcats
|
|
# /proc/config.gz and greps ^CONFIG_NFT_FIB_INET=[ym]; absent means the
|
|
# environment reports no disable_internet capability and a restricted task
|
|
# stops up front with "network_mode='no-network' is not supported by
|
|
# EnvironmentType.DOCKER"; no /proc/config.gz means Harbor continues
|
|
# optimistically. Preflight reads that file and nothing else, exactly as
|
|
# Harbor does, and reports present, absent or unknown. An earlier probe
|
|
# fell back to the daemon's /boot/config-<release> through a read-only
|
|
# bind mount; Docker Desktop refuses that mount ("mounts denied: The path
|
|
# /boot is not shared from the host and is not known to Docker"), so the
|
|
# probe never ran there and preflight warned instead of deciding, and a
|
|
# reading from /boot can only produce a verdict Harbor itself would not
|
|
# reach, since Harbor reads /proc/config.gz alone. Some daemons expose no
|
|
# /proc/config.gz, so the config signal alone cannot decide, which is why
|
|
# the functional signal does.
|
|
#
|
|
# Verdicts: rules load and config present or unknown, PASS. Rules load but
|
|
# config absent, FAIL: Harbor reads that config before enabling egress control
|
|
# and will refuse restricted tasks on this daemon. Rules fail to load, FAIL with
|
|
# nft's message. A container that cannot run, or output nothing here
|
|
# recognises, WARN. The image digest and the ruleset below are copied from
|
|
# the sidecar of the Harbor release EGRESS_PROBE_HARBOR_VERSION names: its
|
|
# Dockerfile for the image, its bin/network-policy setup_nftables (mark
|
|
# 114514, port 12345) for the ruleset, the table renamed. When
|
|
# HARBOR_VERSION_FLOOR moves, re-check both against that Harbor's sidecar and
|
|
# set the version here; tests/test-preflight-floors.sh fails until the two
|
|
# agree.
|
|
EGRESS_PROBE_HARBOR_VERSION="0.22.0"
|
|
EGRESS_PROBE_IMAGE="gogost/gost:3.2.7-nightly.20260602@sha256:afc0137758ab4ce399d47a299f9abbacbf522b52a17e59cbb4b4e7a1a66e9196"
|
|
EGRESS_PROBE_RULESET='table inet preflight_probe {
|
|
chain output {
|
|
type nat hook output priority dstnat; policy accept;
|
|
meta mark 114514 return
|
|
fib daddr type local return
|
|
meta l4proto tcp redirect to :12345
|
|
}
|
|
chain egress {
|
|
type filter hook output priority filter; policy accept;
|
|
meta mark 114514 accept
|
|
fib daddr type local accept
|
|
ip protocol icmp accept
|
|
ip6 nexthdr icmpv6 accept
|
|
meta l4proto != tcp reject
|
|
}
|
|
}'
|
|
# Runs as sh in the probe container with the ruleset on stdin. One token per
|
|
# line: config:present, config:absent or config:unknown; rules:ok, or
|
|
# rules:fail followed by the first line of nft's stderr; then uname -r. The
|
|
# config read is Harbor 0.22.0's _EGRESS_CONTROL_KERNEL_PROBE_SCRIPT (`if [ !
|
|
# -f /proc/config.gz ]; then exit 0; fi; zcat /proc/config.gz 2>/dev/null |
|
|
# grep -qE '^CONFIG_NFT_FIB_INET=[ym]'`) with its three outcomes named.
|
|
EGRESS_PROBE_SCRIPT='if [ ! -f /proc/config.gz ]; then echo config:unknown; elif zcat /proc/config.gz 2>/dev/null | grep -qE "^CONFIG_NFT_FIB_INET=[ym]"; then echo config:present; else echo config:absent; fi; err="$(nft -f - 2>&1 >/dev/null)"; rc=$?; if [ "$rc" -eq 0 ]; then echo rules:ok; else echo "rules:fail $(printf "%s\n" "$err" | head -n 1)"; fi; nft delete table inet preflight_probe >/dev/null 2>&1; uname -r'
|
|
|
|
run_egress_probe() {
|
|
# run_egress_probe: the probe container, its entrypoint (gost) replaced by
|
|
# sh, with the ruleset on stdin (a here-string, so no pipe can fail
|
|
# underneath docker) and nothing mounted from the daemon's host; its
|
|
# stdout and stderr on stdout, docker's exit status.
|
|
run_with_timeout 120 docker container run -i --rm --cap-add NET_ADMIN --cap-add NET_RAW --network none --entrypoint sh "$EGRESS_PROBE_IMAGE" -c "$EGRESS_PROBE_SCRIPT" <<< "$EGRESS_PROBE_RULESET" 2>&1
|
|
}
|
|
|
|
check_egress_control_support() {
|
|
echo ""
|
|
echo "Network Policy Enforcement (Docker Daemon)"
|
|
echo "------------------------------------------"
|
|
|
|
local hint remedy output rc config rules nft_message release
|
|
hint="$(resource_docs_hint)"
|
|
remedy="Fix it on the Docker side: on macOS use Docker Desktop 4.86 or newer (earlier versions on Apple Silicon lack the kernel feature) or OrbStack; on Windows keep Docker Desktop with WSL 2 and update it; or use a Linux Docker host whose kernel enables CONFIG_NFT_FIB_INET; never change the task's network_mode to work around it; $hint (the restricted-network section)."
|
|
if [ "$DOCKER_PS_OK" -ne 1 ]; then
|
|
warn "Docker is not reachable, so the egress-rules probe (Harbor's egress-control ruleset and CONFIG_NFT_FIB_INET) did not run; rerun preflight once docker ps works; $hint."
|
|
return
|
|
fi
|
|
|
|
# One run, asking the daemon for nothing from its host: the kernel config
|
|
# is read from /proc/config.gz inside the container, as Harbor reads it.
|
|
output="$(run_egress_probe)"
|
|
rc=$?
|
|
if [ "$rc" -ne 0 ]; then
|
|
warn "the egress-rules probe container could not run (docker container run $EGRESS_PROBE_IMAGE exited $rc): $(printf '%s' "$output" | tr '\n' ' ' | cut -c1-300). Harbor's egress-control rules and CONFIG_NFT_FIB_INET were not checked; Harbor builds its sidecar from this image, so a pull that fails here fails at trial start too. Check that the image can be pulled and rerun preflight; $hint."
|
|
return
|
|
fi
|
|
config="$(printf '%s\n' "$output" | grep -E '^config:(present|absent|unknown)$' | head -n 1)"
|
|
config="${config#config:}"
|
|
rules="$(printf '%s\n' "$output" | grep -E '^rules:(ok|fail)' | head -n 1)"
|
|
release="$(printf '%s\n' "$output" | tail -n 1)"
|
|
nft_message=""
|
|
case "$rules" in
|
|
rules:ok) rules=ok ;;
|
|
"rules:fail "*) nft_message="${rules#rules:fail }"; rules=fail ;;
|
|
rules:fail*) nft_message="no message"; rules=fail ;;
|
|
*) rules="" ;;
|
|
esac
|
|
if [ -z "$config" ] || [ -z "$rules" ]; then
|
|
warn "the egress-rules probe printed nothing recognisable: $(printf '%s' "$output" | tr '\n' ' ' | cut -c1-300). Harbor's egress-control rules and CONFIG_NFT_FIB_INET were not checked; $hint."
|
|
return
|
|
fi
|
|
case "$rules:$config" in
|
|
ok:present|ok:unknown)
|
|
pass "Docker daemon can load Harbor's egress-control rules; no-network and allowlist tasks can run here (kernel $release)"
|
|
;;
|
|
ok:absent)
|
|
fail "Docker daemon can load Harbor's egress-control rules, but its kernel config says CONFIG_NFT_FIB_INET is off (kernel $release), and Harbor $EGRESS_PROBE_HARBOR_VERSION reads that config before enabling egress control, so it will still refuse no-network and allowlist tasks on this daemon (network_mode='no-network' is not supported by EnvironmentType.DOCKER). $remedy"
|
|
;;
|
|
fail:*)
|
|
fail "Docker daemon cannot load Harbor's egress-control rules (nft: $nft_message; kernel $release). Harbor's sidecar fails the same way when a trial starts, so no-network and allowlist tasks cannot run on this daemon. $remedy"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
check_tools() {
|
|
echo ""
|
|
echo "Toolkit Commands"
|
|
echo "----------------"
|
|
|
|
if check_required_command harbor "validate/trial/submit use Harbor" "--version"; then
|
|
check_harbor_version_floor
|
|
check_harbor_setup_controls
|
|
check_harbor_terminus_agent
|
|
fi
|
|
if check_required_command claude "quality checks and trial analysis use Claude Code" "--version"; then
|
|
check_claude_code_version_floor
|
|
fi
|
|
# The authoring helper is optional for validate, trial and submit: a codex
|
|
# missing from PATH (an image built from an earlier toolkit) is a WARN with
|
|
# the rebuild, not the FAIL a missing harbor or claude is.
|
|
if command -v codex >/dev/null 2>&1; then
|
|
if check_required_command codex "the authoring helper, Codex CLI on gpt-6.1-sol" "--version"; then
|
|
check_codex_version_floor
|
|
fi
|
|
else
|
|
warn "codex not found (the authoring helper, Codex CLI on gpt-6.1-sol; validate, trial and submit run without it). The dev container installs it: rebuild the dev container (npx @devcontainers/cli up --remove-existing-container), then rerun preflight."
|
|
fi
|
|
}
|
|
|
|
check_lane_credentials() {
|
|
# check_lane_credentials <label> <agent> <model>: the lane is a Terminus-2
|
|
# lane with a known provider prefix (trial.sh refuses anything else before
|
|
# any harbor run), and its .env variables are set.
|
|
local label="$1" agent="$2" model="$3" needed missing
|
|
if ! lane_agent_supported "$agent"; then
|
|
fail "$label $agent=$model: $agent is not a supported trial harness; trials run on terminus-2 under the task's offline policy (an agent installed in the task container cannot start there), and trial.sh refuses this lane."
|
|
return
|
|
fi
|
|
needed="$(lane_credential_vars "$agent" "$model")"
|
|
if [ -z "$needed" ]; then
|
|
fail "$label $agent=$model: the model needs a provider prefix this toolkit knows (gemini/, anthropic/, openai/), which decides the lane's credentials; trial.sh refuses this lane."
|
|
return
|
|
fi
|
|
missing="$(lane_missing_credentials "$agent" "$model")"
|
|
if [ -z "$missing" ]; then
|
|
pass "$label $agent=$model: $(printf '%s' "$needed" | sed 's/ /, /g') set"
|
|
elif [ "${TRIAL_ROSTER_FILTER_BY_CREDENTIALS:-1}" = "0" ]; then
|
|
fail "$label $agent=$model needs $(printf '%s' "$needed" | sed 's/ /, /g') in .env; missing: $(printf '%s' "$missing" | sed 's/ /, /g'). Every lane is mandatory in this profile (TRIAL_ROSTER_FILTER_BY_CREDENTIALS=0), so trial.sh will refuse to start; set the variables in .env (see .env.example)."
|
|
else
|
|
warn "$label $agent=$model needs $(printf '%s' "$needed" | sed 's/ /, /g'); missing: $(printf '%s' "$missing" | sed 's/ /, /g'). trial.sh will skip this lane unless it is requested with --agents."
|
|
fi
|
|
}
|
|
|
|
describe_lanes() {
|
|
# describe_lanes <agent=model:quota>...: "N trial slots, Q1 on M1 + Q2 on M2 via AGENT"
|
|
local total=0 parts="" agents="" entry agent model quota
|
|
for entry in "$@"; do
|
|
lane_entry_valid "$entry" || continue
|
|
agent="$(lane_entry_agent "$entry")"
|
|
model="$(lane_entry_model "$entry")"
|
|
quota="$(lane_entry_quota "$entry")"
|
|
total=$((total + quota))
|
|
parts="${parts:+$parts + }$quota on $model"
|
|
case " $agents " in
|
|
*" $agent "*) ;;
|
|
*) agents="${agents:+$agents, }$agent" ;;
|
|
esac
|
|
done
|
|
printf '%s trial slots, %s via %s' "$total" "$parts" "$agents"
|
|
}
|
|
|
|
check_env_and_credentials() {
|
|
echo ""
|
|
echo "Credentials And Trial Defaults"
|
|
echo "------------------------------"
|
|
|
|
# Where the model runs, so nothing here reads as hosts allowed inside the
|
|
# container: Terminus-2 calls the model from this machine.
|
|
info "Model calls happen on this machine through the LLM proxy; the task container stays under the task's declared network policy"
|
|
|
|
load_env
|
|
|
|
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
|
|
pass "ANTHROPIC_API_KEY is set"
|
|
else
|
|
fail "ANTHROPIC_API_KEY is not set. Copy .env.example to .env and fill it in."
|
|
fi
|
|
|
|
# The authoring helper's credentials: the same proxy key and the proxy's
|
|
# OpenAI route, which scripts/lib/codex-config.sh renders into Codex's
|
|
# config at each launch of `codex`. The helper is optional for validate,
|
|
# trial and submit, so a missing variable is a WARN, never a FAIL.
|
|
local helper_missing=""
|
|
[ -n "${OPENAI_API_KEY:-}" ] || helper_missing="OPENAI_API_KEY"
|
|
[ -n "${OPENAI_BASE_URL:-}" ] || helper_missing="${helper_missing:+$helper_missing, }OPENAI_BASE_URL"
|
|
if [ -n "$helper_missing" ]; then
|
|
warn "Authoring helper codex on gpt-6.1-sol needs OPENAI_API_KEY and OPENAI_BASE_URL in .env; missing: $helper_missing. The helper is optional (validate, trial and submit run without it); to use it, fill both in .env as in .env.example (the same proxy key as ANTHROPIC_API_KEY, and the proxy's /openai/v1 route)."
|
|
else
|
|
case "$OPENAI_BASE_URL" in
|
|
*/openai/v1) pass "Authoring helper codex on gpt-6.1-sol: OPENAI_API_KEY and OPENAI_BASE_URL set" ;;
|
|
*) warn "Authoring helper codex on gpt-6.1-sol: OPENAI_API_KEY and OPENAI_BASE_URL set, but OPENAI_BASE_URL should end in /openai/v1 (Codex appends /responses; the proxy serves gpt-6.1-sol on the Responses API there): $OPENAI_BASE_URL" ;;
|
|
esac
|
|
fi
|
|
|
|
# Every roster lane's credentials, and the cheat lane's
|
|
# (scripts/lib/trial-lanes.sh: terminus-2 by its model's provider prefix;
|
|
# any other agent is refused). A missing variable FAILs when the profile
|
|
# makes lanes mandatory (TRIAL_ROSTER_FILTER_BY_CREDENTIALS=0, trial.sh
|
|
# refuses to start) and WARNs otherwise (trial.sh skips the lane).
|
|
local lane_entry
|
|
for lane_entry in $TRIAL_ROSTER; do
|
|
lane_entry_valid "$lane_entry" || continue
|
|
check_lane_credentials "Trial lane" "$(lane_entry_agent "$lane_entry")" "$(lane_entry_model "$lane_entry")"
|
|
done
|
|
if [ -n "${CHEAT_TRIAL_AGENT:-}" ]; then
|
|
check_lane_credentials "Cheat lane" "$CHEAT_TRIAL_AGENT" "${CHEAT_TRIAL_MODEL:-}"
|
|
fi
|
|
|
|
# The default run and the cheat run, rendered from the profile's values:
|
|
# the slots per lane and the harness; top-ups only replace slots that
|
|
# produced no verifier reward.
|
|
local topup_note="top-ups add attempts only when a slot fails for infrastructure or tooling reasons and yields no substantive signal"
|
|
# $TRIAL_ROSTER is split on purpose: one lane entry per word.
|
|
info "Default run: $(describe_lanes $TRIAL_ROSTER); $topup_note"
|
|
if [ -n "${TRIAL_REASONING_EFFORT:-}" ]; then
|
|
info "Regular trial reasoning effort: $TRIAL_REASONING_EFFORT (explicit provider settings)"
|
|
fi
|
|
if [ -n "${CHEAT_TRIAL_REASONING_EFFORT:-}" ]; then
|
|
info "Cheat trial reasoning effort: $CHEAT_TRIAL_REASONING_EFFORT (initial and fallback models)"
|
|
fi
|
|
if [ -n "${CHEAT_TRIAL_AGENT:-}" ] && [ -n "${CHEAT_TRIAL_MODEL:-}" ]; then
|
|
# The cheat lane's quota is CHEAT_TRIAL_COUNT (TRIAL_MIN_VALID sizes the
|
|
# regular roster); trial.sh and check-trial-signal.sh refuse without it.
|
|
if is_nonnegative_integer "${CHEAT_TRIAL_COUNT:-}" && [ "${CHEAT_TRIAL_COUNT:-0}" -gt 0 ]; then
|
|
info "Cheat run: $(describe_lanes "$CHEAT_TRIAL_AGENT=$CHEAT_TRIAL_MODEL:$CHEAT_TRIAL_COUNT"); $topup_note"
|
|
else
|
|
fail "$PROFILE_ENV_FILE sets no CHEAT_TRIAL_COUNT (the number of substantive cheat trials); scripts/cheat-trial.sh and scripts/check-trial-signal.sh refuse to run without it"
|
|
fi
|
|
fi
|
|
|
|
# LiteLLM builds the Gemini request URL as GEMINI_API_BASE/models/<model>:generateContent,
|
|
# and the proxy serves v1beta only.
|
|
local gemini_base="${GEMINI_API_BASE:-}"
|
|
if [ -n "$gemini_base" ]; then
|
|
case "$gemini_base" in
|
|
*/v1beta) pass "GEMINI_API_BASE ends in /v1beta" ;;
|
|
*) warn "GEMINI_API_BASE should end in /v1beta (LiteLLM appends /models/<model>:generateContent; the proxy serves v1beta only): $gemini_base" ;;
|
|
esac
|
|
fi
|
|
|
|
local base_url="${ANTHROPIC_BASE_URL:-}"
|
|
if [ -z "$base_url" ]; then
|
|
warn "ANTHROPIC_BASE_URL is not set. Use .env.example's app-llmproxy URL unless you intentionally use a direct Anthropic key."
|
|
elif echo "$base_url" | grep -Eq '^https://app\.(dataannotation\.tech|surgehq\.ai)/api/llm_proxy'; then
|
|
warn "ANTHROPIC_BASE_URL uses the old app.* LLM proxy domain. Replace app. with app-llmproxy."
|
|
elif echo "$base_url" | grep -Eq '^https://app-llmproxy\.(dataannotation\.tech|surgehq\.ai)/api/llm_proxy'; then
|
|
pass "ANTHROPIC_BASE_URL uses the app-llmproxy domain"
|
|
else
|
|
warn "ANTHROPIC_BASE_URL is set to a non-standard URL: $base_url"
|
|
fi
|
|
|
|
local tokens="${CLAUDE_CODE_MAX_OUTPUT_TOKENS:-}"
|
|
if [ -z "$tokens" ]; then
|
|
# trial.sh must default the ceiling from the profile key preflight reads.
|
|
if grep -Fq 'CLAUDE_CODE_MAX_OUTPUT_TOKENS:-$CLAUDE_CODE_MAX_OUTPUT_TOKENS_DEFAULT' "$TOOLKIT_ROOT/scripts/trial.sh"; then
|
|
pass "CLAUDE_CODE_MAX_OUTPUT_TOKENS is unset; trial.sh will default its Claude Code analysis and summary runs to $CLAUDE_CODE_MAX_OUTPUT_TOKENS_DEFAULT"
|
|
else
|
|
fail "CLAUDE_CODE_MAX_OUTPUT_TOKENS is unset and this trial.sh does not appear to default to $CLAUDE_CODE_MAX_OUTPUT_TOKENS_DEFAULT"
|
|
fi
|
|
elif ! echo "$tokens" | grep -Eq '^[0-9]+$'; then
|
|
fail "CLAUDE_CODE_MAX_OUTPUT_TOKENS must be numeric, got: $tokens"
|
|
elif [ "$tokens" -ne "$CLAUDE_CODE_MAX_OUTPUT_TOKENS_DEFAULT" ]; then
|
|
fail "CLAUDE_CODE_MAX_OUTPUT_TOKENS is $tokens; set it to $CLAUDE_CODE_MAX_OUTPUT_TOKENS_DEFAULT for the trial analysis and the reviews"
|
|
else
|
|
pass "CLAUDE_CODE_MAX_OUTPUT_TOKENS is $CLAUDE_CODE_MAX_OUTPUT_TOKENS_DEFAULT"
|
|
fi
|
|
|
|
local setup_multiplier="${HARBOR_AGENT_SETUP_TIMEOUT_MULTIPLIER:-}"
|
|
if [ -n "$setup_multiplier" ]; then
|
|
if is_positive_number "$setup_multiplier"; then
|
|
pass "HARBOR_AGENT_SETUP_TIMEOUT_MULTIPLIER is $setup_multiplier"
|
|
else
|
|
fail "HARBOR_AGENT_SETUP_TIMEOUT_MULTIPLIER must be a positive number, got: $setup_multiplier"
|
|
fi
|
|
fi
|
|
|
|
local setup_retries="${HARBOR_AGENT_SETUP_RETRIES:-}"
|
|
if [ -n "$setup_retries" ]; then
|
|
if is_nonnegative_integer "$setup_retries"; then
|
|
pass "HARBOR_AGENT_SETUP_RETRIES is $setup_retries"
|
|
else
|
|
fail "HARBOR_AGENT_SETUP_RETRIES must be a non-negative integer, got: $setup_retries"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_network_target() {
|
|
local label="$1"
|
|
local url="$2"
|
|
local severity="$3"
|
|
|
|
if run_with_timeout 10 curl -L -I -sS --connect-timeout 4 --max-time 8 -o /dev/null "$url" >/dev/null 2>&1; then
|
|
pass "$label reachable"
|
|
else
|
|
if [ "$severity" = "fail" ]; then
|
|
fail "$label not reachable: $url"
|
|
else
|
|
warn "$label not reachable: $url"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_network() {
|
|
echo ""
|
|
echo "Network Reachability"
|
|
echo "--------------------"
|
|
|
|
# Trials pass Harbor no --allow-*-host flag: the task container runs under
|
|
# the task's declared policy, and the model is called from this machine.
|
|
info "Trials run under the task's declared network policy: the model is called from this machine through the LLM proxy, nothing is installed in the task container"
|
|
|
|
if ! command -v curl >/dev/null 2>&1; then
|
|
warn "curl not found; skipping targeted network checks"
|
|
return
|
|
fi
|
|
|
|
local proxy_url="${ANTHROPIC_BASE_URL:-https://app-llmproxy.dataannotation.tech/api/llm_proxy/anthropic}"
|
|
check_network_target "LLM proxy host" "$proxy_url" "fail"
|
|
check_network_target "Claude install host" "https://claude.ai/" "fail"
|
|
check_network_target "Claude download host" "https://downloads.claude.ai/" "fail"
|
|
check_network_target "Debian apt mirror" "https://deb.debian.org/debian/" "fail"
|
|
check_network_target "uv installer host" "https://astral.sh/" "warn"
|
|
check_network_target "Python package index" "https://pypi.org/simple/" "warn"
|
|
check_network_target "npm registry" "https://registry.npmjs.org/" "warn"
|
|
}
|
|
|
|
run_task_check() {
|
|
local label="$1"
|
|
local check="$2"
|
|
local task_path="$3"
|
|
local output
|
|
|
|
PREFLIGHT_CHECKS_RUN="$PREFLIGHT_CHECKS_RUN $(basename "$check")"
|
|
# The profile decides which checks exist; a check this profile does not
|
|
# ship is not a preflight failure.
|
|
if [ ! -f "$check" ]; then
|
|
info "$label: $(basename "$check") is not part of this profile; skipped"
|
|
return
|
|
fi
|
|
output="$(mktemp)"
|
|
|
|
if bash "$check" "$task_path" >"$output" 2>&1; then
|
|
if grep -Eq '^WARN(ING)?([[:space:]:]|$)' "$output"; then
|
|
# The check passed but warned (a Dockerfile instruction the
|
|
# pipeline's image builder handles differently, a fetch under
|
|
# solution/, a BuildKit platform ARG). scripts/validate.sh shows
|
|
# such lines; a worker who runs preflight instead would otherwise
|
|
# never see them.
|
|
warn "$label passed with warnings"
|
|
indent_output < "$output"
|
|
else
|
|
pass "$label passed"
|
|
fi
|
|
else
|
|
fail "$label failed"
|
|
indent_output < "$output"
|
|
fi
|
|
rm -f "$output"
|
|
}
|
|
|
|
check_task_static() {
|
|
echo ""
|
|
echo "Task-Specific Static Preflight"
|
|
echo "------------------------------"
|
|
|
|
if [ -z "$TASK_PATH" ]; then
|
|
info "No task path supplied; skipping task-specific checks"
|
|
info "Run scripts/preflight.sh tasks/<task-slug> before trialing a task"
|
|
return
|
|
fi
|
|
|
|
if [ ! -d "$TASK_PATH" ]; then
|
|
fail "Task directory not found: $TASK_PATH"
|
|
return
|
|
fi
|
|
pass "Task directory exists: $TASK_PATH"
|
|
|
|
# README.md is rendered from task.toml (the whole file, or the managed
|
|
# header above authored sections); scripts/validate.sh runs this check
|
|
# before the static checks, so preflight does too.
|
|
if [ "${EXPLANATION_FIELDS_IN_TOML:-0}" = "1" ] || [ "${README_MANAGED_HEADER:-0}" = "1" ]; then
|
|
local readme_output
|
|
readme_output="$(mktemp)"
|
|
if "$SCRIPT_DIR/render-readme.sh" --check "$TASK_PATH" >"$readme_output" 2>&1; then
|
|
pass "README.md is current with task.toml (scripts/render-readme.sh --check)"
|
|
else
|
|
fail "README.md is stale: run scripts/render-readme.sh $TASK_PATH, then rerun preflight"
|
|
indent_output < "$readme_output"
|
|
fi
|
|
rm -f "$readme_output"
|
|
fi
|
|
|
|
run_task_check "Task identity" "$PROFILE_CHECKS_DIR/check-task-identity.sh" "$TASK_PATH"
|
|
run_task_check "Benchmark markers" "$PROFILE_CHECKS_DIR/check-no-benchmark-markers.sh" "$TASK_PATH"
|
|
run_task_check "Package name" "$PROFILE_CHECKS_DIR/check-task-package-name.sh" "$TASK_PATH"
|
|
run_task_check "Metadata/taxonomy" "$PROFILE_CHECKS_DIR/check-task-fields.sh" "$TASK_PATH"
|
|
run_task_check "Instruction suffix" "$PROFILE_CHECKS_DIR/check-instruction-suffix.sh" "$TASK_PATH"
|
|
run_task_check "Separate verifier/artifacts" "$PROFILE_CHECKS_DIR/check-separate-verifier.sh" "$TASK_PATH"
|
|
run_task_check "Internet policy" "$PROFILE_CHECKS_DIR/check-internet-policy.sh" "$TASK_PATH"
|
|
run_task_check "Dockerfile references" "$PROFILE_CHECKS_DIR/check-dockerfile-references.sh" "$TASK_PATH"
|
|
run_task_check "Verifier offline" "$PROFILE_CHECKS_DIR/check-verifier-offline.sh" "$TASK_PATH"
|
|
run_task_check "Python dependency pins" "$PROFILE_CHECKS_DIR/check-pip-pinning.sh" "$TASK_PATH"
|
|
run_task_check "Pytest pins" "$PROFILE_CHECKS_DIR/check-pytest-version.sh" "$TASK_PATH"
|
|
|
|
# Every other static check of the profile, run the way scripts/validate.sh
|
|
# runs them (bash "$check" "$TASK_PATH"), so a worker sees the whole static
|
|
# picture before spending a trial; the checks above are not run twice.
|
|
local check check_name
|
|
for check in "$PROFILE_CHECKS_DIR"/check-*.sh; do
|
|
[ -f "$check" ] || continue
|
|
check_name="$(basename "$check")"
|
|
case " $PREFLIGHT_CHECKS_RUN " in
|
|
*" $check_name "*) continue ;;
|
|
esac
|
|
run_task_check "${check_name%.sh}" "$check" "$TASK_PATH"
|
|
done
|
|
|
|
# What preflight does not do: the network policy is Harbor's to enforce,
|
|
# from the values read here (scripts/lib/toml.sh, toml_network_phases: a
|
|
# missing [verifier.environment] block inherits [environment], as Harbor
|
|
# resolves a separate verifier's baseline).
|
|
local phases="no task.toml"
|
|
if [ -f "$TASK_PATH/task.toml" ]; then
|
|
phases="$(toml_network_phases "$TASK_PATH/task.toml")"
|
|
fi
|
|
info "The offline policy is enforced by Harbor at trial time, from task.toml's network_mode values ($phases); preflight only reads those values and starts no task container"
|
|
}
|
|
|
|
echo "=========================================="
|
|
echo "TOOLKIT PREFLIGHT"
|
|
echo "=========================================="
|
|
echo "Toolkit root: $TOOLKIT_ROOT"
|
|
# Worker-facing: the version and the build. The profile name and the release
|
|
# tag stay in .toolkit-manifest and .toolkit-version; a smoke cut says so.
|
|
PREFLIGHT_BUILD="$(toolkit_resolved_value commit_short)"
|
|
if [ "$(toolkit_resolved_value toolkit_release)" = "untagged" ]; then
|
|
echo "Toolkit version ${PROFILE_VERSION:-unknown} (build $PREFLIGHT_BUILD, untagged)"
|
|
else
|
|
echo "Toolkit version ${PROFILE_VERSION:-unknown} (build $PREFLIGHT_BUILD)"
|
|
fi
|
|
if [ -n "$TASK_PATH" ]; then
|
|
echo "Task path: $TASK_PATH"
|
|
else
|
|
echo "Task path: (none)"
|
|
fi
|
|
|
|
check_docker
|
|
check_trial_resources
|
|
check_egress_control_support
|
|
check_tools
|
|
check_env_and_credentials
|
|
check_network
|
|
check_task_static
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "PREFLIGHT SUMMARY"
|
|
echo "=========================================="
|
|
echo -e "Pass: ${GREEN}$PASS_COUNT${NC} Warn: ${YELLOW}$WARN_COUNT${NC} Fail: ${RED}$FAIL_COUNT${NC}"
|
|
|
|
if [ "$FAIL_COUNT" -gt 0 ]; then
|
|
echo ""
|
|
echo "Preflight found blocker(s). Fix the FAIL items before running trials."
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$WARN_COUNT" -gt 0 ]; then
|
|
echo ""
|
|
echo "Preflight passed with warnings. Review WARN items before long trial runs."
|
|
else
|
|
echo ""
|
|
echo "Preflight passed."
|
|
fi
|