Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
mergeda4edd3e22361d8a5 #1056 · opened 2026-11-07 01:05 UTC · closed 2026-11-15 14:36 UTC · merged 2026-11-15 14:36 UTC
Imported from GitHub aien-dev/omega-mv#1056, by drakestapleton
Base a2fd14f7ba75fdfbc3ef8e42f5469f3f045b294e · Head 9dfc35b608cb947b58e20a4b2b274f85899ecd5d
Merged on GitHub as 9dfc35b608cb947b58e20a4b2b274f85899ecd5d; reachable from main c7acd2607139eedfabeac16b6042cefe8ede431f (observed 2026-11-18T16:35:39Z)
drakestapleton wrote on 2026-11-07 01:05 UTC
DRA-286: resident .om process supervision and epoch turnover for the Omega Node arena. Stacked on #1055 (feat/shared-memory-node-transport); the diff shown is only this work.
Status: IMPLEMENTED, EXERCISED on native Linux AArch64 (DGX Spark host CPU, no GPU). Not QUALIFIED: the Spark judge has not run it, there is no independent review yet, and it is not connected to the live hive (NOT_DEPLOYED).
What changed (all .om, seed compiler 5f90edea…)
File
Change
seed/node/pool.om (new)
K≤8 arenas plus a control page, all mapped before fork. Epoch-based reuse: a worker stores its hold, then re-reads the epoch (pool_hold). An arena is reset only when its epoch is older than the current one and unheld. pool_roll returns -9 and changes nothing while every other arena is held.
seed/node/super.om (new)
sup_spawn/sup_wwait/sup_poll/sup_reap/sup_stop. Close-on-exec life pipes detect worker death (creator side) and creator death (worker side, sup_wwait → 3). Reaping waits for the exact PID, and a dead worker's hold is cleared only after that reap. Stop escalates to SIGKILL after a bounded wait.
seed/node/transport.om
node_reset (creator only: count 0 first, then record versions, stop, epoch) and node_epoch.
Pool and supervision contracts, the control-page layout, memory-ordering argument and the controls table. Removes the stale "no slot recycling / supervision missing" lines.
What the gate checks with forked processes:
A worker holding an old epoch sees it complete and unchanged after newer epochs are published.
SIGKILL of the last holder is detected through its life pipe. Its hold is released only after the reap, and then rollover succeeds.
A respawned worker joins.
A worker that ignores stop is SIGKILLed after the deadline and not before, even with an ack pending (check 90).
An orphaned worker sees the creator's exit (status 3).
waitpid -1 reports ECHILD at teardown.
pool_hold refuses when run after pool_roll+pool_pick, the order that breaks a hold without the recheck.
Concurrent stress: 2 workers acquire, scan and release in a loop while the creator rolls 2000 epochs over 2 arenas.
Bug found and fixed in this PR (commit 25c8aa17): sup_stop polled the ack eventfds. One pending ack made the "bounded" wait spin through its 100000 iterations in ~0.2 s and SIGKILL a cooperative worker early. sup_pollx … false waits on deaths only; control pm10 reproduces the old behaviour and exits 90.
Command and observed output
Run on spark-b87b, Linux 7.0.0-1019-nvidia aarch64, cores 8-9 (flock … taskset -c 8-9 nice -n 10), clean head 0d0eadfc, tree ad5697e1:
Receipt (addition only): evidence/node-pool/receipt.8bd61eb98b0290106fd4ff3858008d5c423db94391ce5379c248e7a67bd5e18d.json. It holds full binary SHA-256s, stdout and per-run stress counts for all 50 repeats.
The #1055 transport controls nc1-nc5 still fail as that README specifies against the changed transport.om.
Negative controls are one-line sed edits of a disposable copy (the table is in seed/node/README.md). Every one compiles and fails with its predicted code.
A timing-only version of the recheck control (ps9: if eq mapget c 16 8 e → if true under stress) exited 0 in 5/5 probes, because the race needs two rolls inside one announce window. That is why the recheck is gated by the deterministic step-order check (pm9, exit 144) instead.
Repository gates on this head: crumb verify . with the crumb.lock tool d0f0b95d → OK: 189 crumbs current. tests/gates/run.sh zero-disk-secrets → Zero plaintext .env files verified.tests/gates/run.sh evidence-immutable (base origin/main 943d9555) → evidence/: additions only.
Not claimed
Weak-memory correctness is argued from mapset/mapget DSB SY fences and exercised by the stress phase on this one host CPU. It is not proved.
A stalled worker that never calls sup_wwait outlives a crashed creator until its own work ends. Death detection on the worker side needs it to wait. There is no PDEATHSIG host word.
Workers must not exec; tools must fork first. Cancellation of child tools is DRA-288.
No Spark judge run, no GB10 path involved, no deployment.
#!/bin/bash
# Native Linux AArch64 run: DRA-286 pool/supervisor gate + negative controls,
# and the #1055 transport gate + its 5 controls against the changed transport.om.
# Run under ~/work/omega-node-run.sh (one hive core pool).
set -u
cd ~/work/omega-node
E=${E:-~/work/omega-node-evidence-286-$(date -u +%Y%m%dT%H%M%SZ)}; mkdir -p $E build/node
echo "host $(uname -srm) $(hostname)" | tee $E/platform.txt
echo "head $(git rev-parse HEAD) tree $(git rev-parse HEAD^{tree}) dirty=$(git status --porcelain | wc -l)" | tee -a $E/platform.txt
echo "cpus $(taskset -p $$ | sed 's/.*: //')" | tee -a $E/platform.txt
sha256sum seed/out/omc seed/node/*.om | tee $E/hashes.txt
N=seed/node
cat $N/transport.om $N/transport-test.om > build/node/composed.om
cmp build/node/composed.om $N/transport-gate.om && echo "transport compose cmp OK" | tee -a $E/hashes.txt
cat $N/transport.om $N/pool.om $N/super.om $N/pool-test.om > build/node/pool-composed.om
cmp build/node/pool-composed.om $N/pool-gate.om && echo "pool compose cmp OK" | tee -a $E/hashes.txt
run() { # name src expected-regex [arg]
local n=$1 src=$2 want=$3 arg=${4:-}
seed/out/omc < $src > build/node/$n 2> $E/$n.cerr; local c=$?
if [ $c != 0 ]; then echo "FAIL $n compile=$c $(cat $E/$n.cerr)"; return; fi
chmod +x build/node/$n; sha256sum build/node/$n | cut -c1-64 > $E/$n.sha; local sha=$(cut -c1-16 $E/$n.sha)
local t0=$(date +%s%N)
timeout 90 build/node/$n $arg > $E/$n.out 2> $E/$n.err; local r=$?
local ms=$(( ($(date +%s%N) - t0) / 1000000 ))
local v=FAIL; echo "$r" | grep -qxE "$want" && v=PASS
echo "$v $n compile=0 exit=$r want=$want ms=$ms bin=$sha stdout=$(tr "\n" " " < $E/$n.out | cut -c1-60)"
}
run transport-gate $N/transport-gate.om 0 | tee $E/results.txt
run pool-gate $N/pool-gate.om 0 | tee -a $E/results.txt
# transport mutants (from #1055 README), applied to the changed transport.om
tmk() { # name sed-expr expected
sed "$2" $N/transport.om > build/node/$1.src
if cmp -s build/node/$1.src $N/transport.om; then echo "FAIL $1 mutation did not apply" | tee -a $E/results.txt; return; fi
cat build/node/$1.src $N/transport-test.om > build/node/$1.om
run $1 build/node/$1.om $3 | tee -a $E/results.txt
}
tmk nc1_private "s/NBYTES 3 33/NBYTES 3 34/" 87
tmk nc2_version "s/if ne mapget h off 8 v\$/if false/" 33
tmk nc3_topic "s/if ne and mapget h add off 16 8 topics 0\$/if true/" 21
tmk nc4_stop "s/^\\(\\s*\\)ret 2\$/\\1ret 1/" 55
tmk nc5_owner "s/if ne mapget h 32 8 ulong getpid\$/if false/" 87
# pool/supervisor mutants: file sed-expr expected
pmk() { # name file sed-expr expected-regex [arg]
local f=$2
sed "$3" $N/$f > build/node/$1.src
if cmp -s build/node/$1.src $N/$f; then echo "FAIL $1 mutation did not apply" | tee -a $E/results.txt; return; fi
local tr=$N/transport.om po=$N/pool.om su=$N/super.om
case $f in transport.om) tr=build/node/$1.src;; pool.om) po=build/node/$1.src;; super.om) su=build/node/$1.src;; esac
cat $tr $po $su $N/pool-test.om > build/node/$1.om
run $1 build/node/$1.om "$4" "${5:-}" | tee -a $E/results.txt
}
pmk pm1_hold_ignored pool.om "s/^ret true\$/ret false/" 28
pmk pm2_reset_keeps_count transport.om "/^r = mapset h 16 8 0\$/d" 34
pmk pm3_death_keeps_hold super.om "/^r = pool_clear c w\$/d" 74
pmk pm4_no_kill super.om "/^r = killpid int /d" 84
pmk pm5_child_keeps_creator_end super.om "/^r = fclose get swpar 1\$/d" 99
pmk pm6_orphan_ignored super.om "s/^if ne get p 22 0\$/if false/" 99
pmk pm7_no_hold_announce pool.om "/^r = mapset c hw 8 e\$/d" 24
pmk pm8_creator_keeps_life_end super.om "/^r = fclose wr\$/d" 72
pmk pm9_no_recheck pool.om "s/^if ne mapget c 16 8 e\$/if false/" 144
pmk pm10_stop_polls_acks super.om "s/^r = sup_pollx c sub dl now false\$/r = sup_pollx c sub dl now true/" 90
run pool-stress $N/pool-gate.om 0 stress | tee -a $E/results.txt
pmk ps1_hold_ignored pool.om "s/^ret true\$/ret false/" "129|130|133" stress
pmk ps7_no_hold_announce pool.om "/^r = mapset c hw 8 e\$/d" "129|130|133" stress
# Repeat the unmodified gate: a timing-dependent failure would show here.
R=${R:-50}; ok=0; seed/out/omc < $N/pool-gate.om > build/node/pool-rep && chmod +x build/node/pool-rep
for i in $(seq $R); do timeout 120 build/node/pool-rep > $E/rep.out 2>&1 && ok=$((ok+1)); grep stress $E/rep.out >> $E/repeat-stress.txt; done
v=FAIL; [ $ok = $R ] && v=PASS; echo "$v pool-gate-repeat $ok/$R" | tee -a $E/results.txt
# The sources must not change during the run.
v=FAIL; sha256sum seed/out/omc seed/node/*.om | cmp -s - <(grep -E '^[0-9a-f]{64} ' $E/hashes.txt) && [ "$(git status --porcelain | wc -l)" = 0 ] && v=PASS
echo "$v tree-unchanged-during-run" | tee -a $E/results.txt
grep -c ^PASS $E/results.txt | sed 's/^/PASS count /' | tee -a $E/results.txt
grep -c ^FAIL $E/results.txt | sed 's/^/FAIL count /' | tee -a $E/results.txt
echo "evidence $E"
</details>
aien-spark reviewed (COMMENTED) on 2026-11-07 03:55 UTC
COMMENT, not an approval. Head 9dfc35b608cb. Reviewer hardware execution NOT_RUN; author native host-CPU evidence is not independent qualification.
Verdict
MERGE_AFTER_FIX: pool shutdown does not stop publication into a non-full current arena. One blocking finding. This remains a draft; no GitHub state change or merge authorization is implied.
What I read at this head
First Hermes review: live issue comments, review records and inline comments were empty. No unchanged reviewed head to skip.
Exact stacked comparison: a2fd14f7ba75fdfbc3ef8e42f5469f3f045b294e...9dfc35b608cb947b58e20a4b2b274f85899ecd5d (#1055 to #1056), all 11 changed paths, with the compare inventory checked against the PR file inventory.
seed/node/pool.om:1-278, super.om:1-392, pool-test.om:1-527, transport.om:1-251 (new reset/epoch implementation at 131-155), README.md:1-271.
pool-gate.om:1-1448 and transport-gate.om:1-535 reviewed through their component sources and independently checked byte-for-byte composition. Unchanged transport-test.om:1-284 was read at the base head.
evidence/node-pool/receipt.8bd61eb98b0290106fd4ff3858008d5c423db94391ce5379c248e7a67bd5e18d.json:1-282; changed root .crumb:108-122, seed/node/.crumb:1-30, and contributor addition at CONTRIBUTORS.md:11.
Relied-on narrative: this PR's body and committed receipt. The #1055 native-run comment, issuecomment-6699611230, belongs to the base transport, not this pool's independent qualification. Linked planning tickets were not treated as implementation evidence.
Blocking finding
P1: reject publication after the pool's sticky stop.seed/node/pool.om:217-234, especially 218-224, with pool.om:237-245 and seed/node/transport.om:32-63.
[INFERENCE from the exact source, not an executed reproduction] Start a fresh pool, call pool_stop c, then call pool_publish c 1 src 1 as the creator. pool_stop sets offset 24 in the control mapping only. pool_publish gets the current arena and immediately calls node_publish; that function checks offset 24 in the arena mapping, which is still zero. The call therefore appends a record and returns a positive version while stopped. It only consults the pool stop indirectly when an already-full arena needs pool_roll. This contradicts sup_stop's stop-admission contract at super.om:353-357 and makes shutdown behavior depend on remaining arena capacity.
Smallest fix: after validating the pool (and preserving the intended creator/refusal ordering), check the pool stop word in pool_publish before any arena mutation and return the stopped refusal. Add a deterministic regression using a non-full arena: stop, attempt publication, require -1 and unchanged epoch, count and previously published bytes. Repeat with a full arena to cover both branches. Recompose the committed gate and refresh evidence/crumbs after the author runs the checks.
Other reviewed concerns
Reclamation: the intended hold/recheck sequence is present, not formally proved.pool.om:103-123,156-212 publishes a worker hold before re-reading the current epoch and only chooses a non-current unheld arena. pool-test.om:139-155 supplies a deterministic losing-order control. The compiler source actually brackets the mapping access with its documented fences; this review does not promote that inspection into a weak-memory proof.
Death cleanup: holds are cleared after the exact-PID reap.super.om:270-305. sup_stop's grace-period poll excludes acknowledgements at 376, matching the regression at pool-test.om:313-323. Failure injection, descendant-tool lifetime and teardown error recovery were not executed by the reviewer.
Evidence and limits
IMPLEMENTED: source-level pool and supervisor component, with the stop-admission defect above. Not connected to the live hive.
Author EXERCISED: receipt records native Linux AArch64 gate, controls, stress and 50 repeated passes at source commit 0d0eadfc9c0990b532122d9587162833abc91090. I independently matched the current component/gate bytes to every listed source hash, and matched the receipt filename to its SHA-256. This ties the recorded source to this head; it does not replay the execution.
Live exact-head CI: AIEN Checks, sbom, evidence-immutable and om-units report SUCCESS; AIEN Alpha is SKIPPED. These statuses do not establish that the new node gate is independently qualified.
Reviewer checks: read-only inventory, SHA-256 and composition checks passed; head re-read unchanged. No PR code, build, suite, GPU, server or hardware test executed. Reviewer runtime and hardware NOT_RUN. QUALIFIED: not established; deployment NOT_RUN.
diff --git a/.crumb b/.crumb
index 11c93e5fe..8683776a6 100644
--- a/.crumb
+++ b/.crumb
@@ -108,14 +108,14 @@
}
],
"children_root": "sha256:966bedb54caa4209f9ab84526da66f6b13ce72e8831470170364eb5881355748",
- "compiled_at": "2026-11-07T00:26:53Z",
+ "compiled_at": "2026-11-07T01:09:36Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:31ec1e1de3c1207374722f27c73f8b9f96c26203f71e0f11bfb6f8175b702c76",
- "evidence_files": 15690,
- "evidence_root": "sha256:60f0de6749e3c0e4fe16b543fc8937fc2771c8681029fdf5a11eaa34015baa78",
- "files": 24228,
- "generated_at_commit": "c16a2a46ad188fe6d3a361c928c91cca4709e593",
- "source_tree": "sha256:0b1acc8ae544c2770c48cb3614db6ad778ded73acc88ba2bdd7b44dd2d0dad45"
+ "digest": "sha256:df39a9a1aa6434153c7b9e8159128cb01d911cd82fc5031d27b4a7ac8d1c2440",
+ "evidence_files": 15691,
+ "evidence_root": "sha256:cfc94942b3e7fdfaa212979b0e1d3b2f774ea88a29b3bff73e40b5211e1d0c6e",
+ "files": 24233,
+ "generated_at_commit": "a7208595bfcf05d69d2df42bbd722ddfcef8f5ac",
+ "source_tree": "sha256:9ee6c15b48b781e67f5c9aa7057cf0a629ce88c3d9fa378f190e7db4e9fa3149"
},
"owner_lane": "",
"provenance": {
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 56f7d7bfd..21aef58c0 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -8,6 +8,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE
| Model | What it did |
|---|---|
| Codex (OpenAI, ChatGPT Work Mode) | Implemented `seed/node` bounded shared-memory artifact transport in seeded Omega: immutable publication, topic cursors, per-worker eventfd hints, stop priority, and forked-process acceptance with negative controls. Native AArch64 qualification remains pending. |
+| Claude Opus 5.5 (via omp) | DRA-286 for `seed/node`: `pool.om`, epoch-based reuse of K pre-forked shared arenas. Reader holds are checked again after they are stored, and rollover fails closed when every other arena is held. `super.om`: forked-worker supervision with close-on-exec life pipes for worker death and creator loss, exact-PID reaping, and a bounded stop with SIGKILL escalation. `node_reset`/`node_epoch` added to `transport.om`. `pool-gate.om` runs a real-process acceptance test and a 2000-epoch concurrent stress test. It has ten deterministic negative controls plus two stress controls. Native AArch64 host evidence only; not QUALIFIED on the Spark gate. |
| Grok 4.7 (via Cursor Agent) | Merged main `fd3751b31` (#1020, carrying #1045 and #1050) into #1052. The only conflict was the generated root `.crumb` (child `last_commit` stamps, the `tests` digest, and the root digest). Recompiled with the crumb.lock tool (`d0f0b95d`); `crumb verify .` current. The #525/#962 pins were left as committed: `src/checker2/c2_check.c`, `src/compiler/osc_ir.c` and `src/compiler/osc_ir.h` still hash to the SHA-256s in `ACCEPTED`. |
| Claude Opus 5.5 (via omp) | #1020 (actions/cache-4.3.0 ->6.1.0): merged main `d3d1b1bc` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d`). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). |
| Claude Opus 5.5 (via omp) | #1018 (actions/upload-artifact-4 ->7): merged main `d3d1b1bc` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d`). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). |
diff --git a/evidence/node-pool/receipt.8bd61eb98b0290106fd4ff3858008d5c423db94391ce5379c248e7a67bd5e18d.json b/evidence/node-pool/receipt.8bd61eb98b0290106fd4ff3858008d5c423db94391ce5379c248e7a67bd5e18d.json
new file mode 100644
index 000000000..042f79e46
--- /dev/null
+++ b/evidence/node-pool/receipt.8bd61eb98b0290106fd4ff3858008d5c423db94391ce5379c248e7a67bd5e18d.json
@@ -0,0 +1,282 @@
+{
+ "issue": "DRA-286",
+ "source_commit": "0d0eadfc9c0990b532122d9587162833abc91090",
+ "source_tree": "ad5697e1e22856fc1ecd6b4fbd03d116229c7b79",
+ "platform": "Linux 7.0.0-1019-nvidia aarch64 spark-b87b",
+ "cpu_affinity_mask_hex": "300",
+ "execution": "NATIVE Linux AArch64 host CPU (DGX Spark host, no GPU opened)",
+ "timestamp_utc": "2026-11-07T01:04:28.308128+00:00",
+ "independent_review": false,
+ "native_aarch64": "PASS",
+ "spark_gate_judge": "NOT_RUN",
+ "live_hive": "NOT_DEPLOYED",
+ "script": "omega-node-286.sh (compile with seed/out/omc, run under timeout; mutants are one-line sed edits of a disposable copy)",
+ "hashes": {
+ "seed/out/omc": "5f90edea61bac241398df5036990d899361a5acd9decb37954ce088ec0f6f6df",
+ "seed/node/pool-gate.om": "ff59643757a7d4a6e936cedf53633857ef2a8387f1bacfa77671f26ef208b2dd",
+ "seed/node/pool.om": "e7fba928bdc5c4194e7aee42109265de4f172d2b197946133d788b2dbcb30ccc",
+ "seed/node/pool-test.om": "7e18abdc5d0b377995e210aa336ba03a35d88af193d5387d5da3e8b0b6c01042",
+ "seed/node/super.om": "d104ac8116c6df57fdc93f03791d7315e5b60875d8d6177480ef9967b6f53d5a",
+ "seed/node/transport-gate.om": "176a5053a2d42df4fa97ad86c9bdfc41f4c615b7832223baf674624a7801e55c",
+ "seed/node/transport.om": "321b8d848b7fcc589d0195a268f5735716514cf35b52a8e1b2236b08774c1022",
+ "seed/node/transport-test.om": "d00b22082c781c5300065faf321f9126a7801fc5b639dbfc47bd75798e5dbae9"
+ },
+ "checks": [
+ {
+ "case": "transport-gate",
+ "compile_exit": 0,
+ "expected_exit": "0",
+ "run_exit": 0,
+ "wall_ms": 13,
+ "stdout": "PASS node transport\n",
+ "binary_sha256": "9a124f5b26495e3151d0af053914f64e5d565302b24db802a18c024a875d8e8b",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pool-gate",
+ "compile_exit": 0,
+ "expected_exit": "0",
+ "run_exit": 0,
+ "wall_ms": 4948,
+ "stdout": "stress rolls=2000 busy=6646030 reads=227780 114301\nPASS node pool\n",
+ "binary_sha256": "cd9b9906eeb80b33302b32fdcd9808aa42af4d1927572132c28e65a198cb57af",
+ "verdict": "PASS"
+ },
+ {
+ "case": "nc1_private",
+ "compile_exit": 0,
+ "expected_exit": "87",
+ "run_exit": 87,
+ "wall_ms": 10044,
+ "stdout": "",
+ "binary_sha256": "55fc511c703653464e83eb43657c51e6122784755ef1a88ff5379b8b79e02004",
+ "verdict": "PASS"
+ },
+ {
+ "case": "nc2_version",
+ "compile_exit": 0,
+ "expected_exit": "33",
+ "run_exit": 33,
+ "wall_ms": 2,
+ "stdout": "",
+ "binary_sha256": "d9d9d653cedd2f3614bc012832e5be95b837b35733678496380daa73366f0fe4",
+ "verdict": "PASS"
+ },
+ {
+ "case": "nc3_topic",
+ "compile_exit": 0,
+ "expected_exit": "21",
+ "run_exit": 21,
+ "wall_ms": 1,
+ "stdout": "",
+ "binary_sha256": "4e7edfb98db917be1b41399920d2f287c7ced1df57b8eda9cde232e41c9ebdcf",
+ "verdict": "PASS"
+ },
+ {
+ "case": "nc4_stop",
+ "compile_exit": 0,
+ "expected_exit": "55",
+ "run_exit": 55,
+ "wall_ms": 1,
+ "stdout": "",
+ "binary_sha256": "c693a170cb77c81b6da4ec33b0207d238777b93b1d2ed9754fe797821e6c1db8",
+ "verdict": "PASS"
+ },
+ {
+ "case": "nc5_owner",
+ "compile_exit": 0,
+ "expected_exit": "87",
+ "run_exit": 87,
+ "wall_ms": 13,
+ "stdout": "",
+ "binary_sha256": "9a395b0249e61e35d6dd506b9dec64a77033b5e15d76991be1ce615ccfdbc0fc",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm1_hold_ignored",
+ "compile_exit": 0,
+ "expected_exit": "28",
+ "run_exit": 28,
+ "wall_ms": 4,
+ "stdout": "",
+ "binary_sha256": "13e4601d28b4daf2e44e6318ec6f27963ba82552d44ad177b0c7ba4177cf7b95",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm2_reset_keeps_count",
+ "compile_exit": 0,
+ "expected_exit": "34",
+ "run_exit": 34,
+ "wall_ms": 3,
+ "stdout": "",
+ "binary_sha256": "b6f68525df84bcbebf6c93a4a7fc01c976566528965bca6cfe9721df38361189",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm3_death_keeps_hold",
+ "compile_exit": 0,
+ "expected_exit": "74",
+ "run_exit": 74,
+ "wall_ms": 4,
+ "stdout": "",
+ "binary_sha256": "579418fe1dbfbb19858fb84d6e04136787057ca7a9efac8a6d8614b304eb1c3d",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm4_no_kill",
+ "compile_exit": 0,
+ "expected_exit": "84",
+ "run_exit": 84,
+ "wall_ms": 30016,
+ "stdout": "",
+ "binary_sha256": "e6f6246354f4e9399eaa5282d3b4d2f1c58182e0cc8af39d8eeb42b6230a430c",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm5_child_keeps_creator_end",
+ "compile_exit": 0,
+ "expected_exit": "99",
+ "run_exit": 99,
+ "wall_ms": 5022,
+ "stdout": "",
+ "binary_sha256": "f10c2112ea51cba50a5cffa39fbad17018c7482c97afce6120dfc68a963d18a1",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm6_orphan_ignored",
+ "compile_exit": 0,
+ "expected_exit": "99",
+ "run_exit": 99,
+ "wall_ms": 3,
+ "stdout": "",
+ "binary_sha256": "72c2637ba2a4ba69bd7a8baaf519542553ae84292f8e000d95d3e321519e693d",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm7_no_hold_announce",
+ "compile_exit": 0,
+ "expected_exit": "24",
+ "run_exit": 24,
+ "wall_ms": 1,
+ "stdout": "",
+ "binary_sha256": "ad82a1a846db3d7e44895cd157b439e03feaca1f559c5ea5a9dcca4ba1965c81",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm8_creator_keeps_life_end",
+ "compile_exit": 0,
+ "expected_exit": "72",
+ "run_exit": 72,
+ "wall_ms": 5059,
+ "stdout": "",
+ "binary_sha256": "ec9f8833bae148a8eef0357e7ab1d9761567744dbcd3fd328c93edbfe46b88f4",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm9_no_recheck",
+ "compile_exit": 0,
+ "expected_exit": "144",
+ "run_exit": 144,
+ "wall_ms": 2,
+ "stdout": "",
+ "binary_sha256": "df9f70dfbd5fb3d4e12dcdef7fd1399c77c68e7c20ae5444c647157aee58e388",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pm10_stop_polls_acks",
+ "compile_exit": 0,
+ "expected_exit": "90",
+ "run_exit": 90,
+ "wall_ms": 176,
+ "stdout": "",
+ "binary_sha256": "a003669bd21f82de11395bfa75d5a481b9b47ee898b835614d5bd1efd9e6971a",
+ "verdict": "PASS"
+ },
+ {
+ "case": "pool-stress",
+ "compile_exit": 0,
+ "expected_exit": "0",
+ "run_exit": 0,
+ "wall_ms": 920,
+ "stdout": "stress rolls=2000 busy=4427608 reads=37193 37006\n",
+ "binary_sha256": "cd9b9906eeb80b33302b32fdcd9808aa42af4d1927572132c28e65a198cb57af",
+ "verdict": "PASS"
+ },
+ {
+ "case": "ps1_hold_ignored",
+ "compile_exit": 0,
+ "expected_exit": "129|130|133",
+ "run_exit": 129,
+ "wall_ms": 29,
+ "stdout": "",
+ "binary_sha256": "13e4601d28b4daf2e44e6318ec6f27963ba82552d44ad177b0c7ba4177cf7b95",
+ "verdict": "PASS"
+ },
+ {
+ "case": "ps7_no_hold_announce",
+ "compile_exit": 0,
+ "expected_exit": "129|130|133",
+ "run_exit": 129,
+ "wall_ms": 27,
+ "stdout": "",
+ "binary_sha256": "ad82a1a846db3d7e44895cd157b439e03feaca1f559c5ea5a9dcca4ba1965c81",
+ "verdict": "PASS"
+ }
+ ],
+ "repeat": {
+ "runs": 50,
+ "passed": 50,
+ "stress_lines": [
+ "stress rolls=2000 busy=5925193 reads=211740 110103",
+ "stress rolls=2000 busy=10543778 reads=362160 183078",
+ "stress rolls=2000 busy=13065713 reads=444026 222689",
+ "stress rolls=2000 busy=5280428 reads=186540 95921",
+ "stress rolls=2000 busy=7950244 reads=274170 139172",
+ "stress rolls=2000 busy=8509728 reads=160338 101340",
+ "stress rolls=2000 busy=7279675 reads=253496 129110",
+ "stress rolls=2000 busy=6265482 reads=221692 114240",
+ "stress rolls=2000 busy=7082827 reads=146144 205510",
+ "stress rolls=2000 busy=15807892 reads=269245 177902",
+ "stress rolls=2000 busy=9242912 reads=271253 202053",
+ "stress rolls=2000 busy=4791557 reads=166304 83860",
+ "stress rolls=2000 busy=12170458 reads=417760 211354",
+ "stress rolls=2000 busy=3911013 reads=138994 71324",
+ "stress rolls=2000 busy=7283991 reads=254859 130523",
+ "stress rolls=2000 busy=6823322 reads=136259 85512",
+ "stress rolls=2000 busy=13092094 reads=365958 294874",
+ "stress rolls=2000 busy=9002134 reads=311392 157804",
+ "stress rolls=2000 busy=5265639 reads=187531 97016",
+ "stress rolls=2000 busy=8952746 reads=214438 123903",
+ "stress rolls=2000 busy=5005657 reads=179225 93074",
+ "stress rolls=2000 busy=6870766 reads=86533 67354",
+ "stress rolls=2000 busy=6472677 reads=222152 111441",
+ "stress rolls=2000 busy=4846963 reads=168056 84535",
+ "stress rolls=2000 busy=9963844 reads=340309 170833",
+ "stress rolls=2000 busy=8001493 reads=218114 189291",
+ "stress rolls=2000 busy=7794830 reads=269909 136510",
+ "stress rolls=2000 busy=9453676 reads=326059 165227",
+ "stress rolls=2000 busy=7393734 reads=196498 178245",
+ "stress rolls=2000 busy=6365279 reads=188765 142962",
+ "stress rolls=2000 busy=11913651 reads=378922 233079",
+ "stress rolls=2000 busy=6490064 reads=229301 118188",
+ "stress rolls=2000 busy=7014411 reads=246797 126945",
+ "stress rolls=2000 busy=10696080 reads=173437 345767",
+ "stress rolls=2000 busy=7462495 reads=260833 133849",
+ "stress rolls=2000 busy=11098083 reads=226981 166983",
+ "stress rolls=2000 busy=8821987 reads=118678 117646",
+ "stress rolls=2000 busy=10349014 reads=124886 200977",
+ "stress rolls=2000 busy=6952595 reads=241149 122132",
+ "stress rolls=2000 busy=9652655 reads=222942 190580",
+ "stress rolls=2000 busy=6628206 reads=231970 118490",
+ "stress rolls=2000 busy=7247328 reads=251128 126892",
+ "stress rolls=2000 busy=6670476 reads=235213 120968",
+ "stress rolls=2000 busy=8864133 reads=303502 152415",
+ "stress rolls=2000 busy=12693581 reads=431775 216073",
+ "stress rolls=2000 busy=7464565 reads=259467 132093",
+ "stress rolls=2000 busy=7898249 reads=67581 67596",
+ "stress rolls=2000 busy=8466543 reads=224501 206669",
+ "stress rolls=2000 busy=9922386 reads=312826 193173",
+ "stress rolls=2000 busy=9502592 reads=330688 167739"
+ ]
+ }
+}
diff --git a/seed/node/.crumb b/seed/node/.crumb
index 59a45dfc7..b7ecffe8c 100644
--- a/seed/node/.crumb
+++ b/seed/node/.crumb
@@ -3,14 +3,14 @@
"generated": {
"children": [],
"children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "compiled_at": "2026-11-07T00:26:14Z",
+ "compiled_at": "2026-11-07T00:56:36Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:61e5171c98e0586ad53b86c252d060a1c8d5f4a3cf6cfccd342643e0be620c79",
+ "digest": "sha256:4ee3438febfd9afe2bfd389ea04db2cb8d0d8357059a0f61ecfa6824f427a9be",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "files": 4,
- "generated_at_commit": "4ae618ff343da29dd68b0d17712e1133adaf15c1",
- "source_tree": "sha256:76ff8fc8a4aad581b9f5b12b053f4c85f2c25ea275a42055cbeea1d4c364347a"
+ "files": 8,
+ "generated_at_commit": "25c8aa17ab9115172656d789f9d759d86aab1c10",
+ "source_tree": "sha256:e073bf5b1a013488d0f2be01bd615eeb258e9617f2e47086a6eceeef9e5ed093"
},
"owner_lane": "",
"seed": {
diff --git a/seed/node/README.md b/seed/node/README.md
index 0bac2b18a..8b1a79286 100644
--- a/seed/node/README.md
+++ b/seed/node/README.md
@@ -1,4 +1,4 @@
-# Omega Node shared-memory transport
+# Omega Node shared-memory transport, epoch pool and worker supervision
This is the first implementation component of [Omega Node](https://github.com/aien-dev/omega-harness/issues/205).
It provides a bounded, single-publisher artifact log for trusted forked Omega
@@ -6,9 +6,17 @@ processes. Runtime consumers can share artifact storage and wake only interested
workers. The existing `seed/agent/agent.om` is the coding-agent consumer to evaluate
for integration; this change does not replace its model or tool dispatcher.
+Three source fragments, concatenated in this order before one program with `fn main`:
+
+| Fragment | Adds |
+| --- | --- |
+| `transport.om` | one arena: 64 immutable records, topic scan, eventfd hints, stop flag (#1055) |
+| `pool.om` | K arenas reused by epoch, reader holds, fail-closed rollover (DRA-286) |
+| `super.om` | forked workers, death detection, reaping, creator-loss detection, bounded stop (DRA-286) |
+
The component is not yet connected to the live hive. Persistent recovery,
-authority integration, worker supervision, epoch rollover, a dashboard and a real
-model-backed coding workflow remain implementation work. The
+authority integration, a dashboard and a real model-backed coding workflow remain
+implementation work (DRA-287 to DRA-292). The
[Linear project](https://linear.app/drake-stapleton/project/omega-node-shared-memory-hive-runtime-37058a1eac4b)
tracks that integration. This is a component contract, not a whole-system master plan.
@@ -66,6 +74,8 @@ timeout 30 qemu-aarch64-static build/node/transport-gate
| `node_notify fd` | Adds a wake hint to one nonblocking eventfd; zero on success or saturation, negative error otherwise. |
| `node_drain fd` | Consumes a coalesced hint; an already empty descriptor is harmless. |
| `node_wait h wake stop interval` | Waits on distinct nonnegative descriptors. Returns 2 for stop, 1 for work hint, 0 for timeout, negative error otherwise. Interval is nanoseconds; negative means infinite. |
+| `node_reset h epoch` | Creator only. Drops the published count to zero, clears every record version, clears stop and records `epoch` (nonzero) at header offset 40. Only `pool.om` calls it, after proving no reader holds the arena. |
+| `node_epoch h` | The epoch recorded by the last `node_reset`; zero for a fresh arena. |
All handles must be live handles from `node_new`, and descriptors must remain
owned and open throughout the call. Invalid mapping handles trap in the compiler
@@ -113,19 +123,18 @@ scheduled within a deadline. Cancellation of running model/tool work is separate
## Capacity and lifetime
The arena holds 64 immutable records. Full publication returns -2 without
-overwriting old data. No reference counter or slot recycling exists in this
-component. Drop mappings only after all readers finish; unmap each process's
-handle or terminate that process. Fork inherits the arena; exec does not.
+overwriting old data. Inside one epoch nothing is recycled. Drop mappings only
+after all readers finish; unmap each process's handle or terminate that process.
+Fork inherits the arena; exec does not.
-A long-running supervisor must explicitly close an epoch, stop admission, finish
-or cancel readers, reap workers, and create the next arena. That lifecycle is an
-integration prerequisite, not an automatic behavior of these functions. This
-bounded design keeps the first version free of ABA and unsafe reclamation paths.
+Reuse across epochs is `pool.om`'s job (next section): it resets an arena only
+after the current epoch has moved past it and no worker holds it.
MODELED layout, checked with Wolfram Language:
`{4096+64*(64+4096), Mod[64+4096,64]}` returned `{270336, 0}`.
The first value is arena bytes; the second checks slot-stride alignment. Header
-words at offsets 0, 8, 16, 24 and 32 hold magic, ABI, count, stop and creator PID.
+words at offsets 0, 8, 16, 24, 32 and 40 hold magic, ABI, count, stop, creator PID
+and epoch.
Record slots start at 4096 with stride 4160; version, length and topic mask are
at slot offsets 0, 8 and 16, followed by payload at offset 64. These are ordinary
CPU mappings, with no GPU-coherence or cross-machine shared-memory claim.
@@ -152,3 +161,111 @@ test, compile successfully, and run with the same timeout:
These controls check observable protocol behavior. Emulation does not establish
weak-memory correctness on physical ARM hardware. The abstract Lean model in
omega-harness PR 206 does not prove this implementation or its memory ordering.
+
+## Epoch pool and worker supervision (DRA-286)
+
+Status: IMPLEMENTED in `pool.om` and `super.om`. Exercised by `pool-gate.om` and
+the negative controls below on native Linux AArch64. Evidence and pins are in the
+DRA-286 pull request. Not connected to the live hive.
+
+### Build and check
+
+`pool-gate.om` is the exact byte concatenation of `transport.om`, `pool.om`,
+`super.om` and `pool-test.om`:
+
+```sh
+cat seed/node/transport.om seed/node/pool.om seed/node/super.om seed/node/pool-test.om > build/node/pool-composed.om
+cmp build/node/pool-composed.om seed/node/pool-gate.om
+seed/out/omc < seed/node/pool-gate.om > build/node/pool-gate
+chmod +x build/node/pool-gate
+timeout 120 build/node/pool-gate # all phases, ends "PASS node pool"
+timeout 90 build/node/pool-gate stress # concurrent stress phase only
+```
+
+The gate forks real processes, uses anonymous shared mappings, pipes and
+eventfds, sends SIGKILL only to the exact PIDs it created, and opens no GPU,
+model endpoint or socket. It needs about 3 s, most of it the stalled worker's
+2 s stop deadline.
+
+### Pool contract
+
+`pool_new K W` maps K arenas (1..8) and one 4096-byte control page before any
+fork, so every worker inherits the same shared memory. Arena 0 opens epoch 1.
+Epoch numbers only grow; an arena is reused for a later epoch, never an epoch
+number.
+
+| Function | Contract |
+| --- | --- |
+| `pool_new k w` | Control handle, -7 for K outside 1..8 or W outside 1..64, or a mapping errno (all mappings made so far are dropped). |
+| `pool_acquire c w` | Worker w holds the current epoch: returns that arena, -1 stopped, -5 invalid, -7 bad worker, -8 the epoch moved 16 times running. |
+| `pool_hold c w e` | The step `pool_acquire` repeats: store hold e, read the epoch again, refuse -8 if it moved. Every refusal clears the hold. |
+| `pool_release c w` | Clears hold w. The old arena must not be read afterwards. |
+| `pool_roll c` | Creator only. Opens epoch E+1 in a free arena or one whose older epoch no worker holds, then publishes E+1. -9 when every other arena is held: nothing changes (fail closed). -1 once stopped, -6 from a non-creator. |
+| `pool_pick c`, `pool_reuse c i n` | The two steps of `pool_roll`, separate so the gate can interleave them with a worker. |
+| `pool_publish c topics src n` | Creator: publish to the current epoch; when that arena is full, roll once and publish there. |
+| `pool_current c`, `pool_epoch c` | Current arena handle and epoch. |
+| `pool_stop c`, `pool_stopped c` | Sticky stop flag on the control page; creator only. |
+| `pool_setw c w pid state`, `pool_clear c w` | Creator bookkeeping: worker PID and state (1 live, 2 reaped), and clearing a reaped worker's hold. |
+| `pool_free c` | Drop this process's mappings of the pool. |
+
+Control page u64 words: 0 magic, 8 ABI, 16 current epoch, 24 stop, 32 creator
+PID, 40 K, 48 W, 64+8k arena handle, 128+8k arena epoch (0 while free or being
+reset), 256+8w hold of worker w, 768+8w worker PID, 1280+8w worker state.
+
+Writers: the creator writes the epoch, the arena table and every arena record.
+Worker w writes only hold word w while it lives. The creator clears hold w only
+after it has reaped worker w, so a dead worker's hold never blocks reuse forever
+and a live worker's hold is never cleared under it.
+
+Reclamation is epoch-based. A worker stores its hold, then reads the current
+epoch again; the creator publishes the new epoch before it scans holds. `mapset`
+and `mapget` each put `DSB SY` on both sides of their access, so either the scan
+sees the hold or the worker's second read sees the move and it retries. An arena
+is reset only when its epoch is older than the current one and unheld. A held
+older epoch therefore stays complete and unchanged for as long as it is held,
+while newer epochs are published in other arenas.
+
+### Supervision contract
+
+| Function | Contract |
+| --- | --- |
+| `sup_init c` | Creator: one creator life pipe and wake, stop and ack eventfds for each of W slots. On failure everything it opened is closed. |
+| `sup_spawn c w` | Creator: fork worker w. 0 in the child, the PID in the creator, -16 if slot w is live, -7 bad slot, or an errno. |
+| `sup_wwait c w interval` | Worker: 3 creator gone, 2 stop, 1 wake hint (drained; rescan state), 0 timeout, or an errno. Creator loss outranks stop, stop outranks work. |
+| `sup_ack w`, `sup_wake w`, `sup_take fd` | Post an ack, post a wake hint, read and reset an eventfd counter. |
+| `sup_poll c interval`, `sup_pollx c interval acks` | Creator: wait for deaths and, unless `acks` is false, acks (left pending for `sup_take`). Reap every worker whose life pipe hung up. Returns the number reaped, or the first reap or poll error. |
+| `sup_reap c w` | Creator: reap the exact PID (SIGKILL after about 1 s if it has not exited), then close its life pipe, clear its hold and mark it reaped. A `waitpid` error releases nothing. |
+| `sup_stop c interval` | Creator: set stop, post every live worker's stop eventfd, and reap until all exit or the interval ends. That wait ignores acks, so a pending ack cannot turn it into a spin that kills before the deadline. Then SIGKILL and reap the rest. Returns how many were killed. |
+| `sup_live c`, `sup_closeall` | Live worker count; close every descriptor this module opened. |
+
+Death is detected without scanning PIDs. Each worker alone holds the write end
+of its close-on-exec life pipe: the creator closes its copy right after the
+fork, so later workers never inherit it. The worker's exit hangs up the
+creator's read end. In the other direction, each child closes the creator's
+life-pipe write end at once, so creator death hangs up every worker's read end
+and `sup_wwait` returns 3. Workers must not `exec` themselves: exec closes the
+life pipe and is treated as death. Tools started by a worker should fork first.
+
+### Negative controls
+
+Each control is a one-line change to a disposable copy, composed with the
+unchanged other fragments and test, compiled and run with the same timeout:
+
+| Change | Expected exit |
+| --- | --- |
+| `pool.om`: `pool_held`'s `ret true` to `ret false` (holds ignored) | 28; with `stress`, 129, 130 or 133 |
+| `transport.om`: delete `r = mapset h 16 8 0` in `node_reset` (count kept) | 34 |
+| `super.om`: delete `r = pool_clear c w` (dead worker keeps its hold) | 74 |
+| `super.om`: delete every `r = killpid int` line (no kill escalation) | 84 |
+| `super.om`: delete `r = fclose get swpar 1` (child keeps creator end) | 99 |
+| `super.om`: `if ne get p 22 0` to `if false` (creator loss ignored) | 99 |
+| `pool.om`: delete `r = mapset c hw 8 e` (hold never stored) | 24; with `stress`, 129, 130 or 133 |
+| `super.om`: delete `r = fclose wr` (creator keeps a worker's life end) | 72 |
+| `pool.om`: `if ne mapget c 16 8 e` to `if false` (no epoch recheck) | 144 |
+| `super.om`: `sup_stop` waits with `acks` true (pending ack spins the wait) | 90 |
+
+The recheck control is deterministic because the gate runs the protocol steps
+in the losing order (`pool_hold` after `pool_roll` and `pool_pick`). The same
+mutant under the timing-dependent `stress` phase exited 0 in 5 of 5 probes:
+the window needs two rolls inside one announce, so stress alone does not prove
+the recheck.
diff --git a/seed/node/pool-gate.om b/seed/node/pool-gate.om
new file mode 100644
index 000000000..9d5e54cc3
--- /dev/null
+++ b/seed/node/pool-gate.om
@@ -0,0 +1,1448 @@
+note Omega Node transport, concatenate with a program-mode consumer.
+note Trusted forked processes only. This is transport, not write authority.
+note One publisher PID, 64 immutable records per epoch; reuse only via node_reset.
+note Layout: 4096 byte header then 64 slots of 4160 bytes.
+note Header u64: magic, ABI, published count, stop, publisher PID, epoch.
+note Slot u64: version, length, topic mask; payload begins at offset 64.
+const NCAP ulong 64
+const NBYTES ulong 270336
+const NMAGIC ulong 1313817669
+
+fn node_new to long
+h = mapnew neg int 1 0 NBYTES 3 33
+if le h 0
+ret h
+end
+r = mapset h 8 8 1
+r = mapset h 32 8 ulong getpid
+r = mapset h 0 8 NMAGIC
+ret h
+end
+
+fn node_valid h long to bool
+ret and eq mapget h 0 8 NMAGIC eq mapget h 8 8 1
+end
+
+fn node_offset v ulong to ulong
+ret add 4096 mul sub v 1 4160
+end
+
+note Return version, or -1 stopped, -2 full, -3 length, -4 topic,
+note -5 invalid header, -6 wrong publisher. Refusals do not publish.
+fn node_publish h long topics ulong src view uchar 4096 n ulong to long
+if not node_valid h
+ret neg long 5
+end
+if ne mapget h 32 8 ulong getpid
+ret neg long 6
+end
+if ne mapget h 24 8 0
+ret neg long 1
+end
+if gt n 4096
+ret neg long 3
+end
+if eq topics 0
+ret neg long 4
+end
+v = mapget h 16 8
+if gt v NCAP
+ret neg long 5
+end
+if eq v NCAP
+ret neg long 2
+end
+v = add v 1
+off = node_offset v
+r = mapwrite h add off 64 src 0 n
+r = mapset h add off 8 8 n
+r = mapset h add off 16 8 topics
+note mapset has barriers before and after its aligned store.
+r = mapset h off 8 v
+r = mapset h 16 8 v
+ret long v
+end
+
+note Header and record checks precede copying. No partial publication is read.
+note Returns payload length, -5 invalid header/record, -7 unavailable version.
+fn node_read h long v ulong dst edit uchar 4096 to long
+if not node_valid h
+ret neg long 5
+end
+if or eq v 0 gt v NCAP
+ret neg long 7
+end
+latest = mapget h 16 8
+if gt latest NCAP
+ret neg long 5
+end
+if gt v latest
+ret neg long 7
+end
+off = node_offset v
+if ne mapget h off 8 v
+ret neg long 5
+end
+n = mapget h add off 8 8
+if gt n 4096
+ret neg long 5
+end
+ret mapread h add off 64 dst 0 n
+end
+
+note Return the next matching version after cursor, zero if caught up,
+note or negative refusal. Caller advances its cursor through returned versions.
+fn node_next h long cursor ulong topics ulong to long
+if not node_valid h
+ret neg long 5
+end
+if or gt cursor NCAP eq topics 0
+ret neg long 7
+end
+latest = mapget h 16 8
+if or gt latest NCAP gt cursor latest
+ret neg long 5
+end
+v = cursor
+note At most NCAP published slots can be examined.
+while lt v latest bound 64
+v = add v 1
+off = node_offset v
+if ne mapget h off 8 v
+ret neg long 5
+end
+if ne and mapget h add off 16 8 topics 0
+ret long v
+end
+end
+ret 0
+end
+
+fn node_stop h long to long
+if not node_valid h
+ret neg long 5
+end
+if ne mapget h 32 8 ulong getpid
+ret neg long 6
+end
+ret mapset h 24 8 1
+end
+
+note Creator only. Retire every record so a pool can reuse the arena for a new
+note epoch. The caller must first prove no reader holds the old epoch (pool.om).
+note The count drops to zero before any record version is cleared.
+fn node_reset h long epoch ulong to long
+if not node_valid h
+ret neg long 5
+end
+if ne mapget h 32 8 ulong getpid
+ret neg long 6
+end
+if eq epoch 0
+ret neg long 7
+end
+r = mapset h 16 8 0
+for i ulong NCAP
+r = mapset h node_offset add i 1 8 0
+end
+r = mapset h 24 8 0
+r = mapset h 40 8 epoch
+ret 0
+end
+
+fn node_epoch h long to ulong
+ret mapget h 40 8
+end
+
+note One nonblocking eventfd per consumer. Saturation means already readable.
+note Interrupted operations retry at most 64 times, then return EINTR.
+fn node_notify fd int to long
+buf = new uchar 8 0
+put buf 0 1
+for i ulong 64
+r = write fd buf 0 8
+if eq r 8
+ret 0
+end
+if eq r neg long 11
+ret 0
+end
+if ne r neg long 4
+if lt r 0
+ret r
+end
+ret neg long 5
+end
+end
+ret neg long 4
+end
+
+fn node_drain fd int to long
+buf = new uchar 8 0
+for i ulong 64
+r = read fd buf 0 8
+if or eq r 8 eq r neg long 11
+ret 0
+end
+if ne r neg long 4
+if lt r 0
+ret r
+end
+ret neg long 5
+end
+end
+ret neg long 4
+end
+
+fn node_pollfd p edit uchar 16 off ulong fd int to void
+for i ulong 4
+put p add off i uchar and shr uint fd uint mul i 8 255
+end
+put p add off 4 1
+end
+
+note Returns 2 stop, 1 wake, 0 timeout or negative errno.
+note Control takes priority when both descriptors are ready.
+note EINTR returns to caller so it can recompute its monotonic deadline.
+fn node_wait h long wake int stop int interval long to long
+p = new uchar 16 0
+if not node_valid h
+ret neg long 5
+end
+if or lt wake 0 lt stop 0
+ret neg long 9
+end
+if eq wake stop
+ret neg long 22
+end
+if ne mapget h 24 8 0
+ret 2
+end
+node_pollfd p 0 wake
+node_pollfd p 8 stop
+r = pollfds p 0 16 interval
+if lt r 0
+ret r
+end
+if ne mapget h 24 8 0
+ret 2
+end
+if ne and get p 14 56 0
+ret neg long 5
+end
+if ne and get p 14 1 0
+r = node_drain stop
+if lt r 0
+ret r
+end
+ret 2
+end
+if ne and get p 6 56 0
+ret neg long 5
+end
+if ne and get p 6 1 0
+r = node_drain wake
+if lt r 0
+ret r
+end
+ret 1
+end
+ret 0
+end
+note Omega Node epoch pool. Concatenate after transport.om, before super.om.
+note K arenas (1..8) and one control page are mapped before any worker fork,
+note so every forked worker inherits the same shared mappings.
+note Single writer: the creator writes the current epoch, the arena table and
+note every arena record. Worker w alone writes hold word w while it lives;
+note the creator clears hold w only after it has reaped worker w.
+note Control u64: 0 magic, 8 ABI, 16 current epoch, 24 stop, 32 creator PID,
+note 40 arena count K, 48 worker slots W, 64+8k arena handle k,
+note 128+8k epoch of arena k (0 free), 256+8w hold of worker w (0 none),
+note 768+8w worker PID, 1280+8w worker state (0 empty, 1 live, 2 reaped).
+const PMAGIC ulong 1347374924
+const PCAP ulong 8
+const PWCAP ulong 64
+const PBYTES ulong 4096
+
+fn pool_valid c long to bool
+ret and eq mapget c 0 8 PMAGIC eq mapget c 8 8 1
+end
+
+fn pool_mine c long to bool
+ret eq mapget c 32 8 ulong getpid
+end
+
+fn pool_arena c long k ulong to long
+ret long mapget c add 64 mul k 8 8
+end
+
+note Drop the first n arenas and the control page of a pool being refused.
+fn pool_unwind c long n ulong to long
+for i ulong n bound 8
+r = mapdrop pool_arena c i
+end
+ret mapdrop c
+end
+
+note Return the control handle, or -7 bad size, or a negative mapping errno.
+note Arena 0 starts as epoch 1. Call before forking any worker.
+fn pool_new k ulong w ulong to long
+if or eq k 0 gt k PCAP
+ret neg long 7
+end
+if or eq w 0 gt w PWCAP
+ret neg long 7
+end
+c = mapnew neg int 1 0 PBYTES 3 33
+if le c 0
+ret c
+end
+r = mapset c 32 8 ulong getpid
+r = mapset c 40 8 k
+r = mapset c 48 8 w
+for i ulong k bound 8
+h = node_new
+if le h 0
+r = pool_unwind c i
+ret h
+end
+r = mapset c add 64 mul i 8 8 ulong h
+end
+r = node_reset pool_arena c 0 1
+r = mapset c 128 8 1
+r = mapset c 16 8 1
+r = mapset c 8 8 1
+r = mapset c 0 8 PMAGIC
+ret c
+end
+
+note Arena index holding epoch e, or -5 when no arena holds it.
+fn pool_slot c long e ulong to long
+k = mapget c 40 8
+if gt k PCAP
+ret neg long 5
+end
+for i ulong k bound 8
+if eq mapget c add 128 mul i 8 8 e
+ret long i
+end
+end
+ret neg long 5
+end
+
+note Creator: the arena of the current epoch, or a negative refusal.
+fn pool_current c long to long
+if not pool_valid c
+ret neg long 5
+end
+k = pool_slot c mapget c 16 8
+if lt k 0
+ret k
+end
+ret pool_arena c ulong k
+end
+
+fn pool_epoch c long to ulong
+ret mapget c 16 8
+end
+
+note Worker step: store hold e for worker w, then read the epoch again. mapset
+note and mapget fence both sides, so a creator that moved the epoch before it
+note scanned holds either sees this hold or this read sees the move. Returns
+note the arena of e, -8 when the epoch moved, or -5 when no arena holds e.
+note Every refusal clears the hold.
+fn pool_hold c long w ulong e ulong to long
+if ge w mapget c 48 8
+ret neg long 7
+end
+hw = add 256 mul w 8
+r = mapset c hw 8 e
+if ne mapget c 16 8 e
+r = mapset c hw 8 0
+ret neg long 8
+end
+k = pool_slot c e
+if lt k 0
+r = mapset c hw 8 0
+ret k
+end
+h = pool_arena c ulong k
+if ne node_epoch h e
+r = mapset c hw 8 0
+ret neg long 5
+end
+ret h
+end
+
+note Worker w holds the current epoch and returns its arena. Returns -1
+note stopped, -5 invalid, -7 bad worker, -8 the epoch kept moving.
+fn pool_acquire c long w ulong to long
+if not pool_valid c
+ret neg long 5
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+for t ulong 16
+if ne mapget c 24 8 0
+r = mapset c add 256 mul w 8 8 0
+ret neg long 1
+end
+h = pool_hold c w mapget c 16 8
+if ne h neg long 8
+ret h
+end
+end
+ret neg long 8
+end
+
+note Worker w gives up its hold. Its old arena must not be read afterwards.
+fn pool_release c long w ulong to long
+if ge w mapget c 48 8
+ret neg long 7
+end
+ret mapset c add 256 mul w 8 8 0
+end
+
+fn pool_held c long e ulong to bool
+n = mapget c 48 8
+for w ulong n bound 64
+if eq mapget c add 256 mul w 8 8 e
+ret true
+end
+end
+ret false
+end
+
+note Creator step: retire arena i and open epoch n in it, then publish n.
+fn pool_reuse c long i ulong n ulong to long
+off = add 128 mul i 8
+r = mapset c off 8 0
+r = node_reset pool_arena c i n
+if lt r 0
+ret r
+end
+r = mapset c off 8 n
+r = mapset c 16 8 n
+ret long n
+end
+
+note Creator step: an arena that is free or whose older epoch no worker holds,
+note or -9. Call only after the current epoch has moved past that arena.
+fn pool_pick c long to long
+e = mapget c 16 8
+k = mapget c 40 8
+for i ulong k bound 8
+ek = mapget c add 128 mul i 8 8
+if ne ek e
+if or eq ek 0 not pool_held c ek
+ret long i
+end
+end
+end
+ret neg long 9
+end
+
+note Creator: open the next epoch in a free or unheld arena and make it current.
+note Returns the new epoch, -1 stopped, -5 invalid, -6 not creator, or -9 when
+note every other arena is still held: the pool fails closed, nothing changes.
+fn pool_roll c long to long
+if not pool_valid c
+ret neg long 5
+end
+if not pool_mine c
+ret neg long 6
+end
+if ne mapget c 24 8 0
+ret neg long 1
+end
+k = pool_pick c
+if lt k 0
+ret k
+end
+ret pool_reuse c ulong k add mapget c 16 8 1
+end
+
+note Creator: publish to the current epoch; when it is full, roll once and retry.
+note Returns the version, or the refusal of the publish or of the roll.
+fn pool_publish c long topics ulong src view uchar 4096 n ulong to long
+h = pool_current c
+if lt h 0
+ret h
+end
+v = node_publish h topics src n
+if ne v neg long 2
+ret v
+end
+r = pool_roll c
+if lt r 0
+ret r
+end
+h = pool_current c
+if lt h 0
+ret h
+end
+ret node_publish h topics src n
+end
+
+fn pool_stop c long to long
+if not pool_valid c
+ret neg long 5
+end
+if not pool_mine c
+ret neg long 6
+end
+ret mapset c 24 8 1
+end
+
+fn pool_stopped c long to bool
+ret ne mapget c 24 8 0
+end
+
+note Creator: record worker w's PID and state for observers.
+fn pool_setw c long w ulong pid ulong st ulong to long
+if not pool_mine c
+ret neg long 6
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+r = mapset c add 768 mul w 8 8 pid
+ret mapset c add 1280 mul w 8 8 st
+end
+
+note Creator: clear hold w. Only after worker w has been reaped.
+fn pool_clear c long w ulong to long
+if not pool_mine c
+ret neg long 6
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+ret mapset c add 256 mul w 8 8 0
+end
+
+note Drop every mapping of the pool in this process. Other processes keep
+note their own inherited mappings until they drop them or exit.
+fn pool_free c long to long
+ret pool_unwind c mapget c 40 8
+end
+note Omega Node worker supervision. Concatenate after transport.om and pool.om.
+note The creator forks trusted workers from its own binary: sup_spawn returns 0
+note in the child, which runs its worker function and exits with its result.
+note Death is seen without polling PIDs. Worker w alone holds the write end of
+note its close-on-exec life pipe, so its exit hangs up the creator's read end.
+note Every worker holds the read end of the creator's life pipe, whose only
+note writer is the creator, so creator death hangs up every worker.
+note Per worker: wake, stop and ack eventfds, kept across respawns.
+note Workers must not exec: exec closes the life pipe and reads as death.
+global swpid long 64
+global swwake int 64
+global swstop int 64
+global swack int 64
+global swlife int 64
+global swst ulong 64
+global swpw ulong 64
+global swpar int 2
+global swme ulong 1
+global swws uchar 4
+global swpf uchar 8
+global swpoll uchar 1024
+
+fn sup_fd off ulong to int
+v = ulong get swpf off
+v = or v shl ulong get swpf add off 1 8
+v = or v shl ulong get swpf add off 2 16
+v = or v shl ulong get swpf add off 3 24
+ret int v
+end
+
+note Poll record j at swpoll offset off; a negative fd is stored as itself
+note (bit pattern) so the kernel ignores that record.
+fn sup_gpfd off ulong fd int to void
+u = bitcast uint fd
+for i ulong 4
+put swpoll add off i uchar and shr u uint mul i 8 255
+end
+put swpoll add off 4 1
+put swpoll add off 5 0
+put swpoll add off 6 0
+put swpoll add off 7 0
+end
+
+fn sup_lpfd p edit uchar 24 off ulong fd int to void
+for i ulong 4
+put p add off i uchar and shr uint fd uint mul i 8 255
+end
+put p add off 4 1
+end
+
+note Read and reset an eventfd counter: the number of hints since the last
+note take, 0 when none is pending, or a negative errno.
+fn sup_take fd int to long
+buf = new uchar 8 0
+for i ulong 64
+r = read fd buf 0 8
+if eq r 8
+v = ulong 0
+for j ulong 8
+v = or v shl ulong get buf j mul j 8
+end
+ret long and v 9223372036854775807
+end
+if eq r neg long 11
+ret 0
+end
+if ne r neg long 4
+if lt r 0
+ret r
+end
+ret neg long 5
+end
+end
+ret neg long 4
+end
+
+fn sup_closeall to void
+for i ulong 64
+if ge get swwake i 0
+r = fclose get swwake i
+end
+if ge get swstop i 0
+r = fclose get swstop i
+end
+if ge get swack i 0
+r = fclose get swack i
+end
+if ge get swlife i 0
+r = fclose get swlife i
+end
+put swwake i neg int 1
+put swstop i neg int 1
+put swack i neg int 1
+put swlife i neg int 1
+end
+for i ulong 2
+if ge get swpar i 0
+r = fclose get swpar i
+end
+put swpar i neg int 1
+end
+end
+
+note Creator: create the creator life pipe and three eventfds per worker slot.
+note Call once after pool_new and before sup_spawn. 0 or a negative errno;
+note a failure closes everything this call opened.
+fn sup_init c long to long
+if not pool_mine c
+ret neg long 6
+end
+for i ulong 64
+put swpid i 0
+put swst i 0
+put swwake i neg int 1
+put swstop i neg int 1
+put swack i neg int 1
+put swlife i neg int 1
+end
+put swme 0 0
+put swpar 0 neg int 1
+put swpar 1 neg int 1
+r = pipefds swpf 0 8 524288
+if lt r 0
+ret r
+end
+put swpar 0 sup_fd 0
+put swpar 1 sup_fd 4
+n = mapget c 48 8
+for i ulong n bound 64
+a = eventfd uint 0
+if lt a 0
+sup_closeall
+ret a
+end
+put swwake i int a
+a = eventfd uint 0
+if lt a 0
+sup_closeall
+ret a
+end
+put swstop i int a
+a = eventfd uint 0
+if lt a 0
+sup_closeall
+ret a
+end
+put swack i int a
+end
+ret 0
+end
+
+note Creator: fork worker w. Returns 0 in the child, the child PID in the
+note creator, -7 bad slot, -16 slot still live, or a negative errno. The
+note child keeps only its own life write end; the creator keeps the read end.
+fn sup_spawn c long w ulong to long
+if not pool_mine c
+ret neg long 6
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+if ne get swpid w 0
+ret neg long 16
+end
+r = pipefds swpf 0 8 524288
+if lt r 0
+ret r
+end
+rd = sup_fd 0
+wr = sup_fd 4
+pid = fork
+if eq pid 0
+r = fclose get swpar 1
+put swpar 1 neg int 1
+r = fclose rd
+put swlife w wr
+put swme 0 add w 1
+ret 0
+end
+r = fclose wr
+if lt pid 0
+r = fclose rd
+ret pid
+end
+put swpid w pid
+put swlife w rd
+r = pool_setw c w ulong pid 1
+ret pid
+end
+
+note Worker: 3 creator gone, 2 stop, 1 wake hint, 0 timeout, negative errno.
+note Creator loss outranks stop, which outranks work. A set stop flag makes
+note the poll nonblocking. Hints are drained; rescan shared state after 1.
+fn sup_wwait c long w ulong interval long to long
+p = new uchar 24 0
+if ge w 64
+ret neg long 7
+end
+iv = interval
+if pool_stopped c
+iv = 0
+end
+sup_lpfd p 0 get swwake w
+sup_lpfd p 8 get swstop w
+sup_lpfd p 16 get swpar 0
+r = pollfds p 0 24 iv
+if lt r 0
+ret r
+end
+if ne get p 22 0
+ret 3
+end
+if pool_stopped c
+ret 2
+end
+if ne and get p 14 56 0
+ret neg long 5
+end
+if ne and get p 14 1 0
+r = node_drain get swstop w
+ret 2
+end
+if ne and get p 6 56 0
+ret neg long 5
+end
+if ne and get p 6 1 0
+r = node_drain get swwake w
+if lt r 0
+ret r
+end
+ret 1
+end
+ret 0
+end
+
+note Worker or creator: post a hint on worker w's ack eventfd.
+fn sup_ack w ulong to long
+if ge w 64
+ret neg long 7
+end
+ret node_notify get swack w
+end
+
+note Creator: wake worker w with a work hint.
+fn sup_wake w ulong to long
+if ge w 64
+ret neg long 7
+end
+if le get swpid w 0
+ret neg long 3
+end
+ret node_notify get swwake w
+end
+
+fn sup_live c long to ulong
+n = mapget c 48 8
+k = ulong 0
+for w ulong n bound 64
+if gt get swpid w 0
+k = add k 1
+end
+end
+ret k
+end
+
+note Creator: reap worker w, then release what it held. A worker that has not
+note exited within about one second gets SIGKILL first. Only after the exact
+note PID is reaped are its hold, PID and life pipe released. Returns the raw
+note wait status, -3 no live worker, or the waitpid errno (nothing released).
+fn sup_reap c long w ulong to long
+if ge w 64
+ret neg long 7
+end
+pid = get swpid w
+if le pid 0
+ret neg long 3
+end
+done = false
+for t ulong 100
+r = waitpid int pid swws 0 4 1
+if eq r pid
+done = true
+break
+end
+if ne r 0
+ret r
+end
+r = sleepns 10000000
+end
+if not done
+r = killpid int pid 9
+r = waitpid int pid swws 0 4 0
+if ne r pid
+ret r
+end
+end
+st = ulong get swws 0
+st = or st shl ulong get swws 1 8
+put swst w st
+r = fclose get swlife w
+put swlife w neg int 1
+put swpid w 0
+r = pool_clear c w
+r = pool_setw c w 0 2
+ret long st
+end
+
+note Creator: wait up to interval ns for deaths and, when acks is true, acks.
+note Ack counts are left pending for sup_take. Every worker whose life pipe
+note hung up is reaped. Returns the number reaped, or a negative errno.
+fn sup_pollx c long interval long acks bool to long
+n = mapget c 48 8
+m = ulong 0
+for w ulong n bound 64
+if gt get swpid w 0
+o = mul m 16
+if acks
+sup_gpfd o get swack w
+else
+sup_gpfd o neg int 1
+end
+sup_gpfd add o 8 get swlife w
+put swpw m w
+m = add m 1
+end
+end
+if eq m 0
+ret 0
+end
+r = pollfds swpoll 0 mul m 16 interval
+if lt r 0
+ret r
+end
+dead = long 0
+for j ulong m bound 64
+o = add mul j 16 14
+if ne get swpoll o 0
+r = sup_reap c get swpw j
+if lt r 0
+ret r
+end
+dead = add dead 1
+end
+end
+ret dead
+end
+
+note Creator: wait up to interval ns for acks and deaths (see sup_pollx).
+fn sup_poll c long interval long to long
+ret sup_pollx c interval true
+end
+
+note Creator: stop admission, post every live worker's stop eventfd, then reap
+note until all have exited or interval ns pass; survivors get SIGKILL and are
+note reaped. Returns how many had to be killed, or a refusal.
+fn sup_stop c long interval long to long
+r = pool_stop c
+if lt r 0
+ret r
+end
+n = mapget c 48 8
+for w ulong n bound 64
+if gt get swpid w 0
+r = node_notify get swstop w
+end
+end
+dl = add monons interval
+for t ulong 100000
+if eq sup_live c 0
+ret 0
+end
+now = monons
+if ge now dl
+break
+end
+r = sup_pollx c sub dl now false
+if lt r 0
+if ne r neg long 4
+break
+end
+end
+end
+killed = long 0
+for w ulong n bound 64
+if gt get swpid w 0
+r = killpid int get swpid w 9
+r = sup_reap c w
+killed = add killed 1
+end
+end
+ret killed
+end
+note Concatenate after transport.om, pool.om and super.om. CPU-only acceptance
+note of epoch turnover, held old versions, worker death, respawn, orphaning and
+note bounded teardown with real forked processes. No GPU, model or network.
+text pok "PASS node pool\n"
+global ptc long 1
+global ptm long 1
+global pth long 1
+global ptws uchar 4
+
+fn pt_ok ok bool code int to void
+if not ok
+exit code
+end
+end
+
+fn pt_fd4 p view uchar 8 off ulong to int
+v = ulong get p off
+v = or v shl ulong get p add off 1 8
+v = or v shl ulong get p add off 2 16
+v = or v shl ulong get p add off 3 24
+ret int v
+end
+
+fn pt_byte e ulong v ulong to uchar
+ret uchar and add mul e 16 v 255
+end
+
+note Creator: publish n full records into the current epoch, bytes f(epoch, v).
+fn pt_fill c long n ulong to bool
+buf = new uchar 4096 0
+e = pool_epoch c
+h = pool_current c
+if lt h 0
+ret false
+end
+for k ulong n bound 64
+v = add mapget h 16 8 1
+b = pt_byte e v
+for j ulong 4096
+put buf j b
+end
+if ne pool_publish c 1 buf 4096 long v
+ret false
+end
+end
+ret true
+end
+
+note 0 when arena h holds exactly n complete records of its own epoch, else a code.
+fn pt_verify h long n ulong to int
+buf = new uchar 4096 0
+e = node_epoch h
+cur = ulong 0
+cnt = ulong 0
+for k ulong 65
+v = node_next h cur 1
+if eq v 0
+break
+end
+if lt v 0
+ret 1
+end
+cur = ulong v
+if ne node_read h cur buf 4096
+ret 2
+end
+b = pt_byte e cur
+for j ulong 4096
+if ne get buf j b
+ret 3
+end
+end
+cnt = add cnt 1
+end
+if ne cnt n
+ret 4
+end
+ret 0
+end
+
+fn pt_refusals to void
+pt_ok eq pool_new 0 4 neg long 7 10
+pt_ok eq pool_new 9 4 neg long 7 11
+pt_ok eq pool_new 2 0 neg long 7 12
+pt_ok eq pool_new 2 65 neg long 7 13
+c = pool_new 2 4
+pt_ok gt c 0 14
+pt_ok eq pool_epoch c 1 15
+pt_ok eq pool_acquire c 4 neg long 7 16
+pt_ok eq pool_release c 4 neg long 7 17
+pt_ok eq node_epoch pool_current c 1 18
+pt_ok eq node_reset pool_current c 0 neg long 7 19
+pt_ok eq pool_free c 0 20
+end
+
+note One process: the creator also plays worker slots 0 and 1, whose holds are
+note plain words. Epoch numbers never repeat; arenas are reused only unheld.
+fn pt_epochs to void
+dst = new uchar 4096 0
+c = pool_new 2 4
+pt_ok gt c 0 21
+pt_ok pt_fill c 1 22
+h1 = pool_acquire c 0
+pt_ok eq h1 pool_current c 23
+pt_ok eq mapget c 256 8 1 24
+pt_ok eq pool_roll c 2 25
+pt_ok ne pool_current c h1 26
+pt_ok eq node_next pool_current c 0 1 0 27
+pt_ok eq pool_roll c neg long 9 28
+pt_ok eq pool_epoch c 2 29
+pt_ok eq pt_verify h1 1 0 30
+pt_ok eq pool_release c 0 0 31
+pt_ok eq pool_roll c 3 32
+pt_ok eq pool_slot c 3 0 33
+pt_ok eq node_read h1 1 dst neg long 7 34
+pt_ok eq node_epoch h1 3 35
+pt_ok pt_fill c 64 36
+for j ulong 4096
+put dst j pt_byte 4 1
+end
+pt_ok eq pool_publish c 1 dst 4096 1 37
+pt_ok eq pool_epoch c 4 38
+h4 = pool_acquire c 1
+pt_ok eq node_epoch h4 4 39
+pt_ok pt_fill c 63 40
+pt_ok eq pool_epoch c 4 41
+pt_ok eq pool_roll c 5 42
+pt_ok pt_fill c 64 43
+pt_ok eq pool_publish c 1 dst 1 neg long 9 44
+pt_ok eq pool_epoch c 5 45
+pt_ok eq pt_verify h4 64 0 46
+pt_ok eq pool_stop c 0 47
+pt_ok eq pool_roll c neg long 1 48
+pt_ok eq pool_acquire c 2 neg long 1 49
+pt_ok eq mapget c 272 8 0 50
+pt_ok eq pool_free c 0 51
+end
+
+note The announce race, made deterministic by running the protocol steps in
+note the order that breaks a hold without its recheck: worker 2 read epoch e,
+note the creator moved past e and picked e's arena, then worker 2 stores its
+note hold. The recheck must refuse; reuse of the arena must then proceed.
+fn pt_race to void
+c = pool_new 2 4
+pt_ok gt c 0 140
+pt_ok pt_fill c 1 141
+e = pool_epoch c
+pt_ok eq pool_roll c 2 142
+pt_ok eq pool_pick c 0 143
+pt_ok eq pool_hold c 2 e neg long 8 144
+pt_ok eq mapget c 272 8 0 145
+pt_ok eq pool_reuse c 0 3 3 146
+pt_ok eq pool_acquire c 2 pool_current c 147
+pt_ok eq pool_hold c 4 3 neg long 7 148
+pt_ok eq pool_free c 0 149
+end
+
+note Worker phase: 1 acquire and verify, 2 verify the held epoch again,
+note 3 release, acquire the current epoch and verify, 4 stall ignoring stop.
+fn pt_step c long w ulong ph ulong to int
+buf = new uchar 4096 0
+m = get ptm 0
+n = mapget m 8 8
+if eq ph 1
+if ne pool_roll c neg long 6
+ret 11
+end
+if ne pool_stop c neg long 6
+ret 12
+end
+if ne pool_clear c w neg long 6
+ret 13
+end
+h = pool_acquire c w
+if le h 0
+ret 14
+end
+put pth 0 h
+if ne node_publish h 1 buf 1 neg long 6
+ret 15
+end
+ret pt_verify h n
+end
+if eq ph 2
+ret pt_verify get pth 0 mapget m 16 8
+end
+if eq ph 3
+r = pool_release c w
+h = pool_acquire c w
+if le h 0
+ret 16
+end
+put pth 0 h
+ret pt_verify h n
+end
+if eq ph 4
+r = sleepns 30000000000
+ret 17
+end
+ret 18
+end
+
+fn pt_worker w ulong to int
+c = get ptc 0
+m = get ptm 0
+put pth 0 0
+for it ulong 64
+r = sup_wwait c w 5000000000
+if eq r 2
+if gt get pth 0 0
+r = pool_release c w
+end
+ret 0
+end
+if eq r 3
+ret 41
+end
+if eq r 0
+ret 42
+end
+if ne r 1
+ret 43
+end
+res = pt_step c w mapget m 0 8
+r = mapset m add 64 mul w 8 8 ulong res
+if ne sup_ack w 0
+ret 44
+end
+end
+ret 45
+end
+
+note Creator: wake worker w for phase ph and wait up to about 5 s for its ack.
+note Returns the worker's phase result, or 90 no ack, 91 the worker died.
+fn pt_phase c long w ulong ph ulong to int
+m = get ptm 0
+r = mapset m 0 8 ph
+r = mapset m add 64 mul w 8 8 99
+if ne sup_wake w 0
+ret 92
+end
+for t ulong 500
+if gt sup_take get swack w 0
+ret int mapget m add 64 mul w 8 8
+end
+if le get swpid w 0
+ret 91
+end
+r = sup_poll c 10000000
+end
+ret 90
+end
+
+fn pt_spawn c long w ulong to bool
+p = sup_spawn c w
+if eq p 0
+exit pt_worker w
+end
+ret gt p 0
+end
+
+fn pt_procs to void
+c = pool_new 2 4
+pt_ok gt c 0 52
+put ptc 0 c
+m = mapnew neg int 1 0 4096 3 33
+pt_ok gt m 0 53
+put ptm 0 m
+pt_ok eq sup_init c 0 54
+pt_ok pt_fill c 8 55
+r = mapset m 8 8 8
+r = mapset m 16 8 8
+pt_ok pt_spawn c 0 56
+pt_ok pt_spawn c 1 57
+pt_ok pt_spawn c 2 58
+pt_ok eq sup_spawn c 2 neg long 16 59
+for w ulong 3
+pt_ok eq pt_phase c w 1 0 60
+end
+pt_ok eq mapget c 272 8 1 61
+pt_ok eq mapget c 1288 8 1 62
+pt_ok eq pool_roll c 2 63
+pt_ok pt_fill c 5 64
+pt_ok eq pool_roll c neg long 9 65
+note An older epoch stays complete for its holder after newer publication.
+pt_ok eq pt_phase c 0 2 0 66
+r = mapset m 8 8 5
+pt_ok eq pt_phase c 0 3 0 67
+pt_ok eq pt_phase c 1 3 0 68
+pt_ok eq mapget c 256 8 2 69
+pt_ok eq pool_roll c neg long 9 70
+note Kill the last holder of epoch 1. Its death is seen through its life pipe.
+pt_ok eq killpid int get swpid 2 9 0 71
+dead = long 0
+for t ulong 500
+dead = add dead sup_poll c 10000000
+if gt dead 0
+break
+end
+end
+pt_ok eq dead 1 72
+pt_ok eq and get swst 2 127 9 73
+pt_ok eq mapget c 272 8 0 74
+pt_ok eq mapget c 1296 8 2 75
+pt_ok eq pool_roll c 3 76
+pt_ok pt_fill c 3 77
+r = mapset m 8 8 3
+pt_ok pt_spawn c 2 78
+pt_ok eq pt_phase c 2 3 0 79
+r = mapset m 0 8 4
+pt_ok eq sup_wake 1 0 80
+r = sleepns 100000000
+note A pending ack from the stalled worker must not turn the stop wait into a
+note spin that kills it before the 2 s deadline.
+pt_ok eq sup_ack 1 0 89
+t0 = monons
+k = sup_stop c 2000000000
+pt_ok ge sub monons t0 1900000000 90
+pt_ok eq k 1 81
+pt_ok eq get swst 0 0 82
+pt_ok eq get swst 2 0 83
+pt_ok eq and get swst 1 127 9 84
+pt_ok eq waitpid neg int 1 ptws 0 4 1 neg long 10 85
+pt_ok eq sup_live c 0 86
+sup_closeall
+pt_ok eq pool_free c 0 87
+pt_ok eq mapdrop m 0 88
+end
+
+note A creator that exits without stopping its worker must not leave the worker
+note waiting: the worker sees the creator's life pipe hang up and reports 3.
+fn pt_orphan to void
+pf = new uchar 8 0
+b = new uchar 1 0
+pt_ok ge pipefds pf 0 8 524288 0 93
+rd = pt_fd4 pf 0
+wr = pt_fd4 pf 4
+s = fork
+if eq s 0
+c = pool_new 1 1
+if le c 0
+exit 50
+end
+if ne sup_init c 0
+exit 51
+end
+put ptc 0 c
+p = sup_spawn c 0
+if eq p 0
+r = sup_wwait c 0 5000000000
+put b 0 uchar and ulong add r 128 255
+r = write wr b 0 1
+exit 0
+end
+exit 0
+end
+pt_ok gt s 0 94
+r = fclose wr
+pt_ok eq waitpid int s ptws 0 4 0 s 95
+pt_ok eq get ptws 0 0 96
+pt_ok gt waitio rd 1 6000000000 0 97
+pt_ok eq read rd b 0 1 1 98
+pt_ok eq get b 0 131 99
+r = fclose rd
+end
+
+note Stress: 0 when arena h shows only complete records of epoch e from start
+note to end of one hold. A reclaimed held arena changes its epoch, drops its
+note count or rewrites bytes, so a missing hold check shows up here.
+fn pt_scan h long e ulong to int
+buf = new uchar 4096 0
+if ne node_epoch h e
+ret 1
+end
+cur = ulong 0
+for k ulong 65
+v = node_next h cur 1
+if eq v 0
+break
+end
+if lt v 0
+ret 2
+end
+cur = ulong v
+if ne node_read h cur buf 4096
+ret 3
+end
+b = pt_byte e cur
+for j ulong 4096
+if ne get buf j b
+ret 4
+end
+end
+end
+if ne node_epoch h e
+ret 5
+end
+ret 0
+end
+
+fn pt_sworker w ulong to int
+c = get ptc 0
+m = get ptm 0
+n = ulong 0
+for it ulong 10000000
+if pool_stopped c
+r = mapset m add 64 mul w 8 8 n
+ret 0
+end
+h = pool_acquire c w
+if eq h neg long 1
+r = mapset m add 64 mul w 8 8 n
+ret 0
+end
+if gt h 0
+r = pt_scan h mapget c add 256 mul w 8 8
+if ne r 0
+ret add 20 r
+end
+q = pool_release c w
+n = add n 1
+end
+end
+ret 29
+end
+
+fn pt_num v ulong to void
+d = new uchar 20 0
+x = v
+k = ulong 20
+for i ulong 20
+k = sub k 1
+put d k uchar add rem x 10 48
+x = div x 10
+if eq x 0
+break
+end
+end
+r = write 1 d k sub 20 k
+end
+
+text pstress "stress rolls="
+text pbusy " busy="
+text preads " reads="
+text pnl "\n"
+text psp " "
+
+note Two workers acquire, scan and release in a tight loop while the creator
+note rolls 2000 epochs over two arenas, publishing four records per epoch.
+fn pt_stress to void
+c = pool_new 2 2
+pt_ok gt c 0 120
+put ptc 0 c
+m = mapnew neg int 1 0 4096 3 33
+pt_ok gt m 0 121
+put ptm 0 m
+pt_ok eq sup_init c 0 122
+pt_ok pt_fill c 4 123
+for w ulong 2
+p = sup_spawn c w
+if eq p 0
+exit pt_sworker w
+end
+pt_ok gt p 0 124
+end
+rolls = ulong 0
+busy = ulong 0
+for i ulong 100000000
+if ge rolls 2000
+break
+end
+r = pool_roll c
+if eq r neg long 9
+busy = add busy 1
+if eq and busy 1023 0
+pt_ok eq sup_poll c 0 0 133
+end
+cpurelax
+continue
+end
+pt_ok gt r 0 125
+rolls = add rolls 1
+pt_ok pt_fill c 4 126
+end
+pt_ok eq rolls 2000 127
+pt_ok eq sup_stop c 5000000000 0 128
+pt_ok eq get swst 0 0 129
+pt_ok eq get swst 1 0 130
+r = write 1 pstress 0 len pstress
+pt_num rolls
+r = write 1 pbusy 0 len pbusy
+pt_num busy
+r = write 1 preads 0 len preads
+pt_num mapget m 64 8
+r = write 1 psp 0 1
+pt_num mapget m 72 8
+r = write 1 pnl 0 1
+sup_closeall
+pt_ok eq pool_free c 0 131
+pt_ok eq mapdrop m 0 132
+end
+
+fn pt_isarg to bool
+a = new uchar 16 0
+if ne argcnt 2
+ret false
+end
+ret eq argread 1 a 0 16 6
+end
+
+note With one argument (any 6 bytes, "stress"), run only the stress phase.
+fn main to int
+if pt_isarg
+pt_stress
+ret 0
+end
+pt_refusals
+pt_epochs
+pt_race
+pt_orphan
+pt_procs
+pt_stress
+if ne write 1 pok 0 len pok long len pok
+ret 100
+end
+ret 0
+end
diff --git a/seed/node/pool-test.om b/seed/node/pool-test.om
new file mode 100644
index 000000000..de0d2be95
--- /dev/null
+++ b/seed/node/pool-test.om
@@ -0,0 +1,527 @@
+note Concatenate after transport.om, pool.om and super.om. CPU-only acceptance
+note of epoch turnover, held old versions, worker death, respawn, orphaning and
+note bounded teardown with real forked processes. No GPU, model or network.
+text pok "PASS node pool\n"
+global ptc long 1
+global ptm long 1
+global pth long 1
+global ptws uchar 4
+
+fn pt_ok ok bool code int to void
+if not ok
+exit code
+end
+end
+
+fn pt_fd4 p view uchar 8 off ulong to int
+v = ulong get p off
+v = or v shl ulong get p add off 1 8
+v = or v shl ulong get p add off 2 16
+v = or v shl ulong get p add off 3 24
+ret int v
+end
+
+fn pt_byte e ulong v ulong to uchar
+ret uchar and add mul e 16 v 255
+end
+
+note Creator: publish n full records into the current epoch, bytes f(epoch, v).
+fn pt_fill c long n ulong to bool
+buf = new uchar 4096 0
+e = pool_epoch c
+h = pool_current c
+if lt h 0
+ret false
+end
+for k ulong n bound 64
+v = add mapget h 16 8 1
+b = pt_byte e v
+for j ulong 4096
+put buf j b
+end
+if ne pool_publish c 1 buf 4096 long v
+ret false
+end
+end
+ret true
+end
+
+note 0 when arena h holds exactly n complete records of its own epoch, else a code.
+fn pt_verify h long n ulong to int
+buf = new uchar 4096 0
+e = node_epoch h
+cur = ulong 0
+cnt = ulong 0
+for k ulong 65
+v = node_next h cur 1
+if eq v 0
+break
+end
+if lt v 0
+ret 1
+end
+cur = ulong v
+if ne node_read h cur buf 4096
+ret 2
+end
+b = pt_byte e cur
+for j ulong 4096
+if ne get buf j b
+ret 3
+end
+end
+cnt = add cnt 1
+end
+if ne cnt n
+ret 4
+end
+ret 0
+end
+
+fn pt_refusals to void
+pt_ok eq pool_new 0 4 neg long 7 10
+pt_ok eq pool_new 9 4 neg long 7 11
+pt_ok eq pool_new 2 0 neg long 7 12
+pt_ok eq pool_new 2 65 neg long 7 13
+c = pool_new 2 4
+pt_ok gt c 0 14
+pt_ok eq pool_epoch c 1 15
+pt_ok eq pool_acquire c 4 neg long 7 16
+pt_ok eq pool_release c 4 neg long 7 17
+pt_ok eq node_epoch pool_current c 1 18
+pt_ok eq node_reset pool_current c 0 neg long 7 19
+pt_ok eq pool_free c 0 20
+end
+
+note One process: the creator also plays worker slots 0 and 1, whose holds are
+note plain words. Epoch numbers never repeat; arenas are reused only unheld.
+fn pt_epochs to void
+dst = new uchar 4096 0
+c = pool_new 2 4
+pt_ok gt c 0 21
+pt_ok pt_fill c 1 22
+h1 = pool_acquire c 0
+pt_ok eq h1 pool_current c 23
+pt_ok eq mapget c 256 8 1 24
+pt_ok eq pool_roll c 2 25
+pt_ok ne pool_current c h1 26
+pt_ok eq node_next pool_current c 0 1 0 27
+pt_ok eq pool_roll c neg long 9 28
+pt_ok eq pool_epoch c 2 29
+pt_ok eq pt_verify h1 1 0 30
+pt_ok eq pool_release c 0 0 31
+pt_ok eq pool_roll c 3 32
+pt_ok eq pool_slot c 3 0 33
+pt_ok eq node_read h1 1 dst neg long 7 34
+pt_ok eq node_epoch h1 3 35
+pt_ok pt_fill c 64 36
+for j ulong 4096
+put dst j pt_byte 4 1
+end
+pt_ok eq pool_publish c 1 dst 4096 1 37
+pt_ok eq pool_epoch c 4 38
+h4 = pool_acquire c 1
+pt_ok eq node_epoch h4 4 39
+pt_ok pt_fill c 63 40
+pt_ok eq pool_epoch c 4 41
+pt_ok eq pool_roll c 5 42
+pt_ok pt_fill c 64 43
+pt_ok eq pool_publish c 1 dst 1 neg long 9 44
+pt_ok eq pool_epoch c 5 45
+pt_ok eq pt_verify h4 64 0 46
+pt_ok eq pool_stop c 0 47
+pt_ok eq pool_roll c neg long 1 48
+pt_ok eq pool_acquire c 2 neg long 1 49
+pt_ok eq mapget c 272 8 0 50
+pt_ok eq pool_free c 0 51
+end
+
+note The announce race, made deterministic by running the protocol steps in
+note the order that breaks a hold without its recheck: worker 2 read epoch e,
+note the creator moved past e and picked e's arena, then worker 2 stores its
+note hold. The recheck must refuse; reuse of the arena must then proceed.
+fn pt_race to void
+c = pool_new 2 4
+pt_ok gt c 0 140
+pt_ok pt_fill c 1 141
+e = pool_epoch c
+pt_ok eq pool_roll c 2 142
+pt_ok eq pool_pick c 0 143
+pt_ok eq pool_hold c 2 e neg long 8 144
+pt_ok eq mapget c 272 8 0 145
+pt_ok eq pool_reuse c 0 3 3 146
+pt_ok eq pool_acquire c 2 pool_current c 147
+pt_ok eq pool_hold c 4 3 neg long 7 148
+pt_ok eq pool_free c 0 149
+end
+
+note Worker phase: 1 acquire and verify, 2 verify the held epoch again,
+note 3 release, acquire the current epoch and verify, 4 stall ignoring stop.
+fn pt_step c long w ulong ph ulong to int
+buf = new uchar 4096 0
+m = get ptm 0
+n = mapget m 8 8
+if eq ph 1
+if ne pool_roll c neg long 6
+ret 11
+end
+if ne pool_stop c neg long 6
+ret 12
+end
+if ne pool_clear c w neg long 6
+ret 13
+end
+h = pool_acquire c w
+if le h 0
+ret 14
+end
+put pth 0 h
+if ne node_publish h 1 buf 1 neg long 6
+ret 15
+end
+ret pt_verify h n
+end
+if eq ph 2
+ret pt_verify get pth 0 mapget m 16 8
+end
+if eq ph 3
+r = pool_release c w
+h = pool_acquire c w
+if le h 0
+ret 16
+end
+put pth 0 h
+ret pt_verify h n
+end
+if eq ph 4
+r = sleepns 30000000000
+ret 17
+end
+ret 18
+end
+
+fn pt_worker w ulong to int
+c = get ptc 0
+m = get ptm 0
+put pth 0 0
+for it ulong 64
+r = sup_wwait c w 5000000000
+if eq r 2
+if gt get pth 0 0
+r = pool_release c w
+end
+ret 0
+end
+if eq r 3
+ret 41
+end
+if eq r 0
+ret 42
+end
+if ne r 1
+ret 43
+end
+res = pt_step c w mapget m 0 8
+r = mapset m add 64 mul w 8 8 ulong res
+if ne sup_ack w 0
+ret 44
+end
+end
+ret 45
+end
+
+note Creator: wake worker w for phase ph and wait up to about 5 s for its ack.
+note Returns the worker's phase result, or 90 no ack, 91 the worker died.
+fn pt_phase c long w ulong ph ulong to int
+m = get ptm 0
+r = mapset m 0 8 ph
+r = mapset m add 64 mul w 8 8 99
+if ne sup_wake w 0
+ret 92
+end
+for t ulong 500
+if gt sup_take get swack w 0
+ret int mapget m add 64 mul w 8 8
+end
+if le get swpid w 0
+ret 91
+end
+r = sup_poll c 10000000
+end
+ret 90
+end
+
+fn pt_spawn c long w ulong to bool
+p = sup_spawn c w
+if eq p 0
+exit pt_worker w
+end
+ret gt p 0
+end
+
+fn pt_procs to void
+c = pool_new 2 4
+pt_ok gt c 0 52
+put ptc 0 c
+m = mapnew neg int 1 0 4096 3 33
+pt_ok gt m 0 53
+put ptm 0 m
+pt_ok eq sup_init c 0 54
+pt_ok pt_fill c 8 55
+r = mapset m 8 8 8
+r = mapset m 16 8 8
+pt_ok pt_spawn c 0 56
+pt_ok pt_spawn c 1 57
+pt_ok pt_spawn c 2 58
+pt_ok eq sup_spawn c 2 neg long 16 59
+for w ulong 3
+pt_ok eq pt_phase c w 1 0 60
+end
+pt_ok eq mapget c 272 8 1 61
+pt_ok eq mapget c 1288 8 1 62
+pt_ok eq pool_roll c 2 63
+pt_ok pt_fill c 5 64
+pt_ok eq pool_roll c neg long 9 65
+note An older epoch stays complete for its holder after newer publication.
+pt_ok eq pt_phase c 0 2 0 66
+r = mapset m 8 8 5
+pt_ok eq pt_phase c 0 3 0 67
+pt_ok eq pt_phase c 1 3 0 68
+pt_ok eq mapget c 256 8 2 69
+pt_ok eq pool_roll c neg long 9 70
+note Kill the last holder of epoch 1. Its death is seen through its life pipe.
+pt_ok eq killpid int get swpid 2 9 0 71
+dead = long 0
+for t ulong 500
+dead = add dead sup_poll c 10000000
+if gt dead 0
+break
+end
+end
+pt_ok eq dead 1 72
+pt_ok eq and get swst 2 127 9 73
+pt_ok eq mapget c 272 8 0 74
+pt_ok eq mapget c 1296 8 2 75
+pt_ok eq pool_roll c 3 76
+pt_ok pt_fill c 3 77
+r = mapset m 8 8 3
+pt_ok pt_spawn c 2 78
+pt_ok eq pt_phase c 2 3 0 79
+r = mapset m 0 8 4
+pt_ok eq sup_wake 1 0 80
+r = sleepns 100000000
+note A pending ack from the stalled worker must not turn the stop wait into a
+note spin that kills it before the 2 s deadline.
+pt_ok eq sup_ack 1 0 89
+t0 = monons
+k = sup_stop c 2000000000
+pt_ok ge sub monons t0 1900000000 90
+pt_ok eq k 1 81
+pt_ok eq get swst 0 0 82
+pt_ok eq get swst 2 0 83
+pt_ok eq and get swst 1 127 9 84
+pt_ok eq waitpid neg int 1 ptws 0 4 1 neg long 10 85
+pt_ok eq sup_live c 0 86
+sup_closeall
+pt_ok eq pool_free c 0 87
+pt_ok eq mapdrop m 0 88
+end
+
+note A creator that exits without stopping its worker must not leave the worker
+note waiting: the worker sees the creator's life pipe hang up and reports 3.
+fn pt_orphan to void
+pf = new uchar 8 0
+b = new uchar 1 0
+pt_ok ge pipefds pf 0 8 524288 0 93
+rd = pt_fd4 pf 0
+wr = pt_fd4 pf 4
+s = fork
+if eq s 0
+c = pool_new 1 1
+if le c 0
+exit 50
+end
+if ne sup_init c 0
+exit 51
+end
+put ptc 0 c
+p = sup_spawn c 0
+if eq p 0
+r = sup_wwait c 0 5000000000
+put b 0 uchar and ulong add r 128 255
+r = write wr b 0 1
+exit 0
+end
+exit 0
+end
+pt_ok gt s 0 94
+r = fclose wr
+pt_ok eq waitpid int s ptws 0 4 0 s 95
+pt_ok eq get ptws 0 0 96
+pt_ok gt waitio rd 1 6000000000 0 97
+pt_ok eq read rd b 0 1 1 98
+pt_ok eq get b 0 131 99
+r = fclose rd
+end
+
+note Stress: 0 when arena h shows only complete records of epoch e from start
+note to end of one hold. A reclaimed held arena changes its epoch, drops its
+note count or rewrites bytes, so a missing hold check shows up here.
+fn pt_scan h long e ulong to int
+buf = new uchar 4096 0
+if ne node_epoch h e
+ret 1
+end
+cur = ulong 0
+for k ulong 65
+v = node_next h cur 1
+if eq v 0
+break
+end
+if lt v 0
+ret 2
+end
+cur = ulong v
+if ne node_read h cur buf 4096
+ret 3
+end
+b = pt_byte e cur
+for j ulong 4096
+if ne get buf j b
+ret 4
+end
+end
+end
+if ne node_epoch h e
+ret 5
+end
+ret 0
+end
+
+fn pt_sworker w ulong to int
+c = get ptc 0
+m = get ptm 0
+n = ulong 0
+for it ulong 10000000
+if pool_stopped c
+r = mapset m add 64 mul w 8 8 n
+ret 0
+end
+h = pool_acquire c w
+if eq h neg long 1
+r = mapset m add 64 mul w 8 8 n
+ret 0
+end
+if gt h 0
+r = pt_scan h mapget c add 256 mul w 8 8
+if ne r 0
+ret add 20 r
+end
+q = pool_release c w
+n = add n 1
+end
+end
+ret 29
+end
+
+fn pt_num v ulong to void
+d = new uchar 20 0
+x = v
+k = ulong 20
+for i ulong 20
+k = sub k 1
+put d k uchar add rem x 10 48
+x = div x 10
+if eq x 0
+break
+end
+end
+r = write 1 d k sub 20 k
+end
+
+text pstress "stress rolls="
+text pbusy " busy="
+text preads " reads="
+text pnl "\n"
+text psp " "
+
+note Two workers acquire, scan and release in a tight loop while the creator
+note rolls 2000 epochs over two arenas, publishing four records per epoch.
+fn pt_stress to void
+c = pool_new 2 2
+pt_ok gt c 0 120
+put ptc 0 c
+m = mapnew neg int 1 0 4096 3 33
+pt_ok gt m 0 121
+put ptm 0 m
+pt_ok eq sup_init c 0 122
+pt_ok pt_fill c 4 123
+for w ulong 2
+p = sup_spawn c w
+if eq p 0
+exit pt_sworker w
+end
+pt_ok gt p 0 124
+end
+rolls = ulong 0
+busy = ulong 0
+for i ulong 100000000
+if ge rolls 2000
+break
+end
+r = pool_roll c
+if eq r neg long 9
+busy = add busy 1
+if eq and busy 1023 0
+pt_ok eq sup_poll c 0 0 133
+end
+cpurelax
+continue
+end
+pt_ok gt r 0 125
+rolls = add rolls 1
+pt_ok pt_fill c 4 126
+end
+pt_ok eq rolls 2000 127
+pt_ok eq sup_stop c 5000000000 0 128
+pt_ok eq get swst 0 0 129
+pt_ok eq get swst 1 0 130
+r = write 1 pstress 0 len pstress
+pt_num rolls
+r = write 1 pbusy 0 len pbusy
+pt_num busy
+r = write 1 preads 0 len preads
+pt_num mapget m 64 8
+r = write 1 psp 0 1
+pt_num mapget m 72 8
+r = write 1 pnl 0 1
+sup_closeall
+pt_ok eq pool_free c 0 131
+pt_ok eq mapdrop m 0 132
+end
+
+fn pt_isarg to bool
+a = new uchar 16 0
+if ne argcnt 2
+ret false
+end
+ret eq argread 1 a 0 16 6
+end
+
+note With one argument (any 6 bytes, "stress"), run only the stress phase.
+fn main to int
+if pt_isarg
+pt_stress
+ret 0
+end
+pt_refusals
+pt_epochs
+pt_race
+pt_orphan
+pt_procs
+pt_stress
+if ne write 1 pok 0 len pok long len pok
+ret 100
+end
+ret 0
+end
diff --git a/seed/node/pool.om b/seed/node/pool.om
new file mode 100644
index 000000000..bac77eadd
--- /dev/null
+++ b/seed/node/pool.om
@@ -0,0 +1,278 @@
+note Omega Node epoch pool. Concatenate after transport.om, before super.om.
+note K arenas (1..8) and one control page are mapped before any worker fork,
+note so every forked worker inherits the same shared mappings.
+note Single writer: the creator writes the current epoch, the arena table and
+note every arena record. Worker w alone writes hold word w while it lives;
+note the creator clears hold w only after it has reaped worker w.
+note Control u64: 0 magic, 8 ABI, 16 current epoch, 24 stop, 32 creator PID,
+note 40 arena count K, 48 worker slots W, 64+8k arena handle k,
+note 128+8k epoch of arena k (0 free), 256+8w hold of worker w (0 none),
+note 768+8w worker PID, 1280+8w worker state (0 empty, 1 live, 2 reaped).
+const PMAGIC ulong 1347374924
+const PCAP ulong 8
+const PWCAP ulong 64
+const PBYTES ulong 4096
+
+fn pool_valid c long to bool
+ret and eq mapget c 0 8 PMAGIC eq mapget c 8 8 1
+end
+
+fn pool_mine c long to bool
+ret eq mapget c 32 8 ulong getpid
+end
+
+fn pool_arena c long k ulong to long
+ret long mapget c add 64 mul k 8 8
+end
+
+note Drop the first n arenas and the control page of a pool being refused.
+fn pool_unwind c long n ulong to long
+for i ulong n bound 8
+r = mapdrop pool_arena c i
+end
+ret mapdrop c
+end
+
+note Return the control handle, or -7 bad size, or a negative mapping errno.
+note Arena 0 starts as epoch 1. Call before forking any worker.
+fn pool_new k ulong w ulong to long
+if or eq k 0 gt k PCAP
+ret neg long 7
+end
+if or eq w 0 gt w PWCAP
+ret neg long 7
+end
+c = mapnew neg int 1 0 PBYTES 3 33
+if le c 0
+ret c
+end
+r = mapset c 32 8 ulong getpid
+r = mapset c 40 8 k
+r = mapset c 48 8 w
+for i ulong k bound 8
+h = node_new
+if le h 0
+r = pool_unwind c i
+ret h
+end
+r = mapset c add 64 mul i 8 8 ulong h
+end
+r = node_reset pool_arena c 0 1
+r = mapset c 128 8 1
+r = mapset c 16 8 1
+r = mapset c 8 8 1
+r = mapset c 0 8 PMAGIC
+ret c
+end
+
+note Arena index holding epoch e, or -5 when no arena holds it.
+fn pool_slot c long e ulong to long
+k = mapget c 40 8
+if gt k PCAP
+ret neg long 5
+end
+for i ulong k bound 8
+if eq mapget c add 128 mul i 8 8 e
+ret long i
+end
+end
+ret neg long 5
+end
+
+note Creator: the arena of the current epoch, or a negative refusal.
+fn pool_current c long to long
+if not pool_valid c
+ret neg long 5
+end
+k = pool_slot c mapget c 16 8
+if lt k 0
+ret k
+end
+ret pool_arena c ulong k
+end
+
+fn pool_epoch c long to ulong
+ret mapget c 16 8
+end
+
+note Worker step: store hold e for worker w, then read the epoch again. mapset
+note and mapget fence both sides, so a creator that moved the epoch before it
+note scanned holds either sees this hold or this read sees the move. Returns
+note the arena of e, -8 when the epoch moved, or -5 when no arena holds e.
+note Every refusal clears the hold.
+fn pool_hold c long w ulong e ulong to long
+if ge w mapget c 48 8
+ret neg long 7
+end
+hw = add 256 mul w 8
+r = mapset c hw 8 e
+if ne mapget c 16 8 e
+r = mapset c hw 8 0
+ret neg long 8
+end
+k = pool_slot c e
+if lt k 0
+r = mapset c hw 8 0
+ret k
+end
+h = pool_arena c ulong k
+if ne node_epoch h e
+r = mapset c hw 8 0
+ret neg long 5
+end
+ret h
+end
+
+note Worker w holds the current epoch and returns its arena. Returns -1
+note stopped, -5 invalid, -7 bad worker, -8 the epoch kept moving.
+fn pool_acquire c long w ulong to long
+if not pool_valid c
+ret neg long 5
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+for t ulong 16
+if ne mapget c 24 8 0
+r = mapset c add 256 mul w 8 8 0
+ret neg long 1
+end
+h = pool_hold c w mapget c 16 8
+if ne h neg long 8
+ret h
+end
+end
+ret neg long 8
+end
+
+note Worker w gives up its hold. Its old arena must not be read afterwards.
+fn pool_release c long w ulong to long
+if ge w mapget c 48 8
+ret neg long 7
+end
+ret mapset c add 256 mul w 8 8 0
+end
+
+fn pool_held c long e ulong to bool
+n = mapget c 48 8
+for w ulong n bound 64
+if eq mapget c add 256 mul w 8 8 e
+ret true
+end
+end
+ret false
+end
+
+note Creator step: retire arena i and open epoch n in it, then publish n.
+fn pool_reuse c long i ulong n ulong to long
+off = add 128 mul i 8
+r = mapset c off 8 0
+r = node_reset pool_arena c i n
+if lt r 0
+ret r
+end
+r = mapset c off 8 n
+r = mapset c 16 8 n
+ret long n
+end
+
+note Creator step: an arena that is free or whose older epoch no worker holds,
+note or -9. Call only after the current epoch has moved past that arena.
+fn pool_pick c long to long
+e = mapget c 16 8
+k = mapget c 40 8
+for i ulong k bound 8
+ek = mapget c add 128 mul i 8 8
+if ne ek e
+if or eq ek 0 not pool_held c ek
+ret long i
+end
+end
+end
+ret neg long 9
+end
+
+note Creator: open the next epoch in a free or unheld arena and make it current.
+note Returns the new epoch, -1 stopped, -5 invalid, -6 not creator, or -9 when
+note every other arena is still held: the pool fails closed, nothing changes.
+fn pool_roll c long to long
+if not pool_valid c
+ret neg long 5
+end
+if not pool_mine c
+ret neg long 6
+end
+if ne mapget c 24 8 0
+ret neg long 1
+end
+k = pool_pick c
+if lt k 0
+ret k
+end
+ret pool_reuse c ulong k add mapget c 16 8 1
+end
+
+note Creator: publish to the current epoch; when it is full, roll once and retry.
+note Returns the version, or the refusal of the publish or of the roll.
+fn pool_publish c long topics ulong src view uchar 4096 n ulong to long
+h = pool_current c
+if lt h 0
+ret h
+end
+v = node_publish h topics src n
+if ne v neg long 2
+ret v
+end
+r = pool_roll c
+if lt r 0
+ret r
+end
+h = pool_current c
+if lt h 0
+ret h
+end
+ret node_publish h topics src n
+end
+
+fn pool_stop c long to long
+if not pool_valid c
+ret neg long 5
+end
+if not pool_mine c
+ret neg long 6
+end
+ret mapset c 24 8 1
+end
+
+fn pool_stopped c long to bool
+ret ne mapget c 24 8 0
+end
+
+note Creator: record worker w's PID and state for observers.
+fn pool_setw c long w ulong pid ulong st ulong to long
+if not pool_mine c
+ret neg long 6
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+r = mapset c add 768 mul w 8 8 pid
+ret mapset c add 1280 mul w 8 8 st
+end
+
+note Creator: clear hold w. Only after worker w has been reaped.
+fn pool_clear c long w ulong to long
+if not pool_mine c
+ret neg long 6
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+ret mapset c add 256 mul w 8 8 0
+end
+
+note Drop every mapping of the pool in this process. Other processes keep
+note their own inherited mappings until they drop them or exit.
+fn pool_free c long to long
+ret pool_unwind c mapget c 40 8
+end
diff --git a/seed/node/super.om b/seed/node/super.om
new file mode 100644
index 000000000..c6e062c90
--- /dev/null
+++ b/seed/node/super.om
@@ -0,0 +1,392 @@
+note Omega Node worker supervision. Concatenate after transport.om and pool.om.
+note The creator forks trusted workers from its own binary: sup_spawn returns 0
+note in the child, which runs its worker function and exits with its result.
+note Death is seen without polling PIDs. Worker w alone holds the write end of
+note its close-on-exec life pipe, so its exit hangs up the creator's read end.
+note Every worker holds the read end of the creator's life pipe, whose only
+note writer is the creator, so creator death hangs up every worker.
+note Per worker: wake, stop and ack eventfds, kept across respawns.
+note Workers must not exec: exec closes the life pipe and reads as death.
+global swpid long 64
+global swwake int 64
+global swstop int 64
+global swack int 64
+global swlife int 64
+global swst ulong 64
+global swpw ulong 64
+global swpar int 2
+global swme ulong 1
+global swws uchar 4
+global swpf uchar 8
+global swpoll uchar 1024
+
+fn sup_fd off ulong to int
+v = ulong get swpf off
+v = or v shl ulong get swpf add off 1 8
+v = or v shl ulong get swpf add off 2 16
+v = or v shl ulong get swpf add off 3 24
+ret int v
+end
+
+note Poll record j at swpoll offset off; a negative fd is stored as itself
+note (bit pattern) so the kernel ignores that record.
+fn sup_gpfd off ulong fd int to void
+u = bitcast uint fd
+for i ulong 4
+put swpoll add off i uchar and shr u uint mul i 8 255
+end
+put swpoll add off 4 1
+put swpoll add off 5 0
+put swpoll add off 6 0
+put swpoll add off 7 0
+end
+
+fn sup_lpfd p edit uchar 24 off ulong fd int to void
+for i ulong 4
+put p add off i uchar and shr uint fd uint mul i 8 255
+end
+put p add off 4 1
+end
+
+note Read and reset an eventfd counter: the number of hints since the last
+note take, 0 when none is pending, or a negative errno.
+fn sup_take fd int to long
+buf = new uchar 8 0
+for i ulong 64
+r = read fd buf 0 8
+if eq r 8
+v = ulong 0
+for j ulong 8
+v = or v shl ulong get buf j mul j 8
+end
+ret long and v 9223372036854775807
+end
+if eq r neg long 11
+ret 0
+end
+if ne r neg long 4
+if lt r 0
+ret r
+end
+ret neg long 5
+end
+end
+ret neg long 4
+end
+
+fn sup_closeall to void
+for i ulong 64
+if ge get swwake i 0
+r = fclose get swwake i
+end
+if ge get swstop i 0
+r = fclose get swstop i
+end
+if ge get swack i 0
+r = fclose get swack i
+end
+if ge get swlife i 0
+r = fclose get swlife i
+end
+put swwake i neg int 1
+put swstop i neg int 1
+put swack i neg int 1
+put swlife i neg int 1
+end
+for i ulong 2
+if ge get swpar i 0
+r = fclose get swpar i
+end
+put swpar i neg int 1
+end
+end
+
+note Creator: create the creator life pipe and three eventfds per worker slot.
+note Call once after pool_new and before sup_spawn. 0 or a negative errno;
+note a failure closes everything this call opened.
+fn sup_init c long to long
+if not pool_mine c
+ret neg long 6
+end
+for i ulong 64
+put swpid i 0
+put swst i 0
+put swwake i neg int 1
+put swstop i neg int 1
+put swack i neg int 1
+put swlife i neg int 1
+end
+put swme 0 0
+put swpar 0 neg int 1
+put swpar 1 neg int 1
+r = pipefds swpf 0 8 524288
+if lt r 0
+ret r
+end
+put swpar 0 sup_fd 0
+put swpar 1 sup_fd 4
+n = mapget c 48 8
+for i ulong n bound 64
+a = eventfd uint 0
+if lt a 0
+sup_closeall
+ret a
+end
+put swwake i int a
+a = eventfd uint 0
+if lt a 0
+sup_closeall
+ret a
+end
+put swstop i int a
+a = eventfd uint 0
+if lt a 0
+sup_closeall
+ret a
+end
+put swack i int a
+end
+ret 0
+end
+
+note Creator: fork worker w. Returns 0 in the child, the child PID in the
+note creator, -7 bad slot, -16 slot still live, or a negative errno. The
+note child keeps only its own life write end; the creator keeps the read end.
+fn sup_spawn c long w ulong to long
+if not pool_mine c
+ret neg long 6
+end
+if ge w mapget c 48 8
+ret neg long 7
+end
+if ne get swpid w 0
+ret neg long 16
+end
+r = pipefds swpf 0 8 524288
+if lt r 0
+ret r
+end
+rd = sup_fd 0
+wr = sup_fd 4
+pid = fork
+if eq pid 0
+r = fclose get swpar 1
+put swpar 1 neg int 1
+r = fclose rd
+put swlife w wr
+put swme 0 add w 1
+ret 0
+end
+r = fclose wr
+if lt pid 0
+r = fclose rd
+ret pid
+end
+put swpid w pid
+put swlife w rd
+r = pool_setw c w ulong pid 1
+ret pid
+end
+
+note Worker: 3 creator gone, 2 stop, 1 wake hint, 0 timeout, negative errno.
+note Creator loss outranks stop, which outranks work. A set stop flag makes
+note the poll nonblocking. Hints are drained; rescan shared state after 1.
+fn sup_wwait c long w ulong interval long to long
+p = new uchar 24 0
+if ge w 64
+ret neg long 7
+end
+iv = interval
+if pool_stopped c
+iv = 0
+end
+sup_lpfd p 0 get swwake w
+sup_lpfd p 8 get swstop w
+sup_lpfd p 16 get swpar 0
+r = pollfds p 0 24 iv
+if lt r 0
+ret r
+end
+if ne get p 22 0
+ret 3
+end
+if pool_stopped c
+ret 2
+end
+if ne and get p 14 56 0
+ret neg long 5
+end
+if ne and get p 14 1 0
+r = node_drain get swstop w
+ret 2
+end
+if ne and get p 6 56 0
+ret neg long 5
+end
+if ne and get p 6 1 0
+r = node_drain get swwake w
+if lt r 0
+ret r
+end
+ret 1
+end
+ret 0
+end
+
+note Worker or creator: post a hint on worker w's ack eventfd.
+fn sup_ack w ulong to long
+if ge w 64
+ret neg long 7
+end
+ret node_notify get swack w
+end
+
+note Creator: wake worker w with a work hint.
+fn sup_wake w ulong to long
+if ge w 64
+ret neg long 7
+end
+if le get swpid w 0
+ret neg long 3
+end
+ret node_notify get swwake w
+end
+
+fn sup_live c long to ulong
+n = mapget c 48 8
+k = ulong 0
+for w ulong n bound 64
+if gt get swpid w 0
+k = add k 1
+end
+end
+ret k
+end
+
+note Creator: reap worker w, then release what it held. A worker that has not
+note exited within about one second gets SIGKILL first. Only after the exact
+note PID is reaped are its hold, PID and life pipe released. Returns the raw
+note wait status, -3 no live worker, or the waitpid errno (nothing released).
+fn sup_reap c long w ulong to long
+if ge w 64
+ret neg long 7
+end
+pid = get swpid w
+if le pid 0
+ret neg long 3
+end
+done = false
+for t ulong 100
+r = waitpid int pid swws 0 4 1
+if eq r pid
+done = true
+break
+end
+if ne r 0
+ret r
+end
+r = sleepns 10000000
+end
+if not done
+r = killpid int pid 9
+r = waitpid int pid swws 0 4 0
+if ne r pid
+ret r
+end
+end
+st = ulong get swws 0
+st = or st shl ulong get swws 1 8
+put swst w st
+r = fclose get swlife w
+put swlife w neg int 1
+put swpid w 0
+r = pool_clear c w
+r = pool_setw c w 0 2
+ret long st
+end
+
+note Creator: wait up to interval ns for deaths and, when acks is true, acks.
+note Ack counts are left pending for sup_take. Every worker whose life pipe
+note hung up is reaped. Returns the number reaped, or a negative errno.
+fn sup_pollx c long interval long acks bool to long
+n = mapget c 48 8
+m = ulong 0
+for w ulong n bound 64
+if gt get swpid w 0
+o = mul m 16
+if acks
+sup_gpfd o get swack w
+else
+sup_gpfd o neg int 1
+end
+sup_gpfd add o 8 get swlife w
+put swpw m w
+m = add m 1
+end
+end
+if eq m 0
+ret 0
+end
+r = pollfds swpoll 0 mul m 16 interval
+if lt r 0
+ret r
+end
+dead = long 0
+for j ulong m bound 64
+o = add mul j 16 14
+if ne get swpoll o 0
+r = sup_reap c get swpw j
+if lt r 0
+ret r
+end
+dead = add dead 1
+end
+end
+ret dead
+end
+
+note Creator: wait up to interval ns for acks and deaths (see sup_pollx).
+fn sup_poll c long interval long to long
+ret sup_pollx c interval true
+end
+
+note Creator: stop admission, post every live worker's stop eventfd, then reap
+note until all have exited or interval ns pass; survivors get SIGKILL and are
+note reaped. Returns how many had to be killed, or a refusal.
+fn sup_stop c long interval long to long
+r = pool_stop c
+if lt r 0
+ret r
+end
+n = mapget c 48 8
+for w ulong n bound 64
+if gt get swpid w 0
+r = node_notify get swstop w
+end
+end
+dl = add monons interval
+for t ulong 100000
+if eq sup_live c 0
+ret 0
+end
+now = monons
+if ge now dl
+break
+end
+r = sup_pollx c sub dl now false
+if lt r 0
+if ne r neg long 4
+break
+end
+end
+end
+killed = long 0
+for w ulong n bound 64
+if gt get swpid w 0
+r = killpid int get swpid w 9
+r = sup_reap c w
+killed = add killed 1
+end
+end
+ret killed
+end
diff --git a/seed/node/transport-gate.om b/seed/node/transport-gate.om
index 51135d9e4..beae704bd 100644
--- a/seed/node/transport-gate.om
+++ b/seed/node/transport-gate.om
@@ -1,8 +1,8 @@
note Omega Node transport, concatenate with a program-mode consumer.
note Trusted forked processes only. This is transport, not write authority.
-note One publisher PID, 64 immutable records per arena lifetime, no slot reuse.
+note One publisher PID, 64 immutable records per epoch; reuse only via node_reset.
note Layout: 4096 byte header then 64 slots of 4160 bytes.
-note Header u64: magic, ABI, published count, stop, publisher PID.
+note Header u64: magic, ABI, published count, stop, publisher PID, epoch.
note Slot u64: version, length, topic mask; payload begins at offset 64.
const NCAP ulong 64
const NBYTES ulong 270336
@@ -128,6 +128,32 @@ end
ret mapset h 24 8 1
end
+note Creator only. Retire every record so a pool can reuse the arena for a new
+note epoch. The caller must first prove no reader holds the old epoch (pool.om).
+note The count drops to zero before any record version is cleared.
+fn node_reset h long epoch ulong to long
+if not node_valid h
+ret neg long 5
+end
+if ne mapget h 32 8 ulong getpid
+ret neg long 6
+end
+if eq epoch 0
+ret neg long 7
+end
+r = mapset h 16 8 0
+for i ulong NCAP
+r = mapset h node_offset add i 1 8 0
+end
+r = mapset h 24 8 0
+r = mapset h 40 8 epoch
+ret 0
+end
+
+fn node_epoch h long to ulong
+ret mapget h 40 8
+end
+
note One nonblocking eventfd per consumer. Saturation means already readable.
note Interrupted operations retry at most 64 times, then return EINTR.
fn node_notify fd int to long
diff --git a/seed/node/transport.om b/seed/node/transport.om
index 5d750c0d1..fe41d6bbe 100644
--- a/seed/node/transport.om
+++ b/seed/node/transport.om
@@ -1,8 +1,8 @@
note Omega Node transport, concatenate with a program-mode consumer.
note Trusted forked processes only. This is transport, not write authority.
-note One publisher PID, 64 immutable records per arena lifetime, no slot reuse.
+note One publisher PID, 64 immutable records per epoch; reuse only via node_reset.
note Layout: 4096 byte header then 64 slots of 4160 bytes.
-note Header u64: magic, ABI, published count, stop, publisher PID.
+note Header u64: magic, ABI, published count, stop, publisher PID, epoch.
note Slot u64: version, length, topic mask; payload begins at offset 64.
const NCAP ulong 64
const NBYTES ulong 270336
@@ -128,6 +128,32 @@ end
ret mapset h 24 8 1
end
+note Creator only. Retire every record so a pool can reuse the arena for a new
+note epoch. The caller must first prove no reader holds the old epoch (pool.om).
+note The count drops to zero before any record version is cleared.
+fn node_reset h long epoch ulong to long
+if not node_valid h
+ret neg long 5
+end
+if ne mapget h 32 8 ulong getpid
+ret neg long 6
+end
+if eq epoch 0
+ret neg long 7
+end
+r = mapset h 16 8 0
+for i ulong NCAP
+r = mapset h node_offset add i 1 8 0
+end
+r = mapset h 24 8 0
+r = mapset h 40 8 epoch
+ret 0
+end
+
+fn node_epoch h long to ulong
+ret mapget h 40 8
+end
+
note One nonblocking eventfd per consumer. Saturation means already readable.
note Interrupted operations retry at most 64 times, then return EINTR.
fn node_notify fd int to long