#!/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/ 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:-}" 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 `. 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:-}" 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:-}" 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 : 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- 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