interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

flow: sandboxed gates and a seed installer (build.sh step 12b)

merged 92d2d028343d41b7 #8 · opened 2026-11-08 13:50 UTC · closed 2026-11-08 14:58 UTC · merged 2026-11-08 14:58 UTC

Imported from GitHub drakestapleton/sovereign-intelligence#8, by drakestapleton

Base 74a2e30509d794e4731fa4b7538ebcd292317e8f · Head 598f132ff01bd1c401839cd401ba5b35ca03e55f

Merged on GitHub as b4a96b1c3b5a42bf544d7910c4f2f04585bfb64f; not reachable from main e659ab3defe05c03ac1dd6cb39f8aa4626b905b1 (observed 2026-11-18T16:38:59Z)

drakestapleton wrote on 2026-11-08 13:50 UTC

Follow-up to drakestapleton/sovereign-intelligence#7: what the merge queue needs before it runs on the seed, and the installer that puts it there.

Sandboxed gates

A gate runs the patch's code, so flow.sh now runs it in a bubblewrap sandbox:

  • no network;
  • /home, /root, /run and /tmp hidden, and the Radicle home with them;
  • a clean environment.

Before a gate runs, flow.sh starts that exact sandbox once. If it cannot start, the step stops with bwrap's error, so a broken sandbox is never recorded as a fail verdict. FLOW_SANDBOX=none runs gates unsandboxed, for a repository whose patch authors are all trusted.

A seed installer

tools/flow-install.sh RID, run as the delegate on the seed:

  1. checks the tools and the sandbox, and that this identity is a delegate of RID;
  2. builds the planner from the seed (build.sh must end RC=0) and installs the native build;
  3. checks the working copy out of the node's storage and creates the receipt ledger;
  4. writes systemd user units that run a cycle 15 s after the last one ended, and enables the timer.

flow-cycle.sh now holds a lock on the ledger, so two cycles never run at once. The deploy steps are in tools/FLOW.md, under "Deploy on a seed".

Lean

Flow.lean was checked after #7 opened (commit 8f9cce0): Lean 4.15.0 accepts it, and every theorem depends only on propext and Quot.sound, with no sorry. The README, tools/FLOW.md and the file's header now say so.

Evidence (2026-11-08; x86-64 host, AArch64 under qemu-aarch64 8.2.2)

  • sh build.sh: RC=0, 295 PASS, 0 FAIL.
  • e2e, with each build: 7 of 7 checks pass. The e2e repository's gate fails if it can see a network, the Radicle key directory or the delegate's environment.
  • Control: with FLOW_SANDBOX=none, e2e fails at its first gate.
  • tests/flow/install.sh (new, step 12b): 5 of 5 checks pass. They cover three refusals (bad ID, foreign working copy, not a delegate), the install and its first cycle, systemd-analyze --user verify passing on both units with no warning, the cycle lock, and a reinstall that keeps the ledger and merges. I also ran it once by hand with the installer building the planner from the seed itself: 5 of 5.
  • SI's own build.sh inside the gate's sandbox, with rad visible: RC=0. Step 12b reports NOT_RUN there, because procfs cannot be mounted in a nested sandbox. Before that fix, the same run failed every gate, which would have failed every patch to SI.
  • Rehearsal: SI as a throwaway Radicle repository, with this branch's predecessor as a patch, installed with the seed build. The sandboxed gate passed it and the queue merged it. A second patch was then gated by the merged build.sh (now with step 12) and merged too. Each gate of SI took about 14 s.

Not done

  • The queue is not running on the seed yet. That needs the seed itself; the commands are in tools/FLOW.md, "Deploy on a seed".
  • Patches from separate peers (tools/FLOW.md, next step 2).

Generated by Claude Code

Apply it

git checkout -b patch-92d2d028343d41b7 74a2e30509d794e4731fa4b7538ebcd292317e8f
curl -fsSL https://interplane.io/drakestapleton/sovereign-intelligence/patches/92d2d028343d41b7.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
drakestapleton/sovereign-intelligence
8
598f132ff01bd1c401839cd401ba5b35ca03e55f
{"kind":"github-import","owner":"drakestapleton","repo":"sovereign-intelligence","number":8,"url":"https://github.com/drakestapleton/sovereign-intelligence/pull/8","export_sha256":"85088da80106edb3b212296d819945207557a69781e27119bdd34d69a98189de","imported_utc":"2026-11-18T16:38:59Z"}

Changes

