interplane.Get Omega
Read in your language

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

fix(blake3): fail closed on stdout errors (#726)

closed 814308dd311a7062 #733 · opened 2026-10-25 04:03 UTC · closed 2026-10-30 18:06 UTC

Imported from GitHub aien-dev/omega-mv#733, by drakestapleton

Base 62d1d0d668f897386a0e311374f8dbcc5c32dde8 · Head 0cd68a4c4f1916e9f9779433f2eb5853ccbe7074

drakestapleton wrote on 2026-10-25 04:03 UTC

Refs #726; follow-up to #732.

Defect and minimal fix

At #732 head c2156c7069df619797a113582fa6ad658c3db999, emit discards both write return values and main unconditionally returns zero. The pinned compiler lowers write directly to Linux AArch64 syscall 64. A returned ENOSPC/EBADF therefore falsely reports successful output.

Keep all BLAKE3 arithmetic unchanged. Emit the 64 hex characters and newline through a bounded 65-byte write loop; resume positive short writes and return 74 on a returned error or zero progress. Propagate that status from main. Default SIGPIPE signal termination is not promised to return 74.

Gate wiring

tests/gates/run.sh om-units now compiles om/blake3/blake3.om with the seed-born omc and runs om/blake3/test-output.sh on it, so the om-units CI check (om-units-arm64) covers the output contract.

Verification

  • Native red/green, forced short write and the 64-case parity corpus: see the aien-spark comment (omc 734f0a39, 2026-10-25).
  • At 0cd68a4c (origin/main 62d1d0d6 merged), arm64 host, no GPU: sh seed/omega-from-seed.sh → RC=0, omc 62775d2a…712b; blake3.om compiles to the same 8,664-byte binary f3e343d2…2dbd. bash tests/gates/run.sh om-units → exit 0 (SHA256-PARITY PASS, BLAKE3-PARITY PASS with both mutants killed, PASS: empty digest, /dev/full and closed stdout). Negative control: test-output.sh on the origin/main blake3.om binary → FAIL: /dev/full returned 0, wanted 74, rc 1.
  • crumb verify . → OK: 166 crumbs current.
  • Short write followed by a successful continuation, and EINTR: NOT_RUN (not forced by the fixture).
  • Host results only, not hardware qualification. No GPU tests, live server changes, consumer cutover or deployment.

Bridge #8 remains the separate native ABI dependency; src/omega_blake3.c remains in place.

drakestapleton reviewed (COMMENTED) on 2026-10-30 11:34 UTC

blake3 output fix looks correct: emit now writes 64 hex digits plus the newline in one buffer (hex grows to 65), loops on short writes, and returns 74 on write error, which main propagates (ret emit). test-output.sh covers /dev/full and closed stdout. But the body says "Draft only", native compile and tests are NOT_RUN, and root .crumb is not regenerated. Please run test-output.sh on a compiled binary and regenerate the crumbs.

— Grokbot

Fetch it

A git bundle of the pull request's head, 12663 bytes.

curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/814308dd311a7062.bundle -o 814308dd311a7062.bundle
git fetch 814308dd311a7062.bundle refs/pull/733/head

Raw bundle · 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
733
0cd68a4c4f1916e9f9779433f2eb5853ccbe7074
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":733,"url":"https://github.com/aien-dev/omega-mv/pull/733","export_sha256":"7319147b350ad908bf0b731068ec3be7b8dee848041dc862f71455e8e4680140","imported_utc":"2026-11-18T16:35:44Z"}

Changes

diff --git a/.crumb b/.crumb
index f3e51fe46..b26f5b72b 100644
--- a/.crumb
+++ b/.crumb
@@ -72,7 +72,7 @@
         },
         {
           "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986",
-          "last_commit": "a8a6a3d3c",
+          "last_commit": "d94a503f7",
           "name": "spec",
           "purpose": "Directory spec. Purpose not yet described by a human."
         },
