Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/patches/fce527c3ffaf3ef4 # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers ## node: proposals, one commit owner and tool cancellation (DRA-288) merged `fce527c3ffaf3ef4` #1058 · opened 2026-11-07 01:32 UTC · closed 2026-11-15 14:36 UTC · merged 2026-11-15 14:36 UTC Imported from GitHub aien-dev/omega-mv#1058, by drakestapleton Base `725ea44ca66a4db5c7ca4df590350cda9552f26a` · Head `e581746f7853e01324fe13209364ccd781e64da2` Merged on GitHub as `e581746f7853e01324fe13209364ccd781e64da2`; reachable from main `c7acd2607139eedfabeac16b6042cefe8ede431f` (observed 2026-11-18T16:35:39Z) drakestapleton wrote on 2026-11-07 01:32 UTC DRA-288: typed proposals, one commit owner, stale-input and authority rejection, operator control, cancellation of real child tools, UNKNOWN preserved. Stacked on #1057 (DRA-287) → #1056 (DRA-286) → #1055; the diff shown is only this work. Status: IMPLEMENTED, EXERCISED on native Linux AArch64 (DGX Spark host CPU, cores 16-18, no GPU). Not QUALIFIED: no Spark judge run and no independent review. Not deployed or connected to the live hive. ## What changed (all `.om`, seed compiler `5f90edea…`) File Change `seed/node/auth.om` (new) Proposal, decision and commit layer over the existing `seed/authority/action.om` (reused unchanged: `actstart`, `actrecon`, `actlost`). Per-worker control eventfd, control and proposal pages, process-group tool runner. `seed/node/auth-test.om`, `auth-gate.om` (new) Real-process acceptance with forked workers running `/bin/sh` tools. `auth-gate.om` is byte-for-byte `transport + pool + super + sched + seed/authority/action.om + auth + auth-test`. `seed/node/sched.om` `sched_pause c on` (no assignment while paused) and `sched_cancel j` (1 freed before start, 2 running, 3 in review, 4 UNKNOWN). `sched-gate.om` recomposed. `seed/node/README.md` "Proposals, authority and cancellation (DRA-288)": model, cell layout, verdicts, API contract, limits, controls table. Authority behaviour - One commit owner: workers only propose (words 0..15 of their proposal page, then a seq, then an ack). The creator alone decides, and every effect is one `action.om` record keyed by its 4-word operation identity. A performed or UNKNOWN operation is never started again (verdict 7), enforced by `actstart`. - Refusals, in order: malformed (1), not the worker's current assignment (2), another incarnation of the slot (3), stale input (4: input differs from the assignment, epoch rolled, or a newer version on one of the job's dependency topics, via `node_next`), revoked authority generation (5), job being cancelled (6). - Real tools: the granted tool is forked as its own process-group leader (`setpgid` on both sides), stdin `/dev/null`, output into the proposal page. Cancel, revoke, stop and creator loss SIGKILL the whole group. The outcome comes from the wait status alone: a tool that exited is performed even if a cancel raced its exit; a killed external-effect tool is UNKNOWN; leftover group members are killed either way. If the worker dies, the creator kills the tool group from the worker's cell and records `actlost` (UNKNOWN). - Control notification: a dedicated control eventfd per worker, a control seq the worker acknowledges with the paused flag it saw. Pause stops assignment and decisions; running tools continue. Revoke moves the generation on and cancels running granted tools; a report already made is still recorded as made. ## Command and observed output Run on spark-b87b, `Linux 7.0.0-1019-nvidia aarch64`, cores 16-18, clean head `46807d35`, tree `8eb59f6b`: ``` ~/work/omega-node-run.sh ~/work/omega-node-288.sh PASS transport-gate compile=0 exit=0 want=0 ms=12 bin=470aefe90345217a leaked_tools=0 stdout=PASS node transport PASS pool-gate compile=0 exit=0 want=0 ms=2190 bin=afd1063c4e534ade leaked_tools=0 stdout=stress rolls=2000 busy=89820 reads=5295 3656 PASS node pool PASS sched-gate compile=0 exit=0 want=0 ms=8031 bin=68b835c0821b4458 leaked_tools=0 stdout=idle ticks workers=0 creator=0 wake rounds=200 mean_us=65 max_us=3482 PASS node sched PASS auth-gate compile=0 exit=0 want=0 ms=756 bin=4dbaff2acc0d90f1 leaked_tools=0 stdout=PASS node authority PASS am1_no_process_group compile=0 exit=58 want=58 ms=3322 bin=483340b3ce809478 leaked_tools=1 stdout= PASS am2_direct_kill_only compile=0 exit=58 want=58 ms=3334 bin=44fa8f6a4d80b7a0 leaked_tools=1 stdout= PASS am3_kill_means_unknown compile=0 exit=85 want=85 ms=381 bin=8acaaec9c1c79f26 leaked_tools=0 stdout= PASS am4_stale_ignored compile=0 exit=27 want=27 ms=45 bin=b1e2480ea3456b4b leaked_tools=0 stdout= PASS am5_generation_ignored compile=0 exit=52 want=52 ms=100 bin=194b600110618c7f leaked_tools=0 stdout= PASS am6_incarnation_ignored compile=0 exit=40 want=40 ms=90 bin=0fee955870510199 leaked_tools=0 stdout= PASS am7_duplicate_performed compile=0 exit=17 want=17 ms=25 bin=435785140b4fee4e leaked_tools=0 stdout= PASS am8_revoke_no_cancel compile=0 exit=55 want=55 ms=5099 bin=d08cb2f3af98900d leaked_tools=0 stdout= PASS am9_cancel_no_control compile=0 exit=75 want=75 ms=5142 bin=1f67fd216958537f leaked_tools=0 stdout= PASS am10_lost_tool_not_killed compile=0 exit=96 want=96 ms=3622 bin=976f4dfa30120e35 leaked_tools=1 stdout= PASS am11_decide_while_paused compile=0 exit=120 want=120 ms=690 bin=dd502d4726b81c71 leaked_tools=0 stdout= PASS am12_dispatch_while_paused compile=0 exit=121 want=121 ms=699 bin=591fcbfdb91bb97e leaked_tools=0 stdout= PASS auth-gate-repeat 30/30 leaked_tools=0 PASS tree-unchanged-during-run PASS count 18 FAIL count 0 ``` - `leaked_tools` counts `/bin/sleep 30|1` processes left after the run. It is 0 for the real gate and all 30 repeats; the three controls that remove the group kill (am1, am2, am10) leave exactly the 30 s grandchild behind, which is what each control proves (the script reaps it before the next case). - Receipt (addition only): `evidence/node-auth/receipt.2b986676bc06a020b62622ea839aafe7e044875895db66314c3553c565364259.json`. - Source hashes: `auth.om 348893f0…`, `sched.om 9bd18158…`, `auth-gate.om 4fa565bb…`, `seed/authority/action.om 698aa7d6…` (unchanged); `transport.om`, `pool.om`, `super.om` unchanged from #1057. - Negative controls are one-line `sed` edits of a disposable copy (table in `seed/node/README.md`); each compiles and fails with its predicted code. - Repository gates on head `e581746f`: - `crumb verify .` (crumb.lock tool `d0f0b95d`): `OK: 189 crumbs current`. - `AIEN_BASE_REF=origin/main tests/gates/run.sh evidence-immutable`: `evidence/: additions only`. - `tests/gates/run.sh zero-disk-secrets`: `Zero plaintext .env files verified.` ## Not claimed - Action records live in creator memory only; a creator restart loses them. The durable journal and restart recovery are DRA-289. - Between a worker's death and the creator's next `auth_step`, the dead worker's tool group id could in principle be reused before the group kill; the window is one creator step. - The operator view (snapshot + delta, reconnect) is DRA-291; here the controls are creator API calls (`auth_pause`, `auth_cancel`, `auth_revoke`). - `seed/agent/agent.om` `agexec` still kills only the direct child on timeout; it is switched to this group runner when the agent is integrated (DRA-290). - No Spark judge run and no deployment.
Evidence script omega-node-288.sh ``` #!/bin/bash # Native Linux AArch64 run: DRA-288 authority gate + negative controls, plus the # #1055 transport, DRA-286 pool and DRA-287 scheduler gates against the changed sched.om. # Run under ~/work/omega-node-run.sh (one hive core pool). set -u cd ~/work/omega-node-288 E=${E:-~/work/omega-node-evidence-288-$(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 seed/authority/action.om | tee $E/hashes.txt N=seed/node A=seed/authority/action.om cat $N/transport.om $N/transport-test.om | cmp - $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 | cmp - $N/pool-gate.om && echo "pool compose cmp OK" | tee -a $E/hashes.txt cat $N/transport.om $N/pool.om $N/super.om $N/sched.om $N/sched-test.om | cmp - $N/sched-gate.om && echo "sched compose cmp OK" | tee -a $E/hashes.txt cat $N/transport.om $N/pool.om $N/super.om $N/sched.om $A $N/auth.om $N/auth-test.om | cmp - $N/auth-gate.om && echo "auth compose cmp OK" | tee -a $E/hashes.txt leaks() { pgrep -f '^/bin/sleep (30|1)$' | wc -l; } run() { # name src expected-regex local n=$1 src=$2 want=$3 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 120 build/node/$n > $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 leaked_tools=$(leaks) stdout=$(tr "\n" " " < $E/$n.out | cut -c1-90)" } 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 run sched-gate $N/sched-gate.om 0 | tee -a $E/results.txt run auth-gate $N/auth-gate.om 0 | tee -a $E/results.txt # authority mutants: name file sed-expr expected-exit amk() { 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 sc=$N/sched.om au=$N/auth.om case $f in sched.om) sc=build/node/$1.src;; auth.om) au=build/node/$1.src;; esac cat $N/transport.om $N/pool.om $N/super.om $sc $A $au $N/auth-test.om > build/node/$1.om run $1 build/node/$1.om "$4" | tee -a $E/results.txt # a mutant that lets a tool group escape leaves /bin/sleep behind; reap it pkill -9 -f '^/bin/sleep (30|1)$'; sleep 0.2 } amk am1_no_process_group auth.om "/^r = setpgid /d" 58 amk am2_direct_kill_only auth.om "s/^r = killpid neg int pid 9\$/r = killpid int pid 9/" 58 amk am3_kill_means_unknown auth.om "s/^ret au_outcome st class\$/if k\nret 0\nend\nret au_outcome st class/" 85 amk am4_stale_ignored auth.om "s/^ret ne node_next h au_pw w 7 t 0\$/ret false/" 27 amk am5_generation_ignored auth.om "s/^if ne au_pw w 8 get augen 0\$/if ne au_pw w 8 au_pw w 8/" 52 amk am6_incarnation_ignored auth.om "s/^if ne au_pw w 5 get auinc w\$/if ne au_pw w 5 au_pw w 5/" 40 amk am7_duplicate_performed auth.om "/^fn au_commit /,/^fn /s/^k = au_find op\$/k = neg long 1/" 17 amk am8_revoke_no_cancel auth.om "/^au_ctl w au_cell w 16\$/d" 55 amk am9_cancel_no_control auth.om "/^au_ctl w sc_cell w 0\$/d" 75 amk am10_lost_tool_not_killed auth.om "/^x = killpid neg int p 9\$/d" 96 amk am11_decide_while_paused auth.om "s/^if and eq get scpause 0 0 gt au_cell w 72 au_cell w 16\$/if gt au_cell w 72 au_cell w 16/" 120 amk am12_dispatch_while_paused sched.om "s/^if ne get scpause 0 0\$/if false/" 121 # Repeat the unmodified authority gate. R=${R:-30}; ok=0; seed/out/omc < $N/auth-gate.om > build/node/auth-rep && chmod +x build/node/auth-rep for i in $(seq $R); do timeout 120 build/node/auth-rep > $E/rep.out 2>&1 && ok=$((ok+1)); done v=FAIL; [ $ok = $R ] && [ "$(leaks)" = 0 ] && v=PASS; echo "$v auth-gate-repeat $ok/$R leaked_tools=$(leaks)" | tee -a $E/results.txt v=FAIL; sha256sum seed/out/omc seed/node/*.om seed/authority/action.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" ```
aien-spark reviewed (COMMENTED) on 2026-11-07 03:54 UTC COMMENT, not an approval. Head `e581746f7853`. Source-only review; reviewer execution NOT_RUN and Spark qualification NOT_RUN. ## What I read at this head First review of this head. Live metadata and PR body, issue comments, inline review comments and previous reviews were read; the comment/review collections were empty. No signed review of this PR was found in prior sweep output. Exact stacked compare: `725ea44ca66a4db5c7ca4df590350cda9552f26a...e581746f7853e01324fe13209364ccd781e64da2` (base #1057, not main). Changed-file inventory and inspected ranges: - `.crumb:108-121`, `CONTRIBUTORS.md:10-16`, `seed/node/.crumb:3-16`: metadata changes. - `seed/node/README.md:1-4,322-328,357-461`. - `seed/node/auth.om:1-763`, `auth-test.om:1-637`, `auth-gate.om:1-2920` through the corresponding source constituents. The gate's inherited transport/pool/supervisor prefix and existing action contract were also read. - `seed/node/sched.om:25-31,65-72,135-146,288-336`; mirrored `sched-gate.om` hunks at `951-957,992-998,1063-1071,1219-1261`. - `evidence/node-auth/receipt.2b986676bc06a020b62622ea839aafe7e044875895db66314c3553c565364259.json:1-215`. - Unchanged `seed/authority/action.om:1-163` for start, loss and reconciliation. Compiler baseline `7caba0c0094628b384abf8961a33bd95ae9412cc`, `seed/omc/omc.om:5833-5992,7454-7530`: ordinary fork/host syscall lowering and mapped-word access. No hidden fork-to-supervisor publication transaction is supplied by these paths. Sources: PR and author evidence , exact compare , pinned compiler host lowering . No external issue's acceptance criteria were assumed. ## Blocking concern P1 Blocking: worker death between fork and PID publication leaves an executing tool outside cleanup. `seed/node/auth.om:272-293` forks the tool and allows the child to enter `execprog` immediately; only the worker-parent later publishes the tool PID in word 112. `au_lost:650-657` can kill only the PID already stored in that word. Fork/publication window , loss cleanup . [INFERENCE from the source interleaving, not an executed reproduction] Schedule the tool child first, let it exec, then kill its worker before line 293. The supervisor eventually reaps the worker and records UNKNOWN, but reads zero for its tool group and sends no kill. The orphan can continue external effects after the action is treated as lost. Calling `setpgid` in both processes does not close this publication gap. This is distinct from the acknowledged later process-group-ID reuse window. Smallest fix: add a fail-closed launch handshake. The child must not exec or produce effects until its identity is registered for supervisor cleanup; if the worker dies before completing registration, the child's launch wait must observe that loss and exit. Check setup failures rather than ignoring them. Add deterministic kill points immediately after fork and before PID publication, and prove no effect executes and no tool remains. The current worker-death test waits for the grandchild's printed PID before killing the worker, so it starts after the vulnerable window. ## Other concern and evidence Inherited dependency: this stack still carries #1057's per-worker result-buffer reuse issue. Its fix belongs in that base and should be included in the eventual integrated re-review; it is not counted again as a new blocker here. - IMPLEMENTED: typed proposals, action records and control/tool-runner source are present. - Author EXERCISED: receipt source `46807d35a7bc30f17764c8b6bf8a7bc815109678` reports native AArch64 component/control runs and 30 authority repeats. This is not reviewer execution. - Reviewer read-only verification: exact-head `auth.om` SHA-256 is `348893f04ac8fc6ed3d6ff385c5d4382862ab0998b6f91dc602cac3d806a35de`; the full added gate reconstructed from its exact compare has SHA-256 `4fa565bb5110268f00346bc357847b513ec7d48525e569a4eac94b27e7dff8aa`. Both match the receipt. No PR code was run. - CI observed: `pr checks 1058` shows AIEN Checks, evidence-immutable, om-units and sbom passing, AIEN Alpha skipped. AIEN run . - QUALIFIED: not established. Native replay, launch-window fault injection, compiler rebuild, Spark judge and deployment are reviewer NOT_RUN. Draft remains in progress. VERDICT aien-dev/omega-mv#1058 head=`e581746f7853e01324fe13209364ccd781e64da2` verdict=MERGE_AFTER_FIX model=gpt-6-astra provider=openai-codex reasoning=medium session=local-`497f78483f6acb0308504e402fea50328dd487fa167bab8bdb244d2de82960eb` findings=1 — Hermes ### Apply it ``` git checkout -b patch-fce527c3ffaf3ef4 725ea44ca66a4db5c7ca4df590350cda9552f26a curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/fce527c3ffaf3ef4.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-mv 1058 e581746f7853e01324fe13209364ccd781e64da2 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":1058,"url":"https://github.com/aien-dev/omega-mv/pull/1058","export_sha256":"7319147b350ad908bf0b731068ec3be7b8dee848041dc862f71455e8e4680140","imported_utc":"2026-11-18T16:35:39Z"} ``` ### Changes ``` diff --git a/.crumb b/.crumb index f334543ac..5c56e64d3 100644 --- a/.crumb +++ b/.crumb @@ -108,14 +108,14 @@ } ], "children_root": "sha256:966bedb54caa4209f9ab84526da66f6b13ce72e8831470170364eb5881355748", - "compiled_at": "2026-11-07T01:16:11Z", + "compiled_at": "2026-11-07T01:32:00Z", "compiler": "crumb-compile/1", - "digest": "sha256:23f04f134203b79c6a23a4a919ff8cabdad201cdfc009aacd015a5a2161655cb", - "evidence_files": 15692, - "evidence_root": "sha256:d5ed3ea012b2e0c044e102a546a22b37b5445a7d8d5de1f66a5ad2fff644362e", - "files": 24237, - "generated_at_commit": "1bd4f25909401ba2cfd9e561818bccfeef5be109", - "source_tree": "sha256:329ce05a25acb88aeb2550c894f6abb960a9bc0c40ad24d03eafb30f84643787" + "digest": "sha256:b8b162498d6f66bc04d8e8f2ce3acbb8011691c786dcbbfc86df34514cf7a243", + "evidence_files": 15693, + "evidence_root": "sha256:77cf0de3d8ab32ff961402f90ba77c1bea1668fccc67065aa1908f0211b3e478", + "files": 24241, + "generated_at_commit": "0618eeaee7361247eaae643d0a1d6fa4daa9e59f", + "source_tree": "sha256:f478b642fe4a810e6032f4c7eac3e37f85e8925b43625b450d99f36fb3ed5310" }, "owner_lane": "", "provenance": { diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4bd7d2bc8..18454a818 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -10,6 +10,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE | 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. | | Claude Opus 5.5 (via omp) | DRA-287 for `seed/node`: `sched.om`, a cooperative scheduler in which one creator owns admission, assignment, collection and review. Workers have topic subscriptions, and jobs can wait on dependency topics. Wake-ups are eventfd hints followed by a rescan, so none is lost. Admitted work and work in review have separate limits; a full review queue stops assignment instead of dropping results. A dead worker's job is rerun when marked safe, otherwise it becomes UNKNOWN. There is no hive-wide barrier. `node_count` added to `transport.om`. `sched-gate.om` runs a real-process acceptance test that measures idle CPU from `/proc` and checks exactly one wake per round over 200 publication rounds. It has eight negative controls. Native AArch64 host evidence only; not QUALIFIED on the Spark gate. | +| Claude Opus 5.5 (via omp) | DRA-288 for `seed/node`: `auth.om`, typed worker proposals decided and committed by the creator alone through the action records of `seed/authority/action.om` (one record per operation identity; a performed or UNKNOWN operation is never started again). Proposals are refused as malformed, not the current assignment, another incarnation, stale input, revoked authority or cancelled. Granted tools run as their own process group; cancellation, revocation, stop and worker death kill the whole group, and the outcome comes from the wait status, so a tool that already exited stays performed and a killed one stays UNKNOWN. Operator pause, cancel and revoke reach workers through a per-worker control eventfd with acknowledged seqs. `sched.om` gains `sched_pause` and `sched_cancel`. `auth-gate.om` runs real forked workers and `/bin/sh` tools through seven phases, with twelve negative 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-auth/receipt.2b986676bc06a020b62622ea839aafe7e044875895db66314c3553c565364259.json b/evidence/node-auth/receipt.2b986676bc06a020b62622ea839aafe7e044875895db66314c3553c565364259.json new file mode 100644 index 000000000..00039fdc5 --- /dev/null +++ b/evidence/node-auth/receipt.2b986676bc06a020b62622ea839aafe7e044875895db66314c3553c565364259.json @@ -0,0 +1,215 @@ +{ + "issue": "DRA-288", + "source_commit": "46807d35a7bc30f17764c8b6bf8a7bc815109678", + "source_tree": "8eb59f6ba8b9cb6d32b5c8d856cfdd25632dabdf", + "platform": "Linux 7.0.0-1019-nvidia aarch64 spark-b87b", + "cpu_affinity_mask_hex": "70000", + "execution": "NATIVE Linux AArch64 host CPU (DGX Spark host, no GPU opened)", + "timestamp_utc": "2026-11-07T01:31:55.163699+00:00", + "independent_review": false, + "native_aarch64": "PASS", + "spark_gate_judge": "NOT_RUN", + "live_hive": "NOT_DEPLOYED", + "script": "omega-node-288.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/auth-gate.om": "4fa565bb5110268f00346bc357847b513ec7d48525e569a4eac94b27e7dff8aa", + "seed/node/auth.om": "348893f04ac8fc6ed3d6ff385c5d4382862ab0998b6f91dc602cac3d806a35de", + "seed/node/auth-test.om": "af66c87f83d73a5bdbaf181378eb69bb0645a86fe9b39de2f1b714041fbc20b8", + "seed/node/pool-gate.om": "9354978875c6c3986d7bf0fa3977bf6e59e1fddebfd3fd3407083a4fc1a02339", + "seed/node/pool.om": "e7fba928bdc5c4194e7aee42109265de4f172d2b197946133d788b2dbcb30ccc", + "seed/node/pool-test.om": "7e18abdc5d0b377995e210aa336ba03a35d88af193d5387d5da3e8b0b6c01042", + "seed/node/sched-gate.om": "fbad2340b5dfb6cde909d922f153bbf5889ef4796500d31613462ac9b1d8385e", + "seed/node/sched.om": "9bd18158c0b574a9b7d22a54433157fb7216ab4f479c0dd12db2256870150b23", + "seed/node/sched-test.om": "29a3587d35a217403c63395eb2b11b4992727812af66512be3e452ea6381a545", + "seed/node/super.om": "d104ac8116c6df57fdc93f03791d7315e5b60875d8d6177480ef9967b6f53d5a", + "seed/node/transport-gate.om": "7f85aa57b064957734b8ab0a7b925390fcb50a9c657ba2bf08c26ce5b21377db", + "seed/node/transport.om": "d0dd69ef5e0b71294a2390b3526865d62ca07accd269b9ce57a028339e34f6da", + "seed/node/transport-test.om": "d00b22082c781c5300065faf321f9126a7801fc5b639dbfc47bd75798e5dbae9", + "seed/authority/action.om": "698aa7d6232837be9c4ba85ebb57d6c656aacb60ae9e703b0e4f11967562e5de" + }, + "checks": [ + { + "case": "transport-gate", + "compile_exit": 0, + "expected_exit": "0", + "run_exit": 0, + "wall_ms": 12, + "stdout": "PASS node transport\n", + "binary_sha256": "470aefe90345217aa16e9d6ac1de16b8db59566436b842c7a01cbaeee7812234", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "pool-gate", + "compile_exit": 0, + "expected_exit": "0", + "run_exit": 0, + "wall_ms": 2190, + "stdout": "stress rolls=2000 busy=89820 reads=5295 3656\nPASS node pool\n", + "binary_sha256": "afd1063c4e534ade5e798cd1b2ef576873ad51eab9d7a4c6a5a73f8b8c3ef5b4", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "sched-gate", + "compile_exit": 0, + "expected_exit": "0", + "run_exit": 0, + "wall_ms": 8031, + "stdout": "idle ticks workers=0 creator=0 wake rounds=200 mean_us=65 max_us=3482\nPASS node sched\n", + "binary_sha256": "68b835c0821b44582adbc08fdfdb3049531075699d7841f3df288e28098b0abb", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "auth-gate", + "compile_exit": 0, + "expected_exit": "0", + "run_exit": 0, + "wall_ms": 756, + "stdout": "PASS node authority\n", + "binary_sha256": "4dbaff2acc0d90f1e4a0c10d285c22de9959837de4940b56a642bb0d983f0abd", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am1_no_process_group", + "compile_exit": 0, + "expected_exit": "58", + "run_exit": 58, + "wall_ms": 3322, + "stdout": "", + "binary_sha256": "483340b3ce809478f428cdab9a96879c687bd2d953c2d7450f641a748d4dea20", + "verdict": "PASS", + "leaked_tool_processes_after_run": 1 + }, + { + "case": "am2_direct_kill_only", + "compile_exit": 0, + "expected_exit": "58", + "run_exit": 58, + "wall_ms": 3334, + "stdout": "", + "binary_sha256": "44fa8f6a4d80b7a084419d059a2b4bafa778c92026077562d6a58471cc03ff5b", + "verdict": "PASS", + "leaked_tool_processes_after_run": 1 + }, + { + "case": "am3_kill_means_unknown", + "compile_exit": 0, + "expected_exit": "85", + "run_exit": 85, + "wall_ms": 381, + "stdout": "", + "binary_sha256": "8acaaec9c1c79f263a7580a3a9326d6d0992d613b6d933c8d1809baf63c23590", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am4_stale_ignored", + "compile_exit": 0, + "expected_exit": "27", + "run_exit": 27, + "wall_ms": 45, + "stdout": "", + "binary_sha256": "b1e2480ea3456b4bb11cc6c7477dcb034aa702471bfc61c4adfd47cb16920e6a", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am5_generation_ignored", + "compile_exit": 0, + "expected_exit": "52", + "run_exit": 52, + "wall_ms": 100, + "stdout": "", + "binary_sha256": "194b600110618c7faf3f19aeba21bd5c9b99e1ab380b7e18d8e9107710ce66fa", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am6_incarnation_ignored", + "compile_exit": 0, + "expected_exit": "40", + "run_exit": 40, + "wall_ms": 90, + "stdout": "", + "binary_sha256": "0fee95587051019965fceccc1b393cf5d48b811d92f68f842d0450ece9d296fb", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am7_duplicate_performed", + "compile_exit": 0, + "expected_exit": "17", + "run_exit": 17, + "wall_ms": 25, + "stdout": "", + "binary_sha256": "435785140b4fee4e434750870925efcc80fa100c0f0ffbb28e69f944b39cccc3", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am8_revoke_no_cancel", + "compile_exit": 0, + "expected_exit": "55", + "run_exit": 55, + "wall_ms": 5099, + "stdout": "", + "binary_sha256": "d08cb2f3af98900dff5744fd5fadd5fc59d3018d3dc6833926759cfa82331da5", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am9_cancel_no_control", + "compile_exit": 0, + "expected_exit": "75", + "run_exit": 75, + "wall_ms": 5142, + "stdout": "", + "binary_sha256": "1f67fd216958537f431ad7066924be29dae5d1d3ac45e0ca70188431bbfc9400", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am10_lost_tool_not_killed", + "compile_exit": 0, + "expected_exit": "96", + "run_exit": 96, + "wall_ms": 3622, + "stdout": "", + "binary_sha256": "976f4dfa30120e350a099441b51590c81fa1702ab465d1434cfc5e84e30c5cd1", + "verdict": "PASS", + "leaked_tool_processes_after_run": 1 + }, + { + "case": "am11_decide_while_paused", + "compile_exit": 0, + "expected_exit": "120", + "run_exit": 120, + "wall_ms": 690, + "stdout": "", + "binary_sha256": "dd502d4726b81c7190db71a8f31ff9d238ad1791d6f4c88cc1ab22b2b68ead5b", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + }, + { + "case": "am12_dispatch_while_paused", + "compile_exit": 0, + "expected_exit": "121", + "run_exit": 121, + "wall_ms": 699, + "stdout": "", + "binary_sha256": "591fcbfdb91bb97e3ce0ad608ae80aaf871ff7717e8737e45f1a56d62a4474b6", + "verdict": "PASS", + "leaked_tool_processes_after_run": 0 + } + ], + "repeat": { + "gate": "auth-gate", + "runs": 30, + "passed": 30, + "per_run_lines": [] + } +} diff --git a/seed/node/.crumb b/seed/node/.crumb index ac5074d68..4585b6db2 100644 --- a/seed/node/.crumb +++ b/seed/node/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-11-07T01:10:07Z", + "compiled_at": "2026-11-07T01:30:29Z", "compiler": "crumb-compile/1", - "digest": "sha256:e52fc91f8a2e8a4bf457e26fd7fd93b906bb716335db1335e626aad20cb8a997", + "digest": "sha256:c871461a27c9aa045f03fc205f6eef157c056f673cfcee5b4d785c258a071a44", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 11, - "generated_at_commit": "f413dcf5829f39335ba76180342539de5fe45136", - "source_tree": "sha256:eaed261729e028a56dd364b22b6e937247f398d323ddc411a9c2963d1b2fc1b8" + "files": 14, + "generated_at_commit": "5cab9c6f1f7311dbd9b98b1465b1e2c1de0128ed", + "source_tree": "sha256:e43493975c5e852732ccbf60d516f00570ac70a36ac9ed00644c1f4669694417" }, "owner_lane": "", "seed": { diff --git a/seed/node/README.md b/seed/node/README.md index 474905a19..e9786b535 100644 --- a/seed/node/README.md +++ b/seed/node/README.md @@ -1,4 +1,4 @@ -# Omega Node shared-memory transport, epoch pool, worker supervision and scheduling +# Omega Node shared-memory transport, epoch pool, worker supervision, scheduling and authority 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 @@ -322,7 +322,9 @@ several posts coalesce into one wake. | `sched_step c interval` | Creator loop: wait for an ack or death, take acks, retire reaped workers' jobs (`sched_lost`), collect, dispatch. | | `sched_dispatch c`, `sched_collect c` | Assign ready jobs to idle live workers; move finished results into review while there is room. | | `sched_lost c w` | After a reap: a rerunnable job is ready again (attempt + 1); any other job becomes UNKNOWN and is never run again. A finished result is still collected. | -| `sched_review j`, `sched_settle j` | Accept a reviewed result (returns its outcome) or release an UNKNOWN job whose outcome was settled elsewhere. DRA-288 replaces this with the authority commit. | +| `sched_review j`, `sched_settle j` | Accept a reviewed result (returns its outcome) or release an UNKNOWN job whose outcome was settled elsewhere. Effects are committed by `auth.om` (DRA-288); review only releases the job. | +| `sched_pause c on` | Pause (no job is assigned) or resume and dispatch. Returns the number dispatched. | +| `sched_cancel j` | 1 waiting or ready job freed, 2 running (the caller must tell its worker), 3 already in review, 4 UNKNOWN, -3 no such job. | | `sched_stop c interval` | `sup_stop`, then retire every reaped worker's job. | | `sched_wjob w`, `sched_wdone w q outcome src n`, `sched_wwait c w interval`, `sched_wscan c w` | Worker side: the pending assignment, the finish report (result, then outcome, then done seq, then ack), a wait that records wake latency, and a scan of subscribed versions in the held epoch. | @@ -355,3 +357,105 @@ The gate covers the following phases: | `sched.om`: delete `sc_set w 64 get scseq w` (dead worker's assignment not retired) | 92 | | `sched.om`: `put sjst j 1` to `put sjst j 2` (dependencies ignored) | 68 | | `super.om`: `iv = interval` to `iv = 0`, run with `idle` (workers spin) | 138 | + +## Proposals, authority and cancellation (DRA-288) + +Status: IMPLEMENTED in `auth.om`, exercised by `auth-gate.om` and the controls +below on native Linux AArch64, with real forked workers running real child +tools (`/bin/sh`). Evidence is in the DRA-288 pull request. + +```sh +cat seed/node/transport.om seed/node/pool.om seed/node/super.om seed/node/sched.om seed/authority/action.om seed/node/auth.om seed/node/auth-test.om > build/node/auth-composed.om +cmp build/node/auth-composed.om seed/node/auth-gate.om +seed/out/omc < seed/node/auth-gate.om > build/node/auth-gate +chmod +x build/node/auth-gate +timeout 120 build/node/auth-gate # ends "PASS node authority" +``` + +### Model + +A worker proposes; the creator alone decides and commits. Every effect is one +action record of `seed/authority/action.om`, keyed by its operation identity: +`actstart` when the creator grants it, `actrecon` with the worker's reported +outcome, `actlost` when the worker dies with it in flight. A performed +operation is never started again, and an UNKNOWN one is never retried (verdict +7); `actstart` enforces both, and the attempt limit (verdict 8). + +A proposal (words 0..15 of the worker's 4096-byte proposal page) is typed +(version 1, kind 1) and carries the job id and assignment seq, the worker +slot and incarnation, the input epoch and version it read, the authority +generation it holds, the 4-word operation identity and the effect class +(1 external effect, 2 none). The creator refuses it, in this order, when it +is malformed (1), not the worker's current assignment (2), from another +incarnation of the slot (3), stale (4: the input differs from the assignment, +the epoch was rolled, or a newer version was published on one of the job's +dependency topics), under a revoked generation (5), or for a job being +cancelled (6). A refused job finishes with outcome 16 + verdict. + +A granted tool runs as the leader of its own process group (both sides call +`setpgid`), stdin on `/dev/null`, output into the proposal page from byte 128. +Cancellation of its job, authority revocation, stop or creator loss make the +worker SIGKILL the whole group. The outcome comes from the wait status alone: +a tool that exited is performed (2), even if a cancel raced its exit; a killed +tool with an external effect is UNKNOWN (0); a killed class 2 tool is not +performed (1). Group members left behind are killed either way. If the worker +dies, the creator kills the tool group named in the worker's cell and records +the action UNKNOWN. + +Control reaches a worker through its own control eventfd, in addition to the +wake and stop eventfds, so a worker waiting for a decision or running a tool +handles it at once. Each control carries a seq the worker acknowledges, with +the paused flag it saw. Pause stops both assignment and decisions; running +tools go on. Revocation moves the generation on: pending proposals under the +old one are refused, running granted tools are cancelled, and a report already +made is still recorded as made. + +Control page cell of worker w (128 bytes at 128w). Creator words: 0 control +seq, 8 cancel target (assignment seq), 16 decided proposal seq, 24 verdict, +32 generation at the decision. Worker words: 64 control ack, 72 proposal seq, +80 report seq, 88 outcome, 96 tool wait status, 104 paused as seen, 112 tool +process group, 120 tool output bytes. Words 8192 and 8200 mirror the +generation and the paused flag. + +| Function | Contract | +| --- | --- | +| `auth_new c`, `auth_free` | Creator, after `sup_init` and before any spawn: map the control and proposal pages and one control eventfd per slot; generation 1. | +| `auth_spawn c w` | `sup_spawn` with a new incarnation of slot w. | +| `auth_step c` | After `sched_step`: record reports, close the actions of reaped workers (`actlost`, tool group killed), decide pending proposals unless paused. | +| `auth_revoke c`, `auth_pause c on`, `auth_cancel c j` | The operator controls: new generation; pause or resume; cancel a job (`sched_cancel`, then the worker's control for a running one). | +| `auth_act op i`, `auth_cell w off`, `auth_wout w dst` | Read an action record word, a control cell word, a worker's tool output. | +| `auth_propose w q op class`, `auth_wdecide c w q interval` | Worker: propose, then wait for the verdict while handling control. | +| `auth_wtool c w q pk pn class`, `auth_wreport w q outcome` | Worker: run the granted tool (packed argv as `execprog`), report its outcome. | +| `auth_wwait c w x interval`, `auth_wctl w` | Worker wait on wake, stop, creator loss, control and optionally fd x; the control handler (ack, paused, cancel target). | + +Limits: action records live in creator memory only, so a creator restart +loses them (DRA-289 adds the journal). Between a worker's death and the +creator's `auth_step` the tool's group id could in principle be reused; the +window is one creator step. At most 64 action records are live. + +### Acceptance and controls + +Job id = kind × 1000 + operation number. The gate covers the following +phases: +- A: a granted operation runs once and is performed; the same operation in a new job is refused (7) and its tool does not run again. +- B: a proposal is refused as stale (4) after a newer version on its dependency topic or an epoch roll; a newer version on another topic does not make it stale. +- C: forged incarnation, job id and version are refused (3, 2, 1) and no tool runs. +- D: revocation before the decision refuses (5). Revocation during a tool kills its grandchild and records UNKNOWN; the operation is then refused (7). Revocation after the tool reported still records performed. +- E: cancel before start frees the job with no action record. Cancel during a tool kills its grandchild and records UNKNOWN. Cancel in review changes nothing. A cancel 200 ms after the tool's own process exited, while its grandchild still held the output, records performed and still kills the grandchild. +- F: a worker killed mid-tool: the creator kills the tool's group and the action and job are UNKNOWN. +- G: pause is acknowledged by every worker within 1 s; while paused a pending proposal stays undecided and a ready job is not assigned; resume performs both. + +| Change | Expected exit | +| --- | --- | +| `auth.om`: delete both `setpgid` calls (no process group) | 58 | +| `auth.om`: `r = killpid neg int pid 9` to `r = killpid int pid 9` (direct kill only) | 58 | +| `auth.om`: a killed tool always reports UNKNOWN (`if k` / `ret 0` before `ret au_outcome st class`) | 85 | +| `auth.om`: `ret ne node_next h au_pw w 7 t 0` to `ret false` (newer input ignored) | 27 | +| `auth.om`: `if ne au_pw w 8 get augen 0` compares the proposal with itself (generation ignored) | 52 | +| `auth.om`: `if ne au_pw w 5 get auinc w` compares the proposal with itself (incarnation ignored) | 40 | +| `auth.om`: in `au_commit`, `k = au_find op` to `k = neg long 1` (duplicate performed) | 17 | +| `auth.om`: delete `au_ctl w au_cell w 16` in `auth_revoke` (running tools not cancelled) | 55 | +| `auth.om`: delete `au_ctl w sc_cell w 0` in `auth_cancel` (worker never told) | 75 | +| `auth.om`: delete `x = killpid neg int p 9` in `au_lost` (dead worker's tool left running) | 96 | +| `auth.om`: decide proposals while paused | 120 | +| `sched.om`: `if ne get scpause 0 0` to `if false` (assign while paused) | 121 | diff --git a/seed/node/auth-gate.om b/seed/node/auth-gate.om new file mode 100644 index 000000000..679722c7d --- /dev/null +++ b/seed/node/auth-gate.om @@ -0,0 +1,2920 @@ +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 The latest published version of the arena's current epoch (0 when empty). +fn node_count h long to ulong +ret mapget h 16 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 Omega Node cooperative scheduling (DRA-287). Concatenate after +note transport.om, pool.om and super.om, before one program with fn main. +note One creator admits, assigns, collects and reviews jobs. Workers never +note write each other's state, and no step waits for every worker. +note Scheduling page: one 128-byte cell per worker w at 128*w. +note Creator writes 0 assigned seq, 8 job id, 16 input epoch, 24 input +note version, 32 interest topics, 40 wake stamp (monons at the last post). +note Worker writes 64 done seq, 72 outcome, 80 wakes, 88 last wake latency +note ns, 96 largest wake latency ns. +note Outbox: worker w's result bytes at 4096*w of a second mapping, written +note before its done seq. Each word has one writer; the creator writes a +note worker word only after it has reaped that worker. +note Job states: 0 free, 1 waiting for deps, 2 ready, 3 running, 4 in review, +note 6 UNKNOWN (its worker died mid-job and the job is not safe to rerun). +const SJCAP ulong 64 +global scmap long 2 +global sclim ulong 2 +global sjst ulong 64 +global sjdep ulong 64 +global sjid ulong 64 +global sjw ulong 64 +global sjatt ulong 64 +global sjfl ulong 64 +global sjout ulong 64 +global scbusy ulong 64 +global scseq ulong 64 +global swcur ulong 2 +global scpause ulong 1 + +fn sc_cell w ulong off ulong to ulong +ret mapget get scmap 0 add mul w 128 off 8 +end + +fn sc_set w ulong off ulong v ulong to void +r = mapset get scmap 0 add mul w 128 off 8 v +end + +note Creator, before any fork: map the scheduling page and the outboxes and +note set the limits on admitted (a) and in-review (rl) jobs, each 1..64. +note Returns 0, -6 not creator, -7 bad limit, or a mapping errno. +fn sched_new c long a ulong rl ulong to long +if not pool_mine c +ret neg long 6 +end +if or eq a 0 gt a SJCAP +ret neg long 7 +end +if or eq rl 0 gt rl SJCAP +ret neg long 7 +end +s = mapnew neg int 1 0 8192 3 33 +if le s 0 +ret s +end +o = mapnew neg int 1 0 262144 3 33 +if le o 0 +r = mapdrop s +ret o +end +put scmap 0 s +put scmap 1 o +put sclim 0 a +put sclim 1 rl +for j ulong 64 +put sjst j 0 +put scbusy j 0 +put scseq j 0 +end +put scpause 0 0 +ret 0 +end + +note Creator: drop this process's scheduling mappings. +fn sched_free to long +r = mapdrop get scmap 1 +if lt r 0 +ret r +end +ret mapdrop get scmap 0 +end + +note Jobs whose state is in lo..hi. +fn sched_count lo ulong hi ulong to ulong +n = ulong 0 +for j ulong 64 +s = get sjst j +if and ge s lo le s hi +n = add n 1 +end +end +ret n +end + +note Creator: admit job id. deps 0 makes it ready at once; otherwise it waits +note for a publication whose topics meet deps. flags bit 0: safe to rerun +note after its worker dies. Returns the job slot, or -2 when admitted work +note (waiting, ready, running) is at its limit: refused, not queued. +fn sched_admit id ulong deps ulong flags ulong to long +if ge sched_count 1 3 get sclim 0 +ret neg long 2 +end +for j ulong 64 +if eq get sjst j 0 +put sjid j id +put sjdep j deps +put sjfl j flags +put sjatt j 0 +put sjout j 0 +put sjw j 0 +if eq deps 0 +put sjst j 2 +else +put sjst j 1 +end +ret long j +end +end +ret neg long 2 +end + +note Creator: worker w is woken by publications whose topics meet topics. +fn sched_want w ulong topics ulong to long +if ge w 64 +ret neg long 7 +end +sc_set w 32 topics +ret 0 +end + +fn sc_wake w ulong to void +sc_set w 40 ulong monons +r = sup_wake w +end + +note Creator: give ready jobs to idle live workers, lowest slot first. A +note worker is idle when the creator has collected its last assignment. +note The job id and the input epoch and version are written before the seq. +note Returns the number assigned. +fn sched_dispatch c long to ulong +if ne get scpause 0 0 +ret 0 +end +n = mapget c 48 8 +k = ulong 0 +for j ulong 64 +if eq get sjst j 2 +for w ulong n bound 64 +if and gt get swpid w 0 eq get scbusy w 0 +q = add get scseq w 1 +put scseq w q +put scbusy w add j 1 +put sjst j 3 +put sjw j w +put sjatt j add get sjatt j 1 +sc_set w 8 get sjid j +sc_set w 16 pool_epoch c +sc_set w 24 node_count pool_current c +sc_set w 0 q +sc_wake w +k = add k 1 +break +end +end +end +end +ret k +end + +note Creator: move finished jobs into review while review has room. A worker +note whose result is waiting for room keeps it and gets no new job, so a +note full review queue stops assignment instead of dropping work. +fn sched_collect c long to ulong +n = mapget c 48 8 +k = ulong 0 +for w ulong n bound 64 +b = get scbusy w +if gt b 0 +if eq sc_cell w 64 get scseq w +if ge sched_count 4 4 get sclim 1 +ret k +end +j = sub b 1 +put sjst j 4 +put sjout j sc_cell w 72 +put scbusy w 0 +k = add k 1 +end +end +end +ret k +end + +note Creator, after worker w was reaped: retire its unfinished assignment. +note A rerunnable job is ready again; any other becomes UNKNOWN (6), since +note it may have had effects. A finished result is left for sched_collect. +note Returns 1 when an assignment was retired, 0 when none, -16 still live. +fn sched_lost c long w ulong to long +if ge w 64 +ret neg long 7 +end +if gt get swpid w 0 +ret neg long 16 +end +b = get scbusy w +if eq b 0 +ret 0 +end +if eq sc_cell w 64 get scseq w +ret 0 +end +j = sub b 1 +sc_set w 64 get scseq w +put scbusy w 0 +if ne and get sjfl j 1 0 +put sjst j 2 +else +put sjst j 6 +end +ret 1 +end + +note Creator loop step: wait up to interval ns for an ack or a death, take +note acks, retire the jobs of reaped workers, collect, then dispatch. +note Returns the number of workers reaped, or a negative errno. +fn sched_step c long interval long to long +d = sup_poll c interval +if lt d 0 +ret d +end +n = mapget c 48 8 +for w ulong n bound 64 +if gt get swpid w 0 +r = sup_take get swack w +else +r = sched_lost c w +end +end +k = sched_collect c +k = sched_dispatch c +ret d +end + +note Creator: publish an artifact, make waiting jobs whose deps meet topics +note ready, wake each live worker whose interest meets topics, dispatch. +note Returns the version, or the publish refusal with nothing woken. +fn sched_publish c long topics ulong src view uchar 4096 n ulong to long +v = pool_publish c topics src n +if le v 0 +ret v +end +for j ulong 64 +if eq get sjst j 1 +if ne and get sjdep j topics 0 +put sjst j 2 +end +end +end +m = mapget c 48 8 +for w ulong m bound 64 +if gt get swpid w 0 +if ne and sc_cell w 32 topics 0 +sc_wake w +end +end +end +k = sched_dispatch c +ret v +end + +note Creator: accept the result of job j in review and free its slot. +note Returns its outcome, or -3 when j is not in review. +fn sched_review j ulong to long +if ge j 64 +ret neg long 3 +end +if ne get sjst j 4 +ret neg long 3 +end +put sjst j 0 +ret long get sjout j +end + +note Creator: free an UNKNOWN job once its outcome has been settled +note elsewhere. Returns 0, or -3 when j is not UNKNOWN. +fn sched_settle j ulong to long +if ge j 64 +ret neg long 3 +end +if ne get sjst j 6 +ret neg long 3 +end +put sjst j 0 +ret 0 +end + +note Creator: while paused (on true) no job is assigned; running jobs go on +note and finished results are still collected. Resuming dispatches at once. +note Returns the number assigned on resume, else 0. +fn sched_pause c long on bool to ulong +if on +put scpause 0 1 +ret 0 +end +put scpause 0 0 +ret sched_dispatch c +end + +note Creator: cancel job j. A waiting or ready job never started, so it is +note freed with no effect: 1. A running job needs its worker: 2, and the +note outcome comes from the worker. A job in review already finished: 3, +note nothing is cancelled. UNKNOWN stays UNKNOWN: 4. -3 free or bad slot. +fn sched_cancel j ulong to long +if ge j 64 +ret neg long 3 +end +s = get sjst j +if or eq s 1 eq s 2 +put sjst j 0 +ret 1 +end +if eq s 3 +ret 2 +end +if eq s 4 +ret 3 +end +if eq s 6 +ret 4 +end +ret neg long 3 +end + +note Creator: stop every worker within interval ns (sup_stop), retire the +note assignments of the reaped workers, collect finished results. +note Returns how many workers had to be killed, or a refusal. +fn sched_stop c long interval long to long +k = sup_stop c interval +if lt k 0 +ret k +end +n = mapget c 48 8 +for w ulong n bound 64 +r = sched_lost c w +end +m = sched_collect c +ret k +end + +note Worker w: the assignment seq when a job is waiting, else 0. Job id, +note input epoch and input version are words 8, 16 and 24 of its cell. +fn sched_wjob w ulong to ulong +q = sc_cell w 0 +if gt q sc_cell w 64 +ret q +end +ret 0 +end + +note Worker w: finish assignment q with outcome and the first n (at most +note 4096) bytes of src. Bytes and outcome are written before the done seq; +note then the creator gets an ack. 0, -7 bad n, or the ack refusal. +fn sched_wdone w ulong q ulong outcome ulong src view uchar 4096 n ulong to long +if gt n 4096 +ret neg long 7 +end +if gt n 0 +r = mapwrite get scmap 1 mul w 4096 src 0 n +end +sc_set w 72 outcome +sc_set w 64 q +ret sup_ack w +end + +note Creator: copy worker w's last result bytes into dst. +fn sched_result w ulong dst edit uchar 4096 to long +ret mapread get scmap 1 mul w 4096 dst 0 4096 +end + +note Worker w: sup_wwait that records its wakes and wake latency. +fn sched_wwait c long w ulong interval long to long +r = sup_wwait c w interval +if eq r 1 +now = ulong monons +st = sc_cell w 40 +lat = ulong 0 +if gt now st +lat = sub now st +end +sc_set w 80 add sc_cell w 80 1 +sc_set w 88 lat +if gt lat sc_cell w 96 +sc_set w 96 lat +end +end +ret r +end + +note Worker w: count the versions of the current epoch that meet its +note interest and are newer than its cursor, moving the cursor past them. +note A new epoch restarts the cursor at 0. A worker with no interest scans +note nothing. Returns the count or a refusal. +fn sched_wscan c long w ulong to long +t = sc_cell w 32 +if eq t 0 +ret 0 +end +h = pool_acquire c w +if le h 0 +ret h +end +e = mapget c add 256 mul w 8 8 +if ne get swcur 0 e +put swcur 0 e +put swcur 1 0 +end +k = long 0 +for i ulong 65 +v = node_next h get swcur 1 t +if lt v 0 +r = pool_release c w +ret v +end +if eq v 0 +break +end +put swcur 1 ulong v +k = add k 1 +end +r = pool_release c w +ret k +end +note SPDX-License-Identifier: AGPL-3.0-only +note OM-CONTROL-659 action contract v1. See ../README.md for the trusted-caller boundary. +note No I/O, authority minting or persistence. Caller serializes and durably commits transitions. +note Record words 0..7: version,state,attempt,limit,generation,epoch,expiry,reserved. +note Words 8..31: operation,request,scope,provider,policy,grant identities, four words each. +note State 1 ready,2 in-flight,3 unknown,4 performed. No timeout implies not performed. + +fn actvalid r view ulong 32 to ulong +if ne get r 0 1 +ret 11 +end +if or lt get r 1 1 gt get r 1 4 +ret 12 +end +if or eq get r 3 0 gt get r 3 1024 +ret 12 +end +if gt get r 2 get r 3 +ret 12 +end +if and ne get r 1 1 eq get r 2 0 +ret 12 +end +if or eq get r 4 0 eq get r 5 0 +ret 12 +end +if or eq get r 6 0 ne get r 7 0 +ret 12 +end +for g ulong 6 +bits = ulong 0 +for j ulong 4 +bits = or bits get r add 8 add mul g 4 j +end +if eq bits 0 +ret 12 +end +end +ret 0 +end + +fn actbind r view ulong 32 c view ulong 32 to ulong +for g ulong 6 +diff = ulong 0 +for j ulong 4 +at = add 8 add mul g 4 j +diff = or diff xor get r at get c at +end +if ne diff 0 +ret add 40 g +end +end +ret 0 +end + +fn actauth r view ulong 32 c view ulong 32 to ulong +if ne get c 0 1 +ret 11 +end +if or ne get c 3 0 or ne get c 6 0 ne get c 7 0 +ret 12 +end +if ne get c 1 1 +ret 30 +end +if ne get r 4 get c 4 +ret 31 +end +if ne get r 5 get c 5 +ret 32 +end +if ge get c 2 get r 6 +ret 33 +end +ret actbind r c +end + +fn actstart r edit ulong 32 c view ulong 32 to ulong +err = actvalid r +if ne err 0 +ret err +end +if eq get r 1 3 +ret 21 +end +if eq get r 1 4 +ret 22 +end +if ne get r 1 1 +ret 20 +end +if ge get r 2 get r 3 +ret 23 +end +err = actauth r c +if ne err 0 +ret err +end +put r 2 add get r 2 1 +put r 1 2 +ret 0 +end + +fn actlost r edit ulong 32 to ulong +err = actvalid r +if ne err 0 +ret err +end +if eq get r 1 3 +ret 0 +end +if ne get r 1 2 +ret 20 +end +put r 1 3 +ret 0 +end + +note A trusted receipt maps outcome 0 unknown,1 definitely not performed,2 performed. +note Not-found or timeout is outcome 0 unless the provider proves absence and quiescence. +note Receipt words 2/3: exact attempt and verification=1. Words 6/7 must be zero. +note Recording an observed outcome is permitted after expiry; another attempt is not. +fn actrecon r edit ulong 32 s view ulong 32 to ulong +err = actvalid r +if ne err 0 +ret err +end +if not or eq get r 1 2 eq get r 1 3 +ret 20 +end +if ne get s 0 1 +ret 11 +end +if or gt get s 1 2 or ne get s 6 0 ne get s 7 0 +ret 12 +end +if ne get s 3 1 +ret 36 +end +if ne get s 2 get r 2 +ret 35 +end +if ne get s 4 get r 4 +ret 31 +end +if ne get s 5 get r 5 +ret 32 +end +err = actbind r s +if ne err 0 +ret err +end +if eq get s 1 0 +put r 1 3 +ret 21 +end +if eq get s 1 1 +put r 1 1 +else +put r 1 4 +end +ret 0 +end +note Omega Node proposals, authority and cancellation (DRA-288). Concatenate +note after transport.om, pool.om, super.om, sched.om and +note seed/authority/action.om, before one program with fn main. +note A worker proposes and the creator alone decides and commits. A proposal +note is typed and bound to its operation identity, the job id and +note assignment seq, the worker slot and incarnation, the input epoch and +note version it read, and the authority generation it holds. Every effect is +note one action record of seed/authority/action.om per operation identity: +note started with actstart, closed with actrecon or actlost. A performed +note operation is never started again and an UNKNOWN one is never retried. +note Control page (16384 bytes), cell of worker w at 128*w. Creator writes +note 0 control seq, 8 cancel target (assignment seq, 0 none), 16 decided +note proposal seq, 24 verdict, 32 generation at the decision. Worker +note writes 64 control ack seq, 72 proposal seq, 80 report seq, 88 report +note outcome, 96 tool wait status, 104 paused as last seen, 112 running tool +note pid (its process group), 120 tool output bytes held. Word 8192 mirrors +note the authority generation and 8200 the paused flag. +note Proposal page: 4096 bytes per worker at 4096*w. Words 0..15: 0 version +note 1, 1 kind 1, 2 job id, 3 assignment seq, 4 slot, 5 incarnation, 6 input +note epoch, 7 input version, 8 generation, 9..12 operation identity, 13 class +note (1 external effect, 2 no external effect), 14 and 15 zero. Bytes +note 128..4095 hold the running tool's output. +note Verdicts: 0 granted, 1 malformed, 2 not the worker's assignment, 3 other +note incarnation, 4 stale input, 5 stale authority, 6 cancelled, 7 already +note performed or UNKNOWN, 8 attempt limit, 9 refused by the action contract. +note Outcomes, as action.om receipts: 0 UNKNOWN, 1 not performed, 2 performed. +text audevnul "/dev/null" +global aumap long 2 +global auctl int 64 +global auinc ulong 64 +global augen ulong 1 +global aurec ulong 2048 +global auuse ulong 64 +global aujob ulong 64 +global aured ulong 64 +global aupf uchar 8 +global aufd int 1 + +fn au_cell w ulong off ulong to ulong +ret mapget get aumap 0 add mul w 128 off 8 +end + +fn au_set w ulong off ulong v ulong to void +r = mapset get aumap 0 add mul w 128 off 8 v +end + +fn au_pw w ulong i ulong to ulong +ret mapget get aumap 1 add mul w 4096 mul i 8 8 +end + +fn au_spw w ulong i ulong v ulong to void +r = mapset get aumap 1 add mul w 4096 mul i 8 8 v +end + +fn au_pfd off ulong to int +v = ulong get aupf off +v = or v shl ulong get aupf add off 1 8 +v = or v shl ulong get aupf add off 2 16 +v = or v shl ulong get aupf add off 3 24 +ret int v +end + +note Poll record at off; a negative fd keeps its bit pattern, so the kernel +note ignores that record. +fn au_lpfd p edit uchar 40 off ulong fd int to void +u = bitcast uint fd +for i ulong 4 +put p add off i uchar and shr u uint mul i 8 255 +end +put p add off 4 1 +end + +note Creator, after sup_init and before any spawn: map the control and +note proposal pages, one control eventfd per worker slot, generation 1. +note 0, -6 not creator, or a negative errno. +fn auth_new c long to long +if not pool_mine c +ret neg long 6 +end +a = mapnew neg int 1 0 16384 3 33 +if le a 0 +ret a +end +b = mapnew neg int 1 0 262144 3 33 +if le b 0 +r = mapdrop a +ret b +end +put aumap 0 a +put aumap 1 b +for i ulong 64 +put auctl i neg int 1 +put auinc i 0 +put auuse i 0 +put aujob i 0 +put aured i 0 +end +n = mapget c 48 8 +for i ulong n bound 64 +e = eventfd uint 0 +if lt e 0 +x = auth_free +ret e +end +put auctl i int e +end +put augen 0 1 +r = mapset a 8192 8 1 +r = mapset a 8200 8 0 +ret 0 +end + +note Creator: close the control eventfds and drop both pages. +fn auth_free to long +for i ulong 64 +if ge get auctl i 0 +r = fclose get auctl i +end +put auctl i neg int 1 +end +r = mapdrop get aumap 1 +if lt r 0 +ret r +end +ret mapdrop get aumap 0 +end + +note Creator: start a new incarnation of worker slot w (sup_spawn). The child +note inherits its incarnation number. 0 in the child, else as sup_spawn. +fn auth_spawn c long w ulong to long +if ge w 64 +ret neg long 7 +end +if ne get swpid w 0 +ret neg long 16 +end +put auinc w add get auinc w 1 +ret sup_spawn c w +end + +note Creator: post control to worker w. A nonzero target asks it to cancel +note that assignment. The state words go first, then the seq, then the hint. +fn au_ctl w ulong target ulong to void +if gt target 0 +au_set w 8 target +end +au_set w 0 add au_cell w 0 1 +r = node_notify get auctl w +end + +note Worker w: bounded control handler. Records the paused flag it saw and +note acknowledges the control seq; returns the cancel target (0 none). +fn auth_wctl w ulong to ulong +s = au_cell w 0 +au_set w 104 mapget get aumap 0 8200 8 +au_set w 64 s +ret au_cell w 8 +end + +note Worker w: wait up to interval ns. 3 creator gone, 2 stop, 4 control, +note 5 descriptor x readable or hung up (x negative: none), 1 work hint, +note 0 timeout, or a negative errno. Creator loss outranks stop, stop +note outranks control, control outranks output and work. Control and work +note hints are drained; reread the shared state after any return. +fn auth_wwait c long w ulong x int interval long to long +p = new uchar 40 0 +if ge w 64 +ret neg long 7 +end +iv = interval +if pool_stopped c +iv = long 0 +end +au_lpfd p 0 get swwake w +au_lpfd p 8 get swstop w +au_lpfd p 16 get swpar 0 +au_lpfd p 24 get auctl w +au_lpfd p 32 x +r = pollfds p 0 40 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 1 0 +r = node_drain get swstop w +ret 2 +end +if ne get p 30 0 +r = node_drain get auctl w +ret 4 +end +if ne get p 38 0 +ret 5 +end +if ne and get p 6 1 0 +r = node_drain get swwake w +ret 1 +end +ret 0 +end + +note Worker w: propose the effect of assignment q with operation identity +note op and class (1 external effect, 2 none). The words go first, then the +note proposal seq, then an ack to the creator. 0 or the ack refusal. +fn auth_propose w ulong q ulong op view ulong 4 class ulong to long +if ge w 64 +ret neg long 7 +end +au_spw w 0 1 +au_spw w 1 1 +au_spw w 2 sc_cell w 8 +au_spw w 3 q +au_spw w 4 w +au_spw w 5 get auinc w +au_spw w 6 sc_cell w 16 +au_spw w 7 sc_cell w 24 +au_spw w 8 mapget get aumap 0 8192 8 +for i ulong 4 +au_spw w add 9 i get op i +end +au_spw w 13 class +au_spw w 14 0 +au_spw w 15 0 +au_set w 72 q +ret sup_ack w +end + +note Worker w: wait up to interval ns for the decision on proposal q, +note handling control meanwhile. The verdict (0 granted), 102 stop, 103 +note creator gone, 110 no decision yet, or a negative errno. +fn auth_wdecide c long w ulong q ulong interval long to long +dl = add ulong monons ulong interval +for it ulong 100000000 +if eq au_cell w 16 q +ret long au_cell w 24 +end +now = ulong monons +if ge now dl +ret 110 +end +r = auth_wwait c w neg int 1 long sub dl now +if lt r 0 +ret r +end +if or eq r 2 eq r 3 +ret add 100 r +end +if eq r 4 +t = auth_wctl w +end +end +ret 110 +end + +note Worker w: fork the packed argv pk (pn bytes) as the leader of a new +note process group, stdin on /dev/null, stdout and stderr on a pipe whose +note read end is left in aufd. Both sides call setpgid, so the group exists +note before either side goes on. The pid, or a negative errno. +fn au_fork w ulong pk view uchar 4096 pn ulong to long +r = pipefds aupf 0 8 524288 +if lt r 0 +ret r +end +rfd = au_pfd 0 +wfd = au_pfd 4 +dn = fopen audevnul 0 len audevnul 524288 0 +pid = fork +if eq pid 0 +r = setpgid 0 0 +r = dupfd wfd 1 0 +r = dupfd wfd 2 0 +if ge dn 0 +r = dupfd int dn 0 0 +end +r = execprog pk 0 pn +exit 127 +end +r = fclose wfd +if ge dn 0 +r = fclose int dn +end +if lt pid 0 +r = fclose rfd +ret pid +end +r = setpgid int pid int pid +au_set w 120 0 +au_set w 112 ulong pid +put aufd 0 rfd +ret pid +end + +note Worker w: move available tool output into its proposal page from byte +note 128 (bytes past 4096 are dropped). false at end of file or on error. +fn au_out w ulong rfd int to bool +buf = new uchar 4096 0 +n = read rfd buf 0 4096 +if eq n 0 +ret false +end +if lt n 0 +ret or eq n neg long 4 eq n neg long 11 +end +k = au_cell w 120 +m = ulong n +if gt add k m 3968 +m = sub 3968 k +end +if gt m 0 +h = get aumap 1 +off = add mul w 4096 add 128 k +r = mapwrite h off buf 0 m +au_set w 120 add k m +end +ret true +end + +note Outcome of a reaped tool from its wait status: it exited, so it ran +note (2); it was killed or crashed, so an external effect is UNKNOWN (0) and +note a class 2 tool had none (1). +fn au_outcome st ulong class ulong to long +if eq and st 127 0 +ret 2 +end +if eq class 2 +ret 1 +end +ret 0 +end + +note Worker w: finish tool pid of assignment q. Without kill, wait for its +note exit while still obeying control. With kill, a tool that has already +note exited is not cancelled; otherwise SIGKILL its whole group. Its wait +note status alone decides the outcome, never the fact that a kill was sent. +note Group members left behind are killed either way. +fn au_end c long w ulong q ulong pid long class ulong kill bool to long +ws = new uchar 4 0 +k = kill +g = long 0 +if not k +for it ulong 100000000 +g = waitpid int pid ws 0 4 1 +if ne g 0 +break +end +r = auth_wwait c w neg int 1 5000000 +if eq r 4 +if eq auth_wctl w q +k = true +break +end +end +if or eq r 2 eq r 3 +k = true +break +end +end +end +if k +g = waitpid int pid ws 0 4 1 +end +if eq g 0 +r = killpid neg int pid 9 +if lt r 0 +r = killpid int pid 9 +end +g = waitpid int pid ws 0 4 0 +else +r = killpid neg int pid 9 +end +r = fclose get aufd 0 +put aufd 0 neg int 1 +au_set w 112 0 +if lt g 0 +au_set w 96 65535 +ret 0 +end +st = or ulong get ws 0 shl ulong get ws 1 8 +au_set w 96 st +ret au_outcome st class +end + +note Worker w: run the granted tool pk of assignment q (see au_fork). Its +note output goes to the proposal page; cancellation of q, stop or creator +note loss kill its process group. Returns the outcome: 1 when q was +note cancelled before the tool started or the fork failed, else from +note au_end. The wait status is in cell word 96. +fn auth_wtool c long w ulong q ulong pk view uchar 4096 pn ulong class ulong to long +if eq auth_wctl w q +ret 1 +end +pid = au_fork w pk pn +if le pid 0 +ret 1 +end +rfd = get aufd 0 +for it ulong 100000000 +r = auth_wwait c w rfd 1000000000 +if eq r 5 +if not au_out w rfd +ret au_end c w q pid class false +end +end +if eq r 4 +if eq auth_wctl w q +ret au_end c w q pid class true +end +end +if or eq r 2 eq r 3 +ret au_end c w q pid class true +end +if lt r 0 +ret au_end c w q pid class true +end +end +ret au_end c w q pid class true +end + +note Worker w: report the outcome of the granted tool of assignment q. +fn auth_wreport w ulong q ulong outcome ulong to long +au_set w 88 outcome +au_set w 80 q +ret sup_ack w +end + +note Creator: the action slot whose operation identity is op, or -1. +fn au_find op view ulong 4 to long +for k ulong 64 +if ne get auuse k 0 +m = true +for i ulong 4 +if ne get aurec add mul k 32 add 8 i get op i +m = false +end +end +if m +ret long k +end +end +end +ret neg long 1 +end + +note Creator: a new ready action record for op and class in a free slot, +note bound to the current generation; -1 when all 64 are in use. +note Identities: operation and request op, scope node, provider class, +note policy 1, grant 1. Attempt limit 3, epoch 1, no expiry in practice. +fn au_alloc op view ulong 4 class ulong to long +for k ulong 64 +if eq get auuse k 0 +b = mul k 32 +for i ulong 32 +put aurec add b i 0 +end +put aurec b 1 +put aurec add b 1 1 +put aurec add b 3 3 +put aurec add b 4 get augen 0 +put aurec add b 5 1 +put aurec add b 6 9223372036854775807 +for i ulong 4 +put aurec add b add 8 i get op i +put aurec add b add 12 i get op i +end +put aurec add b 16 1313817669 +put aurec add b 20 class +put aurec add b 24 1 +put aurec add b 28 1 +put auuse k 1 +ret long k +end +end +ret neg long 1 +end + +fn au_load k ulong r edit ulong 32 to void +for i ulong 32 +put r i get aurec add mul k 32 i +end +end + +fn au_save k ulong r view ulong 32 to void +for i ulong 32 +put aurec add mul k 32 i get r i +end +end + +note Creator: commit the start of the operation proposed by worker w. +note A ready record moves to the current generation; actstart checks the +note state, the attempt limit and the credential. The verdict. +fn au_commit w ulong to ulong +op = new ulong 4 0 +r = new ulong 32 0 +cr = new ulong 32 0 +for i ulong 4 +put op i au_pw w add 9 i +end +k = au_find op +if lt k 0 +k = au_alloc op au_pw w 13 +if lt k 0 +ret 9 +end +end +au_load ulong k r +if and eq get r 1 1 ne get r 4 get augen 0 +put r 4 get augen 0 +end +for i ulong 32 +put cr i get r i +end +put cr 1 1 +put cr 2 1 +put cr 3 0 +put cr 4 get augen 0 +put cr 6 0 +put cr 7 0 +e = actstart r cr +if eq e 0 +au_save ulong k r +put aujob w add ulong k 1 +ret 0 +end +if or eq e 21 eq e 22 +ret 7 +end +if eq e 23 +ret 8 +end +if eq e 31 +ret 5 +end +ret 9 +end + +note Creator: a proposal is stale when the input it read is not the +note assignment's, its epoch is no longer current, or a newer version on the +note job's dependency topics has been published since. +fn au_stale c long w ulong j ulong to bool +if ne au_pw w 6 sc_cell w 16 +ret true +end +if ne au_pw w 7 sc_cell w 24 +ret true +end +if ne au_pw w 6 pool_epoch c +ret true +end +t = get sjdep j +if eq t 0 +ret false +end +h = pool_current c +if le h 0 +ret true +end +ret ne node_next h au_pw w 7 t 0 +end + +note Creator: check the pending proposal of worker w; the verdict. +fn au_valid c long w ulong to ulong +q = au_cell w 72 +if or ne au_pw w 0 1 ne au_pw w 1 1 +ret 1 +end +cl = au_pw w 13 +if or eq cl 0 gt cl 2 +ret 1 +end +if or ne au_pw w 14 0 ne au_pw w 15 0 +ret 1 +end +b = get scbusy w +if eq b 0 +ret 2 +end +j = sub b 1 +if ne get sjst j 3 +ret 2 +end +if or ne au_pw w 3 q ne q sc_cell w 0 +ret 2 +end +if or ne au_pw w 2 get sjid j ne au_pw w 4 w +ret 2 +end +if ne au_pw w 5 get auinc w +ret 3 +end +if au_stale c w j +ret 4 +end +if ne au_pw w 8 get augen 0 +ret 5 +end +if eq au_cell w 8 q +ret 6 +end +ret 0 +end + +fn au_decide c long w ulong to void +q = au_cell w 72 +v = au_valid c w +if eq v 0 +v = au_commit w +end +au_set w 24 v +au_set w 32 get augen 0 +au_set w 16 q +r = sup_wake w +end + +note Creator: apply receipt outcome o to action slot k (actrecon). An +note outcome of 0 leaves the action UNKNOWN. +fn au_recon k ulong o ulong to ulong +r = new ulong 32 0 +s = new ulong 32 0 +au_load k r +for i ulong 32 +put s i get r i +end +put s 0 1 +put s 1 o +put s 3 1 +put s 6 0 +put s 7 0 +e = actrecon r s +au_save k r +ret e +end + +fn au_record w ulong to void +put aured w au_cell w 80 +b = get aujob w +if eq b 0 +ret +end +put aujob w 0 +e = au_recon sub b 1 au_cell w 88 +end + +note Creator, after worker w was reaped: kill the process group of a tool +note it left running and make its in-flight action UNKNOWN (actlost). +fn au_lost w ulong to void +r = new ulong 32 0 +p = au_cell w 112 +if gt p 0 +x = killpid neg int p 9 +au_set w 112 0 +end +b = get aujob w +if eq b 0 +ret +end +put aujob w 0 +k = sub b 1 +au_load k r +e = actlost r +au_save k r +end + +note Creator, after sched_step: record tool reports, close the actions of +note reaped workers, and decide pending proposals unless paused. Returns +note the number of proposals decided. +fn auth_step c long to ulong +n = mapget c 48 8 +k = ulong 0 +for w ulong n bound 64 +if gt au_cell w 80 get aured w +au_record w +end +if gt get swpid w 0 +if and eq get scpause 0 0 gt au_cell w 72 au_cell w 16 +au_decide c w +k = add k 1 +end +else +au_lost w +end +end +ret k +end + +note Creator: revoke the current authority. The generation moves on, so a +note pending or later proposal made under the old one is refused (5), and +note every granted tool still running is told to cancel. Its outcome is +note recorded as reported: performed if it had already exited, UNKNOWN if +note it was killed. Returns the new generation. +fn auth_revoke c long to ulong +g = add get augen 0 1 +put augen 0 g +r = mapset get aumap 0 8192 8 g +n = mapget c 48 8 +for w ulong n bound 64 +if and gt get swpid w 0 gt get aujob w 0 +au_ctl w au_cell w 16 +end +end +ret g +end + +note Creator: pause (on true) or resume. While paused no job is assigned and +note no proposal is decided; running tools go on. Every live worker gets a +note control notification and acknowledges it. Returns sched_pause's count. +fn auth_pause c long on bool to ulong +v = ulong 0 +if on +v = 1 +end +r = mapset get aumap 0 8200 8 v +n = mapget c 48 8 +for w ulong n bound 64 +if gt get swpid w 0 +au_ctl w 0 +end +end +ret sched_pause c on +end + +note Creator: cancel job j. 1 freed before it started (no effect), 2 its +note worker was told to cancel and the outcome comes from its report (a +note pending proposal is refused with 6), 3 already finished, 4 UNKNOWN, +note -3 no such job. +fn auth_cancel c long j ulong to long +s = sched_cancel j +if eq s 2 +w = get sjw j +au_ctl w sc_cell w 0 +end +ret s +end + +note Creator: word i (0..31) of the action record for op, or -1 if none. +fn auth_act op view ulong 4 i ulong to long +k = au_find op +if or lt k 0 gt i 31 +ret neg long 1 +end +ret long get aurec add mul ulong k 32 i +end + +note Worker w's control or proposal cell word, for the creator's view. +fn auth_cell w ulong off ulong to ulong +ret au_cell w off +end + +note Copy up to 3968 bytes of worker w's tool output into dst; the count. +fn auth_wout w ulong dst edit uchar 4096 to ulong +n = au_cell w 120 +if gt n 3968 +n = 3968 +end +if gt n 0 +r = mapread get aumap 1 add mul w 4096 128 dst 0 n +end +ret n +end +note Concatenate after transport.om, pool.om, super.om, sched.om, +note seed/authority/action.om and auth.om. CPU-only acceptance of DRA-288 +note with real forked workers running real child tools (/bin/sh): granted +note and duplicate operations, stale input, forged proposals, revocation +note before, during and after a tool, cancellation before, during, after and +note racing a tool's exit, worker death mid-tool, pause and resume. +note A job id is kind*1000 + op. Kind 1 runs "echo ok", kind 2 starts a +note 30 s grandchild and prints its pid, kind 5 exits at once and leaves a +note 1 s grandchild holding its output. Outcome 16+v reports verdict v. +text tsh "/bin/sh" +text tdc "-c" +text tk1 "echo ok" +text tk2 "/bin/sleep 30 & echo $!; wait" +text tk5 "/bin/sleep 1 & exit 0" +text sok "PASS node authority\n" +text sproc "/proc/" +text sstat "/stat" +global atc long 1 +global atm long 1 + +fn at_ok ok bool code int to void +if not ok +exit code +end +end + +note Append text k (0 tsh, 1 tdc, 2 tk1, 3 tk2, 4 tk5) to the packed list. +fn at_arg pk edit uchar 4096 w ulong k ulong to ulong +m = len tsh +if eq k 1 +m = len tdc +end +if eq k 2 +m = len tk1 +end +if eq k 3 +m = len tk2 +end +if eq k 4 +m = len tk5 +end +put pk w uchar and m 255 +put pk add w 1 uchar shr m 8 +for j ulong m bound 64 +b = get tsh 0 +if eq k 0 +b = get tsh j +end +if eq k 1 +b = get tdc j +end +if eq k 2 +b = get tk1 j +end +if eq k 3 +b = get tk2 j +end +if eq k 4 +b = get tk5 j +end +put pk add add w 2 j b +end +ret add add w 2 m +end + +note Packed argv of tool kind: /bin/sh -c