interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / tools / ops / README.md

50 lines · 12085 bytes Raw Blame History Source

tools/ops: the Spark's shared measurement base

Shell tools installed in ~/.local/bin on the Spark. These are the committed copies; install by copying each file over the old one (copy to a temporary name, then rename, so running jobs keep the old file). How and when to use them: docs/ops/MEASUREMENT_WINDOWS.md.

FilePurpose
spark-build-onceBuild cache keyed by the source tree, command and env knobs; concurrent callers build once
spark-windowOne measurement window at a time; holds the quiet lock exclusive; box state at open and close. A bare close only closes a window you opened (same shell tree, or SPARK_WINDOW set); otherwise refused with exit 3, use close <ID>
test_spark_window_close.shOffline test for the close rule above (scratch locks and folder, never the live windows)
test-spark-window-starve.shOffline test, scratch locks and window root only. Case 1: no contention. Cases 2 and 3: one and two shared holders take $SPARK_QUIET_GATE and then the quiet lock, the quiet-build order, so the gate at spark-window:330-336 keeps new holders out and the drain finishes. Case 4 (chip busy): with the chip lock held for 6 s, the window waits for the chip and opens only after it is free. Plain flock -s skips that gate: one plain holder leaves only a timing-dependent gap, and two can starve an exclusive waiter, because Linux flock gives the waiter no priority. Those plain-flock cases (2p, 5) are skipped unless SPARK_STARVE_PLAIN=1
test-quiet-lock-order.shL217 replay (quiet-lock-order/suite.sh), scratch locks only. A measurement queued for a busy chip must not hold the quiet lock or raise the want flag. The fixed copy passes every check, the pre-fix copy (quiet-lock-order/quiet-measure.pre-L217) fails the starvation checks A1-A3, and six mutants of the fix each fail their own check. Exit 0 only when all three hold
spark-calibratePer-window calibration: memcpy bandwidth (omega#583 probe) and 30 s idle power at the wall
spark-baselinePer-window 27B baseline: fixed 64-token streamed reply on 127.0.0.1:18091, decode tok/s and J/token
spark-receiptEnergy receipt for any command; now stamps window_id and calibration
quiet-measureExclusive quiet lock for a measurement; runs directly inside its own open window. L217: if the command starts with flock LOCKFILE, that lock is taken first while holding nothing, and the want flag is raised only after it is held, so a measurement queued for the GPU does not freeze builds
quiet-buildCPU-heavy jobs. Waits for a live measurement flag (at most 1 min), then the quiet gate, then a shared quiet lock. The whole wait is capped at 25 min (SPARK_BUILD_MAX_WAIT, default 1500 s). If the lock is acquired in time, the command runs as given. Past the cap it runs at nice 19, with no lock and no core pinning, and the open window is marked shared machine (L405). Waits are logged
spark-cleanupDisk clean-up, run by an agent (dry run first, then --apply) and, for one repository's copies, by the store hook (next row); nothing runs it on a clock. Removes regenerable build output, caches and old /tmp entries; a /tmp entry that holds a git repository (itself, nested or bare) goes only when everything in every repository in it is saved in ~/git (class 8's meaning), otherwise it stays as class5 SKIP unsaved. Size never decides a removal: there is no size cap; any entry removed, or kept unsaved by class 5, above SPARK_CLEANUP_BIG_ALARM bytes (default 5 GiB) is named in one ALARM line at the end of the run. Removes a worktree only when its HEAD is present in ~/git (the store Interplane serves), not merely on some remote, and the worktree has no unsaved bytes (including untracked and ignored files hidden from a plain status, skip-worktree or assume-unchanged edits to bytes or the executable bit, and unsaved files inside nested checkouts) and no nested repository, bare ones included whatever their folder is named. A worktree that is locked (git worktree lock) or that a current claim names (claims read as --landed reads them, next row) stays: class2 SKIP locked or class2 SKIP claimed. Class 8 is an alarm that never deletes: agent copies idle 3 days, each called leftover (every ref, nested repository, submodule branch and submodule commit is in ~/git: a finished task left its copy), unstored, dirty or unreadable, and model weights copied instead of linked. ~/work/hive/uxl-brief-20261113/FourBit is never deleted or named for removal. A verified cargo target under ~/handoffs/hive/factory-bays may be removed because it is rebuildable; evidence, receipts, keys, bundles, jsonl, and every other file under ~/handoffs stay. Class 8 runs after the quiet lock is released and posts one board line when the set of copies changes. With no scratch folder (TMPDIR missing or full) it stops with an ALARM and removes nothing. Dry run by default; --help lists every class and setting
spark-cleanup --landed REPORun, detached, by the store hook store-post-update each time REPO lands. Looks only at copies of REPO (remote URL …/REPO.git, or the same root commit as ~/git/**/REPO.git) in class 8's folders (~/workspace, ~/work, ~/.claude/jobs), and at copies an earlier landing kept for a reason that passes (open, claimed, written recently, no room to archive; listed in ~/.local/state/spark-cleanup/landed-pending). Removes a copy when every ref, nested repository and file in it is in ~/git and it was not written in the last 6 h (SPARK_CLEANUP_LANDED_IDLE_H). A copy with unsaved work that was not written for 3 days (SPARK_CLEANUP_LANDED_ARCHIVE_D) is packed to ~/archive/agent-work/<name>.tar.zst (SPARK_CLEANUP_ARCHIVE) without its build output (ignored target/, build/, node_modules/, .lake/ and the like, and cargo targets, each only when no repository is inside; named in ARCHIVED.txt), checked against the copy by entry count and by contents (tar -d), and replaced by an ARCHIVED.txt giving the one-line restore (a linked worktree's unsaved HEAD goes in as a bundle). When the archive's disk has less free space than the copy without build output plus 20 GB (SPARK_CLEANUP_ARCHIVE_RESERVE_GB) the copy stays, with an ALARM line in the log. Never touches main clones (a folder directly in ~/workspace with a real .git folder whose name has no - or is a repository's name: a store <name>.git or <name>-mv.git, or the last part of one of its remote URLs), protected paths, copies open by a process (looked at again just before each removal), copies that a CLAIM line on the board or in ~/handoffs/hive/CLAIMS.md names, together with a folder above them or a path inside them, when the line is dated in the last 14 days (SPARK_CLEANUP_CLAIM_DAYS) or not dated at all, unless a later RELEASE line of the same lane ends the claim (a CLAIM line whose lane cannot be read is never ended), or locked worktrees, nor anything under /tmp or ~/handoffs. Either claim file may be missing (the other still counts); one that exists but cannot be read is an ALARM line in the log. A CLAIM of a whole copy folder (~/workspace, ~/work, ~/.claude/jobs) or of ~ is not used, since it would keep every copy: it is an ALARM line in the log at every landing and one ALARM line on the board per set of such claims (written with a lower-case "claim", so it is not read as a CLAIM itself). It waits for a running spark-cleanup; a wait past 30 min (SPARK_CLEANUP_LOCK_WAIT_MIN) is one ALARM line on the board, and the wait goes on. Every decision is a line in the day's log; it never fails the landing (exit 0)
store-post-updateThe post-update hook of every repository in the git store ~/git, nested folders and repositories created later included (see Store hook below). After each push (on the Spark, each landing) it runs the bazinga-git public sync, then, detached so the push never waits or fails, spark-cleanup --landed NAME and disk-alarm --quiet, with git's GIT_* variables cleared
test-store-post-update.shReal pushes in a scratch home with its own ~/.gitconfig and store: a landing runs the three steps in order with no GIT_* variable, a nested repository gets the hook, a repository outside the store does not (negative control), failing steps never fail the push, a slow step never delays it, and a mutant without the variable reset is caught
disk-alarmOne ALARM line on the board and a comment on the standing Linear issue (DISK_ALARM_LINEAR_ISSUE, default DRA-521) when / has less than 300 GB free (DISK_ALARM_MIN_GB) or falls faster than 20 GB/h; names the processes that wrote the most, by real working folder, cut to a fixed character set (other users' processes are read through sudo -n; those it still cannot read are counted in the line, never taken as writing nothing). The comment goes straight to Linear's API (disk-alarm --linear-comment ISSUE TEXT, key from atlas-vault run LINEAR_API_KEY, never on a command line); it counts as posted only when Linear returns a comment id, which goes in ~/.local/state/disk-alarm/linear.log. A failed post is one ALARM line on the board and is sent again at the next check. Run by the store hook after each landing and by aien-bays when a bay finishes, or by hand; nothing else runs it, so while there is no landing, bay finish or manual run the disk is not checked and a quiet board is not proof that the disk is fine. Never deletes anything
test-disk-alarm.shdisk-alarm with a fake df, /proc, board and Linear route: quiet above the floor, alarm below it reaching board and Linear with the comment id recorded, repeats held back, a further 25 GB fall posted again, the cleared line, a failed post (board ALARM once, kept, sent at the next check), hostile process names, a process whose writes cannot be read (counted, not "no process wrote"), the floor setting
test-spark-cleanup.shOffline test of classes 1, 2, 5 and 8 and of --landed in scratch homes, git stores and boards (class 5 reads a scratch folder in place of /tmp; the archive is restored), then mutants of spark-cleanup that must each fail a case; prints the case and mutant counts

SHA256SUMS in this directory is the sha256 of each script. It lists bare file names, so check it from tools/ops: from the repository root, (cd tools/ops && sha256sum -c SHA256SUMS). To check the copies installed on the Spark, run (cd ~/.local/bin && sha256sum -c --ignore-missing <repo>/tools/ops/SHA256SUMS).

Store hook (install once; every repository under ~/git, present or created later, then uses it):

install -D -m 755 tools/ops/store-post-update ~/.local/lib/store-hooks/post-update
printf '[core]\n\thooksPath = %s/.local/lib/store-hooks\n' "$HOME" > ~/.config/git/store.inc
git config --global 'includeIf.gitdir:~/git/.path' .config/git/store.inc

core.hooksPath replaces each repository's own hooks/ folder, so the per-repository copies of the old bazinga-git post-update (which ran only step 1, and were missing from repositories created later) no longer run; they stay on disk unused, and store-post-update runs the same bazinga-git sync as its step 1. The gitdir:~/git/ condition also covers worktrees whose git folder sits under ~/git; git runs post-update only in a repository that receives a push, so for them it changes nothing.

Shown on the Spark (2026-10-19/20): two callers on one source built once in a scratch repo (the second reused the stored result), two windows opened at the same moment (one refused), lease expiry, the --wait line in a sandbox (turns in arrival order, a late open refused, a waiter that gave up dropped). Real runs: two omega worktrees at one commit built once, identical output, a repeat in 4 s (docs/ops/evidence/L113-build-once-two-worktrees.md); window 20261020T095626Z-bd2f56 with a calibration and a passing 27B baseline (~/yardsticks/windows/20261020T095626Z-bd2f56/).