@@ -83,27 +83,27 @@
           "purpose": "Directory src. Purpose not yet described by a human."
         },
         {
-          "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
-          "last_commit": "a8a6a3d3c",
+          "digest": "1f55a88b2efd23502106fc3541f3064ce00dda54e714c15247796f02a5167bd7",
+          "last_commit": "dcccc0211",
           "name": "tests",
           "purpose": "Directory tests. Purpose not yet described by a human."
         },
         {
           "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29",
-          "last_commit": "a8a6a3d3c",
+          "last_commit": "a50c3bd41",
           "name": "tools",
           "purpose": "Directory tools. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc",
-      "compiled_at": "2026-10-30T12:31:50Z",
+      "children_root": "sha256:d1b074657c4e38767de29e0fbcc4994f73514f21478f241decf08fba2b04941e",
+      "compiled_at": "2026-10-30T16:30:44Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6",
+      "digest": "sha256:86a0cd5a28420fef0a9d15fed12e0a6ca8cab5ea53cd8f889e865ba891559aa4",
       "evidence_files": 12622,
       "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9",
-      "files": 17849,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed"
+      "files": 17850,
+      "generated_at_commit": "fb6ece1ce1c50da5a50dc31ae0934fe63adce7cd",
+      "source_tree": "sha256:ac2ab46aa6bab0d91062ba78862b2fa89a7d61f6181da30834b416ba8749a57b"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/om/blake3/README.md b/om/blake3/README.md
index 659be6244..d972db1f2 100644
--- a/om/blake3/README.md
+++ b/om/blake3/README.md
@@ -9,7 +9,7 @@ aien-dev/aien-architecture-mv#300 (zero-legacy migration).
 ## Build
 
 ```
-OMC=/path/to/seed/out/omc     # pinned: sha256 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
+OMC=/path/to/seed/out/omc     # born by: sh seed/omega-from-seed.sh
 $OMC < om/blake3/blake3.om > blake3 && chmod +x blake3
 ./blake3 FILE          # or:  ./blake3 < FILE
 ```
@@ -18,6 +18,32 @@ Exit codes: 0 hash written; 65 input cannot be read (missing file, no permission
 directory, read error); 66 input longer than 16 MiB (16,777,216 bytes is accepted,
 16,777,217 is refused). Messages go to stderr.
 
+Returned stdout write errors or zero-progress writes exit 74. Positive short writes
+resume at the next byte; returned negative results, including interrupted writes,
+fail closed. Signal termination (for example the default SIGPIPE action) is not
+reported as exit 74.
+
+Run the output-contract regression against a freshly compiled binary:
+
+```
+sh om/blake3/test-output.sh ./blake3
+```
+
+The fixture compares the complete empty-input digest, including its newline, and
+checks /dev/full and closed-stdout failures. Positive short writes and EINTR are not
+forced by this fixture. `bash tests/gates/run.sh om-units` compiles `blake3.om` with the
+seed-born omc and runs this fixture, so the om-units CI check covers it.
+
+Native run on the Spark (arm64 host, 2026-10-25), omc 734f0a39…6b61 built by
+`sh seed/omega-from-seed.sh`: this source (sha256 c7c96a26…a150) compiles to an
+8,664-byte binary, sha256 f3e343d2…2dbd. `test-output.sh` exits 0 on it and 1 on the
+PR #732 binary (c51199a3…f77b), which exits 0 for /dev/full (ENOSPC) and closed
+stdout (EBADF). A forced positive short write (`ulimit -f 1`, SIGXFSZ ignored, 994-byte
+file opened for append) shows `write(1, …, 65) = 30` then `write(1, …+30, 35) = -1
+EFBIG` and exit 74. The 64-case corpus below, rerun against this binary with a fresh
+-O2 build of `src/omega_blake3.c` as oracle, gives 64/64, and the binary matches
+`tests/resolve/blake3_vectors.txt` 35/35.
+
 ## Construction
 
 Same as the C: 1024-byte chunks of 64-byte blocks, CHUNK_START on a chunk's first block,
@@ -28,7 +54,7 @@ reference holds trivially), ROOT on the single final compression. 32-bit words l
 split into words 12 and 13 of the state. The message permutation runs 7 times per
 compression, as in the C.
 
-## Oracle and parity
+## Historical oracle and parity (PR #732)
 
 Oracle: `src/omega_blake3.c` compiled with gcc -O2 behind a 12-line C driver (file → hex,
 kept out of the tree). The driver was first checked against the official
@@ -37,6 +63,10 @@ match, and the file is identical to the repo's `tests/resolve/blake3_vectors.txt
 Two single-line mutants of the C (the B3M:root and B3M:merge tags) are caught by the
 vector set (35/35 and 16/35 vectors differ), so the corpus discriminates.
 
+The following corpus and hashes belong to the original source at commit
+`c2156c7069df619797a113582fa6ad658c3db999`, before the output-handling fix.
+They are not verification of the revised source or binary.
+
 Corpus run with omc 734f0a39…6b61, `blake3.om` sha256 79857ee8…baa3, output binary
 sha256 c51199a3…f77b (8,660 bytes). Every row compares the .om output byte for byte to
 the oracle (or the exit status where that is the contract).
@@ -51,7 +81,7 @@ the oracle (or the exit status where that is the contract).
 | Missing file, mode-000 file, directory | 3 | exit 65 all |
 | **Total** | **64** | **64/64** |
 
-Timing on the Spark (arm64): 16 MiB in 0.33 s for the .om versus 0.05 s for the -O2 C.
+Historical timing of the original PR #732 source on the Spark (arm64): 16 MiB in 0.33 s for the .om versus 0.05 s for the -O2 C.
 
 ## Limits
 
diff --git a/om/blake3/blake3.om b/om/blake3/blake3.om
index e5983a13c..ea768a7fc 100644
--- a/om/blake3/blake3.om
+++ b/om/blake3/blake3.om
@@ -9,7 +9,6 @@ note usage: blake3 [FILE]
 
 text tbad "blake3: cannot read input\n"
 text tbig "blake3: input over 16 MiB\n"
-text tnl "\n"
 
 global inp uchar 16777216
 global n ulong 1
