Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/synapse/blob/main/scripts/measure_gate0_baseline.sh # synapse A component of the AienOS ecosystem. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `synapse / scripts / measure_gate0_baseline.sh` 194 lines ยท 7648 bytes Raw Blame History 1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 # Reproducible Gate 0 baseline measurement script for Synapse (Issue #515). 5 # Measures actual AIEN multi-agent development traces on the host: 6 # 1. Active/retained Git worktree counts and disk footprint across hive-worktrees and workspace. 7 # 2. Historical multi-agent lane outcomes and conflict/rebase incidence in hive-ledger.md. 8 # 3. Empirical Git worktree creation, checkout, tree listing, diff, and merge-tree latency on aien-sovereign-core. 9 10 OUT_DIR="${1:-$(pwd)/evidence/gate0-baseline}" 11 mkdir -p "$OUT_DIR" 12 13 WORKSPACE_ROOT="${WORKSPACE_ROOT:-$HOME/workspace}" 14 SC_REPO="${WORKSPACE_ROOT}/aien-sovereign-core" 15 OMEGA_REPO="${WORKSPACE_ROOT}/omega" 16 HIVE_WT_DIR="${WORKSPACE_ROOT}/hive-worktrees" 17 HIVE_LEDGER="${WORKSPACE_ROOT}/hive-ledger.md" 18 19 python3 - "$OUT_DIR" "$WORKSPACE_ROOT" "$SC_REPO" "$OMEGA_REPO" "$HIVE_WT_DIR" "$HIVE_LEDGER" <<'PY' 20 import json 21 import os 22 import platform 23 import re 24 import shutil 25 import statistics 26 import subprocess 27 import sys 28 import tempfile 29 import time 30 31 out_dir, ws_root, sc_repo, omega_repo, hive_wt_dir, hive_ledger = sys.argv[1:7] 32 33 def run_cmd(cmd, cwd=None): 34 return subprocess.check_output(cmd, cwd=cwd, text=True, stderr=subprocess.DEVNULL).strip() 35 36 # 1. Empirical trace inventory from hive-worktrees and workspace 37 hive_wt_count = 0 38 hive_wt_bytes = 0 39 if os.path.isdir(hive_wt_dir): 40 entries = [os.path.join(hive_wt_dir, d) for d in os.listdir(hive_wt_dir)] 41 hive_wt_count = sum(1 for e in entries if os.path.isdir(e)) 42 du_out = run_cmd(["du", "-sb", hive_wt_dir]).split()[0] 43 hive_wt_bytes = int(du_out) 44 45 ws_agent_dirs = [] 46 if os.path.isdir(ws_root): 47 prefixes = ("omega-", "sc-", "interplane-", "physics-", "aienos-") 48 for d in os.listdir(ws_root): 49 p = os.path.join(ws_root, d) 50 if os.path.isdir(p) and d.startswith(prefixes): 51 ws_agent_dirs.append(p) 52 53 sc_worktree_registered = 0 54 if os.path.isdir(sc_repo): 55 sc_worktree_registered = len(run_cmd(["git", "worktree", "list"], cwd=sc_repo).splitlines()) 56 57 omega_worktree_registered = 0 58 if os.path.isdir(omega_repo): 59 omega_worktree_registered = len(run_cmd(["git", "worktree", "list"], cwd=omega_repo).splitlines()) 60 61 # 2. Parse hive-ledger.md for lane counts and conflict/rebase mentions 62 ledger_total_rows = 0 63 ledger_merged_rows = 0 64 ledger_retired_rows = 0 65 ledger_active_rows = 0 66 ledger_conflict_mentions = 0 67 68 if os.path.isfile(hive_ledger): 69 with open(hive_ledger, "r", encoding="utf-8") as f: 70 text = f.read() 71 ledger_conflict_mentions = len(re.findall(r"conflict|rebase|stale|diverge", text, re.IGNORECASE)) 72 for line in text.splitlines(): 73 if line.startswith("|") and not line.startswith("|---") and not line.startswith("| lane") and not line.startswith("| id"): 74 ledger_total_rows += 1 75 lower = line.lower() 76 if "merged" in lower: 77 ledger_merged_rows += 1 78 elif "retired" in lower: 79 ledger_retired_rows += 1 80 elif any(k in lower for k in ("briefed", "running", "tested", "inspected")): 81 ledger_active_rows += 1 82 83 # 3. Measure Git operation latencies on aien-sovereign-core (non-destructive) 84 head_sha = run_cmd(["git", "rev-parse", "origin/main"], cwd=sc_repo) 85 parent_sha = run_cmd(["git", "rev-parse", "origin/main~1"], cwd=sc_repo) 86 87 def bench_op(fn, iterations=9): 88 samples_ms = [] 89 for _ in range(iterations): 90 t0 = time.perf_counter() 91 fn() 92 t1 = time.perf_counter() 93 samples_ms.append((t1 - t0) * 1000.0) 94 samples_ms.sort() 95 return { 96 "iterations": iterations, 97 "p50_ms": round(samples_ms[len(samples_ms) // 2], 3), 98 "p95_ms": round(samples_ms[int(len(samples_ms) * 0.95)], 3), 99 "max_ms": round(samples_ms[-1], 3), 100 "mean_ms": round(statistics.mean(samples_ms), 3), 101 } 102 103 ls_tree_stats = bench_op(lambda: run_cmd(["git", "ls-tree", "-r", head_sha], cwd=sc_repo)) 104 diff_stats = bench_op(lambda: run_cmd(["git", "diff", "--stat", parent_sha, head_sha], cwd=sc_repo)) 105 log_stats = bench_op(lambda: run_cmd(["git", "log", "-n", "50", "--oneline", head_sha], cwd=sc_repo)) 106 merge_tree_stats = bench_op(lambda: run_cmd(["git", "merge-tree", "--write-tree", parent_sha, head_sha], cwd=sc_repo)) 107 108 # Measure full worktree add + remove cost in a temporary directory 109 wt_add_samples_ms = [] 110 wt_disk_bytes = 0 111 for i in range(3): 112 tmp_wt = tempfile.mkdtemp(prefix="synapse-gate0-wt-") 113 os.rmdir(tmp_wt) 114 try: 115 t0 = time.perf_counter() 116 subprocess.run( 117 ["git", "worktree", "add", "--detach", tmp_wt, head_sha], 118 cwd=sc_repo, 119 check=True, 120 stdout=subprocess.DEVNULL, 121 stderr=subprocess.DEVNULL, 122 ) 123 t1 = time.perf_counter() 124 wt_add_samples_ms.append((t1 - t0) * 1000.0) 125 if i == 0: 126 wt_disk_bytes = int(run_cmd(["du", "-sb", tmp_wt]).split()[0]) 127 finally: 128 subprocess.run( 129 ["git", "worktree", "remove", "--force", tmp_wt], 130 cwd=sc_repo, 131 check=False, 132 stdout=subprocess.DEVNULL, 133 stderr=subprocess.DEVNULL, 134 ) 135 shutil.rmtree(tmp_wt, ignore_errors=True) 136 137 wt_add_samples_ms.sort() 138 worktree_checkout_stats = { 139 "iterations": len(wt_add_samples_ms), 140 "p50_ms": round(wt_add_samples_ms[len(wt_add_samples_ms) // 2], 3), 141 "max_ms": round(wt_add_samples_ms[-1], 3), 142 "mean_ms": round(statistics.mean(wt_add_samples_ms), 3), 143 "single_worktree_bytes": wt_disk_bytes, 144 "single_worktree_mib": round(wt_disk_bytes / (1024.0 * 1024.0), 2), 145 "implied_throughput_worktrees_per_sec": round(1000.0 / statistics.mean(wt_add_samples_ms), 3), 146 } 147 148 report = { 149 "schema_version": 1, 150 "gate": "GATE_0_BASELINE", 151 "measured_at_utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), 152 "host": { 153 "hostname": platform.node(), 154 "os": platform.platform(), 155 "arch": platform.machine(), 156 "cpu_model": "ARM Cortex-X925 + Cortex-A725 (20 cores, NVIDIA DGX Spark GB10)", 157 "git_version": run_cmd(["git", "--version"]), 158 }, 159 "empirical_workspace_traces": { 160 "hive_worktrees_directory": hive_wt_dir, 161 "hive_worktrees_count": hive_wt_count, 162 "hive_worktrees_total_bytes": hive_wt_bytes, 163 "hive_worktrees_total_gib": round(hive_wt_bytes / (1024.0 ** 3), 2), 164 "workspace_agent_clones_count": len(ws_agent_dirs), 165 "sovereign_core_registered_worktrees": sc_worktree_registered, 166 "omega_registered_worktrees": omega_worktree_registered, 167 "total_registered_worktrees_sc_plus_omega": sc_worktree_registered + omega_worktree_registered, 168 "hive_ledger_total_rows": ledger_total_rows, 169 "hive_ledger_merged_rows": ledger_merged_rows, 170 "hive_ledger_retired_rows": ledger_retired_rows, 171 "hive_ledger_active_rows": ledger_active_rows, 172 "hive_ledger_conflict_or_rebase_mentions": ledger_conflict_mentions, 173 }, 174 "sovereign_core_git_baseline": { 175 "repository": sc_repo, 176 "head_commit": head_sha, 177 "parent_commit": parent_sha, 178 "worktree_checkout": worktree_checkout_stats, 179 "git_ls_tree_recursive": ls_tree_stats, 180 "git_diff_stat": diff_stats, 181 "git_log_50": log_stats, 182 "git_merge_tree": merge_tree_stats, 183 }, 184 } 185 186 out_path = os.path.join(out_dir, "baseline_report.json") 187 with open(out_path, "w", encoding="utf-8") as f: 188 json.dump(report, f, indent=2, sort_keys=True) 189 f.write("\n") 190 191 print(json.dumps(report, indent=2, sort_keys=True)) 192 PY 193 194 (cd "$OUT_DIR" && sha256sum baseline_report.json > SHA256SUMS)