diff --git a/README.md b/README.md
index d223c5e..414e851 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ GitHub keeps, at most, a read-only mirror of this one repository so that people
 | cuda-crack, a copy of its tables and Omega tools for this gate (its home stays its own Radicle repository, `rad:z631r2JJiVT8it4tST7RK24hpowi`): its Omega table generator, built by the seed-born compilers, regenerates all 471 sm_121 instruction forms. Its Omega reencoder rebuilds the 70 kernels that ran on the GB10 (13,520 instructions) from those tables alone, to the chip receipt's sha256. Its four planted bugs, now made by Omega (`check/mutate.om`, byte for byte the same as the original awk and od), are each caught. | HOST_TESTED, 2026-11-07, AArch64 and native x86-64; the kernels themselves ran on the chip on 2026-10-27 | step 8, [`gpu/cuda-crack/PROVENANCE.md`](gpu/cuda-crack/PROVENANCE.md) |
 | The fork-push generator, [`tools/forkpush.om`](tools/forkpush.om), writes the same script on both targets from [`stack/FORKS.tsv`](stack/FORKS.tsv). It refuses 18 malformed manifests, and a branch marked private appears only as a comment, never as a push. | HOST_TESTED, 2026-11-07 | step 9 |
 | The checked bulk word `count A off n v`, added to omc ([`seed/PROVENANCE.md`](seed/PROVENANCE.md#local-changes)): its 16 examples in [`tests/omc/`](tests/omc/) pass on both targets, and a compiler with its slice check deleted fails both trap-3 examples. Built with it, the stack ledger runs 6.1 times faster on native x86-64. | HOST_TESTED, 2026-11-07; the speed-up was measured over the 44 stack checkouts, outside the gate | steps 10 and 11; speed-up in [`seed/PROVENANCE.md`](seed/PROVENANCE.md#local-changes) |
-| The Omega merge queue, [`tools/flow.om`](tools/flow.om), which replaces GitHub's Actions, required checks and merge queue for Radicle patches ([`tools/FLOW.md`](tools/FLOW.md)): built for both targets, it writes the same plan from the same facts, reproduces its two fixtures byte for byte and refuses 21 malformed inputs and 3 malformed arguments. Run by [`tools/flow-cycle.sh`](tools/flow-cycle.sh) against a real Radicle repository, offline, it gates each distinct tree once with the default branch's `build.sh`, never with the delegate's key in its environment (a patch that rewrites its own `build.sh` to pass still fails), posts every verdict on its patch, and fast-forwards the default branch only to a tree with a pass receipt, one patch per cycle; a plan made before the branch moved refuses to run. It plans 4,096 patches against 16,384 receipts in 0.06 s on native x86-64. The Lean 4 model of its decision rules, [`tests/flow/Flow.lean`](tests/flow/Flow.lean), is written but not yet machine-checked. | HOST_TESTED, 2026-11-08, AArch64 under qemu-aarch64 8.2.2 and native x86-64, radicle-cli 0.23.0 and radicle-node 0.21.1 | step 12; step 12b, [`tests/flow/e2e.sh`](tests/flow/e2e.sh), runs when `rad` is installed |
+| The Omega merge queue, [`tools/flow.om`](tools/flow.om), which replaces GitHub's Actions, required checks and merge queue for Radicle patches ([`tools/FLOW.md`](tools/FLOW.md)): built for both targets, it writes the same plan from the same facts, reproduces its two fixtures byte for byte and refuses 21 malformed inputs and 3 malformed arguments. Run by [`tools/flow-cycle.sh`](tools/flow-cycle.sh) against a real Radicle repository, offline, it gates each distinct tree once with the default branch's `build.sh`, in a bubblewrap sandbox with no network and no access to the delegate's key (a patch that rewrites its own `build.sh` to pass still fails), posts every verdict on its patch, and fast-forwards the default branch only to a tree with a pass receipt, one patch per cycle; a plan made before the branch moved refuses to run. It plans 4,096 patches against 16,384 receipts in 0.06 s on native x86-64. [`tools/flow-install.sh`](tools/flow-install.sh) deploys it on a seed as a systemd user timer; in a rehearsal with SI itself as the Radicle repository it gated and merged this change, then a second patch with the merged `build.sh`. It is not yet running on my seed. Lean 4.15.0 checks a model of its decision rules, [`tests/flow/Flow.lean`](tests/flow/Flow.lean): six safety theorems (it merges only a passing fast-forward, at most one per cycle, never a failed tree, and gates a tree only once and only without a receipt), with no `sorry` and no axiom beyond Lean's `propext` and `Quot.sound`. | HOST_TESTED, 2026-11-08, AArch64 under qemu-aarch64 8.2.2 and native x86-64, radicle-cli 0.23.0 and radicle-node 0.21.1 | step 12; step 12b, [`tests/flow/e2e.sh`](tests/flow/e2e.sh) and [`tests/flow/install.sh`](tests/flow/install.sh), runs when `rad` and `bwrap` are installed |
 | omega-mv's whole FR-9 x86 corpus ran with its x86-64 programs native for the first time: 16,179 rows, 15,499 PASS, 232 FAIL, 32 NOT_RUN, 30 MISSING_IMPLEMENTATION, 75 BLOCKED, 311 EXCLUDED. No FAIL is an x86 miscompile. 150 need om2 candidate compilers whose commits are not published; 46 are omega-bridge refusing the compiler's hash (all 49 bridge rows pass when that one pin is moved); 36 pin the AArch64 bytes of an older omc. The run also found a cross-target bug in omc, fixed in [`seed/LOCAL.patch`](seed/LOCAL.patch). | HOST_TESTED, 2026-11-07, native x86-64; the AArch64 side under qemu-aarch64 8.2.2 | [`evidence/x86-native/`](evidence/x86-native/) |
 
 The whole gate takes 19.3 s on a 4-vCPU x86-64 cloud machine. There, omc-x86 compiles the 337,225-byte compiler in 0.10 s natively.
@@ -55,9 +55,9 @@ The only hardware result above is the cuda-crack kernels' chip run of 2026-10-27
 | [`seed/`](seed/) | the compiler's sources, from the hand-written `seed0.hex` to `omc/omc.om`, copied from omega-mv with [provenance](seed/PROVENANCE.md) |
 | [`build.sh`](build.sh) | the one build and gate |
 | [`compiler/`](compiler/) | `si.om`, the front-door generator |
-| [`tools/`](tools/) | `ledger.om`, the stack ledger; `forkpush.om`, which writes the script that sends my forks' branches to Radicle; `flow.om` and `flow-cycle.sh`, the merge queue that gates and merges Radicle patches ([`FLOW.md`](tools/FLOW.md)) |
+| [`tools/`](tools/) | `ledger.om`, the stack ledger; `forkpush.om`, which writes the script that sends my forks' branches to Radicle; `flow.om`, `flow-cycle.sh` and `flow-install.sh`, the merge queue that gates and merges Radicle patches, and its seed installer ([`FLOW.md`](tools/FLOW.md)) |
 | [`harness/`](harness/) | the Omega harness: agent skills for writing correct Omega; `.claude/skills` points at it |
-| [`tests/`](tests/) | the ledger, fork-push and merge-queue fixtures (with the queue's end-to-end Radicle test and Lean model), the example runner, the compiler regressions and the examples of the words this repository adds to the compiler |
+| [`tests/`](tests/) | the ledger, fork-push and merge-queue fixtures (with the queue's end-to-end Radicle test, installer test and Lean model), the example runner, the compiler regressions and the examples of the words this repository adds to the compiler |
 | [`gpu/cuda-crack/`](gpu/cuda-crack/) | a copy of cuda-crack's sm_121 encoding tables, Omega encoder and reencoder, and chip receipts, so the gate can rebuild the chip kernels; [provenance](gpu/cuda-crack/PROVENANCE.md). cuda-crack itself lives in its own Radicle repository |
 | [`docs/`](docs/) | writing and sites from my personal account that have no Radicle project: the AIEN constitution, drakestapleton.com's source, and the old site as an archive |
 | [`evidence/`](evidence/) | receipts of runs made from this repository, starting with the native x86-64 corpus run |
diff --git a/build.sh b/build.sh
index fb4bac0..ae1b3e1 100644
--- a/build.sh
+++ b/build.sh
@@ -37,8 +37,9 @@
 #      examples of count on every target that runs, while count_word still passes
 #  12. tools/flow.om, the merge queue's planner, built for both targets, must print
 #      tests/flow/expected.sh and expected-empty.sh and refuse every tests/flow/bad/*.tsv and three
-#      malformed arguments; 12b. with rad and git-remote-rad installed, tests/flow/e2e.sh runs the
-#      whole queue against a throwaway Radicle repository with each build, else NOT_RUN
+#      malformed arguments; 12b. with rad, git-remote-rad and bwrap installed, tests/flow/e2e.sh
+#      runs the whole queue, sandboxed, against a throwaway Radicle repository with each build, and
+#      tests/flow/install.sh deploys it on a throwaway seed with tools/flow-install.sh; else NOT_RUN
 # Last line: RC=0 when every step passed.
 set -eu
 R=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
@@ -394,8 +395,18 @@ for t in a64 x86; do
   [ $rc -eq 2 ] || fail "flow ($t) exited $rc, not 2, for four arguments"
   pass "flow ($t) prints tests/flow/expected.sh and expected-empty.sh, refuses all $nbad bad inputs and 3 bad arguments"
 done
-#  12b. The merge queue against a real Radicle repository, offline, when rad is installed.
-if command -v rad > /dev/null 2>&1 && command -v git-remote-rad > /dev/null 2>&1; then
+#  12b. The merge queue against a real Radicle repository, offline, and its installer, when rad
+#  and bwrap are installed and flow.sh's sandbox can start here. It cannot inside another such
+#  sandbox (procfs will not mount there), which is where this gate runs when flow gates SI itself.
+fbox() { # the sandbox fl_box gives a gate, around true
+  bwrap --ro-bind / / --tmpfs /home --tmpfs /root --tmpfs /run --tmpfs /tmp --dir /tmp/home \
+    --dev /dev --proc /proc --unshare-all --die-with-parent --new-session --clearenv true 2> /dev/null
+}
+if ! { command -v rad && command -v git-remote-rad && command -v bwrap; } > /dev/null 2>&1; then
+  note "NOT_RUN flow e2e and install: need rad, git-remote-rad and bwrap (https://radicle.xyz)"
+elif ! fbox; then
+  note "NOT_RUN flow e2e and install: flow.sh's bwrap sandbox cannot start on this host"
+else
   for t in a64 x86; do
     [ -x $O/flow-$t ] || { note "NOT_RUN flow e2e on $t"; continue; }
     if [ $t = a64 ]; then q=$A64; else q=$X86; fi
@@ -405,8 +416,16 @@ if command -v rad > /dev/null 2>&1 && command -v git-remote-rad > /dev/null 2>&1
     tail -1 $O/flow-e2e-$t.log | grep -qx 'RC=0' || fail "flow e2e ($t) did not finish"
     pass "flow e2e ($t): $(grep -c '^PASS' $O/flow-e2e-$t.log) checks against a real Radicle repository"
   done
-else
-  note "NOT_RUN flow e2e: needs rad and git-remote-rad (https://radicle.xyz)"
+  # the installer, with this host's native planner (it installs the native build)
+  case $host in aarch64|arm64) nt=a64 ;; *) nt=x86 ;; esac
+  if [ -x $O/flow-$nt ]; then
+    sh tests/flow/install.sh $O/flow-$nt > $O/flow-install.log 2>&1 || fail "flow install: $(grep '^FAIL' $O/flow-install.log | head -1)"
+    tail -1 $O/flow-install.log | grep -qx 'RC=0' || fail "flow install did not finish"
+    grep '^NOTE' $O/flow-install.log | while IFS= read -r l; do printf '%s\n' "$l"; done
+    pass "flow install: $(grep -c '^PASS' $O/flow-install.log) checks of tools/flow-install.sh on a throwaway seed"
+  else
+    note "NOT_RUN flow install: no native planner"
+  fi
 fi
 
 printf 'RC=0\n'
diff --git a/tests/flow/Flow.lean b/tests/flow/Flow.lean
index ba1ff17..41b8968 100644
--- a/tests/flow/Flow.lean
+++ b/tests/flow/Flow.lean
@@ -22,7 +22,9 @@ What this does not prove: that tools/flow.om implements this model (the fixtures
 and the end-to-end run in tests/flow/e2e.sh test that, they do not prove it), nor anything
 about git, Radicle or the gate itself.
 
-Check: lean tests/flow/Flow.lean (core Lean 4, no Mathlib; checked with leanprover/lean4:v4.15.0).
+Check: lean tests/flow/Flow.lean (core Lean 4, no Mathlib). Checked 2026-11-08 with Lean 4.15.0
+(x86_64-unknown-linux-gnu, commit 11651562caae): no output, exit 0; #print axioms gives
+[propext, Quot.sound] for each of the six theorems and fixture_plan.
 -/
 namespace Flow
 
diff --git a/tests/flow/e2e.sh b/tests/flow/e2e.sh
index 5773990..9e39fdb 100644
--- a/tests/flow/e2e.sh
+++ b/tests/flow/e2e.sh
@@ -9,7 +9,8 @@
 # exits 3.
 #
 # The repository's gate, build.sh, passes when the file state says good, and fails if it can
-# see the delegate's passphrase, Radicle home or agent socket. Five patches:
+# see the delegate's passphrase, Radicle home, agent socket or key directory, or reach any
+# network but loopback: flow.sh's sandbox must hide all of them. Five patches:
 #   A  a good change                      C  a different commit with A's exact tree
 #   B  state=bad                          E  a good change to another file
 #   D  state=bad, and its own build.sh rewritten to pass anyway
@@ -23,7 +24,7 @@ set -eu
 [ $# -eq 1 ] || { echo 'usage: sh tests/flow/e2e.sh FLOW' >&2; exit 2; }
 R=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
 case $1 in /*) flow=$1 ;; *) flow=$(pwd)/$1 ;; esac
-for c in git rad git-remote-rad; do
+for c in git rad git-remote-rad bwrap; do
   command -v $c > /dev/null 2>&1 || { echo "NOT_RUN flow e2e: no $c"; exit 3; }
 done
 fail() { printf 'FAIL %s\n' "$*"; exit 1; }
@@ -44,8 +45,12 @@ g config user.name flow-e2e
 cat > "$w/build.sh" << 'GATE'
 #!/bin/sh
 [ -z "${RAD_PASSPHRASE:-}${RAD_HOME:-}${SSH_AUTH_SOCK:-}" ] || { echo "FAIL the gate can see the delegate's key"; exit 1; }
+[ ! -e '@KEYS@' ] || { echo "FAIL the gate can see the Radicle key directory"; exit 1; }
+[ "$(grep -c : /proc/net/dev)" -le 1 ] || { echo "FAIL the gate can reach a network"; exit 1; }
 if grep -qx good state; then echo PASS state; else echo "FAIL state is not good"; exit 1; fi
 GATE
+sed -i "s|@KEYS@|$RAD_HOME/keys|" "$w/build.sh"
+[ -d "$RAD_HOME/keys" ] || fail "no key directory at $RAD_HOME/keys to hide"
 echo good > "$w/state"
 g add build.sh state
 g commit -qm init
diff --git a/tests/flow/expected-empty.sh b/tests/flow/expected-empty.sh
index 2ad1ada..52e09aa 100644
--- a/tests/flow/expected-empty.sh
+++ b/tests/flow/expected-empty.sh
@@ -9,6 +9,9 @@
 # the default branch's build.sh, never the patch's own, runs in a worktree of the patch head,
 # and the verdict goes into the ledger and onto the patch as a comment. A tree is gated once,
 # however many patches carry it, and never again while the gate is unchanged.
+# A gate runs the patch's code, so it runs in a bubblewrap sandbox: no network, no home
+# directories, no Radicle key or node socket, a clean environment. FLOW_SANDBOX=none runs it
+# unsandboxed, only for a repository whose every patch author is trusted.
 #
 #   sh flow.sh REPO DEFAULT RECEIPTS
 # REPO      a Radicle working copy, fetched, with its delegate's key authenticated (rad auth)
@@ -41,14 +44,32 @@ trap 'exit 1' HUP INT TERM
 fl_tree() { # fl_tree PATCH HEAD TREE: HEAD must be a commit whose tree is TREE
   [ "$(fl_git rev-parse --verify -q "$2^{tree}")" = "$3" ] || fl_die "patch $1: $2 is not a commit with tree $3"
 }
+fl_box() { # fl_box DIR CMD...: run CMD in DIR, sandboxed unless FLOW_SANDBOX=none, with a clean environment
+  d=$1; shift
+  if [ "${FLOW_SANDBOX:-bwrap}" = none ]; then
+    mkdir -p "$d.home"
+    (cd "$d" && env -i PATH="$PATH" HOME="$d.home" "$@")
+  else
+    k=${RAD_HOME:-${HOME:-/nonexistent}/.radicle}; [ -d "$k" ] || k=/tmp/.flow-no-radicle
+    bwrap --ro-bind / / --tmpfs /home --tmpfs /root --tmpfs /run --tmpfs /tmp --tmpfs "$k" \
+      --bind "$d" "$d" --dir /tmp/home --dev /dev --proc /proc \
+      --unshare-all --die-with-parent --new-session --clearenv \
+      --setenv PATH "$PATH" --setenv HOME /tmp/home --chdir "$d" "$@"
+  fi
+}
+fl_box_ok() { # fl_box_ok PATCH: the very sandbox a gate gets must start first, so it never records a false fail
+  [ "${FLOW_SANDBOX:-bwrap}" = none ] && return 0
+  command -v bwrap > /dev/null 2>&1 || fl_die "patch $1: bwrap is required to gate (FLOW_SANDBOX=none runs gates unsandboxed)"
+  mkdir -p "$fl_work/probe"
+  e=$(fl_box "$fl_work/probe" true 2>&1) || fl_die "patch $1: the gate's sandbox does not start here: $e"
+}
 fl_gate() { # fl_gate PATCH HEAD TREE: run the default branch's build.sh on HEAD; record and post the verdict
   fl_tree "$@"
   w=$fl_work/$3
   fl_git worktree add -q --detach "$w" "$2" || fl_die "patch $1: cannot check out $2"
   fl_git cat-file blob "$gate" > "$w/build.sh"
-  mkdir "$w.home"
-  # the gate never sees the delegate's key: no RAD_PASSPHRASE, RAD_SECRET, RAD_HOME, SSH_AUTH_SOCK or HOME
-  if (cd "$w" && env -u RAD_PASSPHRASE -u RAD_SECRET -u RAD_HOME -u SSH_AUTH_SOCK HOME="$w.home" sh ./build.sh) > "$w.log" 2>&1; then v=pass; else v=fail; fi
+  fl_box_ok "$1"
+  if fl_box "$w" sh ./build.sh > "$w.log" 2>&1; then v=pass; else v=fail; fi
   l=$(sha256sum < "$w.log" | cut -c1-64)
   printf '%s\t%s\t%s\t%s\n' "$3" "$gate" "$v" "$l" >> "$rec"
   m="flow gate $v tree $3 gate $gate log $l"
diff --git a/tests/flow/expected.sh b/tests/flow/expected.sh
index a3d0594..2728e19 100644
--- a/tests/flow/expected.sh
+++ b/tests/flow/expected.sh
@@ -9,6 +9,9 @@
 # the default branch's build.sh, never the patch's own, runs in a worktree of the patch head,
 # and the verdict goes into the ledger and onto the patch as a comment. A tree is gated once,
 # however many patches carry it, and never again while the gate is unchanged.
+# A gate runs the patch's code, so it runs in a bubblewrap sandbox: no network, no home
+# directories, no Radicle key or node socket, a clean environment. FLOW_SANDBOX=none runs it
+# unsandboxed, only for a repository whose every patch author is trusted.
 #
 #   sh flow.sh REPO DEFAULT RECEIPTS
 # REPO      a Radicle working copy, fetched, with its delegate's key authenticated (rad auth)
@@ -41,14 +44,32 @@ trap 'exit 1' HUP INT TERM
 fl_tree() { # fl_tree PATCH HEAD TREE: HEAD must be a commit whose tree is TREE
   [ "$(fl_git rev-parse --verify -q "$2^{tree}")" = "$3" ] || fl_die "patch $1: $2 is not a commit with tree $3"
 }
+fl_box() { # fl_box DIR CMD...: run CMD in DIR, sandboxed unless FLOW_SANDBOX=none, with a clean environment
+  d=$1; shift
+  if [ "${FLOW_SANDBOX:-bwrap}" = none ]; then
+    mkdir -p "$d.home"
+    (cd "$d" && env -i PATH="$PATH" HOME="$d.home" "$@")
+  else
+    k=${RAD_HOME:-${HOME:-/nonexistent}/.radicle}; [ -d "$k" ] || k=/tmp/.flow-no-radicle
+    bwrap --ro-bind / / --tmpfs /home --tmpfs /root --tmpfs /run --tmpfs /tmp --tmpfs "$k" \
+      --bind "$d" "$d" --dir /tmp/home --dev /dev --proc /proc \
+      --unshare-all --die-with-parent --new-session --clearenv \
+      --setenv PATH "$PATH" --setenv HOME /tmp/home --chdir "$d" "$@"
+  fi
+}
+fl_box_ok() { # fl_box_ok PATCH: the very sandbox a gate gets must start first, so it never records a false fail
+  [ "${FLOW_SANDBOX:-bwrap}" = none ] && return 0
+  command -v bwrap > /dev/null 2>&1 || fl_die "patch $1: bwrap is required to gate (FLOW_SANDBOX=none runs gates unsandboxed)"
+  mkdir -p "$fl_work/probe"
+  e=$(fl_box "$fl_work/probe" true 2>&1) || fl_die "patch $1: the gate's sandbox does not start here: $e"
+}
 fl_gate() { # fl_gate PATCH HEAD TREE: run the default branch's build.sh on HEAD; record and post the verdict
   fl_tree "$@"
   w=$fl_work/$3
   fl_git worktree add -q --detach "$w" "$2" || fl_die "patch $1: cannot check out $2"
   fl_git cat-file blob "$gate" > "$w/build.sh"
-  mkdir "$w.home"
-  # the gate never sees the delegate's key: no RAD_PASSPHRASE, RAD_SECRET, RAD_HOME, SSH_AUTH_SOCK or HOME
-  if (cd "$w" && env -u RAD_PASSPHRASE -u RAD_SECRET -u RAD_HOME -u SSH_AUTH_SOCK HOME="$w.home" sh ./build.sh) > "$w.log" 2>&1; then v=pass; else v=fail; fi
+  fl_box_ok "$1"
+  if fl_box "$w" sh ./build.sh > "$w.log" 2>&1; then v=pass; else v=fail; fi
   l=$(sha256sum < "$w.log" | cut -c1-64)
   printf '%s\t%s\t%s\t%s\n' "$3" "$gate" "$v" "$l" >> "$rec"
   m="flow gate $v tree $3 gate $gate log $l"
diff --git a/tests/flow/install.sh b/tests/flow/install.sh
new file mode 100644
index 0000000..c62c15b
--- /dev/null
+++ b/tests/flow/install.sh
@@ -0,0 +1,107 @@
+#!/bin/sh
+# tests/flow/install.sh: tools/flow-install.sh against a throwaway seed, offline.
+#
+#   sh tests/flow/install.sh FLOW
+#
+# FLOW is a native planner built from tools/flow.om. Needs git, rad, git-remote-rad and bwrap; it
+# makes a throwaway HOME, Radicle identity and repository under a temporary directory, so no node,
+# network, unit or key of yours is touched; without them it prints NOT_RUN and exits 3. It checks:
+# the installer refuses a non-Radicle ID, an identity that is not a delegate, and a REPO of another
+# repository; installed (from the local storage, with rad checkout, systemctl not called), its
+# first cycle gates the open patch and its units pass systemd-analyze verify when that runs here;
+# installed again, it keeps the ledger and its cycle merges the patch; and a second cycle cannot
+# start while one holds the ledger's lock. Each check prints PASS or FAIL; last line RC=0.
+set -eu
+[ $# -eq 1 ] || { echo 'usage: sh tests/flow/install.sh FLOW' >&2; exit 2; }
+R=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
+case $1 in /*) flow=$1 ;; *) flow=$(pwd)/$1 ;; esac
+for c in git rad git-remote-rad bwrap; do
+  command -v $c > /dev/null 2>&1 || { echo "NOT_RUN flow install: no $c"; exit 3; }
+done
+fail() { printf 'FAIL %s\n' "$*"; exit 1; }
+pass() { printf 'PASS %s\n' "$*"; }
+T=$(mktemp -d)
+if [ -n "${FLOW_E2E_KEEP:-}" ]; then echo "NOTE install directory $T"; else trap 'rm -rf "$T"' EXIT; fi
+unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE XDG_DATA_HOME XDG_CONFIG_HOME FLOW_HOME FLOW_DIR
+export HOME="$T/home" RAD_HOME="$T/rad" RAD_PASSPHRASE=flow-install
+[ "$(id -u)" != 0 ] || export FLOW_ALLOW_ROOT=1
+mkdir -p "$HOME"
+q() { "$@" > "$T/last.out" 2>&1 || { cat "$T/last.out" >&2; fail "$*"; }; }
+q rad auth --alias flow-install
+w=$T/src
+git init -q -b main "$w"
+g() { git -C "$w" "$@"; }
+g config user.email install@flow.invalid
+g config user.name flow-install
+printf '#!/bin/sh\ngrep -qx good state\n' > "$w/build.sh"
+echo good > "$w/state"
+g add build.sh state
+g commit -qm init
+(cd "$w" && q rad init --name demo --description 'flow install' --default-branch main --public --no-confirm --no-seed)
+rid=$(cd "$w" && rad .)
+g checkout -qb change
+echo more > "$w/more"
+g add more
+g commit -qm change
+(cd "$w" && q git push rad HEAD:refs/patches -o patch.message=change)
+g checkout -q main
+inst() { sh "$R/tools/flow-install.sh" --flow "$flow" --no-systemd "$@"; }
+
+if inst rad:notanid > "$T/o" 2>&1; then fail "the installer accepted rad:notanid"; fi
+grep -q 'is not a Radicle ID' "$T/o" || fail "rad:notanid was refused for another reason: $(cat "$T/o")"
+mkdir "$T/other"
+(cd "$T/other" && git init -q -b main && git commit -q --allow-empty -m x 2> /dev/null || true)
+if inst "$rid" "$T/other" > "$T/o" 2>&1; then fail "the installer accepted a REPO of no Radicle repository"; fi
+grep -q "is not a working copy of $rid" "$T/o" || fail "the foreign REPO was refused for another reason: $(cat "$T/o")"
+if RAD_HOME=$T/rad2 sh -c 'rad auth --alias stranger > /dev/null 2>&1 && exec "$@"' sh \
+    sh "$R/tools/flow-install.sh" --flow "$flow" --no-systemd "$rid" "$w" > "$T/o" 2>&1; then
+  fail "the installer accepted an identity that is not a delegate"
+fi
+grep -q 'is not a delegate' "$T/o" || fail "the stranger was refused for another reason: $(cat "$T/o")"
+pass "the installer refuses a bad ID, a foreign REPO and an identity that is not a delegate"
+
+inst --once "$rid" > "$T/o1" 2>&1 || { cat "$T/o1" >&2; fail "the first install failed"; }
+H=$HOME/.local/share/flow
+P=$H/${rid#rad:}
+U=$HOME/.config/systemd/user
+[ -x "$H/bin/flow" ] && [ -x "$H/bin/flow-cycle.sh" ] && [ -f "$H/bin/SOURCE" ] || fail "the planner was not installed"
+cmp -s "$H/bin/flow" "$flow" || fail "the installed planner is not FLOW"
+[ "$(cd "$P/repo" && rad .)" = "$rid" ] || fail "no working copy of $rid at $P/repo"
+grep -q '^flow-install: first cycle: patches 1 merged 0 merge 0 queued 0 rebase 0 fail 0 gate 1 same 0$' "$T/o1" ||
+  fail "the first cycle did not gate the one patch: $(tail -1 "$T/o1")"
+[ "$(awk -F'\t' 'NR > 1 { print $3 }' "$P/receipts.tsv")" = pass ] || fail "the ledger has no single pass receipt"
+pass "installed from the local storage; the first cycle gated the open patch, pass"
+
+for u in service timer; do [ -f "$U/flow-${rid#rad:}.$u" ] || fail "no flow-${rid#rad:}.$u"; done
+grep -qx "ExecStart=/bin/sh $H/bin/flow-cycle.sh $H/bin/flow $P/repo main $P/receipts.tsv" "$U/flow-${rid#rad:}.service" ||
+  fail "the service does not run the installed cycle on $P/repo"
+if command -v systemd-analyze > /dev/null 2>&1; then
+  mkdir -m 700 "$T/run"
+  rc=0; XDG_RUNTIME_DIR=$T/run systemd-analyze --user verify "$U/flow-${rid#rad:}.service" "$U/flow-${rid#rad:}.timer" > "$T/verify" 2>&1 || rc=$?
+  grep -v 'bus' "$T/verify" > "$T/verify.warn" || true
+  [ $rc -eq 0 ] && [ ! -s "$T/verify.warn" ] || { cat "$T/verify" >&2; fail "systemd-analyze --user verify rejects or warns about the units"; }
+  pass "systemd-analyze --user verify accepts both units, without a warning"
+else
+  echo "NOTE NOT_RUN systemd-analyze verify: no systemd-analyze"
+fi
+
+exec 8>> "$P/receipts.tsv.lock"
+if command -v flock > /dev/null 2>&1 && flock -n 8; then
+  if sh "$H/bin/flow-cycle.sh" "$H/bin/flow" "$P/repo" main "$P/receipts.tsv" > "$T/o" 2>&1; then
+    fail "a cycle ran while another held the ledger's lock"
+  fi
+  grep -q 'another cycle holds' "$T/o" || fail "the locked-out cycle failed for another reason: $(cat "$T/o")"
+  flock -u 8
+  pass "a cycle does not start while another holds the ledger's lock"
+else
+  echo "NOTE NOT_RUN flow lock: no flock"
+fi
+exec 8>&-
+
+inst --once "$rid" > "$T/o2" 2>&1 || { cat "$T/o2" >&2; fail "the second install failed"; }
+grep -q '^flow-install: first cycle: patches 1 merged 0 merge 1 queued 0 rebase 0 fail 0 gate 0 same 0$' "$T/o2" ||
+  fail "after reinstalling, the cycle did not merge the gated patch: $(tail -1 "$T/o2")"
+[ "$(grep -c . "$P/receipts.tsv")" -eq 2 ] || fail "reinstalling did not keep the ledger as it was"
+[ "$(git -C "$P/repo" rev-parse refs/remotes/rad/main)" = "$(g rev-parse change)" ] || fail "rad/main is not the patch head"
+pass "installed again: the ledger is kept, no tree is gated twice, and the cycle merged the patch"
+echo RC=0
diff --git a/tools/FLOW.md b/tools/FLOW.md
index 8714b7e..04c874f 100644
--- a/tools/FLOW.md
+++ b/tools/FLOW.md
@@ -33,8 +33,10 @@ middle part decides anything, and it is seeded Omega:
    `merged`, `merge`, `queued`, `rebase`, `fail`, `gate` or `same`, and write the script `flow.sh`
    that carries them out. The output depends only on the input bytes.
 3. **Act** (`flow.sh`): refuse if the default branch moved since step 1; gate each new tree in a
-   worktree with the *default branch's* `build.sh`, never the patch's own; append the verdict to
-   the ledger and post it on the patch; fast-forward the default branch to at most one patch.
+   worktree with the *default branch's* `build.sh`, never the patch's own, inside a bubblewrap
+   sandbox (no network; `/home`, `/root`, `/run`, `/tmp` and the Radicle home hidden; a clean
+   environment); append the verdict to the ledger and post it on the patch; fast-forward the
+   default branch to at most one patch.
 
 Receipts are keyed by (tree, gate): the git tree of the patch head and the blob id of the gate
 that judged it. A tree is gated once, however many patches carry it and however often agents
@@ -51,21 +53,42 @@ abuse filters refused.
 | 4096 patches against 16384 receipts | by hand | 0.06 s native x86-64, 0.13 s AArch64 under qemu |
 | the whole queue against a real, offline Radicle repository: 5 patches, 3 cycles | `tests/flow/e2e.sh`, step 12b | 7 of 7 PASS with each build (radicle-cli 0.23.0, radicle-node 0.21.1, radicle-remote-helper 0.18.1) |
 | a patch that rewrites its own `build.sh` to `exit 0` still fails | e2e cycle 1 | PASS |
-| the gate runs without the delegate's `RAD_PASSPHRASE`, `RAD_HOME`, `SSH_AUTH_SOCK` or `HOME`; a planner built without that scrub fails e2e | e2e cycle 1, control by hand | PASS |
+| a gate in the sandbox sees no network, no Radicle key directory and none of the delegate's environment; unsandboxed (`FLOW_SANDBOX=none`), e2e fails | e2e cycle 1, control by hand | PASS |
+| a sandbox that cannot start stops the step with bwrap's error, never records a fail; SI's own `build.sh` passes inside the sandbox, with step 12b NOT_RUN there | `flow.sh` probe; by hand | PASS, `RC=0` |
+| the installer refuses a bad ID, a foreign working copy and an identity that is not a delegate; installs; its units pass `systemd-analyze --user verify` with no warning; two cycles never overlap; reinstalling keeps the ledger | `tests/flow/install.sh`, step 12b | 5 of 5 PASS |
+| a rehearsal of the seed: SI as a throwaway Radicle repository, this branch as a patch, installed with the seed build; gated in the sandbox by `main`'s `build.sh`, pass, merged; a second patch gated by the merged `build.sh` (now with step 12), pass, merged | by hand, x86-64 | PASS; a gate of SI takes about 14 s there |
 | the merged tree has a pass receipt after every cycle; a stale plan refuses to run | e2e | PASS |
-| merge only to a passing fast-forward, at most one merge, each tree gated once, a failed tree never merges | `tests/flow/Flow.lean` | written, **not yet machine-checked** |
+| merge only to a passing fast-forward, at most one merge, each tree gated once, a failed tree never merges | `tests/flow/Flow.lean` | Lean 4.15.0 accepts all six theorems; `#print axioms`: `propext`, `Quot.sound` only, no `sorry` (commit `8f9cce0`) |
 
 The Lean file models the decision rules, not the Omega program: the fixtures and the e2e run test
 that flow.om follows the model; they do not prove it.
 
+## Deploy on a seed
+
+On the seed, as the user whose Radicle key is a delegate of the repository, with the node running
+(`rad node start`) and the repository seeded there:
+
+```sh
+sudo apt-get install -y bubblewrap
+cd sovereign-intelligence            # a checkout that has tools/flow-install.sh
+sh tools/flow-install.sh --once rad:z2JJz4RDfZZxKGBLn6UhmW5p9VJQj
+sudo loginctl enable-linger "$USER"  # keep the timer running after logout
+journalctl --user -u flow-z2JJz4RDfZZxKGBLn6UhmW5p9VJQj.service -f
+```
+
+The installer builds the planner from the seed (`build.sh` must end `RC=0`), checks the working
+copy out of the node's storage, and enables `flow-ID.timer`: a cycle 15 s after the last one ended.
+Each cycle's facts and plan stay in `~/.local/share/flow/ID/last`, the ledger in
+`~/.local/share/flow/ID/receipts.tsv`. If the key has a passphrase, put `RAD_PASSPHRASE=...` in
+`~/.local/share/flow/ID/secret.env` (mode 0600); the service reads it and no gate sees it. If the
+installer says bwrap cannot make a sandbox, the kernel forbids unprivileged user namespaces (Ubuntu
+24.04 restricts them through AppArmor); allow them for bwrap before going on, because flow never
+gates other people's patches without the sandbox. Run the installer again to upgrade.
+
 ## Next, in order
 
-1. **Run it on the seed.** A timer or a `rad node events` watcher on the seed node runs
-   `flow-cycle.sh` for SI with the delegate's key, so a patch is gated within seconds of reaching
-   the seed. This is the step that makes GitHub unnecessary for day-to-day work. A gate runs the
-   patch's code: flow already keeps the delegate's passphrase, Radicle home and agent socket out of
-   its environment, but on the seed it must also run as its own user with no network and no read
-   access to the delegate's key file, before it gates anyone else's patches.
+1. **Turn it on for SI.** Run the commands above on the seed. Until then the queue is tested and
+   rehearsed, not deployed.
 2. **Patches from other peers.** e2e today opens patches as the delegate itself. Next: agents as
    separate Radicle peers on two local nodes, with the delegate's node gating and merging.
 3. **Signed, shared receipts.** Move the ledger from a local file into a Radicle collaborative
diff --git a/tools/flow-cycle.sh b/tools/flow-cycle.sh
index c54e4e3..57a27e8 100644
--- a/tools/flow-cycle.sh
+++ b/tools/flow-cycle.sh
@@ -19,7 +19,8 @@
 #      refuses if the default branch moved since the facts were collected
 # Run it again to advance the queue: each cycle merges at most one patch.
 # FLOW_DIR=path keeps the cycle's facts and plan there (default: a temporary directory that is
-# removed). Exit status: flow.sh's, or 1 when a part before it fails, or 2 for usage.
+# removed). With flock installed, a cycle holds RECEIPTS.lock, so two never run at once.
+# Exit status: flow.sh's, or 1 when a part before it fails or another cycle runs, or 2 for usage.
 set -eu
 [ $# -eq 4 ] || { echo 'usage: sh tools/flow-cycle.sh FLOW REPO DEFAULT RECEIPTS' >&2; exit 2; }
 flow=$1 repo=$2 def=$3 rec=$4
@@ -27,6 +28,11 @@ die() { printf 'flow-cycle: %s\n' "$*" >&2; exit 1; }
 g() { git -C "$repo" "$@"; }
 [ -x "$flow" ] || die "no planner $flow"
 if [ -n "${FLOW_DIR:-}" ]; then d=$FLOW_DIR; mkdir -p -- "$d"; else d=$(mktemp -d); trap 'rm -rf "$d"' EXIT; fi
+# One cycle at a time per ledger: a second one, from the timer or by hand, does not wait; it exits 1.
+if command -v flock > /dev/null 2>&1; then
+  exec 9>> "$rec.lock"
+  flock -n 9 || die "another cycle holds $rec.lock"
+fi
 
 g fetch -q --prune rad || die "cannot fetch rad in $repo"
 branch=$(g rev-parse --verify -q "refs/remotes/rad/$def^{commit}") || die "$repo has no rad/$def"
@@ -43,5 +49,5 @@ while read -r p h; do
   printf '%s\t%s\t%s\t%s\n' "$p" "$h" "$t" "$r" >> "$d/state.tsv"
 done < "$d/heads"
 
-"$flow" "$branch" "$gate" "$d/state.tsv" "$rec" "$d/flow.sh" || die "the planner refused the facts in $d"
-sh "$d/flow.sh" "$repo" "$def" "$rec"
+"$flow" "$branch" "$gate" "$d/state.tsv" "$rec" "$d/flow.sh" 9>&- || die "the planner refused the facts in $d"
+sh "$d/flow.sh" "$repo" "$def" "$rec" 9>&-
diff --git a/tools/flow-install.sh b/tools/flow-install.sh
new file mode 100644
index 0000000..9acf0ed
--- /dev/null
+++ b/tools/flow-install.sh
@@ -0,0 +1,147 @@
+#!/bin/sh
+# flow-install.sh: deploy the Omega merge queue for one Radicle repository on this seed.
+#
+#   sh tools/flow-install.sh [--flow BIN] [--no-systemd] [--once] RID [REPO]
+#
+# Run it from a checkout of sovereign-intelligence on the seed, as the user whose Radicle key is a
+# delegate of RID (never as root). It:
+#   1. checks git, rad, git-remote-rad, bwrap (and that bwrap can make a sandbox), the Radicle
+#      identity, and that this identity is one of RID's delegates;
+#   2. builds the planner from the seed with build.sh, which must end RC=0, and installs the
+#      native build (out/flow-a64 on AArch64, out/flow-x86 on x86-64) with tools/flow-cycle.sh;
+#      --flow BIN installs BIN instead and skips the build;
+#   3. makes the working copy REPO (default FLOW_HOME/ID/repo, checked out from the local Radicle
+#      storage with rad checkout, so the repository must already be seeded here) and the receipt
+#      ledger FLOW_HOME/ID/receipts.tsv;
+#   4. writes the systemd user units flow-ID.service (one cycle) and flow-ID.timer (a cycle 15 s
+#      after the last one ended), and enables the timer; --no-systemd writes them without
+#      calling systemctl;
+#   5. with --once, runs one cycle now and prints its plan counts.
+# ID is RID without "rad:". FLOW_HOME defaults to ${XDG_DATA_HOME:-$HOME/.local/share}/flow; units
+# go to ${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user. Each cycle's facts and plan stay in
+# FLOW_HOME/ID/last. If the Radicle key has a passphrase, put RAD_PASSPHRASE=... in
+# FLOW_HOME/ID/secret.env, mode 0600; the service reads it, and the gate's sandbox never sees it.
+# Run it again to upgrade: the planner and units are replaced, the ledger and REPO are kept.
+# FLOW_ALLOW_ROOT=1 lets it run as root, for a disposable test container only, never on a seed.
+# Exit status: 0 installed; 1 a check or step failed (one "flow-install:" line says which); 2 usage.
+set -eu
+umask 077
+say() { printf 'flow-install: %s\n' "$*"; }
+die() { printf 'flow-install: %s\n' "$*" >&2; exit 1; }
+usage() { echo 'usage: sh tools/flow-install.sh [--flow BIN] [--no-systemd] [--once] RID [REPO]' >&2; exit 2; }
+SI=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+bin= sysd=1 once=0
+while [ $# -gt 0 ]; do
+  case $1 in
+    --flow) [ $# -ge 2 ] || usage; bin=$2; shift 2 ;;
+    --no-systemd) sysd=0; shift ;;
+    --once) once=1; shift ;;
+    -*) usage ;;
+    *) break ;;
+  esac
+done
+[ $# -eq 1 ] || [ $# -eq 2 ] || usage
+rid=$1
+case $rid in rad:z*) ;; *) die "$rid is not a Radicle ID (rad:z...)" ;; esac
+id=${rid#rad:}
+case $id in *[!0-9A-Za-z]*) die "$rid is not a Radicle ID" ;; esac
+
+# 1. checks
+[ "$(id -u)" != 0 ] || [ "${FLOW_ALLOW_ROOT:-}" = 1 ] || die "refusing to run as root; run it as the delegate's own user"
+for c in git rad git-remote-rad bwrap sha256sum; do
+  command -v $c > /dev/null 2>&1 || die "$c is required"
+done
+bwrap --ro-bind / / --unshare-all --die-with-parent true 2> /dev/null ||
+  die "bwrap cannot make a sandbox here (unprivileged user namespaces off?); gates must not run without one"
+me=$(rad self --did 2> /dev/null) || die "no Radicle identity: run rad auth"
+case $(uname -m) in
+  aarch64|arm64) t=a64 ;;
+  x86_64|amd64) t=x86 ;;
+  *) die "host $(uname -m): the planner is built for AArch64 and x86-64 only" ;;
+esac
+H=${FLOW_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/flow}
+P=$H/$id
+mkdir -p "$H/bin" "$P/last"
+
+# 2. the planner, from the seed
+if [ -z "$bin" ]; then
+  say "building the planner from the seed: sh build.sh (log $P/build.log)"
+  sh "$SI/build.sh" > "$P/build.log" 2>&1 || die "build.sh failed: $(grep '^FAIL' "$P/build.log" | head -1)"
+  [ "$(tail -1 "$P/build.log")" = RC=0 ] || die "build.sh did not end RC=0; see $P/build.log"
+  bin=$SI/out/flow-$t
+fi
+[ -x "$bin" ] || die "no planner at $bin"
+cp "$bin" "$H/bin/flow.new" && mv "$H/bin/flow.new" "$H/bin/flow"
+cp "$SI/tools/flow-cycle.sh" "$H/bin/flow-cycle.sh.new" && mv "$H/bin/flow-cycle.sh.new" "$H/bin/flow-cycle.sh"
+chmod 755 "$H/bin/flow" "$H/bin/flow-cycle.sh"
+src=$(git -C "$SI" rev-parse HEAD 2> /dev/null || echo unknown)
+printf 'si\t%s\nflow\t%s\nflow-cycle.sh\t%s\n' "$src" "$(sha256sum < "$H/bin/flow" | cut -c1-64)" \
+  "$(sha256sum < "$H/bin/flow-cycle.sh" | cut -c1-64)" > "$H/bin/SOURCE"
+
+# 3. the working copy and the ledger
+if [ $# -eq 2 ]; then
+  case $2 in /*) repo=$2 ;; *) repo=$(pwd)/$2 ;; esac
+else
+  repo=$P/repo
+  if [ ! -d "$repo/.git" ]; then
+    rm -rf "$P/co"
+    mkdir "$P/co"
+    (cd "$P/co" && rad checkout "$rid" > /dev/null 2>&1) ||
+      die "rad checkout $rid failed: the repository must be in this seed's storage (rad seed $rid)"
+    set -- "$P/co"/*
+    [ $# -eq 1 ] && [ -d "$1/.git" ] || die "rad checkout $rid did not make one working copy"
+    mv "$1" "$repo"
+    rmdir "$P/co"
+  fi
+fi
+[ "$(cd "$repo" && rad . 2> /dev/null)" = "$rid" ] || die "$repo is not a working copy of $rid"
+(cd "$repo" && rad inspect --delegates 2> /dev/null) | grep -q "^$me\\( \\|\$\\)" ||
+  die "$me is not a delegate of $rid; only a delegate's merges are canonical"
+def=$(cd "$repo" && rad inspect --payload 2> /dev/null | sed -n 's/^ *"defaultBranch": *"\([^"]*\)".*/\1/p' | head -1)
+[ -n "$def" ] || die "cannot read $rid's default branch from rad inspect --payload"
+case $def in *[!0-9A-Za-z._/-]*) die "default branch '$def' has characters the units cannot carry" ;; esac
+git -C "$repo" fetch -q rad || die "cannot fetch rad in $repo"
+git -C "$repo" rev-parse --verify -q "refs/remotes/rad/$def:build.sh" > /dev/null ||
+  die "$rid's $def has no build.sh: flow gates with it"
+rec=$P/receipts.tsv
+[ -f "$rec" ] || printf 'tree\tgate\tverdict\tlog\n' > "$rec"
+
+# 4. the units
+U=${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user
+mkdir -p "$U"
+for v in "$H" "$repo" "$PATH" "${RAD_HOME:-}"; do
+  case $v in *[!0-9A-Za-z._/:+-]*) die "a path or PATH entry has characters the units cannot carry: $v" ;; esac
+done
+{
+  printf '[Unit]\nDescription=Omega flow merge queue: one cycle for %s\n' "$rid"
+  printf 'Documentation=file:%s/tools/FLOW.md\n\n' "$SI"
+  printf '[Service]\nType=oneshot\nNice=10\n'
+  printf 'Environment=PATH=%s\n' "$PATH"
+  [ -z "${RAD_HOME:-}" ] || printf 'Environment=RAD_HOME=%s\n' "$RAD_HOME"
+  printf 'Environment=FLOW_DIR=%s/last\n' "$P"
+  printf 'EnvironmentFile=-%s/secret.env\n' "$P"
+  printf 'ExecStart=/bin/sh %s/bin/flow-cycle.sh %s/bin/flow %s %s %s\n' "$H" "$H" "$repo" "$def" "$rec"
+} > "$U/flow-$id.service"
+{
+  printf '[Unit]\nDescription=Omega flow merge queue for %s, every 15 s\n\n' "$rid"
+  printf '[Timer]\nOnActiveSec=5s\nOnUnitInactiveSec=15s\nAccuracySec=1s\nUnit=flow-%s.service\n\n' "$id"
+  printf '[Install]\nWantedBy=timers.target\n'
+} > "$U/flow-$id.timer"
+if [ $sysd = 1 ]; then
+  command -v systemctl > /dev/null 2>&1 || die "no systemctl: run --no-systemd and start the cycle another way"
+  systemctl --user daemon-reload || die "systemctl --user daemon-reload failed"
+  systemctl --user enable --now "flow-$id.timer" > /dev/null 2>&1 || die "cannot enable flow-$id.timer"
+  if [ "$(loginctl show-user "$(id -un)" -p Linger --value 2> /dev/null)" != yes ]; then
+    say "NOTE the timer stops at logout until lingering is on: sudo loginctl enable-linger $(id -un)"
+  fi
+  say "enabled flow-$id.timer; watch it with: journalctl --user -u flow-$id.service -f"
+else
+  say "wrote $U/flow-$id.service and .timer; systemctl was not called (--no-systemd)"
+fi
+say "installed: planner $H/bin/flow, $repo on $def, ledger $rec"
+
+# 5. one cycle now
+if [ $once = 1 ]; then
+  FLOW_DIR=$P/last sh "$H/bin/flow-cycle.sh" "$H/bin/flow" "$repo" "$def" "$rec" || die "the first cycle failed"
+  say "first cycle: $(sed -n 's/^# plan-counts //p' "$P/last/flow.sh")"
+fi
diff --git a/tools/flow.om b/tools/flow.om
index 5522161..0800a2c 100644
--- a/tools/flow.om
+++ b/tools/flow.om
@@ -158,11 +158,11 @@ text tend "echo 'flow: step done'\n"
 
 note the fixed parts of the script, paragraph by paragraph: the comment header (h0, h1), then the
 note body (b0 checks, b1 fl_tree, b2 fl_gate, b3 fl_merge)
-text h0 "#!/bin/sh\n# flow.sh: one step of the Omega merge queue for one Radicle repository.\n# Generated by tools/flow.om from the repository's open patches and its receipt ledger; do not\n# edit by hand.\n#\n# A patch merges only as a fast-forward of the default branch, and only when a receipt says the\n# default branch's gate passed on the patch head's exact tree, so the default branch only ever\n# moves to a tree that passed the gate guarding it. A patch whose tree has no receipt is gated:\n# the default branch's build.sh, never the patch's own, runs in a worktree of the patch head,\n# and the verdict goes into the ledger and onto the patch as a comment. A tree is gated once,\n# however many patches carry it, and never again while the gate is unchanged.\n#\n"
+text h0 "#!/bin/sh\n# flow.sh: one step of the Omega merge queue for one Radicle repository.\n# Generated by tools/flow.om from the repository's open patches and its receipt ledger; do not\n# edit by hand.\n#\n# A patch merges only as a fast-forward of the default branch, and only when a receipt says the\n# default branch's gate passed on the patch head's exact tree, so the default branch only ever\n# moves to a tree that passed the gate guarding it. A patch whose tree has no receipt is gated:\n# the default branch's build.sh, never the patch's own, runs in a worktree of the patch head,\n# and the verdict goes into the ledger and onto the patch as a comment. A tree is gated once,\n# however many patches carry it, and never again while the gate is unchanged.\n# A gate runs the patch's code, so it runs in a bubblewrap sandbox: no network, no home\n# directories, no Radicle key or node socket, a clean environment. FLOW_SANDBOX=none runs it\n# unsandboxed, only for a repository whose every patch author is trusted.\n#\n"
 text h1 "#   sh flow.sh REPO DEFAULT RECEIPTS\n# REPO      a Radicle working copy, fetched, with its delegate's key authenticated (rad auth)\n# DEFAULT   the name of its default branch\n# RECEIPTS  the receipt ledger this plan was made from; new verdicts are appended to it\n# Exit status: 0 the step ran; 1 the repository is not as planned, or a gate, comment or push\n# could not run; 2 usage.\n# Each patch's decision is one \"# plan ACTION PATCH HEAD TREE\" line, in the order of the input.\n"
 text b0 "set -eu\numask 022\n[ $# -eq 3 ] || { echo 'usage: sh flow.sh REPO DEFAULT RECEIPTS' >&2; exit 2; }\nrepo=$1 def=$2 rec=$3\nfl_die() { printf 'flow: %s\\n' \"$*\" >&2; exit 1; }\nfl_git() { git -C \"$repo\" \"$@\"; }\ncommand -v git >/dev/null 2>&1 || fl_die \"git is required\"\ncommand -v rad >/dev/null 2>&1 || fl_die \"rad is required: https://radicle.xyz\"\n[ -f \"$rec\" ] || fl_die \"no receipt ledger $rec\"\ncur=$(fl_git rev-parse --verify -q \"refs/remotes/rad/$def^{commit}\") || fl_die \"$repo has no rad/$def\"\n[ \"$cur\" = \"$branch\" ] || fl_die \"rad/$def is $cur, not $branch: make a new plan\"\n[ \"$(fl_git rev-parse --verify -q \"$branch:build.sh\")\" = \"$gate\" ] || fl_die \"build.sh at $branch is not blob $gate\"\nfl_work=$(mktemp -d)\ntrap 'rm -rf \"$fl_work\"; fl_git worktree prune' EXIT\n"
 text b1 "trap 'exit 1' HUP INT TERM\nfl_tree() { # fl_tree PATCH HEAD TREE: HEAD must be a commit whose tree is TREE\n  [ \"$(fl_git rev-parse --verify -q \"$2^{tree}\")\" = \"$3\" ] || fl_die \"patch $1: $2 is not a commit with tree $3\"\n}\n"
-text b2 "fl_gate() { # fl_gate PATCH HEAD TREE: run the default branch's build.sh on HEAD; record and post the verdict\n  fl_tree \"$@\"\n  w=$fl_work/$3\n  fl_git worktree add -q --detach \"$w\" \"$2\" || fl_die \"patch $1: cannot check out $2\"\n  fl_git cat-file blob \"$gate\" > \"$w/build.sh\"\n  mkdir \"$w.home\"\n  # the gate never sees the delegate's key: no RAD_PASSPHRASE, RAD_SECRET, RAD_HOME, SSH_AUTH_SOCK or HOME\n  if (cd \"$w\" && env -u RAD_PASSPHRASE -u RAD_SECRET -u RAD_HOME -u SSH_AUTH_SOCK HOME=\"$w.home\" sh ./build.sh) > \"$w.log\" 2>&1; then v=pass; else v=fail; fi\n  l=$(sha256sum < \"$w.log\" | cut -c1-64)\n  printf '%s\\t%s\\t%s\\t%s\\n' \"$3\" \"$gate\" \"$v\" \"$l\" >> \"$rec\"\n  m=\"flow gate $v tree $3 gate $gate log $l\"\n  f=$(sed -n '/^FAIL/{p;q;}' \"$w.log\")\n  [ -z \"$f\" ] || m=\"$m\n$f\"\n  (cd \"$repo\" && rad patch comment \"$1\" -m \"$m\" > /dev/null) || fl_die \"patch $1: cannot post the verdict\"\n  fl_git worktree remove --force \"$w\"\n  printf 'flow: gate %s patch %s tree %s\\n' \"$v\" \"$1\" \"$3\"\n}\n"
+text b2 "fl_box() { # fl_box DIR CMD...: run CMD in DIR, sandboxed unless FLOW_SANDBOX=none, with a clean environment\n  d=$1; shift\n  if [ \"${FLOW_SANDBOX:-bwrap}\" = none ]; then\n    mkdir -p \"$d.home\"\n    (cd \"$d\" && env -i PATH=\"$PATH\" HOME=\"$d.home\" \"$@\")\n  else\n    k=${RAD_HOME:-${HOME:-/nonexistent}/.radicle}; [ -d \"$k\" ] || k=/tmp/.flow-no-radicle\n    bwrap --ro-bind / / --tmpfs /home --tmpfs /root --tmpfs /run --tmpfs /tmp --tmpfs \"$k\" \\\n      --bind \"$d\" \"$d\" --dir /tmp/home --dev /dev --proc /proc \\\n      --unshare-all --die-with-parent --new-session --clearenv \\\n      --setenv PATH \"$PATH\" --setenv HOME /tmp/home --chdir \"$d\" \"$@\"\n  fi\n}\nfl_box_ok() { # fl_box_ok PATCH: the very sandbox a gate gets must start first, so it never records a false fail\n  [ \"${FLOW_SANDBOX:-bwrap}\" = none ] && return 0\n  command -v bwrap > /dev/null 2>&1 || fl_die \"patch $1: bwrap is required to gate (FLOW_SANDBOX=none runs gates unsandboxed)\"\n  mkdir -p \"$fl_work/probe\"\n  e=$(fl_box \"$fl_work/probe\" true 2>&1) || fl_die \"patch $1: the gate's sandbox does not start here: $e\"\n}\nfl_gate() { # fl_gate PATCH HEAD TREE: run the default branch's build.sh on HEAD; record and post the verdict\n  fl_tree \"$@\"\n  w=$fl_work/$3\n  fl_git worktree add -q --detach \"$w\" \"$2\" || fl_die \"patch $1: cannot check out $2\"\n  fl_git cat-file blob \"$gate\" > \"$w/build.sh\"\n  fl_box_ok \"$1\"\n  if fl_box \"$w\" sh ./build.sh > \"$w.log\" 2>&1; then v=pass; else v=fail; fi\n  l=$(sha256sum < \"$w.log\" | cut -c1-64)\n  printf '%s\\t%s\\t%s\\t%s\\n' \"$3\" \"$gate\" \"$v\" \"$l\" >> \"$rec\"\n  m=\"flow gate $v tree $3 gate $gate log $l\"\n  f=$(sed -n '/^FAIL/{p;q;}' \"$w.log\")\n  [ -z \"$f\" ] || m=\"$m\n$f\"\n  (cd \"$repo\" && rad patch comment \"$1\" -m \"$m\" > /dev/null) || fl_die \"patch $1: cannot post the verdict\"\n  fl_git worktree remove --force \"$w\"\n  printf 'flow: gate %s patch %s tree %s\\n' \"$v\" \"$1\" \"$3\"\n}\n"
 text b3 "fl_merge() { # fl_merge PATCH HEAD TREE: fast-forward DEFAULT to HEAD, whose tree passed the gate\n  fl_tree \"$@\"\n  fl_git merge-base --is-ancestor \"$branch\" \"$2\" || fl_die \"patch $1: $2 does not fast-forward $branch\"\n  fl_git push -q rad \"$2:refs/heads/$def\" || fl_die \"patch $1: the push of $2 to $def was refused\"\n  printf 'flow: merged patch %s head %s\\n' \"$1\" \"$2\"\n}\n\n"
 
 note wdec: write v in decimal to stderr