#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PACKAGE_ROOT="${PACKAGE_ROOT:-$(cd "$SCRIPT_DIR/../.." && pwd)}" COHORT_ID="${COHORT_ID:?COHORT_ID is required}" COHORT_DISK="${COHORT_DISK:?COHORT_DISK is required (system or data)}" COHORT_PROFILE="${COHORT_PROFILE:?COHORT_PROFILE is required (prefetch-pp-object or pp-object)}" RUN_START_INTERVAL_SECS="${RUN_START_INTERVAL_SECS:-600}" CASE_RUNS="${CASE_RUNS:-5}" DRY_RUN="${DRY_RUN:-0}" FIRST_RUN_NOT_BEFORE_EPOCH="${FIRST_RUN_NOT_BEFORE_EPOCH:-0}" die() { echo "error: $*" >&2 exit 2 } is_true() { case "${1:-}" in 1|true|TRUE|yes|YES|on|ON) return 0 ;; *) return 1 ;; esac } case "$COHORT_DISK" in system|data) ;; *) die "COHORT_DISK must be system or data: $COHORT_DISK" ;; esac case "$COHORT_PROFILE" in prefetch-pp-object) case_set="feature149-prefetch" ;; pp-object) case_set="feature149-no-prefetch" ;; *) die "COHORT_PROFILE must be prefetch-pp-object or pp-object: $COHORT_PROFILE" ;; esac [[ "$CASE_RUNS" == "5" ]] || die "Feature #149 requires CASE_RUNS=5, got $CASE_RUNS" [[ "$RUN_START_INTERVAL_SECS" == "600" ]] || die "Feature #149 requires RUN_START_INTERVAL_SECS=600, got $RUN_START_INTERVAL_SECS" [[ -x "$SCRIPT_DIR/run_cache_ablation_experiment.sh" ]] || die "missing cache ablation driver" [[ -x "$SCRIPT_DIR/summarize_feature149_cohort.py" ]] || die "missing Feature #149 summarizer" [[ -f "$PACKAGE_ROOT/.env" ]] || die "missing package environment: $PACKAGE_ROOT/.env" experiment_dir="$PACKAGE_ROOT/experiments/feature149-$COHORT_ID" summary_jsonl="$experiment_dir/experiment-summary.jsonl" if (( FIRST_RUN_NOT_BEFORE_EPOCH > 0 )) && ! is_true "$DRY_RUN"; then now_epoch="$(date +%s)" if (( now_epoch < FIRST_RUN_NOT_BEFORE_EPOCH )); then wait_secs=$(( FIRST_RUN_NOT_BEFORE_EPOCH - now_epoch )) echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] waiting ${wait_secs}s before cohort=$COHORT_ID" >&2 sleep "$wait_secs" fi fi env \ PACKAGE_ROOT="$PACKAGE_ROOT" \ ENV_FILE="$PACKAGE_ROOT/.env" \ EXPERIMENT_RUN_ROOT="$PACKAGE_ROOT" \ EXPERIMENT_DIR="$experiment_dir" \ EXPERIMENT_CASE_SET="$case_set" \ CASE_RUNS="$CASE_RUNS" \ RUN_SNAPSHOT=1 \ RUN_START_INTERVAL_SECS="$RUN_START_INTERVAL_SECS" \ FIRST_RUN_DELAY_SECS=0 \ RETAIN_RUNS=6 \ DRY_RUN="$DRY_RUN" \ "$SCRIPT_DIR/run_cache_ablation_experiment.sh" if ! is_true "$DRY_RUN"; then "$SCRIPT_DIR/summarize_feature149_cohort.py" \ --cohort-id "$COHORT_ID" \ --cohort-disk "$COHORT_DISK" \ --cohort-profile "$COHORT_PROFILE" \ --package-root "$PACKAGE_ROOT" \ --summary-jsonl "$summary_jsonl" \ --out-dir "$experiment_dir" fi printf 'feature149_cohort_dir=%s\n' "$experiment_dir"