The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore(profile): remove library profiling scripts
Steven Enamakel764664955d66
diff --git a/scripts/profile/README.md b/scripts/profile/README.mddeleted file mode 100644index cbd69fa07a..0000000000--- a/scripts/profile/README.md+++ /dev/null@@ -1,138 +0,0 @@-# `scripts/profile/`--Reproducible benchmarking scripts for the OpenHuman Rust core as an embedded-library (no RPC server), built around the `library-profile` and `rss-bench`-binaries (see `crates/openhuman-cli/src/bin/library_profile/main.rs`).--Six driver scripts: `library-bench.sh` (per-scenario RSS/duration),-`library-cpu.sh` (samply), `library-heap.sh` (dhat), `library-fleet.sh`-(fleet-scale sweep + budget gate), `library-instances.sh` (multi-process-instance sweep), and `rss-bench.sh` (embedded-roster RSS, #5046).--Benchmarks run from these scripts, not in CI.--## Scripts--### `rss-bench.sh` — embedded agent-roster RSS (#5046)--Builds the stripped-release `rss-bench` binary, runs its fixture tests, then-measures steady-state RSS/PSS of 5 fresh processes × {1, 8} agents against the-20 MiB target and 30 MiB hard cap. This was the report-only `rust-rss-bench`-CI job until benchmarks moved out of CI.--```bash-./scripts/profile/rss-bench.sh # build + run, JSON to target/profile/rss-bench.json-./scripts/profile/rss-bench.sh --skip-build --out /path/rss.json-```--### `library-bench.sh` — RSS/duration benchmark--Builds `library-profile` + `rss-bench`, runs each scenario N times as a fresh-process, and aggregates median/min/max duration, settled RSS, retained delta,-and peak delta into `summary.json` + `summary.md`.--```bash-./scripts/profile/library-bench.sh # all 6 scenarios, default build, 5 repeats-./scripts/profile/library-bench.sh --slim --repeat 7 # slim (no-default-features) build-./scripts/profile/library-bench.sh --scenarios "long-agent,subagent-storm" --turns 50 --warm-```--Results land in `target/profile/rust-library/bench-<timestamp>/` (or `--out DIR`).--### `library-cpu.sh` — CPU profile via samply--Wraps `samply record` around one scenario, isolated from persistence/timezone-noise by default (matching the documented cold-path CPU recipe).--```bash-./scripts/profile/library-cpu.sh subagent-storm-./scripts/profile/library-cpu.sh long-agent -- OPENHUMAN_PROFILE_TURNS=50-samply load target/profile/rust-library/subagent-storm-cpu.json.gz-```--### `library-heap.sh` — live heap attribution via dhat--Builds the `rss-bench-dhat` variant and runs one scenario under dhat. RSS and-timing numbers from this build are perturbed by instrumentation; use it only-for allocation-site/retained-bytes attribution, not for RSS comparisons.--```bash-./scripts/profile/library-heap.sh agent-turn-# open https://nnethercote.github.io/dh_view/dh_view.html and load-# target/profile/rust-library/dhat-agent-turn.json-```--### `library-fleet.sh` — fleet sweep + 2 GB / 2 vCPU budget gate--Builds `library-profile` + `rss-bench`, sweeps the `fleet` scenario (N-concurrent live agents with latency-realistic mock inference) across a list-of agent counts, aggregates medians per N, and gates on whether the-projected footprint at the target agent count fits the RAM budget.--```bash-./scripts/profile/library-fleet.sh --agents 100 --latency-ms 200-./scripts/profile/library-fleet.sh --agents "50,100,500" --target 1000 --budget-mib 2048-```--Results land in `target/profile/rust-library/fleet-<timestamp>/` (or-`--out DIR`). Exits nonzero if any swept N reports `fits: false` (use-`--no-gate` to report only). The script's `--help` documents the budget math.--### `library-instances.sh` — multi-instance (many-processes) sweep--Spawns N independent `library-profile` processes (each a live instance held-alive via `OPENHUMAN_PROFILE_HOLD_SECS`), staggered on startup, and measures-**per-process** cost and box survivability — the opencompany "N independent-processes/containers" deployment model, as opposed to `library-fleet.sh`'s-"N agents in one process" model. Samples aggregate sum-RSS + live count every-2s while instances hold, captures a `vm_stat` snapshot at peak (and a-best-effort `footprint` sample if that macOS tool is present), then-aggregates per swept N: launched/ok counts, median settled RSS per instance,-mean and peak aggregate sum-RSS, and — on Linux, where it's meaningful —-summed PSS.--```bash-./scripts/profile/library-instances.sh --instances "10,50" --hold-secs 30-./scripts/profile/library-instances.sh --instances "100,500" --max-instances 500 --gate-```--Results land in `target/profile/rust-library/instances-<timestamp>/` (or-`--out DIR`). Refuses to spawn more than `--max-instances` (default 200)-without an explicit raise — see the script's `--help` for the RAM math. Exits-nonzero with `--gate` if any instance failed to complete cleanly (nonzero-exit or missing/invalid JSON); default is report-only.--### `library-pool-gate.sh` — runtime pool regression gate (#5106)--Drives the `skill-run` scenario with K parallel skill runs and asserts the DoD:-with the shared runtime pool ON, the process tree grows by ~one pooled worker,-**not** K interpreters. The scenario hard-asserts `tree.child_count <= max_workers`-for K > 1 (nonzero exit); this script runs it and reports a pooled-vs-unpooled-comparison. A regression that reintroduces per-run forking fails the gate.--```bash-./scripts/profile/library-pool-gate.sh # K=8, max_workers=1-./scripts/profile/library-pool-gate.sh --concurrency 16 --skip-build-```--Exits 0 = pass, 1 = regression. SKIPs (exit 0) when no system `node` is on-`PATH` (the scenario must never download an interpreter), so node-less CI-runners don't false-fail.--## Quick start--```bash-# 1. Baseline RSS/duration across all scenarios-./scripts/profile/library-bench.sh--# 2. CPU attribution for the slowest/most interesting scenario-./scripts/profile/library-cpu.sh subagent-storm--# 3. If a scenario's RSS looks off, drill into live heap-./scripts/profile/library-heap.sh subagent-storm-```--All scripts require `jq` for JSON parsing/aggregation; `library-cpu.sh` also-requires `samply` (`cargo install samply`). Build commands use-`GGML_NATIVE=OFF` to work around the Apple Silicon whisper-rs/llama.cpp NEON-fp16 build issue.diff --git a/scripts/profile/library-bench.sh b/scripts/profile/library-bench.shdeleted file mode 100755index f21d9843c1..0000000000--- a/scripts/profile/library-bench.sh+++ /dev/null@@ -1,318 +0,0 @@-#!/usr/bin/env bash-# library-bench.sh — reproducible RSS/duration benchmark for the OpenHuman-# core as an embedded library, using the `library-profile` binary.-#-# Runs each scenario N times as a FRESH process (no state shared across-# repeats), captures each run's JSON, and aggregates medians/min/max into a-# markdown + JSON summary. Companion scripts: library-cpu.sh (samply),-# library-heap.sh (dhat).-#-# Usage:-# ./scripts/profile/library-bench.sh [options]-#-# Options:-# --slim Build with --no-default-features (slim library recipe)-# --repeat N Fresh-process repeats per scenario (default: 5)-# --scenarios "a,b,c" Comma-separated scenario list (default: all seven)-# --turns N OPENHUMAN_PROFILE_TURNS for long-agent (default binary default: 25)-# --skip-build Reuse the existing target/release binaries-# --warm Also run PREWARM_SUBAGENTS=1 variants for subagent-storm-# --out DIR Output directory (default: target/profile/rust-library/bench-<timestamp>)-# -h, --help Show this help-#-# Examples:-# ./scripts/profile/library-bench.sh-# ./scripts/profile/library-bench.sh --slim --repeat 7-# ./scripts/profile/library-bench.sh --scenarios "long-agent,subagent-storm" --turns 50 --warm--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"--# The scenarios `library-profile` actually dispatches — keep in sync with-# `crates/openhuman-cli/src/bin/library_profile/scenarios/mod.rs`, which is the source of truth.-#-# This list had drifted before openhuman#6161 touched it: it named two-# scenarios that had not existed for some time. `dispatch` answers "unknown-# scenario: …" for those, so a full sweep exited non-zero on two entries that-# could never run. `memory-ingest` and `cold-phases` leave now-# for a different reason: both measured the in-process memory engine, which-# this binary no longer links.-ALL_SCENARIOS="agent-turn,long-agent,workflow,fleet,skill-run,subagent-storm"-WARM_ELIGIBLE=("subagent-storm")--SLIM=0-REPEAT=5-SCENARIOS="$ALL_SCENARIOS"-TURNS=""-SKIP_BUILD=0-WARM=0-OUT_DIR=""--usage() {- sed -n '2,26p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'- exit "${1:-0}"-}--while [[ $# -gt 0 ]]; do- case "$1" in- --slim) SLIM=1; shift ;;- --repeat)- REPEAT="${2:?--repeat requires a value}"; shift 2 ;;- --scenarios)- SCENARIOS="${2:?--scenarios requires a value}"; shift 2 ;;- --turns)- TURNS="${2:?--turns requires a value}"; shift 2 ;;- --skip-build) SKIP_BUILD=1; shift ;;- --warm) WARM=1; shift ;;- --out)- OUT_DIR="${2:?--out requires a value}"; shift 2 ;;- -h|--help) usage 0 ;;- *)- echo "ERROR: unknown argument: $1" >&2- usage 1 ;;- esac-done--if ! command -v jq >/dev/null 2>&1; then- echo "ERROR: jq is required (aggregation over run JSON). Install it (e.g. 'brew install jq')." >&2- exit 1-fi--if [[ -z "$OUT_DIR" ]]; then- OUT_DIR="$REPO_ROOT/target/profile/rust-library/bench-$(date +%Y%m%d-%H%M%S)"-fi-mkdir -p "$OUT_DIR"--BIN="$REPO_ROOT/target/release/library-profile"--log() { echo "[library-bench] $*" >&2; }--build_binaries() {- if [[ "$SKIP_BUILD" -eq 1 ]]; then- log "skipping build (--skip-build)"- return- fi- local feature_args=(--features rss-bench)- if [[ "$SLIM" -eq 1 ]]; then- feature_args=(--no-default-features --features rss-bench)- log "building slim library-profile + rss-bench (GGML_NATIVE=OFF)"- else- log "building default-feature library-profile + rss-bench (GGML_NATIVE=OFF)"- fi- (- cd "$REPO_ROOT"- GGML_NATIVE=OFF cargo build --release \- "${feature_args[@]}" \- --bin library-profile --bin rss-bench- )-}--run_scenario() {- local scenario="$1"- local variant="$2" # "" or "warm"- local label="$scenario"- [[ -n "$variant" ]] && label="${scenario}-${variant}"-- local scenario_dir="$OUT_DIR/$label"- mkdir -p "$scenario_dir"-- log "running scenario '$label' x$REPEAT (fresh process each run)"-- local i- for ((i = 1; i <= REPEAT; i++)); do- local run_file="$scenario_dir/run-$i.json"- local env_args=()- if [[ "$scenario" == "long-agent" && -n "$TURNS" ]]; then- env_args+=(env "OPENHUMAN_PROFILE_TURNS=$TURNS")- fi- if [[ "$variant" == "warm" ]]; then- env_args+=(env "OPENHUMAN_PROFILE_PREWARM_SUBAGENTS=1")- fi-- if [[ ${#env_args[@]} -gt 0 ]]; then- "${env_args[@]}" "$BIN" "$scenario" >"$run_file"- else- "$BIN" "$scenario" >"$run_file"- fi-- if ! jq empty "$run_file" >/dev/null 2>&1; then- echo "ERROR: run $i for scenario '$label' did not produce valid JSON: $run_file" >&2- exit 1- fi-- # library-heap.sh clobbers target/release/library-profile with the- # rss-bench-dhat build, whose allocator perturbs RSS/timing. The dhat- # binary marks its output, so refuse to benchmark it.- if [[ "$(jq -r '.dhat // false' "$run_file")" == "true" ]]; then- echo "ERROR: $BIN was built with rss-bench-dhat (library-heap.sh clobbered it)." >&2- echo " Re-run without --skip-build to rebuild the plain rss-bench binary." >&2- exit 1- fi- done-}--# Emit the median (lower-middle for even N), min, and max of a jq numeric-# field across the run files for one scenario, as a JSON object on stdout.-aggregate_field() {- local scenario_dir="$1"- local jq_path="$2"- jq -s "- [ .[] | $jq_path | select(. != null) ] as \$vals |- (\$vals | sort) as \$sorted |- (\$sorted | length) as \$n |- {- median: (if \$n == 0 then null else \$sorted[(( \$n - 1) / 2 | floor)] end),- min: (\$sorted[0] // null),- max: (\$sorted[-1] // null),- n: \$n- }- " "$scenario_dir"/run-*.json-}--aggregate_scenario() {- local label="$1"- local scenario_dir="$OUT_DIR/$label"-- local duration settled_rss retained_delta peak_delta- duration=$(aggregate_field "$scenario_dir" ".duration_ms")- settled_rss=$(aggregate_field "$scenario_dir" ".settled.rss_kib")- retained_delta=$(aggregate_field "$scenario_dir" ".retained_delta_kib")- peak_delta=$(aggregate_field "$scenario_dir" ".peak_delta_kib")-- local turn_growth="null"- if [[ "$label" == long-agent* ]]; then- # first-turn vs last-turn checkpoint rss delta (steady-state growth).- turn_growth=$(jq -s '- [ .[] |- (.checkpoints // []) as $cps |- if ($cps | length) >= 2 then- ($cps[-1].rss_kib - $cps[0].rss_kib)- else empty end- ] as $vals |- ($vals | sort) as $sorted |- ($sorted | length) as $n |- if $n == 0 then null- else $sorted[((($n - 1) / 2) | floor)]- end- ' "$scenario_dir"/run-*.json)- fi-- jq -n \- --arg scenario "$label" \- --argjson duration "$duration" \- --argjson settled_rss "$settled_rss" \- --argjson retained_delta "$retained_delta" \- --argjson peak_delta "$peak_delta" \- --argjson turn_growth_kib "$turn_growth" \- '{- scenario: $scenario,- duration_ms: $duration,- settled_rss_kib: $settled_rss,- retained_delta_kib: $retained_delta,- peak_delta_kib: $peak_delta,- long_agent_turn_growth_kib: $turn_growth_kib- }'-}--kib_to_mib() {- # $1: kib value (may be null). Prints "n/a" for null.- local kib="$1"- if [[ "$kib" == "null" || -z "$kib" ]]; then- echo "n/a"- return- fi- jq -n --argjson kib "$kib" '($kib / 1024 * 100 | round) / 100'-}--write_summary() {- local summary_json="$OUT_DIR/summary.json"- local summary_md="$OUT_DIR/summary.md"-- jq -s '{ generated_at: (now | todate), build: ($ENV.LIBRARY_BENCH_BUILD // "default"), repeat: ($ENV.LIBRARY_BENCH_REPEAT | tonumber), scenarios: . }' \- "$OUT_DIR"/*.scenario.json >"$summary_json"-- {- echo "# Library benchmark summary"- echo- echo "Build: \`${LIBRARY_BENCH_BUILD}\` "- echo "Repeats per scenario: ${LIBRARY_BENCH_REPEAT} "- echo "Generated: $(date)"- echo- echo "| Scenario | Median settled RSS (MiB) | Median retained Δ (MiB) | Median peak Δ (MiB) | Median duration (ms) |"- echo "| --- | ---: | ---: | ---: | ---: |"- local f- for f in "$OUT_DIR"/*.scenario.json; do- local scenario settled retained peak duration- scenario=$(jq -r '.scenario' "$f")- settled=$(kib_to_mib "$(jq -r '.settled_rss_kib.median' "$f")")- retained=$(kib_to_mib "$(jq -r '.retained_delta_kib.median' "$f")")- peak=$(kib_to_mib "$(jq -r '.peak_delta_kib.median' "$f")")- duration=$(jq -r '.duration_ms.median // "n/a"' "$f")- echo "| $scenario | $settled | $retained | $peak | $duration |"- done- echo- local long_growth_file- for long_growth_file in "$OUT_DIR"/long-agent*.scenario.json; do- [[ -e "$long_growth_file" ]] || continue- local growth- growth=$(jq -r '.long_agent_turn_growth_kib // "n/a"' "$long_growth_file")- if [[ "$growth" != "n/a" && "$growth" != "null" ]]; then- local growth_mib- growth_mib=$(kib_to_mib "$growth")- echo "**$(jq -r '.scenario' "$long_growth_file") steady-state growth** (first-turn to last-turn checkpoint delta, median across runs): ${growth_mib} MiB."- echo- fi- done- cat <<'EOF'-## External comparison point (not apples-to-apples)--ZeroClaw self-reports (unverified) idling under 5 MiB RAM and roughly 8-12 MiB-under load. OpenHuman's Rust core currently settles around 35-50 MiB depending-on scenario and feature set. Treat this as-a north star, not a like-for-like comparison: ZeroClaw's feature surface and-scope differ substantially from the OpenHuman core.-EOF- } >"$summary_md"-}--main() {- build_binaries-- if [[ ! -x "$BIN" ]]; then- echo "ERROR: $BIN not found or not executable. Build it or drop --skip-build." >&2- exit 1- fi-- IFS=',' read -r -a scenario_list <<<"$SCENARIOS"-- for scenario in "${scenario_list[@]}"; do- run_scenario "$scenario" ""- if [[ "$WARM" -eq 1 ]]; then- for eligible in "${WARM_ELIGIBLE[@]}"; do- if [[ "$scenario" == "$eligible" ]]; then- run_scenario "$scenario" "warm"- fi- done- fi- done-- # Build one *.scenario.json per label for the summary step.- for scenario_dir in "$OUT_DIR"/*/; do- [[ -d "$scenario_dir" ]] || continue- local_label="$(basename "$scenario_dir")"- aggregate_scenario "$local_label" >"$OUT_DIR/${local_label}.scenario.json"- done-- export LIBRARY_BENCH_BUILD- LIBRARY_BENCH_BUILD=$([[ "$SLIM" -eq 1 ]] && echo "slim" || echo "default")- export LIBRARY_BENCH_REPEAT="$REPEAT"-- write_summary-- log "results: $OUT_DIR"- cat "$OUT_DIR/summary.md"-}--main "$@"diff --git a/scripts/profile/library-cpu.sh b/scripts/profile/library-cpu.shdeleted file mode 100755index 4f1b492bf3..0000000000--- a/scripts/profile/library-cpu.sh+++ /dev/null@@ -1,104 +0,0 @@-#!/usr/bin/env bash-# library-cpu.sh — samply wrapper for a CPU profile of one library-profile-# scenario, following the cold-path CPU profiling recipe.-#-# Usage:-# ./scripts/profile/library-cpu.sh <scenario> [-- <extra env VAR=value>...]-# ./scripts/profile/library-cpu.sh --no-isolate <scenario>-#-# Options:-# --no-isolate Do not force OPENHUMAN_PROFILE_DISABLE_MEMORY_WRITES=1 /-# OPENHUMAN_PROFILE_FORCE_UTC=1 (default: isolated, matching-# the documented cold-path CPU recipe)-# --skip-build Reuse the existing target/release/library-profile binary-# -h, --help Show this help-#-# Extra environment variables can be passed after `--`, e.g.:-# ./scripts/profile/library-cpu.sh long-agent -- OPENHUMAN_PROFILE_TURNS=50-#-# Output: target/profile/rust-library/<scenario>-cpu.json.gz-# View it with: samply load target/profile/rust-library/<scenario>-cpu.json.gz--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"--ISOLATE=1-SKIP_BUILD=0-SCENARIO=""-EXTRA_ENV=()--usage() {- sed -n '2,20p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'- exit "${1:-0}"-}--while [[ $# -gt 0 ]]; do- case "$1" in- --no-isolate) ISOLATE=0; shift ;;- --skip-build) SKIP_BUILD=1; shift ;;- -h|--help) usage 0 ;;- --)- shift- EXTRA_ENV=("$@")- break- ;;- *)- if [[ -z "$SCENARIO" ]]; then- SCENARIO="$1"- shift- else- echo "ERROR: unexpected argument: $1" >&2- usage 1- fi- ;;- esac-done--if [[ -z "$SCENARIO" ]]; then- echo "ERROR: scenario is required" >&2- usage 1-fi--if ! command -v samply >/dev/null 2>&1; then- echo "ERROR: samply is required. Install it with 'cargo install samply'." >&2- exit 1-fi--BIN="$REPO_ROOT/target/release/library-profile"--if [[ "$SKIP_BUILD" -eq 0 ]]; then- echo "[library-cpu] building library-profile (GGML_NATIVE=OFF)" >&2- (- cd "$REPO_ROOT"- GGML_NATIVE=OFF cargo build --release --features rss-bench --bin library-profile- )-fi--if [[ ! -x "$BIN" ]]; then- echo "ERROR: $BIN not found or not executable. Build it or drop --skip-build." >&2- exit 1-fi--OUT_DIR="$REPO_ROOT/target/profile/rust-library"-mkdir -p "$OUT_DIR"-OUT_FILE="$OUT_DIR/${SCENARIO}-cpu.json.gz"--ENV_ARGS=()-if [[ "$ISOLATE" -eq 1 ]]; then- ENV_ARGS+=(OPENHUMAN_PROFILE_DISABLE_MEMORY_WRITES=1 OPENHUMAN_PROFILE_FORCE_UTC=1)-fi-ENV_ARGS+=("${EXTRA_ENV[@]+"${EXTRA_ENV[@]}"}")--echo "[library-cpu] recording scenario '$SCENARIO' -> $OUT_FILE" >&2-env "${ENV_ARGS[@]+"${ENV_ARGS[@]}"}" samply record \- --save-only \- --unstable-presymbolicate \- --rate 1000 \- --iteration-count 5 \- --output "$OUT_FILE" \- -- "$BIN" "$SCENARIO"--echo "[library-cpu] done: $OUT_FILE" >&2-echo "[library-cpu] view it with: samply load $OUT_FILE" >&2diff --git a/scripts/profile/library-fleet.sh b/scripts/profile/library-fleet.shdeleted file mode 100755index 4f8221f15a..0000000000--- a/scripts/profile/library-fleet.sh+++ /dev/null@@ -1,371 +0,0 @@-#!/usr/bin/env bash-# library-fleet.sh — sweep the `fleet` scenario of library-profile across-# agent counts and gate the result against the 2 GB RAM / 2 vCPU server-# budget (100-1000 live agents). Companion scripts: library-bench.sh-# (per-scenario RSS/duration), library-cpu.sh (samply), library-heap.sh-# (dhat).-#-# Usage:-# ./scripts/profile/library-fleet.sh [options]-#-# Options:-# --agents "50,100,500" Comma-separated agent-count sweep (default: "50,100,500")-# --turns N OPENHUMAN_PROFILE_TURNS per agent (default: 3)-# --latency-ms N OPENHUMAN_PROFILE_MOCK_LATENCY_MS (default: 200)-# --workers N OPENHUMAN_PROFILE_WORKER_THREADS, simulates the-# 2 vCPU box (default: 2)-# --repeat N Fresh-process repeats per agent count (default: 3)-# --target N OPENHUMAN_PROFILE_TARGET_AGENTS (default: 1000)-# --budget-mib N OPENHUMAN_PROFILE_RAM_BUDGET_MIB (default: 2048)-# --skip-build Reuse the existing target/release binaries-# --slim Build with --no-default-features (slim library recipe)-# --out DIR Output directory (default: target/profile/rust-library/fleet-<timestamp>)-# --no-gate Do not fail the exit code on fits==false (report only)-# -h, --help Show this help-#-# Examples:-# ./scripts/profile/library-fleet.sh-# ./scripts/profile/library-fleet.sh --agents 100 --latency-ms 200-# ./scripts/profile/library-fleet.sh --agents "100,1000" --target 1000 --budget-mib 2048--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"--AGENTS="50,100,500"-TURNS=3-LATENCY_MS=200-WORKERS=2-REPEAT=3-TARGET=1000-BUDGET_MIB=2048-SKIP_BUILD=0-SLIM=0-OUT_DIR=""-GATE=1--# Idle CPU is measured over a 10s parked window and should be ~flat-# regardless of agent count (idle agents cost ~zero CPU). 500ms of CPU-# across that window (5% of one core) is the "low" threshold used in the-# PASS/FAIL verdict line.-IDLE_CPU_MS_MAX=500--usage() {- sed -n '2,27p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'- exit "${1:-0}"-}--while [[ $# -gt 0 ]]; do- case "$1" in- --agents)- AGENTS="${2:?--agents requires a value}"; shift 2 ;;- --turns)- TURNS="${2:?--turns requires a value}"; shift 2 ;;- --latency-ms)- LATENCY_MS="${2:?--latency-ms requires a value}"; shift 2 ;;- --workers)- WORKERS="${2:?--workers requires a value}"; shift 2 ;;- --repeat)- REPEAT="${2:?--repeat requires a value}"; shift 2 ;;- --target)- TARGET="${2:?--target requires a value}"; shift 2 ;;- --budget-mib)- BUDGET_MIB="${2:?--budget-mib requires a value}"; shift 2 ;;- --skip-build) SKIP_BUILD=1; shift ;;- --slim) SLIM=1; shift ;;- --out)- OUT_DIR="${2:?--out requires a value}"; shift 2 ;;- --no-gate) GATE=0; shift ;;- -h|--help) usage 0 ;;- *)- echo "ERROR: unknown argument: $1" >&2- usage 1 ;;- esac-done--if ! command -v jq >/dev/null 2>&1; then- echo "ERROR: jq is required (aggregation over run JSON). Install it (e.g. 'brew install jq')." >&2- exit 1-fi--if [[ -z "$OUT_DIR" ]]; then- OUT_DIR="$REPO_ROOT/target/profile/rust-library/fleet-$(date +%Y%m%d-%H%M%S)"-fi-mkdir -p "$OUT_DIR"--BIN="$REPO_ROOT/target/release/library-profile"--log() { echo "[library-fleet] $*" >&2; }--build_binaries() {- if [[ "$SKIP_BUILD" -eq 1 ]]; then- log "skipping build (--skip-build)"- return- fi- local feature_args=(--features rss-bench)- if [[ "$SLIM" -eq 1 ]]; then- feature_args=(--no-default-features --features rss-bench)- log "building slim library-profile + rss-bench (GGML_NATIVE=OFF)"- else- log "building default-feature library-profile + rss-bench (GGML_NATIVE=OFF)"- fi- (- cd "$REPO_ROOT"- GGML_NATIVE=OFF cargo build --release \- "${feature_args[@]}" \- --bin library-profile --bin rss-bench- )-}--run_sweep_point() {- local n="$1"- local point_dir="$OUT_DIR/fleet-$n"- mkdir -p "$point_dir"-- log "running fleet scenario with $n agents x$REPEAT (fresh process each run)"-- local i- for ((i = 1; i <= REPEAT; i++)); do- local run_file="$point_dir/run-$i.json"-- env \- "OPENHUMAN_PROFILE_AGENTS=$n" \- "OPENHUMAN_PROFILE_TURNS=$TURNS" \- "OPENHUMAN_PROFILE_MOCK_LATENCY_MS=$LATENCY_MS" \- "OPENHUMAN_PROFILE_WORKER_THREADS=$WORKERS" \- "OPENHUMAN_PROFILE_TARGET_AGENTS=$TARGET" \- "OPENHUMAN_PROFILE_RAM_BUDGET_MIB=$BUDGET_MIB" \- "$BIN" fleet >"$run_file"-- if ! jq empty "$run_file" >/dev/null 2>&1; then- echo "ERROR: run $i for agents=$n did not produce valid JSON: $run_file" >&2- exit 1- fi-- # library-heap.sh clobbers target/release/library-profile with the- # rss-bench-dhat build, whose allocator perturbs RSS/timing. The dhat- # binary marks its output, so refuse to benchmark it.- if [[ "$(jq -r '.dhat // false' "$run_file")" == "true" ]]; then- echo "ERROR: $BIN was built with rss-bench-dhat (library-heap.sh clobbered it)." >&2- echo " Re-run without --skip-build to rebuild the plain rss-bench binary." >&2- exit 1- fi- done-}--# Emit the median (lower-middle for even N), min, and max of a jq numeric-# field across the run files for one sweep point, as a JSON object on stdout.-aggregate_field() {- local point_dir="$1"- local jq_path="$2"- jq -s "- [ .[] | $jq_path | select(. != null) ] as \$vals |- (\$vals | sort) as \$sorted |- (\$sorted | length) as \$n |- {- median: (if \$n == 0 then null else \$sorted[(( \$n - 1) / 2 | floor)] end),- min: (\$sorted[0] // null),- max: (\$sorted[-1] // null),- n: \$n- }- " "$point_dir"/run-*.json-}--# fits is a boolean per run; report it as "fits" only when every repeat-# agreed it fits (a single unlucky repeat should not hide a marginal case).-aggregate_fits() {- local point_dir="$1"- jq -s '- [ .[] | .budget.fits // false ] as $vals |- ($vals | length) as $n |- ($vals | map(select(. == true)) | length) as $true_n |- { all_fit: ($n > 0 and $true_n == $n), true_n: $true_n, n: $n }- ' "$point_dir"/run-*.json-}--aggregate_point() {- local n="$1"- local point_dir="$OUT_DIR/fleet-$n"-- local marginal settled_rss idle_cpu threads open_fds p50 p95 p99 projected fits- marginal=$(aggregate_field "$point_dir" ".marginal_rss_kib_per_agent")- settled_rss=$(aggregate_field "$point_dir" ".settled.rss_kib")- idle_cpu=$(aggregate_field "$point_dir" ".idle_cpu_ms")- threads=$(aggregate_field "$point_dir" ".settled.threads")- open_fds=$(aggregate_field "$point_dir" ".settled.open_fds")- p50=$(aggregate_field "$point_dir" ".turn_latency_ms.p50")- p95=$(aggregate_field "$point_dir" ".turn_latency_ms.p95")- p99=$(aggregate_field "$point_dir" ".turn_latency_ms.p99")- projected=$(aggregate_field "$point_dir" ".budget.projected_rss_mib_at_target")- fits=$(aggregate_fits "$point_dir")-- jq -n \- --argjson agents "$n" \- --argjson marginal_rss_kib_per_agent "$marginal" \- --argjson settled_rss_kib "$settled_rss" \- --argjson idle_cpu_ms "$idle_cpu" \- --argjson threads "$threads" \- --argjson open_fds "$open_fds" \- --argjson p50 "$p50" \- --argjson p95 "$p95" \- --argjson p99 "$p99" \- --argjson projected_rss_mib_at_target "$projected" \- --argjson fits "$fits" \- '{- agents: $agents,- marginal_rss_kib_per_agent: $marginal_rss_kib_per_agent,- settled_rss_kib: $settled_rss_kib,- idle_cpu_ms: $idle_cpu_ms,- threads: $threads,- open_fds: $open_fds,- turn_latency_ms: { p50: $p50, p95: $p95, p99: $p99 },- projected_rss_mib_at_target: $projected_rss_mib_at_target,- fits: $fits- }'-}--kib_to_mib() {- # $1: kib value (may be null/"null"). Prints "n/a" for null.- local kib="$1"- if [[ "$kib" == "null" || -z "$kib" ]]; then- echo "n/a"- return- fi- jq -n --argjson kib "$kib" '($kib / 1024 * 100 | round) / 100'-}--num_or_na() {- local v="$1"- [[ "$v" == "null" || -z "$v" ]] && echo "n/a" || echo "$v"-}--write_summary() {- local summary_json="$OUT_DIR/summary.json"- local summary_md="$OUT_DIR/summary.md"-- jq -s \- --argjson turns "$TURNS" \- --argjson latency_ms "$LATENCY_MS" \- --argjson workers "$WORKERS" \- --argjson repeat "$REPEAT" \- --argjson target "$TARGET" \- --argjson budget_mib "$BUDGET_MIB" \- --arg build "$([[ "$SLIM" -eq 1 ]] && echo "slim" || echo "default")" \- '{- generated_at: (now | todate),- build: $build,- config: {- turns: $turns,- mock_latency_ms: $latency_ms,- worker_threads: $workers,- repeat: $repeat,- target_agents: $target,- ram_budget_mib: $budget_mib- },- sweep: .- }' \- "$OUT_DIR"/*.point.json >"$summary_json"-- local any_fail=0-- {- echo "# Fleet benchmark summary"- echo- echo "Build: \`$([[ "$SLIM" -eq 1 ]] && echo "slim" || echo "default")\` "- echo "Repeats per agent count: ${REPEAT} "- echo "Turns/agent: ${TURNS}, mock latency: ${LATENCY_MS}ms, worker threads: ${WORKERS} "- echo "Target: ${TARGET} agents, budget: ${BUDGET_MIB} MiB "- echo "Generated: $(date)"- echo- echo "| N | marginal KiB/agent | settled MiB | idle CPU ms/10s | threads | fds | p95 ms | projected MiB @ target | fits |"- echo "| ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | :---: |"-- local f- for f in "$OUT_DIR"/*.point.json; do- local n marginal settled idle threads fds p95 projected fits_all- n=$(jq -r '.agents' "$f")- marginal=$(num_or_na "$(jq -r '.marginal_rss_kib_per_agent.median' "$f")")- settled=$(kib_to_mib "$(jq -r '.settled_rss_kib.median' "$f")")- idle=$(num_or_na "$(jq -r '.idle_cpu_ms.median' "$f")")- threads=$(num_or_na "$(jq -r '.threads.median' "$f")")- fds=$(num_or_na "$(jq -r '.open_fds.median' "$f")")- p95=$(num_or_na "$(jq -r '.turn_latency_ms.p95.median' "$f")")- projected=$(num_or_na "$(jq -r '.projected_rss_mib_at_target.median' "$f")")- fits_all=$(jq -r '.fits.all_fit' "$f")- echo "| $n | $marginal | $settled | $idle | $threads | $fds | $p95 | $projected | $fits_all |"- done-- echo- echo "## Verdict"- echo-- for f in "$OUT_DIR"/*.point.json; do- local n fits_all idle_median verdict reasons- n=$(jq -r '.agents' "$f")- fits_all=$(jq -r '.fits.all_fit' "$f")- idle_median=$(jq -r '.idle_cpu_ms.median // "null"' "$f")-- reasons=""- verdict="PASS"- if [[ "$fits_all" != "true" ]]; then- verdict="FAIL"- reasons="${reasons}projected RSS at target does not fit ${BUDGET_MIB} MiB budget; "- any_fail=1- fi- local idle_over- idle_over=0- if [[ "$idle_median" != "null" ]]; then- idle_over=$(jq -n --argjson v "$idle_median" --argjson max "$IDLE_CPU_MS_MAX" 'if $v > $max then 1 else 0 end')- fi- if [[ "$idle_over" -eq 1 ]]; then- verdict="FAIL"- reasons="${reasons}idle CPU ${idle_median}ms/10s exceeds ${IDLE_CPU_MS_MAX}ms threshold; "- fi-- if [[ "$verdict" == "PASS" ]]; then- echo "- **N=$n: PASS** — fits budget, idle CPU low."- else- echo "- **N=$n: FAIL** — ${reasons}"- fi- done- } >"$summary_md"-- if [[ "$any_fail" -eq 1 ]]; then- return 1- fi- return 0-}--main() {- build_binaries-- if [[ ! -x "$BIN" ]]; then- echo "ERROR: $BIN not found or not executable. Build it or drop --skip-build." >&2- exit 1- fi-- IFS=',' read -r -a agent_list <<<"$AGENTS"-- local n- for n in "${agent_list[@]}"; do- run_sweep_point "$n"- done-- for n in "${agent_list[@]}"; do- aggregate_point "$n" >"$OUT_DIR/fleet-$n.point.json"- done-- local gate_status=0- write_summary || gate_status=1-- log "results: $OUT_DIR"- cat "$OUT_DIR/summary.md"-- if [[ "$GATE" -eq 1 && "$gate_status" -ne 0 ]]; then- log "GATE FAILED: at least one swept N does not fit the ${BUDGET_MIB} MiB / ${TARGET}-agent budget"- exit 1- fi-}--main "$@"diff --git a/scripts/profile/library-heap.sh b/scripts/profile/library-heap.shdeleted file mode 100755index a62b7de035..0000000000--- a/scripts/profile/library-heap.sh+++ /dev/null@@ -1,93 +0,0 @@-#!/usr/bin/env bash-# library-heap.sh — builds the rss-bench-dhat variant of library-profile and-# runs one scenario under dhat heap profiling.-#-# Note: dhat instrumentation perturbs RSS/timing measurements. Use-# library-bench.sh / library-cpu.sh for RSS and CPU numbers; use this script-# only for live-heap attribution (allocation sites, retained bytes).-#-# This build REPLACES target/release/library-profile with the dhat variant.-# A later `library-bench.sh --skip-build` would pick it up; the bench script-# detects the dhat marker in the output JSON and refuses, but the clean fix-# is to rerun library-bench.sh without --skip-build afterwards.-#-# Usage:-# ./scripts/profile/library-heap.sh <scenario> [-- <extra env VAR=value>...]-#-# Options:-# --skip-build Reuse the existing target/release/library-profile binary-# -h, --help Show this help-#-# Output: target/profile/rust-library/dhat-<scenario>.json-# View it at: https://nnethercote.github.io/dh_view/dh_view.html--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"--SKIP_BUILD=0-SCENARIO=""-EXTRA_ENV=()--usage() {- sed -n '2,17p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'- exit "${1:-0}"-}--while [[ $# -gt 0 ]]; do- case "$1" in- --skip-build) SKIP_BUILD=1; shift ;;- -h|--help) usage 0 ;;- --)- shift- EXTRA_ENV=("$@")- break- ;;- *)- if [[ -z "$SCENARIO" ]]; then- SCENARIO="$1"- shift- else- echo "ERROR: unexpected argument: $1" >&2- usage 1- fi- ;;- esac-done--if [[ -z "$SCENARIO" ]]; then- echo "ERROR: scenario is required" >&2- usage 1-fi--BIN="$REPO_ROOT/target/release/library-profile"-OUT_DIR="$REPO_ROOT/target/profile/rust-library"-mkdir -p "$OUT_DIR"-OUT_FILE="$OUT_DIR/dhat-${SCENARIO}.json"--if [[ "$SKIP_BUILD" -eq 0 ]]; then- echo "[library-heap] building library-profile with rss-bench-dhat (GGML_NATIVE=OFF)" >&2- (- cd "$REPO_ROOT"- GGML_NATIVE=OFF cargo build --release --features rss-bench-dhat --bin library-profile- )-fi--if [[ ! -x "$BIN" ]]; then- echo "ERROR: $BIN not found or not executable. Build it or drop --skip-build." >&2- exit 1-fi--echo "[library-heap] running scenario '$SCENARIO' under dhat" >&2-echo "[library-heap] WARNING: dhat instrumentation perturbs RSS and timing; do not compare these numbers against library-bench.sh output" >&2--env OPENHUMAN_PROFILE_DHAT_OUT="$OUT_FILE" "${EXTRA_ENV[@]+"${EXTRA_ENV[@]}"}" "$BIN" "$SCENARIO" >/dev/null--if [[ ! -f "$OUT_FILE" ]]; then- echo "ERROR: expected dhat output was not written: $OUT_FILE" >&2- exit 1-fi--echo "[library-heap] done: $OUT_FILE" >&2-echo "[library-heap] view it at https://nnethercote.github.io/dh_view/dh_view.html (load the JSON file)" >&2diff --git a/scripts/profile/library-instances.sh b/scripts/profile/library-instances.shdeleted file mode 100755index 1c28e03a90..0000000000--- a/scripts/profile/library-instances.sh+++ /dev/null@@ -1,548 +0,0 @@-#!/usr/bin/env bash-# library-instances.sh — multi-instance fuzz driver: spawn N independent-# `library-profile` processes (one live instance each, held alive at settled-# state via OPENHUMAN_PROFILE_HOLD_SECS) and measure per-INSTANCE cost and-# box survivability under the "N processes" deployment model, as opposed to-# the "N agents in one process" model that `library-fleet.sh` measures.-#-# Where library-fleet.sh answers "how many agents fit in one process", this-# answers "how many independent processes/containers fit on one box" — the-# opencompany per-tenant-instance question. Companion scripts: library-bench.sh-# (per-scenario RSS/duration), library-fleet.sh (one-process fleet sweep).-#-# Usage:-# ./scripts/profile/library-instances.sh [options]-#-# Options:-# --instances "10,25,50" Comma-separated instance-count sweep (default: "10,25,50")-# --hold-secs N Seconds each instance holds alive at settled state-# after finishing its workload (default: 30)-# --scenario NAME library-profile scenario to run per instance-# (default: agent-turn)-# --stagger-ms N Delay between spawning consecutive instances, in-# milliseconds (default: 100)-# --skip-build Reuse the existing target/release binary-# --slim Build with --no-default-features (slim library recipe)-# --max-instances N Hard safety cap on any swept N (default: 200).-# Each held instance settles ~47 MiB RSS on a-# default build, so sum-RSS scales roughly-# linearly: 1000 instances (at default settings)-# is on the order of 1000 x 47 MiB ~= 47 GB-# aggregate RSS. Raising this cap is an explicit-# "yes, I mean to spawn that many processes" — it-# will not happen implicitly.-# --out DIR Output directory (default:-# target/profile/rust-library/instances-<timestamp>)-# --gate Exit nonzero if any instance failed (nonzero exit-# or missing/invalid JSON). Default: report only,-# always exit 0 unless argument/build errors occur.-# -h, --help Show this help-#-# Examples:-# ./scripts/profile/library-instances.sh-# ./scripts/profile/library-instances.sh --instances "10,50" --hold-secs 30-# ./scripts/profile/library-instances.sh --instances "500" --max-instances 500 --gate--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"--INSTANCES="10,25,50"-HOLD_SECS=30-SCENARIO="agent-turn"-STAGGER_MS=100-SKIP_BUILD=0-SLIM=0-MAX_INSTANCES=200-OUT_DIR=""-GATE=0--# Default-build settled RSS per held instance, used only for the safety-cap-# explanation message and the summary.md extrapolation fallback when PSS is-# unavailable (macOS). This is a rule-of-thumb constant, not a measurement —-# the script's own measured settled RSS supersedes it once real data exists.-ASSUMED_PER_INSTANCE_RSS_MIB=47-BUDGET_MIB=2048--usage() {- sed -n '2,38p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'- exit "${1:-0}"-}--while [[ $# -gt 0 ]]; do- case "$1" in- --instances)- INSTANCES="${2:?--instances requires a value}"; shift 2 ;;- --hold-secs)- HOLD_SECS="${2:?--hold-secs requires a value}"; shift 2 ;;- --scenario)- SCENARIO="${2:?--scenario requires a value}"; shift 2 ;;- --stagger-ms)- STAGGER_MS="${2:?--stagger-ms requires a value}"; shift 2 ;;- --skip-build) SKIP_BUILD=1; shift ;;- --slim) SLIM=1; shift ;;- --max-instances)- MAX_INSTANCES="${2:?--max-instances requires a value}"; shift 2 ;;- --out)- OUT_DIR="${2:?--out requires a value}"; shift 2 ;;- --gate) GATE=1; shift ;;- -h|--help) usage 0 ;;- *)- echo "ERROR: unknown argument: $1" >&2- usage 1 ;;- esac-done--if ! command -v jq >/dev/null 2>&1; then- echo "ERROR: jq is required (aggregation over run JSON). Install it (e.g. 'brew install jq')." >&2- exit 1-fi--if [[ -z "$OUT_DIR" ]]; then- OUT_DIR="$REPO_ROOT/target/profile/rust-library/instances-$(date +%Y%m%d-%H%M%S)"-fi-mkdir -p "$OUT_DIR"--BIN="$REPO_ROOT/target/release/library-profile"--log() { echo "[library-instances] $*" >&2; }--# --- safety cap ---------------------------------------------------------------check_cap() {- local n="$1"- if [[ "$n" -gt "$MAX_INSTANCES" ]]; then- local naive_gib- naive_gib=$(jq -n --argjson n "$n" --argjson mib "$ASSUMED_PER_INSTANCE_RSS_MIB" '(($n * $mib) / 1024 * 100 | round) / 100')- echo "ERROR: requested $n instances exceeds --max-instances cap ($MAX_INSTANCES)." >&2- echo " RAM math: each held instance settles ~${ASSUMED_PER_INSTANCE_RSS_MIB} MiB RSS on a" >&2- echo " default build (many-processes model pays that base N times, unlike the" >&2- echo " one-process fleet model, which amortizes it once). $n instances is roughly" >&2- echo " $n x ${ASSUMED_PER_INSTANCE_RSS_MIB} MiB ~= ${naive_gib} GiB of aggregate sum-RSS — likely more" >&2- echo " than this machine has. Pass --max-instances $n (or higher) to confirm you" >&2- echo " intend to spawn that many processes." >&2- exit 1- fi-}--# --- build ---------------------------------------------------------------------build_binaries() {- if [[ "$SKIP_BUILD" -eq 1 ]]; then- log "skipping build (--skip-build)"- return- fi- local feature_args=(--features rss-bench)- if [[ "$SLIM" -eq 1 ]]; then- feature_args=(--no-default-features --features rss-bench)- log "building slim library-profile + rss-bench (GGML_NATIVE=OFF)"- else- log "building default-feature library-profile + rss-bench (GGML_NATIVE=OFF)"- fi- (- cd "$REPO_ROOT"- GGML_NATIVE=OFF cargo build --release \- "${feature_args[@]}" \- --bin library-profile --bin rss-bench- )-}--# One quick, short-lived run before the sweep: confirms the binary emits-# valid schema JSON and is not the dhat-instrumented build (library-heap.sh-# clobbers target/release/library-profile with rss-bench-dhat, whose-# allocator perturbs RSS in a way that would corrupt every number below).-probe_binary() {- log "probe run: validating '$BIN $SCENARIO' before the sweep"- local probe_file="$OUT_DIR/probe.json"- local probe_log="$OUT_DIR/probe.log"-- OPENHUMAN_PROFILE_HOLD_SECS=0 "$BIN" "$SCENARIO" >"$probe_file" 2>"$probe_log"-- if ! jq empty "$probe_file" >/dev/null 2>&1; then- echo "ERROR: probe run did not produce valid JSON: $probe_file" >&2- exit 1- fi- if [[ "$(jq -r '.dhat // false' "$probe_file")" == "true" ]]; then- echo "ERROR: $BIN was built with rss-bench-dhat (library-heap.sh clobbered it)." >&2- echo " Re-run without --skip-build to rebuild the plain rss-bench binary." >&2- exit 1- fi- log "probe OK: settled rss_kib=$(jq -r '.settled.rss_kib' "$probe_file")"-}--# --- spawn + sample ------------------------------------------------------------sleep_ms() {- local ms="$1"- [[ "$ms" -le 0 ]] && return 0- local secs- secs=$(awk -v ms="$ms" 'BEGIN { printf "%.3f", ms / 1000 }')- sleep "$secs"-}--# Best-effort per-process attribution via the macOS `footprint` tool, run-# against a handful of pids for one sweep point only (it is slow and-# invasive; ignore any failure — this is a bonus artifact, not load-bearing).-capture_footprint_sample() {- local point_dir="$1"; shift- local pids=("$@")-- if ! command -v footprint >/dev/null 2>&1; then- log "footprint tool not present, skipping footprint sample"- return 0- fi-- local sampled=0- local pid- for pid in "${pids[@]}"; do- [[ "$sampled" -ge 3 ]] && break- footprint "$pid" >"$point_dir/footprint-pid$pid.txt" 2>&1 || true- sampled=$((sampled + 1))- done- log "footprint: sampled $sampled pid(s) (best-effort, see footprint-pid*.txt)"-}--# Samples aggregate sum-RSS + live count every 2s via `ps -o pid=,rss=` until-# every pid in the list has exited, appending to samples.csv. Records the-# peak sum-RSS observed and takes one `vm_stat` system-memory snapshot at-# that peak.-sample_while_holding() {- local point_dir="$1"; shift- local -a pids=("$@")-- local samples_csv="$point_dir/samples.csv"- echo "elapsed_s,sum_rss_kib,live_count" >"$samples_csv"-- local pid_csv- pid_csv=$(IFS=,; echo "${pids[*]}")-- local start_ts- start_ts=$(date +%s)- local peak_sum=0-- while true; do- local ps_out- ps_out=$(ps -o pid=,rss= -p "$pid_csv" 2>/dev/null || true)-- local live_count sum_rss- if [[ -z "$ps_out" ]]; then- live_count=0- sum_rss=0- else- read -r live_count sum_rss <<<"$(echo "$ps_out" | awk '{s += $2; c += 1} END { print c + 0, s + 0 }')"- fi-- local elapsed=$(( $(date +%s) - start_ts ))- echo "$elapsed,$sum_rss,$live_count" >>"$samples_csv"-- if [[ "$sum_rss" -gt "$peak_sum" ]]; then- peak_sum="$sum_rss"- vm_stat >"$point_dir/vm_stat-peak.txt" 2>/dev/null || true- fi-- if [[ "$live_count" -eq 0 ]]; then- break- fi- sleep 2- done-- echo "$peak_sum" >"$point_dir/.peak_sum_rss_kib"-}--run_sweep_point() {- local n="$1"- local do_footprint="$2"- local point_dir="$OUT_DIR/n$n"- mkdir -p "$point_dir"-- log "spawning $n instance(s) of scenario '$SCENARIO' (hold=${HOLD_SECS}s, stagger=${STAGGER_MS}ms)"-- local -a pids=()- local i- for ((i = 1; i <= n; i++)); do- local out_file="$point_dir/proc-$i.json"- local log_file="$point_dir/proc-$i.log"-- env "OPENHUMAN_PROFILE_HOLD_SECS=$HOLD_SECS" "$BIN" "$SCENARIO" \- >"$out_file" 2>"$log_file" &- pids+=("$!")-- if [[ "$i" -lt "$n" ]]; then- sleep_ms "$STAGGER_MS"- fi- done-- if [[ "$do_footprint" -eq 1 ]]; then- capture_footprint_sample "$point_dir" "${pids[@]}"- fi-- sample_while_holding "$point_dir" "${pids[@]}"-- local ok=0 failed=0- local pid_index=0- for pid in "${pids[@]}"; do- pid_index=$((pid_index + 1))- local out_file="$point_dir/proc-$pid_index.json"- local status=0- wait "$pid" || status=$?-- if [[ "$status" -eq 0 && -s "$out_file" ]] && jq empty "$out_file" >/dev/null 2>&1; then- ok=$((ok + 1))- else- failed=$((failed + 1))- log "WARN: instance $pid_index (pid $pid, n=$n) failed (exit=$status)"- fi- done-- echo "$ok" >"$point_dir/.ok_count"- echo "$failed" >"$point_dir/.failed_count"- log "n=$n done: ok=$ok failed=$failed"-}--# --- aggregate ------------------------------------------------------------------kib_to_mib() {- local kib="$1"- if [[ "$kib" == "null" || -z "$kib" ]]; then- echo "n/a"- return- fi- jq -n --argjson kib "$kib" '($kib / 1024 * 100 | round) / 100'-}--num_or_na() {- local v="$1"- [[ "$v" == "null" || -z "$v" ]] && echo "n/a" || echo "$v"-}--aggregate_point() {- local n="$1"- local point_dir="$OUT_DIR/n$n"-- local ok failed peak_sum_rss_kib- ok=$(cat "$point_dir/.ok_count" 2>/dev/null || echo 0)- failed=$(cat "$point_dir/.failed_count" 2>/dev/null || echo 0)- peak_sum_rss_kib=$(cat "$point_dir/.peak_sum_rss_kib" 2>/dev/null || echo 0)-- local -a valid_files=()- local f- for f in "$point_dir"/proc-*.json; do- [[ -e "$f" ]] || continue- if jq empty "$f" >/dev/null 2>&1; then- valid_files+=("$f")- fi- done-- local settled_rss_median pss_max pss_sum_kib- if [[ "${#valid_files[@]}" -gt 0 ]]; then- settled_rss_median=$(jq -s '- [ .[] | .settled.rss_kib | select(. != null) ] as $vals |- ($vals | sort) as $sorted |- ($sorted | length) as $n |- (if $n == 0 then null else $sorted[(($n - 1) / 2 | floor)] end)- ' "${valid_files[@]}")- pss_max=$(jq -s '[ .[] | .settled.pss_kib // 0 ] | max' "${valid_files[@]}")- pss_sum_kib=$(jq -s '[ .[] | .settled.pss_kib // 0 ] | add' "${valid_files[@]}")- else- settled_rss_median=null- pss_max=0- pss_sum_kib=0- fi-- local mean_sum_rss_kib_per_instance- if [[ "$ok" -gt 0 ]]; then- mean_sum_rss_kib_per_instance=$(jq -n --argjson total "$peak_sum_rss_kib" --argjson ok "$ok" '$total / $ok')- else- mean_sum_rss_kib_per_instance=null- fi-- local pss_available- pss_available=$(jq -n --argjson v "$pss_max" 'if $v > 0 then true else false end')-- jq -n \- --argjson instances "$n" \- --argjson launched "$n" \- --argjson ok "$ok" \- --argjson failed "$failed" \- --argjson peak_sum_rss_kib "$peak_sum_rss_kib" \- --argjson mean_sum_rss_kib_per_instance "$mean_sum_rss_kib_per_instance" \- --argjson settled_rss_kib_median "$settled_rss_median" \- --argjson pss_available "$pss_available" \- --argjson pss_sum_kib "$pss_sum_kib" \- '{- instances: $instances,- launched: $launched,- ok: $ok,- failed: $failed,- peak_sum_rss_kib: $peak_sum_rss_kib,- mean_sum_rss_kib_per_instance: $mean_sum_rss_kib_per_instance,- settled_rss_kib_median: $settled_rss_kib_median,- pss_available: $pss_available,- pss_sum_kib: (if $pss_available then $pss_sum_kib else null end)- }'-}--write_summary() {- local summary_json="$OUT_DIR/summary.json"- local summary_md="$OUT_DIR/summary.md"-- jq -s \- --argjson hold_secs "$HOLD_SECS" \- --arg scenario "$SCENARIO" \- --argjson stagger_ms "$STAGGER_MS" \- --arg build "$([[ "$SLIM" -eq 1 ]] && echo "slim" || echo "default")" \- '{- generated_at: (now | todate),- build: $build,- config: { scenario: $scenario, hold_secs: $hold_secs, stagger_ms: $stagger_ms },- sweep: .- }' \- "$OUT_DIR"/*.point.json >"$summary_json"-- local any_fail=0- local last_point_file=""-- {- echo "# Multi-instance (many-processes) benchmark summary"- echo- echo "Build: \`$([[ "$SLIM" -eq 1 ]] && echo "slim" || echo "default")\` "- echo "Scenario: \`${SCENARIO}\`, hold: ${HOLD_SECS}s, stagger: ${STAGGER_MS}ms "- echo "Generated: $(date)"- echo- echo "This measures the **many-processes** deployment model: N independent"- echo "\`library-profile\` processes, each a live held instance, as opposed to"- echo "\`library-fleet.sh\`'s **one-process** model (N agents inside a single"- echo "process). **Correctness note:** summed RSS below double-counts shared"- echo "clean pages — all instances share one binary's resident executable text"- echo "and any shared library mappings — so sum-RSS is an **upper bound** on"- echo "real physical memory use, not the true cost. On Linux, summed PSS"- echo "(proportional set size, from each instance's \`settled.pss_kib\`) divides"- echo "shared pages across the processes that share them and is the honest"- echo "number; it is surfaced below whenever the field is nonzero. On macOS"- echo "there is no PSS equivalent, so only sum-RSS is available and the table"- echo "says so explicitly."- echo- echo "| N | ok/launched | median settled RSS/instance (MiB) | mean sum-RSS/instance (MiB) | peak aggregate sum-RSS (MiB) | summed PSS (MiB) |"- echo "| ---: | :---: | ---: | ---: | ---: | ---: |"-- local pf- for pf in "$OUT_DIR"/*.point.json; do- [[ -e "$pf" ]] || continue- last_point_file="$pf"- local n ok launched settled_rss mean_sum peak_sum pss_available pss_sum pss_cell- n=$(jq -r '.instances' "$pf")- ok=$(jq -r '.ok' "$pf")- launched=$(jq -r '.launched' "$pf")- settled_rss=$(kib_to_mib "$(jq -r '.settled_rss_kib_median' "$pf")")- mean_sum=$(kib_to_mib "$(jq -r '.mean_sum_rss_kib_per_instance' "$pf")")- peak_sum=$(kib_to_mib "$(jq -r '.peak_sum_rss_kib' "$pf")")- pss_available=$(jq -r '.pss_available' "$pf")- if [[ "$pss_available" == "true" ]]; then- pss_sum=$(kib_to_mib "$(jq -r '.pss_sum_kib' "$pf")")- pss_cell="$pss_sum"- else- pss_cell="n/a (macOS)"- fi-- if [[ "$ok" != "$launched" ]]; then- any_fail=1- fi-- echo "| $n | $ok/$launched | $settled_rss | $mean_sum | $peak_sum | $pss_cell |"- done-- echo- echo "## Verdict (2 GB box extrapolation, estimate)"- echo-- if [[ -n "$last_point_file" ]]; then- local pss_available per_instance_mib per_instance_label fits_estimate- pss_available=$(jq -r '.pss_available' "$last_point_file")- if [[ "$pss_available" == "true" ]]; then- per_instance_mib=$(kib_to_mib "$(jq -r '(.pss_sum_kib / .ok)' "$last_point_file")")- per_instance_label="summed PSS/instance (honest, shared pages divided across sharers)"- else- per_instance_mib=$(kib_to_mib "$(jq -r '.mean_sum_rss_kib_per_instance' "$last_point_file")")- per_instance_label="mean sum-RSS/instance (macOS, no PSS — this OVERSTATES true cost by double-counting shared pages)"- fi-- if [[ "$per_instance_mib" != "n/a" ]]; then- fits_estimate=$(jq -n --argjson budget "$BUDGET_MIB" --argjson per "$per_instance_mib" '($budget / $per) | floor')- echo "Using the largest swept N's ${per_instance_label}: **${per_instance_mib} MiB/instance**."- echo- echo "\`instances_that_fit ~= ${BUDGET_MIB} / ${per_instance_mib} ~= ${fits_estimate}\` — a rough"- echo "**estimate**, not a measured limit. It assumes every additional instance"- echo "costs the same as the ones already measured (no host-level contention,"- echo "no cgroup memory limit enforced here)."- if [[ "$pss_available" == "true" ]]; then- echo "PSS was available (Linux), so this divides shared pages across the"- echo "processes that share them rather than double-counting them — still an"- echo "estimate, but not skewed in a known direction the way the macOS"- echo "sum-RSS fallback is."- else- echo "No PSS was available (macOS), so this uses sum-RSS as a stand-in,"- echo "which double-counts shared pages (executable text, shared library"- echo "mappings) across instances — treat this estimate as"- echo "conservative-in-the-wrong-direction (fewer instances would actually fit"- echo "than the sum-RSS math implies is safe, since real physical use is lower"- echo "than sum-RSS thanks to shared pages, but this is also unverified against"- echo "an actual memory-limited box)."- fi- else- echo "No successful instances at the largest swept N — cannot extrapolate."- any_fail=1- fi- else- echo "No sweep points completed — nothing to extrapolate."- any_fail=1- fi- } >"$summary_md"-- if [[ "$any_fail" -eq 1 ]]; then- return 1- fi- return 0-}--main() {- IFS=',' read -r -a instance_list <<<"$INSTANCES"-- local n- for n in "${instance_list[@]}"; do- check_cap "$n"- done-- build_binaries-- if [[ ! -x "$BIN" ]]; then- echo "ERROR: $BIN not found or not executable. Build it or drop --skip-build." >&2- exit 1- fi-- probe_binary-- local first_n="${instance_list[0]}"- for n in "${instance_list[@]}"; do- local do_footprint=0- [[ "$n" == "$first_n" ]] && do_footprint=1- run_sweep_point "$n" "$do_footprint"- done-- for n in "${instance_list[@]}"; do- aggregate_point "$n" >"$OUT_DIR/n$n.point.json"- done-- local gate_status=0- write_summary || gate_status=1-- log "results: $OUT_DIR"- cat "$OUT_DIR/summary.md"-- if [[ "$GATE" -eq 1 && "$gate_status" -ne 0 ]]; then- log "GATE FAILED: at least one instance failed to complete cleanly"- exit 1- fi-}--main "$@"diff --git a/scripts/profile/library-pool-gate.sh b/scripts/profile/library-pool-gate.shdeleted file mode 100755index c86f648e2d..0000000000--- a/scripts/profile/library-pool-gate.sh+++ /dev/null@@ -1,133 +0,0 @@-#!/usr/bin/env bash-# library-pool-gate.sh — regression gate for the shared runtime pool (#5106).-#-# Runs the `skill-run` scenario with K parallel skill runs and asserts the DoD:-# with the pool ON, the process tree grows by ~one pooled worker, NOT K-# interpreters. The scenario itself hard-asserts `tree.child_count <= max_workers`-# for K > 1 (nonzero exit on failure); this script drives it in the profiling-# suite and adds a pooled-vs-unpooled comparison for the report.-#-# A regression that reintroduces per-run interpreter forking makes the pooled-# run's child_count scale with K → the scenario exits nonzero → this gate fails.-#-# Usage:-# ./scripts/profile/library-pool-gate.sh [--concurrency N] [--workers W] [--skip-build] [--out DIR]-#-# Exits 0 = pass, 1 = regression/failure, 0 (with SKIP notice) = no system node.--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"-REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"--CONCURRENCY=8-POOL_WORKERS=1-SKIP_BUILD=0-OUT_DIR=""--# Reject non-positive-integer values up front so a bad --concurrency/--workers-# fails loudly instead of silently changing the workload.-require_pos_int() {- case "$2" in- ''|*[!0-9]*) echo "ERROR: $1 must be a positive integer, got: $2" >&2; exit 1 ;;- esac- [ "$2" -ge 1 ] || { echo "ERROR: $1 must be >= 1, got: $2" >&2; exit 1; }-}--while [[ $# -gt 0 ]]; do- case "$1" in- --concurrency) CONCURRENCY="${2:?--concurrency requires a value}"; require_pos_int --concurrency "$CONCURRENCY"; shift 2 ;;- --workers) POOL_WORKERS="${2:?--workers requires a value}"; require_pos_int --workers "$POOL_WORKERS"; shift 2 ;;- --skip-build) SKIP_BUILD=1; shift ;;- --out) OUT_DIR="${2:?--out requires a value}"; shift 2 ;;- -h|--help) sed -n '2,18p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;;- *) echo "ERROR: unknown argument: $1" >&2; exit 1 ;;- esac-done-require_pos_int --concurrency "$CONCURRENCY"-require_pos_int --workers "$POOL_WORKERS"--log() { echo "[pool-gate] $*" >&2; }--if ! command -v jq >/dev/null 2>&1; then- echo "ERROR: jq is required. Install it (e.g. 'brew install jq')." >&2- exit 1-fi--# The scenario requires a real system node (it must never download one). No node-# ⇒ SKIP (exit 0) so node-less CI runners don't false-fail; a node-equipped-# runner is where this gate is meaningful.-if ! command -v node >/dev/null 2>&1; then- log "SKIP: no system 'node' on PATH — pool gate needs a real interpreter."- exit 0-fi--[[ -z "$OUT_DIR" ]] && OUT_DIR="$REPO_ROOT/target/profile/rust-library/pool-gate-$(date +%Y%m%d-%H%M%S)"-mkdir -p "$OUT_DIR"-BIN="$REPO_ROOT/target/release/library-profile"--if [[ "$SKIP_BUILD" -eq 0 ]]; then- log "building library-profile (rss-bench, GGML_NATIVE=OFF)"- ( cd "$REPO_ROOT" && GGML_NATIVE=OFF cargo build --release --features rss-bench --bin library-profile )-fi-[[ -x "$BIN" ]] || { echo "ERROR: $BIN not found (drop --skip-build to build it)." >&2; exit 1; }--pooled_json="$OUT_DIR/pooled-k$CONCURRENCY.json"-unpooled_json="$OUT_DIR/unpooled-k$CONCURRENCY.json"--# --- Pooled run (the gate) -------------------------------------------------# The scenario hard-asserts child_count <= POOL_WORKERS; a nonzero exit here-# (via set -e) fails the gate.-log "pooled run: K=$CONCURRENCY, max_workers=$POOL_WORKERS (asserts child_count <= $POOL_WORKERS)"-# Force the pool ON explicitly: an inherited OPENHUMAN_PROFILE_SKILL_RUN_POOL=off-# would run the legacy path and make the scenario skip its pool assertion.-OPENHUMAN_PROFILE_SKILL_RUN_POOL=on \-OPENHUMAN_PROFILE_SKILL_RUN_CONCURRENCY="$CONCURRENCY" \-OPENHUMAN_PROFILE_SKILL_RUN_POOL_WORKERS="$POOL_WORKERS" \- "$BIN" skill-run >"$pooled_json"--# --- Unpooled baseline (report only) ---------------------------------------log "unpooled baseline: K=$CONCURRENCY, pool OFF (expect ~$CONCURRENCY interpreters)"-OPENHUMAN_PROFILE_SKILL_RUN_CONCURRENCY="$CONCURRENCY" \-OPENHUMAN_PROFILE_SKILL_RUN_POOL=off \- "$BIN" skill-run >"$unpooled_json"--# Pooled run: a missing/null tree means nothing was measured — that must FAIL,-# not silently coerce to 0 (which would let the gate pass without observing an-# interpreter). Unpooled is report-only, so its tree may default to 0.-pooled_cc="$(jq -r '.tree.child_count // "null"' "$pooled_json")"-unpooled_cc="$(jq -r '.tree.child_count // 0' "$unpooled_json")"-pooled_rss="$(jq -r '.tree.tree_rss_kib // "null"' "$pooled_json")"-unpooled_rss="$(jq -r '.tree.tree_rss_kib // 0' "$unpooled_json")"--echo-echo "=== runtime pool gate (#5106) — K=$CONCURRENCY ==="-echo " pooled (max_workers=$POOL_WORKERS): child_count=$pooled_cc tree_rss_kib=$pooled_rss"-echo " unpooled (legacy spawn) : child_count=$unpooled_cc tree_rss_kib=$unpooled_rss"--if [[ "$pooled_cc" == "null" ]]; then- echo "FAIL: pooled run captured no process-tree sample — cannot verify the pooled worker." >&2- exit 1-fi-# The pooled worker must actually be observed (>= 1) and must not exceed the-# pool size.-if [[ "$pooled_cc" -lt 1 ]]; then- echo "FAIL: pooled run observed zero interpreter children — the pooled worker was not sampled." >&2- exit 1-fi-if [[ "$pooled_cc" -gt "$POOL_WORKERS" ]]; then- echo "FAIL: pooled child_count=$pooled_cc exceeds max_workers=$POOL_WORKERS — pool is forking per run." >&2- exit 1-fi--# Sanity: the unpooled baseline should fork more than the pool. If it didn't,-# the comparison is inconclusive (likely a sampling miss on a fast machine) —-# warn rather than hard-fail, since the pooled assertion above is the real gate.-if [[ "$unpooled_cc" -le "$pooled_cc" ]]; then- echo "WARN: unpooled baseline child_count=$unpooled_cc did not exceed pooled=$pooled_cc" >&2- echo " (baseline sampling inconclusive; the pooled assertion still passed)." >&2-else- echo "PASS: pool bounded interpreters to $pooled_cc for K=$CONCURRENCY concurrent skill runs (unpooled forked $unpooled_cc)."-fi-echo " artifacts: $OUT_DIR"-exit 0diff --git a/scripts/profile/rss-bench.sh b/scripts/profile/rss-bench.shdeleted file mode 100755index 841f8c0c20..0000000000--- a/scripts/profile/rss-bench.sh+++ /dev/null@@ -1,37 +0,0 @@-#!/usr/bin/env bash-# rss-bench.sh — steady-state RSS of an embedded openhuman_core agent roster-# (#5046): 5 fresh processes x {1, 8} agents, reported against the 20 MiB-# target and 30 MiB hard cap.-#-# Formerly the report-only `rust-rss-bench` CI job; benchmarks run from-# scripts, not CI. The build is a stripped release (thin LTO, one codegen-# unit), so expect a long first compile.-#-# Usage: ./scripts/profile/rss-bench.sh [--out FILE] [--skip-build]-# --out FILE raw samples as JSON (default target/profile/rss-bench.json)-# --skip-build reuse target/release/rss-bench-set -euo pipefail--cd "$(dirname "$0")/../.."--out="target/profile/rss-bench.json"-build=1-while (($#)); do- case "$1" in- --out) out="$2"; shift 2 ;;- --skip-build) build=0; shift ;;- -h | --help) sed -n '2,13p' "$0"; exit 0 ;;- *) echo "unknown argument: $1" >&2; exit 64 ;;- esac-done--if ((build)); then- echo "[rss-bench] building stripped-release rss-bench" >&2- cargo build --release --features rss-bench --bin rss-bench- echo "[rss-bench] running fixture tests" >&2- cargo test --features rss-bench --bin rss-bench-fi--mkdir -p "$(dirname "${out}")"-./target/release/rss-bench --out "${out}"-echo "[rss-bench] raw samples: ${out}" >&2