interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / tools / aien-local-ci / README.md

365 lines · 32269 bytes Raw Blame History Rendered
1# aien-local-ci: host sandbox for the sovereign local pipeline (lane INFRA)
2
3Owner: lane INFRA of the sovereign local pipeline mission (inventory and contracts in
4`~/handoffs/2026-10-11-sovereign-pipeline-M1-inventory.md`, contracts C3, C7, C8, A2, A3).
5Everything here is bash. No Python. Host systemd units are used only for transient scopes; nothing here touches
6Aienux.
7
8## Files
9
10| file | role |
11|---|---|
12| `aien-run-exec` | source of truth for `/usr/local/sbin/aien-run-exec`, the C8 exec contract |
13| `install.sh` | idempotent host install (user, dirs, caches, rustup proxies, trusted `crumb`, exec script, sudoers) |
14| `wt.sh` | trusted-side mirror + worktree management under `/var/lib/aien-run` |
15| `forgejo-webhook.sh` | push trigger: Forgejo post-receive hook that writes the worker trigger file (A3) |
16| `health.sh` | one-screen health (Forgejo, user, exec, crumb, home layout, caches, worktrees, scopes, disk, GPU lock, quiet flag) |
17| `gc.sh` | worktree age + target-dir quota cleanup, dry run by default |
18| `tests/run.sh` | proofs of the contract on this host (33 checks with two wt.sh worktrees present) |
19| `pipeline.sh` | publish verified bundles to aien-receipts, merge `ready-to-merge` PRs that merge cleanly (no Spark gate), tag full-scope Spark PASS commits on main as `alpha/YYYYMMDD.N` |
20| `aien-alpha` | source of `~/.local/bin/aien-alpha`: cut an Alpha (full-scope Spark judge on a main commit, publish, tag); `aien-alpha list` |
21| `tests/pipeline_test.sh` | offline proofs of `pipeline.sh` with fake `gh`, fake `aien-test` and throwaway git repositories (121 checks) |
22| `tests/pipeline_mutants.sh` | six mutants: the publish trust-anchor rule (no `--require`, the commit's own `.aien/always`, a missing anchor that fails open) and the alpha hold (blocked URL ignored, hold journaled every round, hold keyed by URL only); `pipeline_test.sh` must fail on each |
23| `rebase-train.sh` | moves `ready-to-merge` PRs that conflict only in `.crumb` files (or are behind) onto main (no crumb recompile since the DRA-97 retirement), force-with-lease pushes; labels `needs-rebase` and comments once otherwise. The tick no longer runs it (GitHub lane disabled 2026-11-07; the Radicle desk owns patches) |
24| `cron-tick.sh` | the tick the user service `aien-run-local-ci.service` runs every 300 s (cron retired 2026-11-08): sibling map guard (`sibling-map-check`), keeps the trigger-only worker alive, then `pipeline.sh round` |
25| `desk-loop.sh` | the train + round in a 90 s loop while `$STATE/KEEP-RUNNING` exists; separate from the tick |
26| `aien-local-ci` | source of the operator front door `~/.local/bin/aien-local-ci` (status, start/stop named worker lanes, trigger, verify, once, plan, health, log) |
27| `tests/cli_args_test.sh` | offline launcher argument and lane parsing controls with stubbed Git, worker dispatch, process discovery and signals; run with `bash tools/aien-local-ci/tests/cli_args_test.sh` |
28| `crumb-shim.sh` | the operator's `~/.local/bin/crumb`: runs the crumb tool the repository's own CRUMB-VERIFY gate uses (crumb.lock pin, own tree for aien-architecture, else the sandbox tool), so author, readiness check and gate never disagree |
29| `crumb-doctor` | retired from the tick 2026-11-08 with the crumbs: crumb tool agreement, worker sibling maps, `--heal`. Kept for history; its heal and sibling map checks live on, unchanged, in `sibling-map-check` |
30| `sibling-map-check` | source of `~/.local/bin/sibling-map-check`, run by cron-tick.sh: worker sibling maps match origin/main and cover every `need_sibling` / `pin` a repo's `tests/gates/run.sh` asks for; `--heal` keeps this clone's work tree on origin/main; `--alert` writes a `SIBLING-MAP` line into the aien-watch ALERT |
31| `tests/crumb_shim_test.sh`, `tests/crumb_doctor_test.sh`, `tests/sibling_map_check_test.sh` | offline proofs on throwaway fixtures (14, 12 and 10 checks) |
32| `tests/cron_tick_test.sh` | offline proof of what `cron-tick.sh` calls, under a throwaway HOME of logging stubs (8 checks); run with `bash tools/aien-local-ci/tests/cron_tick_test.sh tools/aien-local-ci/cron-tick.sh` |
33| `tests/crumb_real_test.sh` | Spark-only red/green on real trees and on the real failing heads of 2026-10-16..18 (19 checks) |
34
35## C8 exec contract
36
37```
38sudo -n /usr/local/sbin/aien-run-exec --cwd DIR --timeout SECS --profile host|qemu|gb10 [--env K=V]... -- PROGRAM [ARGS...]
39```
40
41Chain (all on the privileged side, then drop): `systemd-run --scope` under `aien-run.slice` with `MemoryMax`,
42`MemorySwapMax=0`, `TasksMax`, `CPUQuota`, `DevicePolicy` -> `unshare -m [-n -i]` -> mount setup (below) ->
43`prlimit --core=0 --nofile=65536` -> `timeout --signal=TERM --kill-after=10 SECS` (host|qemu) -> `setpriv --reuid
44aien-run --regid aien-run --init-groups --reset-env --no-new-privs` -> `env -i -C DIR PATH HOME CARGO_HOME RUSTUP_HOME
45[K=V...] PROGRAM`. After PROGRAM exits the scope is killed and stopped, so a crashed check leaves no strays.
46Unprivileged user namespaces are refused on this host, which is why the namespaces are created as root before
47dropping privileges.
48
49Exit codes: PROGRAM's own code passes through; 124 = timeout (host|qemu); 137 = killed (OOM or SIGKILL);
50143 = the wrapper itself got TERM/INT/HUP (the scope is killed); 2 = refused by the wrapper before anything ran.
51
52Mount setup inside the private mount namespace (every profile): the whole sandbox home `/var/lib/aien-run` is
53read-only, except the worktree that contains `--cwd` and the target dir named by `CARGO_TARGET_DIR`, which stay
54writable. Private empty tmpfs on `/var/tmp`, `/var/crash`, `/var/lib/BrlAPI` (the world-writable places on the root
55disk). host|qemu also get private `/tmp`, `/dev/shm`, `/run/lock`, `/run/screen`, a fresh IPC namespace and a fresh
56`/dev/mqueue`.
57
58| profile | memory | tasks | cpu | network | IPC, /tmp, /dev/shm | devices | timeout |
59|---|---|---|---|---|---|---|---|
60| host | 48G | 4096 | 1600% (16 cores) | none (fresh netns, only its own `lo`, up) | private | closed (null, zero, random, tty, ptmx) | yes |
61| qemu | 48G | 4096 | 1600% | none (as host) | private | closed + `/dev/kvm` (aien-run is in group kvm) | yes |
62| gb10 | 96G | 4096 | 1800% | host network | shared with the host | all (`/dev/nvidia*` are 0666; `/dev/dri/*` via groups video, render) | NO kill |
63
64Argument rules (exit 2 when broken):
65* `--cwd` absolute, existing, canonical (no symlink, no `..`, no trailing slash). Inside `/var/lib/aien-run` only the
66 home itself or `wt/<repo>/<40-hex sha>[/...]`.
67* `--env K=V`: plain names; `PATH`, `HOME`, `CARGO_HOME`, `RUSTUP_HOME`, `LD_*`, `BASH_ENV`, `ENV` refused; each name at
68 most once. `CARGO_TARGET_DIR` must be exactly `/var/lib/aien-run/target/<repo>/pr/<sha40>` or `.../main/<sha40>` (trust class, A2),
69 the worktree's own repo and sha when `--cwd` is in one; it is created on demand (parents root-owned, head dir aien-run).
70* `PROGRAM` may not contain `=` or start with `-` (otherwise `env` would read it as one more variable assignment).
71* The wrapper refuses to run if the home, `cargo`, `cargo/bin`, `rustup`, `target`, `/usr/local/bin` or `/usr/bin`
72 is not root-owned or is group/other-writable.
73
74Optional flags `--memory-max`, `--tasks-max`, `--cpu-quota` override the profile defaults (tests use `--memory-max 64M`).
75Sandbox PATH is `/var/lib/aien-run/cargo/bin:/usr/local/bin:/usr/bin:/bin` (all root-owned). A bare program name
76resolves only through it; a file of the same name inside the worktree is never used.
77
78## Trusted crumb on the sandbox PATH
79
80`/usr/local/bin/crumb` (root 0755) is built by `install.sh` from aien-architecture commit
81`12ad0141b41ec67ef5aa51cb4e1815894c1083bb` (`tools/crumb/crumb.c`, git blob `c272f293...`, checked before building;
82source read from the git object store of `AIEN_ARCH_CLONE`, default `~/workspace/aien-architecture`) with
83`cc -O2 -Wall -std=c11`. With gcc 13.3.0 the binary's sha256 is `2fb09401f1e09682...` (built on the Spark 2026-10-18;
84the installed `/usr/local/bin/crumb` had this sha256 on 2026-10-31). The previous pin `94fffbcf` built to `22015e6b...`,
85which matched the operator's `~/.local/bin/crumb` on 2026-10-11. This repository's `crumb.lock` names the same commit,
86so the (now retired, DRA-97) CRUMB-VERIFY gate, the worker's readiness check and this sandbox tool agree. To move the pin, change
87`CRUMB_COMMIT` and `CRUMB_BLOB` in `install.sh` and `crumb.lock` in one PR.
88
89The worker's readiness check does not trust any PATH `crumb`: it builds the tool each repository names in `crumb.lock`
90(aien-architecture: the tool at the commit under test) and caches it under `<state>/crumb-tool/<pin>/` (sc#602,
91details in `tools/aien-test/docs/LOCAL_VERIFICATION.md`).
92
93## Operator crumb (shim) and crumb-doctor (2026-10-19)
94
95Four places used to pick a crumb build four different ways: each repo's CRUMB-VERIFY gate (crumb.lock pin, own
96tree, or this sandbox tool), the worker's readiness check (`aien-test verify` runs the bare name `crumb`, so
97`~/.local/bin/crumb`), the required hosted "AIEN Verification" (its workflow pin), and whoever ran `crumb compile`.
98`~/.local/bin/crumb` was a fixed 94fffbcf build. Effects seen 2026-10-16..18: every PASS head in omega, aienos and
99physics (pinned d0f0b95d) published as `BLOCKED PASS` / error; every RFC-0003 Am1 migration head read "N of N crumbs
100stale"; authors compiled sc with d0f0b95d and omega with 94fffbcf and the gates called the result stale (12 of 34
101STALE gate failures). Separately, the poll workers read `siblings` from this clone's WORK TREE, which nothing had
102moved since 2026-10-11, so synapse ran CRUMB-VERIFY without `../aien-architecture` (30 failed judgements, exit 3).
103
104- Install the shim: `install -m 0755 tools/aien-local-ci/crumb-shim.sh ~/.local/bin/crumb` (keep the old binary as
105 `crumb.bak-<ts>-<sha8>`). It never falls back silently: a malformed or unbuildable pin exits 97.
106- Install the doctor: `install -m 0755 tools/aien-local-ci/crumb-doctor ~/.local/bin/crumb-doctor`. Until 2026-11-08 cron-tick.sh
107 ran `crumb-doctor --heal-only` every tick and `crumb-doctor --heal --alert` at most every 15 minutes in the
108 background; failures became a `CRUMB-DRIFT` line in the aien-watch ALERT (shown by the gh guard and the chat hook).
109- Before merging any PR that moves a crumb pin (crumb.lock, the hosted workflow pin, tools/crumb, install.sh), run
110 `crumb-doctor --repos <repo>`: every consumer must give the same verdict on the PR head.
111- DRA-97 (2026-11-07) retired the CRUMB-VERIFY gates. A repository whose main has neither a `crumb-verify` step
112 in `tests/gates/run.sh` nor a hosted crumb step passes `AGREE` as "crumb gate retired"; the `SIBMAP` and
113 `PROMOTE` checks and the trusted-clone heal are unchanged. Reinstall the doctor after this lands.
114- 2026-11-08 (Drake: "get rid of crumbs", "keep the parts that worked"): the tick no longer runs crumb-doctor. Its
115 trusted-clone heal and `SIBMAP` checks, unchanged, are `sibling-map-check` (this directory), installed with
116 `install -m 0755 tools/aien-local-ci/sibling-map-check ~/.local/bin/sibling-map-check`. cron-tick.sh runs
117 `sibling-map-check --heal-only` every tick and `sibling-map-check --heal --alert` at most every 15 minutes in the
118 background (`$STATE/sibling-map.last`, `.log`, `.lock`); failures become a `SIBLING-MAP` line in the aien-watch
119 ALERT, and every `--alert` run also drops a leftover `CRUMB-DRIFT` line. Proof:
120 `bash tools/aien-local-ci/tests/sibling_map_check_test.sh tools/aien-local-ci/sibling-map-check`.
121
122
123## Egress decision
124
125No nftables rule for uid aien-run. host and qemu checks run in a fresh network namespace with no interface but its own loopback, which is
126stronger than a packet filter (no DNS). The namespace's own loopback is brought up (SANDBOX lane, 2026-10-11:
127aien-protocols tests start an HTTP server on 127.0.0.1 and failed with "Network is unreachable" while `lo` was down);
128it reaches only processes inside the same run, never the host's 127.0.0.1 services (tests/run.sh 4b: Forgejo on
129127.0.0.1:3443 is "refused" from inside). gb10 is the only profile with network: it keeps the host
130network per the contract; a later nft rule for uid aien-run would be the way to close that and is deliberately not
131added by this lane.
132
133## Layout under /var/lib/aien-run
134
135| path | owner / mode | purpose |
136|---|---|---|
137| `/var/lib/aien-run` | root:aien-run 0750, ACL `u:drakestapleton:r-x` | HOME of aien-run; no skeleton dotfiles |
138| `cargo/` | root 0755 | CARGO_HOME (cargo works with it read-only: `--locked --offline` builds need no writes there) |
139| `cargo/registry`, `cargo/git` | root, read-only | seeded once from `~/.cargo` (1.9 GB + 1.3 GB; the git cache is needed because `Cargo.lock` has 3 git sources) |
140| `registry-refresh.sh <Cargo.lock>` | operator, sudo | adds to `cargo/registry` the crates.io packages a trusted lockfile names that the judge lacks: copied from `~/.cargo`, sha256 checked against the lockfile, unpacked into `registry/src` with cargo's `.cargo-ok` marker (the read-only judge cargo cannot unpack a `.crate` itself), index-cache entry copied, one journal line; a `.crate` the judge has without its source is unpacked after the same check; never deletes or replaces a crate or source directory (#622). `--dry-run` only lists |
141| `cargo/bin` | root | the operator's `rustup` binary + proxy symlinks; no second rustup install |
142| `rustup/` | root, read-only | `settings.toml` (default 1.98.1) + `toolchains/1.98.1-aarch64-unknown-linux-gnu` copied (631 MB), plus `toolchains/nightly-aarch64-unknown-linux-gnu` with miri for SC-MIRI |
143| `.cache/miri` | root, read-only | miri sysroot built once by `install.sh` against the copied nightly (110 MB); `cargo +nightly miri setup` in the sandbox finds it and writes nothing (#600) |
144| `.gitconfig` | root 0644 | `safe.directory = *` (git 2.43 has no path globs; aien-run reaches nothing else) |
145| `/tmp/aien-gb10.lock` | root 0664, ACL `u:drakestapleton:rw-`, `u:aien-run:rw-` | the one GB10 chip lock for operator runs and sandboxed gb10 gates; root ownership gets past `fs.protected_regular=2` in sticky `/tmp`; `/etc/tmpfiles.d/aien-gb10.conf` recreates it at boot (#627); a gb10 gate waits for it in the kernel queue up to 30 min by default (`aien-test --gpu-wait`, between the live server's requests), then is NOT_RUN `gpu_lock`; the wait is in each receipt (`volatile.gpu_wait`) |
146| `mirror/<repo>.git` | drakestapleton 0755 | bare mirror of the trusted clone, refreshed by `wt.sh sync`; unwritable by aien-run |
147| `wt/<repo>/<sha>` | root dir drakestapleton:aien-run 1775, `.git` root 0644, files aien-run | checkouts; aien-run can add files, cannot replace `.git` or write the mirror |
148| `target/`, `target/<repo>/` | root 0755 | parents cannot be swapped by aien-run |
149| `target/<repo>/{pr,main}/<sha40>` | aien-run | one per head inside its trust class (A2); a run can write only its own; `wt.sh remove` deletes it with the worktree (a shared dir let cargo link one head's build into another, sc #605) |
150
151## Trigger file contract (A3)
152
153`~/.local/state/aien-local-ci/trigger/<repo>.<sha>` with one line `<ref> <old> <new> <unix-time>`, written by the
154Forgejo post-receive hook (`forgejo-webhook.sh install <repo>`), consumed and deleted by `aien-test worker`.
155forgejo-runner stays off (its user unit is disabled); Forgejo is git hosting + PR UI + status display only.
156
157## Review (INFRA-2, 2026-10-11)
158
159Fixed in this branch (each has a test in `tests/run.sh`):
1601. The sandbox could write its own home and CARGO_HOME (both were owned by aien-run): a check could plant
161 `/var/lib/aien-run/.cargo/config.toml` or `cargo/config.toml` (for example a `build.rustc-wrapper`), or rename the
162 root-owned `cargo/registry` or `cargo/bin` aside and put poisoned crates or a fake `cargo` in their place. Every later
163 run, including a `main` qualification, would have used them. Now the home, `cargo/` and `target/` are root-owned and
164 the whole home is read-only inside every run.
1652. Cross trust class writes: a PR run could write `target/<repo>/main` and every other worktree (all owned by
166 aien-run). Now only the run's own worktree and the one target dir it names are writable.
1673. `/tmp`, `/var/tmp`, `/var/crash` were shared with the operator: a check could read the operator's temporary files
168 and leave files behind for later runs or for root crash tooling. Now private (see the profile table for gb10).
1694. SysV shared memory, semaphores and POSIX queues were shared with the host; host|qemu now get a fresh IPC namespace.
1705. `PROGRAM` of the form `NAME=VALUE` was read by `env` as one more variable, which bypassed the `--env` refusals
171 (for example `LD_PRELOAD`). Now refused.
1726. `CARGO_TARGET_DIR` and `--cwd` were not checked: a typo or a symlink planted by an earlier run inside a worktree
173 could point a run at another worktree or trust class. Now canonical paths only, target dir only `pr|main`.
1747. `install.sh` staged the sudoers line in a predictable `/tmp/aien-sudoers.<pid>` before installing it as root.
175 (`fs.protected_regular=2` on this host already blocked the race; now a private `mktemp -d` directory.)
1768. The wrapper ran with the caller's PATH via `/usr/bin/env bash`; it now uses `/bin/bash` and pins its own PATH.
1779. Skeleton dotfiles (`.bashrc`, `.profile`, `.config/autostart`, `Desktop`) in the home were aien-run-writable;
178 removed.
17910. The qemu profile allowed `/dev/kvm` in the cgroup policy, but aien-run was not in group `kvm` (`/dev/kvm` is
180 root:kvm 0660), so qemu checks could not use KVM. install.sh now adds the group; host still cannot open it.
181
182Checked and found sound (no change):
183* aien-run cannot read `~/.aien/verify.key`, `~/.config/gh/hosts.yml`, `~/.ssh/id_ed25519` or list `~/workspace`
184 (0600 files, 0700 workspace; tests 10). The trusted clone lives under `~/workspace`; the sandbox only sees the mirror.
185* sudoers: one exact command path, no wildcards; arguments are free by design and validated by the script; sudo's
186 `env_reset` plus `setpriv --reset-env` plus `env -i` clear the caller's environment (test 2).
187* `setpriv --no-new-privs`: setuid programs (sudo, crontab, at) gain nothing inside a run; the scope kills every
188 child at the end, so nothing outlives a run.
189* Repo-controlled files (`.cargo/config.toml`, `build.rs`, `rust-toolchain.toml`, test code) run as aien-run only and
190 cannot change the exec contract, which reads nothing from the tree. A toolchain pin other than 1.98.1 fails offline.
191* The environment whitelist is minimal: PATH, HOME, CARGO_HOME, RUSTUP_HOME (cargo and the rustup proxy need the last
192 two to find the sandbox caches) plus explicit `--env` pairs.
193* gb10 host network is the only network exception (`unshare -n` for host and qemu only).
194* Operator git refuses to run inside a sandbox worktree ("dubious ownership": the `.git` file is root-owned and the
195 files are aien-run-owned), so a `.git` directory planted by a check cannot run hooks or config as the operator.
196
197Accepted risks (recorded, not changed by this lane):
198* gb10 keeps host network, host `/tmp`, `/dev/shm` and IPC: a chip gate can reach local services on 127.0.0.1 (Forgejo
199 3443/2222, Cortex 18080 need credentials it cannot read) and the internet, and can leave files in `/tmp`.
200 Closing it needs either a nft rule for uid aien-run or a netns for gb10 after the chip gates are proven inside one.
201* If the caller kills the wrapper during a gb10 run, the trap kills the chip run too (no strays). The engine must not
202 signal a gb10 run; it only marks its advisory timeout in the receipt.
203* The operator account has `(ALL) NOPASSWD: ALL` in sudoers, so the narrow `aien-local-ci` rule is documentation of
204 intent, not a limit, until that broad rule is removed (operator decision, outside this lane).
205* The operator's home is 0755 (ACL user atlas `--x`); its secrets are 0600 and verified unreadable.
206* Same-SHA reuse: a PR run and a `main` qualification of the same commit share one worktree path. The engine should
207 remove and re-add the worktree (fresh checkout) before a `main` qualification.
208* `git` write operations as aien-run inside a worktree fail (the index lives in the read-only mirror). Gates must not
209 need them.
210* A run's HOME is read-only: a gate that writes to `$HOME` fails; write to `/tmp` (private for host|qemu) instead.
211* Worktree root dirs inherit setgid from the mirror layout (`drwxrwsr-t`); harmless.
212
213## Stages: merge, then Alpha (ADR 0033 amended 2026-10-24)
214
215Drake, 2026-10-24: "Lift the requirement to test on the Spark in order to be merged ... There should instead be tags
216that clearly label when a certain build gets to the Alpha stage. That is the stage that must be tested on the Spark.
217We must not limit our development process by these tests."
218
219| stage | what it takes | who does it |
220|---|---|---|
221| merge to `main` | label `ready-to-merge`, not a draft, merges without conflicts | `pipeline.sh merge` (tick) |
222| Alpha (`alpha/YYYYMMDD.N` tag on a main commit) | full-scope Spark qualification: every gate of the repository, GPU gates included, signed bundle PASS, `verify-bundle --require-full` exit 0 | `aien-alpha REPO` runs the judge; `pipeline.sh alpha` tags |
223
224No pull request is judged on the Spark, no status check is required on GitHub (the `main-protect` rulesets keep only
225no-deletion, no-force-push and PR-only), and nothing ever moves `main` except a PR merge. The hosted `AIEN` workflow
226is advisory on PRs (portable smoke set; its crumb verify step is retired, DRA-97) and verifies every pushed `alpha/*` tag against its published
227bundle.
228
229```
230aien-alpha aien-sovereign-core # qualify origin/main's head; exit 0 only once it carries an alpha tag
231aien-alpha omega <sha-on-main> # any commit already on main
232aien-alpha list # every repository's alpha tags, newest first
233```
234
235## Publish, merge, alpha (pipeline.sh)
236
237```
238tools/aien-local-ci/pipeline.sh publish|merge|alpha|round [--repos a,b] # round = publish, merge, alpha
239bash tools/aien-local-ci/tests/pipeline_test.sh # offline proofs, a few seconds
240bash tools/aien-local-ci/tests/pipeline_mutants.sh # each publish-rule mutant must fail the proofs
241```
242
243It never reads `~/.aien/verify.key` and never signs: it only moves bundles the worker already signed, merges, and
244tags. One instance at a time (`flock` on `$STATE/pipeline.lock`; a second one exits 0 at once, or waits up to
245`AIEN_LOCK_WAIT` seconds when set, as `aien-alpha` does). Every action and refusal is one JSON line in
246`$STATE/pipeline.jsonl`. Exit 0 when the round ran (refusals included), 2 on a usage or configuration error.
247Overrides: `AIEN_STATE`, `AIEN_CLONES`, `AIEN_RECEIPTS`, `AIEN_RECEIPTS_BRANCH`, `AIEN_RECEIPTS_URL`, `AIEN_TEST_BIN`,
248`AIEN_GH_OWNER` (default `aien-dev`), `AIEN_REPOS`, `AIEN_TAGGER_NAME`, `AIEN_TAGGER_EMAIL`, `GH`, `GIT`. GitHub calls
249use the canonical slug (`gh api repos/aien-dev/<repo> --jq .full_name`; e.g. `aien-dev/aegis-runtime-mv`), cached in
250`$STATE/slugs/<repo>` for 24 h (`AIEN_SLUG_TTL`); a failed refresh falls back to the older cached name. Each lookup
251journals `action=slug` with `result=cached`, `refreshed` or `stale-cache`.
252
253* **publish**: for each `$STATE/bundles/<repo>/<sha>/bundle.json` of a repository whose trusted clone has a key in
254 `origin/main:.aien/verify.pub` (several keys allowed, one per line, `#` comments, same rule as aien-test): skip when
255 `plan.blocked` is not null; run `verify-bundle` with `--repo github.com/aien-dev/<repo> --commit <sha>` taken from
256 the path and `--require` set to the gates of `<sha>^1:.aien/always` in the trusted clone (the first-parent trust
257 anchor of aien-receipts `tools/replay_receipt.py`; never the bundle's own required marks, so a commit that deletes a
258 gate is judged by the list it was written against: aien-receipts 264da364 finding F2), once per key; refuse with
259 `no trust anchor` when that parent or its `.aien/always` is missing; publish when any key gives 0 PASS or 1 FAIL,
260 never 2 NOT_RUN or 3 REJECTED (`MISSING_REQUIRED_CHECK` included). Proofs: `tests/pipeline_test.sh`, and
261 `tests/pipeline_mutants.sh` (three mutants of that rule, each must fail the test). Publishing
262 copies the bytes to `<receipts>/<repo>/<sha>/bundle.json` when absent or when its sha256 differs (replacement by
263 digest), one commit per round listing every sha, then `pull --rebase` and push, 3 attempts, never forced. A failed
264 push drops only that round's own commit; the next round recomputes it.
265* **merge**: open PRs labeled exactly `ready-to-merge`, not draft, head unchanged since listing, GitHub mergeable
266 state `clean`, `unstable` (some non-required check failed), `behind` or `has_hooks`. `dirty` (conflicts) and
267 `blocked` are refused, `unknown` waits for a later round. Then `gh pr merge N -R <slug> --merge
268 --match-head-commit <sha>`. Never `--admin`. No bundle, no status check, no up-to-date rule, no limit per round.
269* **alpha**: per repository, the bundles in receipts `origin/main` whose signed plan says `"scope": "full"` (one
270 `git grep`), restricted to commits on the trusted clone's `origin/main`; the newest by committer time that
271 `verify-bundle --require-full --require <origin/main:.aien/always>` passes (exit 0) is the candidate. It is tagged
272 unless it already has an `alpha/*` tag or the newest existing `alpha/*` tag already contains it. The tag is
273 annotated, named `alpha/<UTC date>.<n>` (n from 1 per day), and its message names the commit, the bundle sha256
274 and the receipt URL; it is pushed with git. A failed push deletes the local tag. Never moves a branch. An Alpha tag
275 is public: when the trusted clone's push URL (`git remote get-url --push origin`, `pushInsteadOf` expanded) is
276 `blocked-<reason>://`, no tag is made; the candidate is journaled once as `result=held`
277 `HELD_PUBLISH_BLOCKED` and kept in `$STATE/alpha-held/<repo>` (`<sha> <push URL>`), and it is looked at again only
278 when the candidate or the push URL changes. An unblocked URL clears that state.
279
280Merge pause: while `$STATE/MERGE-PAUSE` exists (Drake, 2026-10-18: "stop all agents from trying to merge"), the
281merge step journals `result=paused` and merges nothing; publish and alpha keep running. `rebase-train.sh` keeps
282rebasing (that is not merging) and never adds `ready-to-merge` or enables auto-merge, paused or not. No script creates
283or deletes the file: only Drake lifts the pause.
284
285## Rebase train (rebase-train.sh; desk-loop.sh only, the tick stopped running it on 2026-11-07)
286
287```
288tools/aien-local-ci/rebase-train.sh [--dry-run] [--repos a,b] [--pr N] # --dry-run: local work only, prints the plan
289```
290
291Why: every merge to main rewrites the root `.crumb` (generated by the pinned crumb compiler), so every other open PR
292turned CONFLICTING and `pipeline.sh merge` refused it as `dirty` forever (2026-10-18: 11 of 12 `ready-to-merge` PRs in
293sovereign-core; the four probed conflicted in the root `.crumb` only). The train does what a person would do.
294
295For each repo (same list as `pipeline.sh`), each open PR labeled exactly `ready-to-merge`, not draft, head branch in
296the same repository (no forks), that GitHub reports `CONFLICTING` or `BEHIND`:
297
2981. fetch `pull/N/head` into `refs/aien-train/N` of the trusted clone, scratch worktree under `$STATE/.train.*`
299 (hooks off: `core.hooksPath=/dev/null`); both removed on exit, also on error;
3002. skip (journal only) when the head commit's committer time is under 10 minutes old (`AIEN_TRAIN_MIN_AGE`, seconds;
301 a proxy for "pushed recently": GitHub's push time costs an extra API call), when the PR touches a trust-surface
302 file (`.aien/verify.pub`, `.github/workflows/*`; never rebased by the train), or when nothing but `.crumb` files
303 would be left after the rebase (the changes are already in main);
3043. `git rebase origin/<base>`; conflicts in `.crumb` files (root or nested) take the base's copy; any other
305 conflicting file aborts the rebase;
3064. (retired 2026-11-07, DRA-97: Crumbs are retired from the active workflow) the train used to recompile and
307 `crumb verify` the `.crumb` files with the pinned crumb tool; it no longer does, `.crumb` files keep the base's copy
308 and no crumb tool pin is needed;
3095. `git push --force-with-lease=refs/heads/<branch>:<old head>` to the PR branch; a `needs-rebase` label is removed.
310
311A conflict outside `.crumb` adds the label `needs-rebase`
312(created once per repo, recorded in `$STATE/train-labels`) and posts one comment that starts with
313`> *This was generated by AI during triage.*` and lists the files. One comment per head sha: recorded in
314`$STATE/train-commented` and marked `<!-- aien-rebase-train head=<sha> -->` in the comment, checked with one
315`gh pr view` before posting. Every decision is one JSON line in `$STATE/train.jsonl` (`utc, repo, pr, head, action,
316reason`); `--dry-run` writes none, pushes, labels and comments nothing. One instance at a time (`flock` on
317`$STATE/train.lock`). API budget per run: one `gh pr list` per repo (GraphQL; the label is filtered locally because
318`gh pr list --label` returned nothing on 2026-10-18), and only for a blocked PR one slug lookup (shared disk cache,
319see pipeline.sh), one label call, one
320`gh pr view` and one comment. Pushes go through git. Exit 0 when the run finished (skips included), 2 on a usage or
321configuration error. Overrides: `AIEN_STATE`, `AIEN_CLONES`, `AIEN_GH_OWNER`, `AIEN_REPOS`,
322`AIEN_TRAIN_MIN_AGE`, `GH`, `GIT`.
323
324GitHub rate-limit guard: every `gh` call of `pipeline.sh` and `rebase-train.sh` goes through `ghc`. When the shared
325guard `~/.local/bin/gh` refuses with exit 98 (allowance reserved or rate-limit marker set), the run makes no further
326GitHub call and every journal line after it carries `deferred: "gh guard exit 98: try next round"` (in train.jsonl
327the same words close the reason). Never a retry loop, never a FAIL: the next tick tries again. Neither script uses
328`gh run watch` (the guard's exit 97). Pushes use git, whose credential helper is `/usr/bin/gh auth git-credential`.
329
330## Tick (cron-tick.sh)
331
332Installed as `~/.local/lib/aien-local-ci/cron-tick.sh` and run every 300 s by the always-on user service
333`~/.config/systemd/user/aien-run-local-ci.service` (`Restart=always`), which replaced the crontab line on 2026-11-08
334(no cron on the Spark; undo map in `~/handoffs/hive/factory-cron/`):
335
336```
337ExecStart=%h/.local/bin/aien-loop 300 /bin/bash -c '$$HOME/.local/lib/aien-local-ci/cron-tick.sh >> $$HOME/.local/state/aien-local-ci/cron-tick.log 2>&1'
338```
339
340Each tick: the sibling map guard (`sibling-map-check --heal-only`, plus `--heal --alert` in the background at most
341every 15 minutes), `aien-local-ci start` (a trigger-only worker: no `--github`, so no pull request is polled, judged
342or given a status; a no-op while it runs), then `pipeline.sh round`. The tick does not run `rebase-train.sh`: the
343GitHub rebase lane was disabled on 2026-11-07 (it queried GitHub PRs despite MERGE-PAUSE) and the Radicle merge desk
344owns patches. `desk-loop.sh` (with `$STATE/KEEP-RUNNING`) is separate and unchanged.
345`touch ~/.local/state/aien-local-ci/PAUSE` stops the tick.
346
347The Spark judges two kinds of work only: Alpha candidates (`aien-alpha`, foreground `worker --once --full
348--operator`) and trigger files written by hand (`aien-local-ci trigger REPO SHA`). The per-PR worker lanes of
3492026-10-18 (`--github`, lanes main/small/big/core) are retired with the merge gate they fed.
350
351## Operate
352
353```
354tools/aien-local-ci/install.sh # idempotent; AIEN_ARCH_CLONE=<aien-architecture clone> for crumb
355tools/aien-local-ci/tests/run.sh # all proofs, about 10 s
356tools/aien-local-ci/wt.sh sync aien-sovereign-core ~/workspace/aien-sovereign-core
357tools/aien-local-ci/wt.sh add aien-sovereign-core <sha>
358tools/aien-local-ci/health.sh
359tools/aien-local-ci/gc.sh [--apply] [--days 3] [--target-quota-gb 120]
360```
361
362Measured 2026-10-11 (sovereign-core 5ef7720, 20 cores, caches seeded): cold `cargo build --workspace --all-targets
363--locked --offline` as aien-run 65.0 s (target dir 27 GB); warm rebuild after touching one crate 2.2 s. After the
364read-only home change: full workspace build of worktree 62542eb into the existing `pr` target 49.9 s (new worktree
365path, so workspace crates rebuilt; dependencies reused), exit 0.