@@ -26,7 +25,7 @@ global cvr ulong 8
 global stk ulong 512
 global sp ulong 1
 global name uchar 4096
-global hex uchar 64
+global hex uchar 65
 global tiny uchar 1
 
 const mask ulong 4294967295
@@ -226,7 +225,7 @@ ret uchar add v 87
 end
 
 note little-endian bytes of co 0..7 as 64 hex digits
-fn emit to void
+fn emit to int
 for i ulong 8
 v = get co i
 for k ulong 4
@@ -236,8 +235,16 @@ put hex p hexd shr bt 4
 put hex add p 1 hexd and bt 15
 end
 end
-r = write 1 hex 0 64
-r = write 1 tnl 0 1
+put hex 64 10
+off = ulong 0
+while lt off 65 bound 65
+r = write 1 hex off sub 65 off
+if le r 0
+ret 74
+end
+off = add off ulong r
+end
+ret 0
 end
 
 note read the whole descriptor into inp; 0 ok, 65 read error, 66 over capacity
@@ -325,6 +332,5 @@ r = write 2 tbig 0 len tbig
 ret 66
 end
 hashall
-emit
-ret 0
+ret emit
 end
diff --git a/om/blake3/test-output.sh b/om/blake3/test-output.sh
new file mode 100644
index 000000000..d4d56964a
--- /dev/null
+++ b/om/blake3/test-output.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Host output-contract regression. Pass a freshly compiled blake3.om binary.
+# Does not compile, access the GPU, or change the live server.
+set -eu
+[ "$#" -eq 1 ] || { echo 'usage: test-output.sh /path/to/blake3' >&2; exit 2; }
+B=$1
+[ -x "$B" ] || { echo 'FAIL: binary is not executable' >&2; exit 1; }
+[ -c /dev/full ] || { echo 'NOT_RUN: /dev/full unavailable' >&2; exit 77; }
+T=$(mktemp -d)
+trap 'rm -rf "$T"' EXIT HUP INT TERM
+bad() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
+"$B" </dev/null >"$T/out" || bad 'empty-input control failed'
+printf '%s\n' af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262 >"$T/want"
+cmp "$T/want" "$T/out" || bad 'empty-input digest or newline differs'
+rc=0
+"$B" </dev/null >/dev/full || rc=$?
+[ "$rc" -eq 74 ] || bad "/dev/full returned $rc, wanted 74"
+rc=0
+"$B" </dev/null 1>&- || rc=$?
+[ "$rc" -eq 74 ] || bad "closed stdout returned $rc, wanted 74"
+printf '%s\n' 'PASS: empty digest, /dev/full and closed stdout'
diff --git a/tests/.crumb b/tests/.crumb
index 5fbfcb29c..6153fd6eb 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -302,14 +302,14 @@
         }
       ],
       "children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902",
-      "compiled_at": "2026-10-30T12:31:50Z",
+      "compiled_at": "2026-10-30T16:30:44Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
+      "digest": "sha256:1f55a88b2efd23502106fc3541f3064ce00dda54e714c15247796f02a5167bd7",
       "evidence_files": 16,
       "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a",
       "files": 1386,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679"
+      "generated_at_commit": "fb6ece1ce1c50da5a50dc31ae0934fe63adce7cd",
+      "source_tree": "sha256:05652cdeb3d191350b053a94dd0f09d60f08a413d538edaff76491f36bd8c4a4"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/tests/gates/run.sh b/tests/gates/run.sh
index 66da8e1a9..6401255d3 100755
--- a/tests/gates/run.sh
+++ b/tests/gates/run.sh
@@ -313,6 +313,7 @@ case "$step" in
   om-units)           # The C entry points whose algorithm is Omega (om/units.sh): omc born from the seed here,
                       # the generator pinned by om/omega-bridge.lock; regenerated binding, SHA-256 and BLAKE3
                       # byte parity against the C they replaced, and the BLAKE3 mutants. NOT_RUN (3) without tools.
+                      # Then the program-mode om/blake3/blake3.om output contract (#726): digest, /dev/full, closed stdout.
     pin omega-bridge omega-bridge "$(lock om/omega-bridge.lock)"
     sh seed/omega-from-seed.sh > build/om-units-seed.log 2>&1 || { tail -3 build/om-units-seed.log; exit 1; }
     export OMEGA_OMC="$ROOT/seed/out/omc" OMEGA_BRIDGE="$PINS/omega-bridge"
@@ -320,6 +321,8 @@ case "$step" in
     sh om/units.sh --check
     sh om/sha256/parity/run.sh
     sh om/blake3/parity/run.sh
+    "$OMEGA_OMC" < om/blake3/blake3.om > build/om-units-blake3 && chmod 700 build/om-units-blake3
+    sh om/blake3/test-output.sh build/om-units-blake3
     ;;
   tilelab)            # omega#906: native .om tile planner and streaming (m,s,p) softmax. omc born from the seed
                       # here, then seed/tilelab/gate.sh (expected output, mutants failing for their own reason).