diff --git a/.crumb b/.crumb index 55ed66ea6..11c93e5fe 100644 --- a/.crumb +++ b/.crumb @@ -42,80 +42,80 @@ "children": [ { "digest": "d02ccdb9f25b2635898d1a3fd8d106aca15bddca6bfaade71399029649caee39", - "last_commit": "ec863f90a", + "last_commit": "ec863f90", "name": "calibration", "purpose": "Directory calibration. Purpose not yet described by a human." }, { "digest": "7ea98a34750464c170bc103e362495ca893b72a7fae9baf192ad8b2606a9551f", - "last_commit": "369f3d486", + "last_commit": "369f3d48", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { "digest": "536f7b8db9a92a1f586bad4379d47544a30d1b8e83c2d799c18e66cf8660c9ae", - "last_commit": "30bb116cc", + "last_commit": "30bb116c", "name": "doctrine", "purpose": "Directory doctrine. Purpose not yet described by a human." }, { "digest": "0eca875ed53fd537a25d261ea2a45e5b62796c384263a38b41adca96cad2dcc2", - "last_commit": "c3c81ac3d", + "last_commit": "c3c81ac3", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, { "digest": "f021abf0e52c893181d2ed09ab0eb9ba5cc957f156b202ae8fdd8ef517b0b257", - "last_commit": "4c71fa37f", + "last_commit": "4c71fa37", "name": "native", "purpose": "Handwritten .om units of omega-mv that are not part of the seed ladder: the ORIG-4 shadow adviso" }, { "digest": "d5116e0cfc02b5ca8f6d5f356f3fc73fd3b1d004fde08fbcf7ef33218577892f", - "last_commit": "e03dfc08c", + "last_commit": "e03dfc08", "name": "neuralese", "purpose": "Bounded untrusted representation envelopes and explicit checked Omega decoding; learned extensio" }, { "digest": "16bd56102894984869d56d0ee92a56ccc51adf6d28ce2be40c39b3b35a3dd0c1", - "last_commit": "bd77148a4", + "last_commit": "bd77148a", "name": "research", "purpose": "Directory research. Purpose not yet described by a human." }, { "digest": "8d9d663ec19165545390b63f7227c6a6934cf3d48f2682a7453080e36e3c9f78", - "last_commit": "9b3d3b964", + "last_commit": "9b3d3b96", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { "digest": "c6ae05f5ca8e295aa12ea3c4ab5143a799adfd377ab40803d9cf5cfe75ea47c9", - "last_commit": "4c71fa37f", + "last_commit": "4c71fa37", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { "digest": "ceecc4d1134cb0e9e54e421676ae51f20fa8928012a137d018746282059f4833", - "last_commit": "874373ad3", + "last_commit": "874373ad", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "d6be5b5d49d6a2946754e459987f094e5fccc5cbd597f269b9c8423e2c29e283", - "last_commit": "6b0682a4f", + "last_commit": "6b0682a4", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], "children_root": "sha256:966bedb54caa4209f9ab84526da66f6b13ce72e8831470170364eb5881355748", - "compiled_at": "2026-11-06T23:34:58Z", + "compiled_at": "2026-11-07T00:26:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:f10cbff0a889dc2c51161a4d34d6410d144d00e0858a919dd5715966e9dfbe0f", - "evidence_files": 15689, - "evidence_root": "sha256:000da5d93352095d76c788394310aeee389738a37a0ff2b48cd2a85b664bbb74", - "files": 24223, - "generated_at_commit": "da6e6ca001755cbf16033f4ff5d1e00b734d7a92", - "source_tree": "sha256:ebf3f8080a543dd356d3d38082843fdff2e1b814b3b267eccaa9608fcd789eed" + "digest": "sha256:31ec1e1de3c1207374722f27c73f8b9f96c26203f71e0f11bfb6f8175b702c76", + "evidence_files": 15690, + "evidence_root": "sha256:60f0de6749e3c0e4fe16b543fc8937fc2771c8681029fdf5a11eaa34015baa78", + "files": 24228, + "generated_at_commit": "c16a2a46ad188fe6d3a361c928c91cca4709e593", + "source_tree": "sha256:0b1acc8ae544c2770c48cb3614db6ad778ded73acc88ba2bdd7b44dd2d0dad45" }, "owner_lane": "", "provenance": { diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 618d4f954..56f7d7bfd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -7,6 +7,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE | Model | What it did | |---|---| +| Codex (OpenAI, ChatGPT Work Mode) | Implemented `seed/node` bounded shared-memory artifact transport in seeded Omega: immutable publication, topic cursors, per-worker eventfd hints, stop priority, and forked-process acceptance with negative controls. Native AArch64 qualification remains pending. | | 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-transport/receipt.bb5d1219bf456fb50484a7d256c888074b92fc2ff8dbfe6dc8a2b042af2bc23e.json b/evidence/node-transport/receipt.bb5d1219bf456fb50484a7d256c888074b92fc2ff8dbfe6dc8a2b042af2bc23e.json new file mode 100644 index 000000000..41fb8c075 --- /dev/null +++ b/evidence/node-transport/receipt.bb5d1219bf456fb50484a7d256c888074b92fc2ff8dbfe6dc8a2b042af2bc23e.json @@ -0,0 +1,123 @@ +{ + "source_commit": "c16a2a46ad188fe6d3a361c928c91cca4709e593", + "source_tree": "6eacf9e1138d5aa493bb7b4ad5ae1e7ac61b24db", + "platform": "x86_64", + "execution": "EMULATED Linux AArch64 under qemu-user", + "timestamp_utc": "2026-11-07T00:26:28.711793+00:00", + "independent_review": false, + "native_aarch64": "NOT_RUN", + "live_hive": "NOT_DEPLOYED", + "hashes": { + "seed/out/omc": "5f90edea61bac241398df5036990d899361a5acd9decb37954ce088ec0f6f6df", + "seed/node/transport.om": "8a11215b1ee793515101cd0f023c2bd0022947da6372bb6206d391368799acad", + "seed/node/transport-test.om": "d00b22082c781c5300065faf321f9126a7801fc5b639dbfc47bd75798e5dbae9", + "seed/node/transport-gate.om": "54989dc8cf26695be42f68f14137b696dbacdfdfb2945bd3ae1bf0335013d5ea" + }, + "checks": [ + { + "case": "positive", + "compile_command": "qemu-aarch64-static seed/out/omc < positive.om > positive", + "compile_exit": 0, + "compile_stderr": "", + "expected_exit": 0, + "run_command": "timeout 30 qemu-aarch64-static positive", + "run_exit": 0, + "stdout": "PASS node transport\n", + "stderr": "", + "binary_sha256": "ebb60f0cd90b8ba71586add190cd87d9612ee808c116cc744f5f2b20e5d6d7fa", + "verdict": "PASS" + }, + { + "case": "private-map", + "compile_command": "qemu-aarch64-static seed/out/omc < private-map.om > private-map", + "compile_exit": 0, + "compile_stderr": "", + "expected_exit": 87, + "run_command": "timeout 30 qemu-aarch64-static private-map", + "run_exit": 87, + "stdout": "", + "stderr": "", + "binary_sha256": "9134b48549c8551e5d296149c38338ffcc56d48ce54178ca120bb1a158642c07", + "verdict": "PASS" + }, + { + "case": "skip-record-version", + "compile_command": "qemu-aarch64-static seed/out/omc < skip-record-version.om > skip-record-version", + "compile_exit": 0, + "compile_stderr": "", + "expected_exit": 33, + "run_command": "timeout 30 qemu-aarch64-static skip-record-version", + "run_exit": 33, + "stdout": "", + "stderr": "", + "binary_sha256": "1816bbd0b1a674701ec1b05462851fb571434c94acf21bc5ad088732a85cb05c", + "verdict": "PASS" + }, + { + "case": "ignore-topics", + "compile_command": "qemu-aarch64-static seed/out/omc < ignore-topics.om > ignore-topics", + "compile_exit": 0, + "compile_stderr": "", + "expected_exit": 21, + "run_command": "timeout 30 qemu-aarch64-static ignore-topics", + "run_exit": 21, + "stdout": "", + "stderr": "", + "binary_sha256": "11484db0606ab0e94265a5f517bd959d4c444824074c0e71e3762eff2ee62521", + "verdict": "PASS" + }, + { + "case": "stop-as-work", + "compile_command": "qemu-aarch64-static seed/out/omc < stop-as-work.om > stop-as-work", + "compile_exit": 0, + "compile_stderr": "", + "expected_exit": 55, + "run_command": "timeout 30 qemu-aarch64-static stop-as-work", + "run_exit": 55, + "stdout": "", + "stderr": "", + "binary_sha256": "4055ceb8bd8ad80be92d6b8c2f23a5b80eb36f98beb9ab8b20167a5dab1bc561", + "verdict": "PASS" + }, + { + "case": "wrong-owner", + "compile_command": "qemu-aarch64-static seed/out/omc < wrong-owner.om > wrong-owner", + "compile_exit": 0, + "compile_stderr": "", + "expected_exit": 87, + "run_command": "timeout 30 qemu-aarch64-static wrong-owner", + "run_exit": 87, + "stdout": "", + "stderr": "", + "binary_sha256": "d2fc75a77d6880530becd4a4c3dd0383402062e02a808f4e8ba237f4eba0c3dc", + "verdict": "PASS" + }, + { + "case": "crumb-verify", + "command": "bash tests/gates/run.sh crumb-verify", + "exit": 0, + "stdout": "AIEN-OBS crumb_tool_commit \"d0f0b95d344b4c6628c3d868346932fd247ce168\"\ncrumb verify: OK: 189 crumbs current\n", + "stderr": "", + "verdict": "PASS" + }, + { + "case": "evidence-immutable", + "command": "bash tests/gates/run.sh evidence-immutable", + "exit": 0, + "stdout": "AIEN-OBS base_ref \"7caba0c0094628b384abf8961a33bd95ae9412cc\"\nAIEN-OBS evidence_rewrites 0\nevidence/: additions only\n", + "stderr": "", + "verdict": "PASS" + }, + { + "case": "zero-disk-secrets", + "command": "bash tests/gates/run.sh zero-disk-secrets", + "exit": 0, + "stdout": "Auditing repository for prohibited plaintext secret files...\nAIEN-OBS env_files_found false\nZero plaintext .env files verified.\n", + "stderr": "", + "verdict": "PASS" + } + ], + "qemu_version": "qemu-aarch64 version 7.2.0 (Debian 1:7.2+dfsg-1~bpo11+2)", + "qemu_sha256": "dce64b2dc6b005485c7aa735a7ea39cb0006bf7e5badc28b324b2cd0c73d883f", + "composition": "PASS: gate is byte-for-byte transport.om + transport-test.om" +} diff --git a/seed/node/.crumb b/seed/node/.crumb new file mode 100644 index 000000000..59a45dfc7 --- /dev/null +++ b/seed/node/.crumb @@ -0,0 +1,30 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-11-07T00:26:14Z", + "compiler": "crumb-compile/1", + "digest": "sha256:61e5171c98e0586ad53b86c252d060a1c8d5f4a3cf6cfccd342643e0be620c79", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 4, + "generated_at_commit": "4ae618ff343da29dd68b0d17712e1133adaf15c1", + "source_tree": "sha256:76ff8fc8a4aad581b9f5b12b053f4c85f2c25ea275a42055cbeea1d4c364347a" + }, + "owner_lane": "", + "seed": { + "files": [ + "README.md", + "transport-gate.om", + "transport-test.om", + "transport.om" + ], + "purpose_auto": "Repository root node. Purpose not yet described by a human." + } + }, + "layer": "seed", + "name": "node", + "purpose": "Bounded shared-memory artifact transport for cooperative Omega workers", + "schema_version": "1.0.0" +} diff --git a/seed/node/README.md b/seed/node/README.md new file mode 100644 index 000000000..0bac2b18a --- /dev/null +++ b/seed/node/README.md @@ -0,0 +1,154 @@ +# Omega Node shared-memory transport + +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 +processes. Runtime consumers can share artifact storage and wake only interested +workers. The existing `seed/agent/agent.om` is the coding-agent consumer to evaluate +for integration; this change does not replace its model or tool dispatcher. + +The component is not yet connected to the live hive. Persistent recovery, +authority integration, worker supervision, epoch rollover, a dashboard and a real +model-backed coding workflow remain implementation work. The +[Linear project](https://linear.app/drake-stapleton/project/omega-node-shared-memory-hive-runtime-37058a1eac4b) +tracks that integration. This is a component contract, not a whole-system master plan. + +## Build and check + +Use a Linux AArch64 host and the existing approved seeded compiler. Record its +hash independently before rebuilding. The source baseline used here is +`7caba0c0094628b384abf8961a33bd95ae9412cc`, with `seed/out/omc` SHA-256 +`5f90edea61bac241398df5036990d899361a5acd9decb37954ce088ec0f6f6df`. + +`transport-gate.om` is the exact byte concatenation of `transport.om` followed by +`transport-test.om`. No separators, headers or substitutions are inserted. Verify +that correspondence before compiling, and stop if any command fails: + +```sh +mkdir -p build/node +cat seed/node/transport.om seed/node/transport-test.om > build/node/composed.om +cmp build/node/composed.om seed/node/transport-gate.om +sha256sum seed/out/omc +seed/out/omc < seed/node/transport-gate.om > build/node/transport-gate +readelf -h build/node/transport-gate +chmod +x build/node/transport-gate +timeout 30 build/node/transport-gate +``` + +Expected: `PASS node transport`, exit 0. A failed compile, signal, timeout or trap +is not a passing refusal test. The test forks real OS processes, uses anonymous +shared mappings and eventfds, and opens no GPU, model endpoint or network socket. +Use a disposable checkout. The standard `crumb-verify`, `evidence-immutable` and +`zero-disk-secrets` gates also apply. The native seed gate remains required before +qualification; an emulated component pass does not replace it. + +For an explicitly labelled emulated development check on x86, run the existing +AArch64 compiler and its accepted ELF output through `qemu-aarch64-static`: + +```sh +qemu-aarch64-static seed/out/omc < seed/node/transport-gate.om > build/node/transport-gate +readelf -h build/node/transport-gate +chmod +x build/node/transport-gate +timeout 30 qemu-aarch64-static build/node/transport-gate +``` + +## Contract and ownership + +`transport.om` is a source fragment. Concatenate it before one consumer containing +`fn main`. It adds no compiler word or hidden runtime dependency. + +| Function | Contract | +| --- | --- | +| `node_new` | Positive mapping handle, or negative OS error. Call before fork. Records creator PID. | +| `node_publish h topics src n` | Creator only; copies up to 4096 bytes from a fixed 4096-byte view. Returns new version or negative refusal. Nonzero 64-bit topic mask. | +| `node_next h cursor topics` | Next matching version greater than cursor; zero if none currently published; negative refusal on invalid input. | +| `node_read h version dst` | Copies immutable bytes to a fixed 4096-byte destination; returns length. Bytes beyond that length are unchanged. | +| `node_stop h` | Creator sets a sticky stop flag. Does not itself wake blocked workers or cancel external effects. | +| `node_notify fd` | Adds a wake hint to one nonblocking eventfd; zero on success or saturation, negative error otherwise. | +| `node_drain fd` | Consumes a coalesced hint; an already empty descriptor is harmless. | +| `node_wait h wake stop interval` | Waits on distinct nonnegative descriptors. Returns 2 for stop, 1 for work hint, 0 for timeout, negative error otherwise. Interval is nanoseconds; negative means infinite. | + +All handles must be live handles from `node_new`, and descriptors must remain +owned and open throughout the call. Invalid mapping handles trap in the compiler +runtime. These API checks do not turn writable shared memory into an isolation +boundary. Only trusted transport code receives the mapping. Untrusted tool +processes must use validated proposals through the existing authority owner. + +Transport refusal codes are local to this API. Eventfd and polling helpers return +Linux-style negative errors. Record APIs return the refusal meanings documented +in the source; callers must interpret the result in the context of the operation. + +The creator PID check catches accidental publication or stop from a forked worker. +It is not authentication, crash fencing or PID-reuse protection. A supervisor must +retire the entire arena and its workers if the publisher dies. Never hand an old +arena to a replacement publisher. Authority generations belong in the integrating +runtime, not in an assertion that a PID is a capability. + +## Publication and wake-up order + +The creator writes payload and immutable record metadata, publishes the record +version, then publishes the latest version. `mapset` and `mapget` use the existing +compiler's fenced aligned accesses. A reader first observes the published count, +then validates the selected record version before accessing its bytes. Readers +never race a rewrite of a published payload. + +After publishing, notify each subscribed worker through its own eventfd. Sharing +one eventfd among workers would distribute wake-ups instead of broadcasting them. +To stop, call `node_stop`, then notify every worker's separate control eventfd. +`node_wait` gives stop priority when work and control are both ready. A caller +must also check stop between bounded work units and validate authority again +before committing effects. + +A consumer scans relevant published versions, processes them, advances its cursor, +then waits. On wake, scan again even if notifications have coalesced. Publication +between the scan and wait leaves an eventfd hint pending. Publication concurrent +with draining is covered by the scan after the drain. Signals may be stale; +they never encode an artifact count or transfer authority. An eventfd error must +be handled by the supervisor; it does not undo an already committed publication. + +`node_wait` returns EINTR to the caller, which can recompute a monotonic deadline. +The eventfd helpers bound interruption retries and return the last interruption +if exhausted. A positive wait result does not promise that the worker will be +scheduled within a deadline. Cancellation of running model/tool work is separate. + +## Capacity and lifetime + +The arena holds 64 immutable records. Full publication returns -2 without +overwriting old data. No reference counter or slot recycling exists in this +component. Drop mappings only after all readers finish; unmap each process's +handle or terminate that process. Fork inherits the arena; exec does not. + +A long-running supervisor must explicitly close an epoch, stop admission, finish +or cancel readers, reap workers, and create the next arena. That lifecycle is an +integration prerequisite, not an automatic behavior of these functions. This +bounded design keeps the first version free of ABA and unsafe reclamation paths. + +MODELED layout, checked with Wolfram Language: +`{4096+64*(64+4096), Mod[64+4096,64]}` returned `{270336, 0}`. +The first value is arena bytes; the second checks slot-stride alignment. Header +words at offsets 0, 8, 16, 24 and 32 hold magic, ABI, count, stop and creator PID. +Record slots start at 4096 with stride 4160; version, length and topic mask are +at slot offsets 0, 8 and 16, followed by payload at offset 64. These are ordinary +CPU mappings, with no GPU-coherence or cross-machine shared-memory claim. + +## Acceptance and negative controls + +The gate checks malformed versions/lengths, nonzero topics, header and record +corruption, retained old data at capacity, worker publication refusal, notification +coalescing, stop priority, and both consumers' selected payloads byte for byte. +Both workers are forked before publication. Their acknowledgements and exits are +checked. Failure cleanup signals and reaps only the exact created child PIDs. + +Generate each control in a disposable copy of `transport.om`, append the unchanged +test, compile successfully, and run with the same timeout: + +| Change in transport source | Expected gate exit | +| --- | --- | +| Mapping mode `NBYTES 3 33` to `NBYTES 3 34` | 87 (child verification failure) | +| Each `if ne mapget h off 8 v` to `if false` | 33 (record-version refusal lost) | +| `if ne and mapget h add off 16 8 topics 0` to `if true` | 21 (topic filter lost) | +| Each `ret 2` to `ret 1` | 55 (stop no longer distinguished from work) | +| Each creator comparison `if ne mapget h 32 8 ulong getpid` to `if false` | 87 (child detects unauthorized publication accepted) | + +These controls check observable protocol behavior. Emulation does not establish +weak-memory correctness on physical ARM hardware. The abstract Lean model in +omega-harness PR 206 does not prove this implementation or its memory ordering. diff --git a/seed/node/transport-gate.om b/seed/node/transport-gate.om new file mode 100644 index 000000000..51135d9e4 --- /dev/null +++ b/seed/node/transport-gate.om @@ -0,0 +1,509 @@ +note Omega Node transport, concatenate with a program-mode consumer. +note Trusted forked processes only. This is transport, not write authority. +note One publisher PID, 64 immutable records per arena lifetime, no slot reuse. +note Layout: 4096 byte header then 64 slots of 4160 bytes. +note Header u64: magic, ABI, published count, stop, publisher PID. +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 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 Concatenate after transport.om. CPU-only process and transport acceptance. +text nok "PASS node transport\n" +global nh long 1 +global nf int 6 +global np long 2 +global ns uchar 4 + +fn node_check ok bool code int to void +if not ok +exit code +end +end + +fn node_refusals to void +src = new uchar 4096 42 +dst = new uchar 4096 99 +h = node_new +node_check gt h 0 10 +node_check eq node_next h 0 1 0 11 +node_check eq node_next h 1 1 neg long 5 12 +node_check eq node_read h 1 dst neg long 7 13 +node_check eq get dst 0 99 14 +node_check eq node_publish h 1 src 4097 neg long 3 15 +node_check eq node_publish h 0 src 1 neg long 4 16 +node_check eq mapget h 16 8 0 17 +node_check eq node_publish h 1 src 0 1 18 +node_check eq node_read h 1 dst 0 19 +node_check eq get dst 0 99 20 +node_check eq node_next h 0 2 0 21 +node_check eq node_next h 0 1 1 22 +node_check eq node_read h 0 dst neg long 7 23 +node_check eq node_read h 65 dst neg long 7 24 +node_check eq node_next h 65 1 neg long 7 25 +node_check eq node_next h 0 0 neg long 7 26 +node_check eq node_stop h 0 27 +node_check eq node_publish h 1 src 1 neg long 1 28 +node_check eq mapget h 16 8 1 29 +node_check eq mapdrop h 0 30 +end + +fn node_faults to void +src = new uchar 4096 42 +dst = new uchar 4096 99 +h = node_new +node_check gt h 0 31 +node_check eq node_publish h 1 src 1 1 32 +r = mapset h 4096 8 9 +node_check eq node_read h 1 dst neg long 5 33 +node_check eq node_next h 0 1 neg long 5 34 +node_check eq get dst 0 99 35 +r = mapset h 4096 8 1 +r = mapset h 4104 8 4097 +node_check eq node_read h 1 dst neg long 5 36 +r = mapset h 16 8 65 +node_check eq node_read h 1 dst neg long 5 37 +node_check eq node_next h 0 1 neg long 5 38 +r = mapset h 0 8 0 +node_check eq node_read h 1 dst neg long 5 39 +node_check eq node_publish h 1 src 1 neg long 5 40 +node_check eq node_stop h neg long 5 41 +node_check eq mapdrop h 0 42 +end + +fn node_wait_checks to void +h = node_new +node_check gt h 0 43 +w = eventfd uint 0 +s = eventfd uint 0 +node_check ge w 0 44 +node_check ge s 0 45 +node_check eq node_wait h int w int s 0 0 46 +node_check eq node_wait h int w int w 0 neg long 22 47 +node_check eq node_wait h neg int 1 int s 0 neg long 9 48 +node_check eq node_notify int w 0 49 +node_check eq node_notify int w 0 50 +node_check eq node_wait h int w int s 0 1 51 +node_check eq node_wait h int w int s 0 0 52 +node_check eq node_notify int s 0 53 +node_check eq node_notify int w 0 54 +node_check eq node_wait h int w int s 0 2 55 +node_check eq node_stop h 0 56 +node_check eq node_wait h int w int s 0 2 57 +node_check eq fclose int w 0 58 +node_check eq fclose int s 0 59 +node_check eq node_notify int w neg long 9 60 +node_check eq mapdrop h 0 61 +end + +fn node_worker idx ulong to int +buf = new uchar 4096 0 +h = get nh 0 +if ne node_publish h 1 buf 1 neg long 6 +ret 70 +end +if ne node_stop h neg long 6 +ret 71 +end +cursor = ulong 0 +count = ulong 0 +topic = add idx 1 +r = node_wait h get nf idx get nf add idx 2 5000000000 +if ne r 1 +ret 72 +end +note A single wake must let each worker discover every matching version. +for k ulong 64 +v = node_next h cursor topic +if eq v 0 +break +end +if lt v 0 +ret 73 +end +cursor = ulong v +if ne node_read h cursor buf 4096 +ret 74 +end +for j ulong 4096 +if ne get buf j uchar cursor +ret 75 +end +end +count = add count 1 +end +if ne count 32 +ret 76 +end +if ne node_notify get nf add idx 4 0 +ret 77 +end +note Parent signals stop only after both independent acknowledgements. +while true bound 64 +r = node_wait h get nf idx get nf add idx 2 5000000000 +if eq r 2 +ret 0 +end +if ne r 1 +ret 78 +end +end +ret 79 +end + +fn node_publish_batch to bool +buf = new uchar 4096 0 +h = get nh 0 +for k ulong 64 +v = add k 1 +for j ulong 4096 +put buf j uchar v +end +if ne node_publish h add rem v 2 1 buf 4096 long v +ret false +end +end +if ne node_publish h 1 buf 1 neg long 2 +ret false +end +if ne mapget h 16 8 64 +ret false +end +note The first version still has its original bytes after arena exhaustion. +if ne node_read h 1 buf 4096 +ret false +end +for j ulong 4096 +if ne get buf j 1 +ret false +end +end +ret true +end + +fn node_processes to int +put nh 0 node_new +if le get nh 0 0 +ret 80 +end +for i ulong 6 +put nf i neg int 1 +end +result = int 0 +for i ulong 6 +fd = eventfd uint 0 +if lt fd 0 +result = 81 +break +end +put nf i int fd +end +if eq result 0 +for i ulong 2 +pid = fork +if eq pid 0 +exit node_worker i +end +if lt pid 0 +result = 82 +break +end +put np i pid +end +end +if eq result 0 +if not node_publish_batch +result = 83 +end +end +if eq result 0 +for i ulong 2 +if ne node_notify get nf i 0 +result = 84 +end +end +end +if eq result 0 +for i ulong 2 +r = waitio get nf add i 4 1 5000000000 +if ne r 1 +result = 85 +end +end +end +if eq node_stop get nh 0 0 +for i ulong 2 +if ge get nf add i 2 0 +r = node_notify get nf add i 2 +end +end +else +result = 86 +end +for i ulong 2 +if gt get np i 0 +note Bounded nonblocking reap, then SIGKILL the exact child if still live. +done = false +for j ulong 100 +r = waitpid int get np i ns 0 4 1 +if eq r get np i +done = true +if or ne get ns 0 0 ne get ns 1 0 +result = 87 +end +break +end +if ne r 0 +result = 88 +break +end +r = sleepns 10000000 +end +if not done +r = killpid int get np i 9 +r = waitpid int get np i ns 0 4 0 +result = 89 +end +end +end +for i ulong 6 +if ge get nf i 0 +if ne fclose get nf i 0 +result = 90 +end +end +end +if ne mapdrop get nh 0 0 +result = 91 +end +ret result +end + +fn main to int +node_refusals +node_faults +node_wait_checks +r = node_processes +if ne r 0 +ret r +end +if ne write 1 nok 0 len nok long len nok +ret 92 +end +ret 0 +end diff --git a/seed/node/transport-test.om b/seed/node/transport-test.om new file mode 100644 index 000000000..a146fd6f8 --- /dev/null +++ b/seed/node/transport-test.om @@ -0,0 +1,284 @@ +note Concatenate after transport.om. CPU-only process and transport acceptance. +text nok "PASS node transport\n" +global nh long 1 +global nf int 6 +global np long 2 +global ns uchar 4 + +fn node_check ok bool code int to void +if not ok +exit code +end +end + +fn node_refusals to void +src = new uchar 4096 42 +dst = new uchar 4096 99 +h = node_new +node_check gt h 0 10 +node_check eq node_next h 0 1 0 11 +node_check eq node_next h 1 1 neg long 5 12 +node_check eq node_read h 1 dst neg long 7 13 +node_check eq get dst 0 99 14 +node_check eq node_publish h 1 src 4097 neg long 3 15 +node_check eq node_publish h 0 src 1 neg long 4 16 +node_check eq mapget h 16 8 0 17 +node_check eq node_publish h 1 src 0 1 18 +node_check eq node_read h 1 dst 0 19 +node_check eq get dst 0 99 20 +node_check eq node_next h 0 2 0 21 +node_check eq node_next h 0 1 1 22 +node_check eq node_read h 0 dst neg long 7 23 +node_check eq node_read h 65 dst neg long 7 24 +node_check eq node_next h 65 1 neg long 7 25 +node_check eq node_next h 0 0 neg long 7 26 +node_check eq node_stop h 0 27 +node_check eq node_publish h 1 src 1 neg long 1 28 +node_check eq mapget h 16 8 1 29 +node_check eq mapdrop h 0 30 +end + +fn node_faults to void +src = new uchar 4096 42 +dst = new uchar 4096 99 +h = node_new +node_check gt h 0 31 +node_check eq node_publish h 1 src 1 1 32 +r = mapset h 4096 8 9 +node_check eq node_read h 1 dst neg long 5 33 +node_check eq node_next h 0 1 neg long 5 34 +node_check eq get dst 0 99 35 +r = mapset h 4096 8 1 +r = mapset h 4104 8 4097 +node_check eq node_read h 1 dst neg long 5 36 +r = mapset h 16 8 65 +node_check eq node_read h 1 dst neg long 5 37 +node_check eq node_next h 0 1 neg long 5 38 +r = mapset h 0 8 0 +node_check eq node_read h 1 dst neg long 5 39 +node_check eq node_publish h 1 src 1 neg long 5 40 +node_check eq node_stop h neg long 5 41 +node_check eq mapdrop h 0 42 +end + +fn node_wait_checks to void +h = node_new +node_check gt h 0 43 +w = eventfd uint 0 +s = eventfd uint 0 +node_check ge w 0 44 +node_check ge s 0 45 +node_check eq node_wait h int w int s 0 0 46 +node_check eq node_wait h int w int w 0 neg long 22 47 +node_check eq node_wait h neg int 1 int s 0 neg long 9 48 +node_check eq node_notify int w 0 49 +node_check eq node_notify int w 0 50 +node_check eq node_wait h int w int s 0 1 51 +node_check eq node_wait h int w int s 0 0 52 +node_check eq node_notify int s 0 53 +node_check eq node_notify int w 0 54 +node_check eq node_wait h int w int s 0 2 55 +node_check eq node_stop h 0 56 +node_check eq node_wait h int w int s 0 2 57 +node_check eq fclose int w 0 58 +node_check eq fclose int s 0 59 +node_check eq node_notify int w neg long 9 60 +node_check eq mapdrop h 0 61 +end + +fn node_worker idx ulong to int +buf = new uchar 4096 0 +h = get nh 0 +if ne node_publish h 1 buf 1 neg long 6 +ret 70 +end +if ne node_stop h neg long 6 +ret 71 +end +cursor = ulong 0 +count = ulong 0 +topic = add idx 1 +r = node_wait h get nf idx get nf add idx 2 5000000000 +if ne r 1 +ret 72 +end +note A single wake must let each worker discover every matching version. +for k ulong 64 +v = node_next h cursor topic +if eq v 0 +break +end +if lt v 0 +ret 73 +end +cursor = ulong v +if ne node_read h cursor buf 4096 +ret 74 +end +for j ulong 4096 +if ne get buf j uchar cursor +ret 75 +end +end +count = add count 1 +end +if ne count 32 +ret 76 +end +if ne node_notify get nf add idx 4 0 +ret 77 +end +note Parent signals stop only after both independent acknowledgements. +while true bound 64 +r = node_wait h get nf idx get nf add idx 2 5000000000 +if eq r 2 +ret 0 +end +if ne r 1 +ret 78 +end +end +ret 79 +end + +fn node_publish_batch to bool +buf = new uchar 4096 0 +h = get nh 0 +for k ulong 64 +v = add k 1 +for j ulong 4096 +put buf j uchar v +end +if ne node_publish h add rem v 2 1 buf 4096 long v +ret false +end +end +if ne node_publish h 1 buf 1 neg long 2 +ret false +end +if ne mapget h 16 8 64 +ret false +end +note The first version still has its original bytes after arena exhaustion. +if ne node_read h 1 buf 4096 +ret false +end +for j ulong 4096 +if ne get buf j 1 +ret false +end +end +ret true +end + +fn node_processes to int +put nh 0 node_new +if le get nh 0 0 +ret 80 +end +for i ulong 6 +put nf i neg int 1 +end +result = int 0 +for i ulong 6 +fd = eventfd uint 0 +if lt fd 0 +result = 81 +break +end +put nf i int fd +end +if eq result 0 +for i ulong 2 +pid = fork +if eq pid 0 +exit node_worker i +end +if lt pid 0 +result = 82 +break +end +put np i pid +end +end +if eq result 0 +if not node_publish_batch +result = 83 +end +end +if eq result 0 +for i ulong 2 +if ne node_notify get nf i 0 +result = 84 +end +end +end +if eq result 0 +for i ulong 2 +r = waitio get nf add i 4 1 5000000000 +if ne r 1 +result = 85 +end +end +end +if eq node_stop get nh 0 0 +for i ulong 2 +if ge get nf add i 2 0 +r = node_notify get nf add i 2 +end +end +else +result = 86 +end +for i ulong 2 +if gt get np i 0 +note Bounded nonblocking reap, then SIGKILL the exact child if still live. +done = false +for j ulong 100 +r = waitpid int get np i ns 0 4 1 +if eq r get np i +done = true +if or ne get ns 0 0 ne get ns 1 0 +result = 87 +end +break +end +if ne r 0 +result = 88 +break +end +r = sleepns 10000000 +end +if not done +r = killpid int get np i 9 +r = waitpid int get np i ns 0 4 0 +result = 89 +end +end +end +for i ulong 6 +if ge get nf i 0 +if ne fclose get nf i 0 +result = 90 +end +end +end +if ne mapdrop get nh 0 0 +result = 91 +end +ret result +end + +fn main to int +node_refusals +node_faults +node_wait_checks +r = node_processes +if ne r 0 +ret r +end +if ne write 1 nok 0 len nok long len nok +ret 92 +end +ret 0 +end diff --git a/seed/node/transport.om b/seed/node/transport.om new file mode 100644 index 000000000..5d750c0d1 --- /dev/null +++ b/seed/node/transport.om @@ -0,0 +1,225 @@ +note Omega Node transport, concatenate with a program-mode consumer. +note Trusted forked processes only. This is transport, not write authority. +note One publisher PID, 64 immutable records per arena lifetime, no slot reuse. +note Layout: 4096 byte header then 64 slots of 4160 bytes. +note Header u64: magic, ABI, published count, stop, publisher PID. +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 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