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
GitHub aien-dev/omega-mv#958 (code only)
Apply it
git checkout -b patch-16f946ac7e9c2c00 62d1d0d668f897386a0e311374f8dbcc5c32dde8 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/16f946ac7e9c2c00.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
958
17d89d612a485abc8e7f056cd92c184456ce75b9
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":958,"url":"https://github.com/aien-dev/omega-mv/pull/958","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:29Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index f3e51fe46..364ff29a9 100644 --- a/.crumb +++ b/.crumb @@ -72,38 +72,38 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", - "last_commit": "bf54b19fa", + "last_commit": "089e5b053", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "digest": "f7d2a0bb37d8d390b9e187eb46545748a037d43e38716cf5783374b6404f2bb1", + "last_commit": "a8b948018", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "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:b5ed23415b7856187ca756378f10e9bf6838f06c0c853a90f6df12f93eb2ceee", + "compiled_at": "2026-10-30T16:03:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", + "digest": "sha256:5e867f9b5939cc199ba541c1e3737b26a870653da3e870cacaeed7a4e77db873", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "files": 17855, + "generated_at_commit": "a8b948018e45f8375d34db67ca96d65d88e0fe99", + "source_tree": "sha256:00561250ef371746a9920e2509d4b617da21cbf3c6fb882896c26ae25f4be1a7" }, "owner_lane": "", "provenance": { diff --git a/seed/README.md b/seed/README.md index b37d60984..51215b6b9 100644 --- a/seed/README.md +++ b/seed/README.md @@ -984,6 +984,17 @@ or unrelated runtime failures are not accepted as control evidence. These checks qualify host parsing only. They do not access or qualify a GPU, alter the empirical scheduling model, or rewrite historical evidence. +## Local trace segment (omega-mv #608) + +`seed/trace/segment.om` is a library unit (no `main`) for a local, append-only trace segment: a +16-byte header and 64-byte records, each with its sequence number and a CRC-32. It can scan a segment +read-only, and its recovery keeps the valid prefix and quarantines the damaged file as `<segment>.bad`. +Run `sh seed/trace/gate.sh` (or `tests/gates/run.sh trace`) from the repository root on an +AArch64 Linux host. The gate checks `seed/out/omc` against its recorded SHA-256, then requires the 71 checks +in `seed/trace/segment-test.om` to print exactly `seed/trace/expected.txt`. It also requires four source +mutants to fail their own checks: CRC comparison removed, torn tail ignored, append alignment guard +weakened, and create with O_TRUNC in place of O_EXCL. `seed/trace/README.md` describes the format. + ## How the checks stay honest - `check/a64check.c` and `check/audit.sh` are reference checks only. They call the repo's existing C diff --git a/seed/trace/README.md b/seed/trace/README.md new file mode 100644 index 000000000..db3fa0756 --- /dev/null +++ b/seed/trace/README.md @@ -0,0 +1,68 @@ +# seed/trace: local trace segment (omega-mv #608) + +`segment.om` is a library unit in seeded Omega. It has no `main`, so concatenate it in front of a program +that defines one (units concatenate; Omega has no import). Host words: `fopen`, `read`, `write`, +`fseek`, `fsync`, `fclose`, `unlink`, `link`, `renames` (OMEGESE section 10). Linux AArch64 only. + +## Format version 1 + +All integers are little-endian. + +| Part | Bytes | Fields | +|------|-------|--------| +| header | 16 | `AITR` (65 73 84 82), version u16 = 1, record size u16 = 64, header size u32 = 16, reserved u32 = 0 | +| record | 64 | type u16, payload length u16 (at most 52), sequence u32, payload 52 bytes (zero past the length), CRC-32 u32 | + +- The sequence is the record index, assigned by the writer. A scan refuses a record whose sequence is + not its position, so a duplicated or reordered record is detected. +- The CRC is CRC-32/IEEE (reflected polynomial 0xEDB88320 = 3988292384, initial value and final xor + 0xFFFFFFFF) over record bytes 0..59. Its check value `CRC-32("123456789") = 3421780262` is the first + test (Wolfram: `Hash["123456789","CRC32"] -> 3421780262`). +- A segment holds at most 4096 records, so the largest segment is `16 + 64*4096 = 262160` bytes. + +## Operations + +| Function | Behaviour | +|----------|-----------| +| `segcreate` | creates `tpath` with O_WRONLY, O_CREAT, O_EXCL and O_NOFOLLOW, mode 0600, and writes and fsyncs the header. An existing path is refused (10); it is never truncated | +| `segready` | creates a missing segment. For an existing one it requires a valid header, and it never recreates the file | +| `segappend t n` | appends one record with payload `pay[0..n)`. It refuses if the file length is not header plus whole records (25: torn tail, recover first), when the segment is full (26), or when the payload is over 52 bytes (20). Each record is fsynced | +| `segscan` | read-only. Sets `scount` (valid records before the first damage), `sreason` (0 clean, 1 torn tail, 2 bad length, 3 CRC mismatch, 4 sequence mismatch, 5 over capacity), `stotal` (file bytes) and `slost` (bytes after the valid prefix). A header that is short, has bad magic (11), an unsupported version (15), or bad geometry or nonzero reserved bytes (16) is refused | +| `segrecover` | returns 0 for a clean segment. Otherwise it writes the header and valid prefix to `<segment>.new` (O_EXCL, fsync), hard-links the damaged file to `<segment>.bad` (refused with 32 if that exists, so a quarantine is never overwritten), renames the new file over the segment and returns 1. Header errors are returned, not recovered | + +Every open uses O_NOFOLLOW, so a symbolic link as the segment path is refused (ELOOP, `serrno = -40`). +The caller creates directories with mode 0700 (`makedir ... 448`); the test does so. + +## Gate + +`sh seed/trace/gate.sh`, or `tests/gates/run.sh trace` (manifest `tests/gates/omega-trace.gate`). It +checks `seed/out/omc` against `seed/out/omc.sha256`, compiles `segment.om` plus `segment-test.om`, and +runs the test in `build/seed/trace/main`. The test must exit 0 and its stdout must equal `expected.txt`. +The 71 checks cover: + +- appending 100 records; +- truncating the last record to 30 of its 64 bytes; the scan must then keep 99 records and report a + torn tail; +- append refused until recovery; recovery keeps 99 records and quarantines the 6382-byte file; the next + append gets sequence 99; +- a flipped payload byte in record 50; the scan must stop at 50 records with a CRC mismatch, and + recovery is refused while `.bad` exists; +- crafted records with payload length 60 and with sequence 7; +- header version, magic, geometry and reserved-byte refusals; +- a symbolic-link path refused by scan, append and recover. + +Four source mutants must each compile, exit 1 and fail their own check: `crc` (CRC no longer compared, +so `crc-reason` fails), `torn` (`torn-reason`), `align` (`torn-append-refused`) and `excl` (create with +O_TRUNC, so `create-again-refused`). + +The expected sizes and offsets were computed in Wolfram Language: +`{16+64*100, 16+64*99+30, 16+64*99, 16+64*50+8, (16+64*100)-16-64*50, 16+64*50, Mod[6382-16,64]} +-> {6416, 6382, 6352, 3224, 3200, 3216, 30}`. The flags were checked the same way: +`{BitOr[1,1024,32768], BitOr[1,32768], BitOr[1,64,128,32768], BitOr[1,64,512,32768]} -> {33793, 32769, +32961, 33345}`. The remaining values (errno 2, 17 and 40, and the result codes) are pinned by the source. + +## Not in this unit + +Issue #608 also lists items this unit does not provide: an index, rotation and retention, an async +writer, schema migration beyond refusing other versions, export, consent and redaction. Concurrent +writers are not supported either: there is no lock, and the unit assumes a single writer. diff --git a/seed/trace/expected.txt b/seed/trace/expected.txt new file mode 100644 index 000000000..9e0b44220 --- /dev/null +++ b/seed/trace/expected.txt @@ -0,0 +1,72 @@ +crc-123456789 3421780262 +crc-empty 0 +missing-scan 10 +missing-errno 2 +create 0 +create-again-refused 10 +create-again-errno 17 +append-100-errors 0 +append-last-seq 99 +scan 0 +scan-count 100 +scan-reason 0 +scan-total 6416 +scan-lost 0 +append-oversize-refused 20 +truncate-last-record 0 +torn-scan 0 +torn-count 99 +torn-reason 1 +torn-lost 30 +torn-append-refused 25 +torn-size-unchanged 6382 +torn-recover 1 +torn-recover-lost 30 +recovered-scan 0 +recovered-count 99 +recovered-reason 0 +recovered-total 6352 +quarantine-size 6382 +append-after-recover 0 +append-after-seq 99 +recover-clean 0 +clean-count 100 +crc-flip-poke 0 +crc-scan 0 +crc-count 50 +crc-reason 3 +crc-lost 3200 +crc-recover-bad-exists 32 +crc-segment-unchanged 6416 +unlink-bad 0 +crc-recover 1 +crc-recovered-scan 0 +crc-recovered-count 50 +crc-recovered-reason 0 +len-raw-append 0 +len-scan 0 +len-count 50 +len-reason 2 +len-recover 1 +seq-raw-append 0 +seq-scan 0 +seq-count 50 +seq-reason 4 +seq-recover 1 +version-poke 0 +version-scan 15 +version-append-refused 15 +version-size-unchanged 3216 +magic-scan 11 +geometry-scan 16 +reserved-scan 16 +restored-scan 0 +restored-count 50 +symlink-create 0 +symlink-scan 10 +symlink-errno 40 +symlink-append-refused 10 +symlink-recover-refused 10 +final-scan 0 +final-count 50 +segment-test checks=71 fails=0 diff --git a/seed/trace/gate.sh b/seed/trace/gate.sh new file mode 100755 index 000000000..ac6ee4b33 --- /dev/null +++ b/seed/trace/gate.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# seed/trace/gate.sh -- host gate for the local trace segment (omega-mv #608). +# Run from anywhere: sh seed/trace/gate.sh +# Compiles segment.om + segment-test.om with seed/out/omc (sha checked against seed/out/omc.sha256), runs +# the test in a fresh scratch directory and requires exit 0 and stdout equal to expected.txt byte for byte. +# The expected values (sizes, offsets, CRC check value, flags) were computed in Wolfram Language; see +# README.md. Then each source mutant (a literal swap of a line that must occur exactly once in segment.om) +# must compile, exit 1, and fail on its own check label: +# crc record CRC no longer compared -> crc-reason FAIL +# torn partial tail not reported as torn -> torn-reason FAIL +# align append ignores a misaligned tail -> torn-append-refused FAIL +# excl create opens with O_TRUNC, not O_EXCL -> create-again-refused FAIL +# Prints PASS trace and exits 0, or FAIL and exits 1. +set -eu +R=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) +cd "$R" +D=seed/trace +B=build/seed/trace +rm -rf "$B" +mkdir -p "$B" +bad() { printf 'FAIL trace: %s\n' "$*" >&2; exit 1; } + +want=$(cut -c1-64 seed/out/omc.sha256) +have=$(sha256sum < seed/out/omc | cut -c1-64) +[ "$want" = "$have" ] || bad "seed/out/omc is $have, omc.sha256 says $want" +OMC="$R/seed/out/omc" + +# run NAME SRC: compile SRC to $B/NAME/t, run it inside $B/NAME, stdout to $B/NAME/out.txt, sets rc +run() { + mkdir -p "$B/$1" + "$OMC" < "$2" > "$B/$1/t" || bad "omc refused $2" + chmod 700 "$B/$1/t" + rc=0 + (cd "$B/$1" && ./t > out.txt) || rc=$? +} + +cat "$D/segment.om" "$D/segment-test.om" > "$B/test.om" +run main "$B/test.om" +printf 'omc %s\nsegment-test %s\n' "$have" "$(sha256sum < "$B/main/t" | cut -c1-64)" +[ "$rc" -eq 0 ] || { cat "$B/main/out.txt" >&2; bad "segment-test exited $rc"; } +cmp -s "$B/main/out.txt" "$D/expected.txt" || { diff "$D/expected.txt" "$B/main/out.txt" >&2 || true; bad "output differs from expected.txt"; } + +n=0 +mutant() { # NAME SITE REPLACEMENT LABEL + c=$(grep -c -x -F "$2" "$D/segment.om" || true) + [ "$c" = 1 ] || bad "mutant $1: site found $c times" + awk -v s="$2" -v r="$3" '$0 == s { print r; next } { print }' "$D/segment.om" > "$B/$1.om" + cmp -s "$B/$1.om" "$D/segment.om" && bad "mutant $1: source unchanged" + cat "$B/$1.om" "$D/segment-test.om" > "$B/$1-test.om" + run "$1" "$B/$1-test.om" + [ "$rc" -eq 1 ] || bad "mutant $1 exited $rc, need 1" + grep -q "^$4 [0-9]* FAIL want=" "$B/$1/out.txt" || bad "mutant $1 did not fail $4" + echo "mutant $1: exit 1, $4 FAIL" + n=$((n + 1)) +} +mutant crc 'if ne want segcrc 60' 'if ne want want' crc-reason +mutant torn 'put sreason 0 1' 'put sreason 0 0' torn-reason +mutant align 'if ne rem r 64 0' 'if ne rem r 1 0' torn-append-refused +mutant excl 'fd = fopen tpath 0 get tlen 0 32961 384' 'fd = fopen tpath 0 get tlen 0 33345 384' create-again-refused +printf 'PASS trace %s checks, %s/4 mutants caught\n' "$(sed -n 's/^segment-test checks=\([0-9]*\) fails=0$/\1/p' "$B/main/out.txt")" "$n" diff --git a/seed/trace/segment-test.om b/seed/trace/segment-test.om new file mode 100644 index 000000000..5f291b2f7 --- /dev/null +++ b/seed/trace/segment-test.om @@ -0,0 +1,333 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note seed/trace/segment-test.om: checks for segment.om (#608). Concatenate after segment.om and compile. +note Runs in the current directory under build/trace-test/. Each check prints "<label> <observed>" and, +note when it differs, " FAIL want=<expected>". The gate compares stdout with expected.txt byte for byte. +note Exit 0 when every check holds, 1 otherwise, 2 when stdout cannot be written. +global checks ulong 1 +global fails ulong 1 +global obuf uchar 256 +global on ulong 1 +global wbad ulong 1 +text labs "crc-123456789\ncrc-empty\nmissing-scan\nmissing-errno\ncreate\ncreate-again-refused\ncreate-again-errno\nappend-100-errors\nappend-last-seq\nscan\nscan-count\nscan-reason\nscan-total\nscan-lost\nappend-oversize-refused\ntruncate-last-record\ntorn-scan\ntorn-count\ntorn-reason\ntorn-lost\ntorn-append-refused\ntorn-size-unchanged\ntorn-recover\ntorn-recover-lost\nrecovered-scan\nrecovered-count\nrecovered-reason\nrecovered-total\nquarantine-size\nappend-after-recover\nappend-after-seq\nrecover-clean\nclean-count\ncrc-flip-poke\ncrc-scan\ncrc-count\ncrc-reason\ncrc-lost\ncrc-recover-bad-exists\ncrc-segment-unchanged\nunlink-bad\ncrc-recover\ncrc-recovered-scan\ncrc-recovered-count\ncrc-recovered-reason\nlen-raw-append\nlen-scan\nlen-count\nlen-reason\nlen-recover\nseq-raw-append\nseq-scan\nseq-count\nseq-reason\nseq-recover\nversion-poke\nversion-scan\nversion-append-refused\nversion-size-unchanged\nmagic-scan\ngeometry-scan\nreserved-scan\nrestored-scan\nrestored-count\nsymlink-create\nsymlink-scan\nsymlink-errno\nsymlink-append-refused\nsymlink-recover-refused\nfinal-scan\nfinal-count\n" +text paths "build/trace-test/segment\nbuild/trace-test/link\n" +text dbuild "build" +text dtest "build/trace-test" +text tgt "segment" +text sfail " FAIL want=" +text sumt "segment-test checks=" +text sumf " fails=" +fn oflush to void +w = write 1 obuf 0 get on 0 +if ne w long get on 0 +put wbad 0 1 +end +put on 0 0 +end +fn obyte b uchar to void +put obuf get on 0 b +put on 0 add get on 0 1 +end +fn onum v ulong to void +d = new uchar 20 0 +x = v +k = ulong 0 +go = true +while go bound 21 +put d k uchar add 48 rem x 10 +k = add k 1 +x = div x 10 +if eq x 0 +go = false +end +end +while gt k 0 bound 21 +k = sub k 1 +obyte get d k +end +end +note label k: emit the k-th newline-terminated line of labs (k from 1). +fn label k ulong to void +line = ulong 1 +for i ulong len labs +b = get labs i +if eq b 10 +line = add line 1 +else +if eq line k +obyte b +end +end +end +end +fn check got ulong want ulong to void +put checks 0 add get checks 0 1 +label get checks 0 +obyte 32 +onum got +if ne got want +put fails 0 add get fails 0 1 +for i ulong len sfail +obyte get sfail i +end +onum want +end +obyte 10 +oflush +end +note setp k: the k-th line of paths (k from 1) becomes the segment path. +fn setp k ulong to void +line = ulong 1 +n = ulong 0 +for i ulong len paths +b = get paths i +if eq b 10 +line = add line 1 +else +if eq line k +put tpath n b +n = add n 1 +end +end +end +put tlen 0 n +end +fn errno to ulong +ret ulong neg get serrno 0 +end +fn fsize to ulong +fd = fopen tpath 0 get tlen 0 32768 0 +if lt fd 0 +ret 0 +end +pos = fseek int fd 0 2 +shut fd +if lt pos 0 +ret 0 +end +ret ulong pos +end +fn fsizebad to ulong +sidepath 1 +fd = fopen opath 0 get olen 0 32768 0 +if lt fd 0 +ret 0 +end +pos = fseek int fd 0 2 +shut fd +if lt pos 0 +ret 0 +end +ret ulong pos +end +note poke off v: overwrite one byte of the segment in place (fault injection, not a library path). +fn poke off ulong v ulong to ulong +fd = fopen tpath 0 get tlen 0 32769 0 +if lt fd 0 +ret 1 +end +put trec 0 uchar v +w = pwrite int fd trec 0 1 long off +shut fd +if ne w 1 +ret 1 +end +ret 0 +end +note rawapp: append trec as-is, bypassing segappend (fault injection for crafted records). +fn rawapp to ulong +fd = fopen tpath 0 get tlen 0 33793 0 +if lt fd 0 +ret 1 +end +w = write int fd trec 0 64 +shut fd +if ne w 64 +ret 1 +end +ret 0 +end +fn unlbad to ulong +sidepath 1 +u = unlink opath 0 get olen 0 +if lt u 0 +ret 1 +end +ret 0 +end +fn mklink to ulong +setp 2 +put tn 0 0 +tput16 2 +tput16 len tgt +for i ulong len tgt +put tpkt add get tn 0 i get tgt i +end +put tn 0 add get tn 0 len tgt +pkttop +s = symlnk tpkt 0 get tn 0 +setp 1 +if lt s 0 +ret 1 +end +ret 0 +end +fn cleanup to void +setp 2 +u1 = unlink tpath 0 get tlen 0 +setp 1 +u2 = unlink tpath 0 get tlen 0 +sidepath 1 +u3 = unlink opath 0 get olen 0 +sidepath 2 +u4 = unlink opath 0 get olen 0 +end +fn crcvec to void +for i ulong 9 +put trec i uchar add 49 i +end +check segcrc 9 3421780262 +check segcrc 0 0 +end +fn fill100 to void +bad = ulong 0 +for i ulong 100 +put pay 0 uchar and i 255 +put pay 1 uchar and shr i 8 255 +put pay 2 0 +put pay 3 0 +if ne segappend 1 4 0 +bad = add bad 1 +end +end +check bad 0 +check get sseq 0 99 +end +fn scan5 c ulong r ulong t ulong l ulong to void +check segscan 0 +check get scount 0 c +check get sreason 0 r +check get stotal 0 t +check get slost 0 l +end +fn phase1 to void +check segscan 10 +check errno 2 +check segcreate 0 +check segcreate 10 +check errno 17 +fill100 +scan5 100 0 6416 0 +check segappend 1 53 20 +check ulong truncate tpath 0 get tlen 0 6382 0 +check segscan 0 +check get scount 0 99 +check get sreason 0 1 +check get slost 0 30 +check segappend 1 4 25 +check fsize 6382 +check segrecover 1 +check get slost 0 30 +check segscan 0 +check get scount 0 99 +check get sreason 0 0 +check get stotal 0 6352 +check fsizebad 6382 +check segappend 1 4 0 +check get sseq 0 99 +check segrecover 0 +e = segscan +end +fn phase2 to void +check get scount 0 100 +check poke 3224 51 0 +check segscan 0 +check get scount 0 50 +check get sreason 0 3 +check get slost 0 3200 +check segrecover 32 +check fsize 6416 +check unlbad 0 +check segrecover 1 +check segscan 0 +check get scount 0 50 +check get sreason 0 0 +end +fn phase3 to void +segpack 1 4 50 +put trec 2 60 +segseal +check rawapp 0 +check segscan 0 +check get scount 0 50 +check get sreason 0 2 +e = unlbad +check segrecover 1 +segpack 1 4 7 +check rawapp 0 +check segscan 0 +check get scount 0 50 +check get sreason 0 4 +e2 = unlbad +check segrecover 1 +end +fn phase4 to void +check poke 4 2 0 +check segscan 15 +check segappend 1 4 15 +check fsize 3216 +p1 = poke 4 1 +p2 = poke 0 0 +check segscan 11 +p3 = poke 0 65 +p4 = poke 6 32 +check segscan 16 +p5 = poke 6 64 +p6 = poke 12 1 +check segscan 16 +p7 = poke 12 0 +check segscan 0 +check get scount 0 50 +end +fn phase5 to void +check mklink 0 +setp 2 +check segscan 10 +check errno 40 +check segappend 1 4 10 +check segrecover 10 +setp 1 +check segscan 0 +check get scount 0 50 +end +fn summary to void +for i ulong len sumt +obyte get sumt i +end +onum get checks 0 +for i ulong len sumf +obyte get sumf i +end +onum get fails 0 +obyte 10 +oflush +end +fn main to int +m1 = makedir dbuild 0 len dbuild 448 +m2 = makedir dtest 0 len dtest 448 +cleanup +setp 1 +crcvec +phase1 +phase2 +phase3 +phase4 +phase5 +summary +if ne get wbad 0 0 +ret 2 +end +if ne get fails 0 0 +ret 1 +end +ret 0 +end diff --git a/seed/trace/segment.om b/seed/trace/segment.om new file mode 100644 index 000000000..0d3cf2670 --- /dev/null +++ b/seed/trace/segment.om @@ -0,0 +1,424 @@ +note SPDX-License-Identifier: AGPL-3.0-only +note seed/trace/segment.om: local trace segment, format version 1 (omega-mv #608). Library unit with no +note main: concatenate it before a program that defines main (units concatenate; there is no import). +note Header, 16 bytes: "AITR", version u16 = 1, record size u16 = 64, header size u32 = 16, reserved +note u32 = 0. Record, 64 bytes: type u16, payload length u16 (at most 52), sequence u32 (= record index, +note assigned by the writer), 52 payload bytes (zero past the length), CRC-32 u32 of bytes 0..59. +note CRC-32 is IEEE 802.3, reflected polynomial 3988292384 (0xEDB88320), initial value and final xor +note 4294967295. Every integer is little-endian. Single writer. No network, consent, export, index, +note rotation or retention in this unit. The caller puts the segment path in tpath and its length in +note tlen; sibling paths are the same path plus ".bad" (quarantine) or ".new" (recovery staging). +note Opens carry O_NOFOLLOW (32768), so a symbolic link in the last path component is refused. +global thdr uchar 16 +global trec uchar 64 +global tpath uchar 1024 +global tlen ulong 1 +global opath uchar 1040 +global olen ulong 1 +global tpkt uchar 2100 +global tn ulong 1 +global pay uchar 52 +global scount ulong 1 +global sreason ulong 1 +global stotal ulong 1 +global slost ulong 1 +global sseq ulong 1 +global serrno long 1 +text sbadsfx ".bad" +text snewsfx ".new" +note Error codes (function results): 0 ok; 10 open refused (missing, exists on create, symlink: +note serrno holds -errno); 11 short header or bad magic; 12 close failed; 13 header write/sync failed; +note 15 unsupported version; 16 bad geometry or nonzero reserved bytes; 17 read error; 20 payload over +note 52 bytes; 21 append open failed; 22 short record write (a torn tail may now exist); 23 fsync; +note 24 close; 25 segment length is not header + whole records (torn tail: recover first); 26 segment +note full (4096 records); 27 seek failed; 30 staging file; 31 copy failed; 32 quarantine link refused +note (segment.bad already exists or link failed); 33 rename of the staged segment failed. +note Scan reasons (sreason): 0 clean; 1 torn tail (partial record); 2 payload length over 52; +note 3 CRC mismatch; 4 sequence is not the record index; 5 more than 4096 records. +fn shut fd long to void +c = fclose int fd +if lt c 0 +put serrno 0 c +end +end +fn sidepath k ulong to void +n = get tlen 0 +for i ulong n +put opath i get tpath i +end +if eq k 1 +for i ulong len sbadsfx +put opath add n i get sbadsfx i +end +put olen 0 add n len sbadsfx +else +for i ulong len snewsfx +put opath add n i get snewsfx i +end +put olen 0 add n len snewsfx +end +end +fn tput16 v ulong to void +put tpkt get tn 0 uchar and v 255 +put tpkt add get tn 0 1 uchar and shr v 8 255 +put tn 0 add get tn 0 2 +end +fn pkttop to void +tput16 get tlen 0 +for i ulong get tlen 0 +put tpkt add get tn 0 i get tpath i +end +put tn 0 add get tn 0 get tlen 0 +end +fn pktoth to void +tput16 get olen 0 +for i ulong get olen 0 +put tpkt add get tn 0 i get opath i +end +put tn 0 add get tn 0 get olen 0 +end +fn segcrc n ulong to ulong +c = ulong 4294967295 +for i ulong n +c = xor c ulong get trec i +for k ulong 8 +if eq and c 1 1 +c = xor shr c 1 3988292384 +else +c = shr c 1 +end +end +end +ret xor c 4294967295 +end +fn ld16 o ulong to ulong +ret or ulong get trec o shl ulong get trec add o 1 8 +end +fn ld32 o ulong to ulong +lo = ld16 o +hi = ld16 add o 2 +ret or lo shl hi 16 +end +fn st32 o ulong v ulong to void +put trec o uchar and v 255 +put trec add o 1 uchar and shr v 8 255 +put trec add o 2 uchar and shr v 16 255 +put trec add o 3 uchar and shr v 24 255 +end +fn segseal to void +st32 60 segcrc 60 +end +fn segpack t ulong n ulong seq ulong to void +for i ulong 64 +put trec i 0 +end +put trec 0 uchar and t 255 +put trec 1 uchar and shr t 8 255 +put trec 2 uchar and n 255 +put trec 3 uchar and shr n 8 255 +st32 4 seq +for i ulong n +put trec add 8 i get pay i +end +segseal +end +fn mkheader to void +for i ulong 16 +put thdr i 0 +end +put thdr 0 65 +put thdr 1 73 +put thdr 2 84 +put thdr 3 82 +put thdr 4 1 +put thdr 6 64 +put thdr 8 16 +end +fn hdrcheck to ulong +if or ne get thdr 0 65 ne get thdr 1 73 +ret 11 +end +if or ne get thdr 2 84 ne get thdr 3 82 +ret 11 +end +if or ne get thdr 4 1 ne get thdr 5 0 +ret 15 +end +if or ne get thdr 6 64 ne get thdr 7 0 +ret 16 +end +if ne get thdr 8 16 +ret 16 +end +for i ulong 7 +if ne get thdr add 9 i 0 +ret 16 +end +end +ret 0 +end +note segcreate refuses an existing path (O_EXCL) instead of truncating it: data is never overwritten. +fn segcreate to ulong +mkheader +fd = fopen tpath 0 get tlen 0 32961 384 +if lt fd 0 +put serrno 0 fd +ret 10 +end +n = write int fd thdr 0 16 +if ne n 16 +shut fd +ret 13 +end +if ne fsync int fd 0 +shut fd +ret 13 +end +if ne fclose int fd 0 +ret 12 +end +ret 0 +end +note segready creates a missing segment and otherwise requires a valid header; it never recreates one. +fn segready to ulong +fd = fopen tpath 0 get tlen 0 32768 0 +if eq fd -2 +ret segcreate +end +if lt fd 0 +put serrno 0 fd +ret 10 +end +n = read int fd thdr 0 16 +if ne fclose int fd 0 +ret 12 +end +if lt n 0 +ret 17 +end +if ne n 16 +ret 11 +end +ret hdrcheck +end +fn segput fd long t ulong n ulong to ulong +pos = fseek int fd 0 2 +if lt pos 16 +ret 27 +end +r = sub ulong pos 16 +if ne rem r 64 0 +ret 25 +end +q = div r 64 +if ge q 4096 +ret 26 +end +segpack t n q +put sseq 0 q +m = write int fd trec 0 64 +if ne m 64 +ret 22 +end +if ne fsync int fd 0 +ret 23 +end +ret 0 +end +note segappend appends one record of type t with payload pay[0..n); the sequence is the record index. +fn segappend t ulong n ulong to ulong +if gt n 52 +ret 20 +end +e = segready +if ne e 0 +ret e +end +fd = fopen tpath 0 get tlen 0 33793 0 +if lt fd 0 +put serrno 0 fd +ret 21 +end +e = segput fd t n +if ne e 0 +shut fd +ret e +end +if ne fclose int fd 0 +ret 24 +end +ret 0 +end +fn recok idx ulong to ulong +if gt ld16 2 52 +ret 2 +end +want = ld32 60 +if ne want segcrc 60 +ret 3 +end +if ne ld32 4 idx +ret 4 +end +ret 0 +end +note Each pass reads one record or ends; at most 4097 full records plus the final read: bound 4098. +fn scanrecs fd long to ulong +go = true +while go bound 4098 +m = read int fd trec 0 64 +if lt m 0 +ret 17 +end +if eq m 0 +go = false +else +if lt m 64 +put sreason 0 1 +go = false +else +if ge get scount 0 4096 +put sreason 0 5 +go = false +else +r = recok get scount 0 +if ne r 0 +put sreason 0 r +go = false +else +put scount 0 add get scount 0 1 +end +end +end +end +end +ret 0 +end +note segscan is read-only. scount = complete valid records before the first damage, sreason = why the +note scan stopped, stotal = file bytes, slost = bytes after the valid prefix (what recovery quarantines). +fn segscan to ulong +put scount 0 0 +put sreason 0 0 +put stotal 0 0 +put slost 0 0 +fd = fopen tpath 0 get tlen 0 32768 0 +if lt fd 0 +put serrno 0 fd +ret 10 +end +n = read int fd thdr 0 16 +if ne n 16 +shut fd +ret 11 +end +e = hdrcheck +if ne e 0 +shut fd +ret e +end +pos = fseek int fd 0 2 +p2 = fseek int fd 16 0 +if or lt pos 16 ne p2 16 +shut fd +ret 27 +end +put stotal 0 ulong pos +e = scanrecs fd +if ne fclose int fd 0 +ret 12 +end +used = add 16 mul get scount 0 64 +put slost 0 sub get stotal 0 used +ret e +end +fn copyrecs src long dst long to ulong +mkheader +w = write int dst thdr 0 16 +if ne w 16 +ret 31 +end +p = fseek int src 16 0 +if ne p 16 +ret 31 +end +for i ulong get scount 0 +m = read int src trec 0 64 +if ne m 64 +ret 31 +end +w2 = write int dst trec 0 64 +if ne w2 64 +ret 31 +end +end +if ne fsync int dst 0 +ret 31 +end +ret 0 +end +note stage writes header + the valid prefix to segment.new (a stale .new from an interrupted recovery is +note removed first; the segment itself is untouched until the final rename). +fn stage to ulong +sidepath 2 +u = unlink opath 0 get olen 0 +if and lt u 0 ne u -2 +put serrno 0 u +ret 30 +end +src = fopen tpath 0 get tlen 0 32768 0 +if lt src 0 +put serrno 0 src +ret 30 +end +dst = fopen opath 0 get olen 0 32961 384 +if lt dst 0 +put serrno 0 dst +shut src +ret 30 +end +e = copyrecs src dst +shut src +if ne fclose int dst 0 +ret 31 +end +ret e +end +note segrecover: a damaged record area is never repaired in place. The valid prefix is staged, the damaged +note file is hard-linked to segment.bad (refused if that exists: a quarantine is never overwritten), then +note the staged file is renamed over the segment. At every step the segment path names either the old +note damaged file or the complete new one. Returns 0 clean, 1 recovered (slost bytes quarantined), or an +note error code. A bad header is not recovered automatically (segscan's error is returned). +fn segrecover to ulong +e = segscan +if ne e 0 +ret e +end +if eq get sreason 0 0 +ret 0 +end +e = stage +if ne e 0 +ret e +end +sidepath 1 +put tn 0 0 +tput16 2 +pkttop +pktoth +lk = link tpkt 0 get tn 0 +if lt lk 0 +put serrno 0 lk +ret 32 +end +sidepath 2 +put tn 0 0 +tput16 2 +pktoth +pkttop +rr = renames tpkt 0 get tn 0 0 +if lt rr 0 +put serrno 0 rr +ret 33 +end +ret 1 +end diff --git a/tests/.crumb b/tests/.crumb index 5fbfcb29c..a01d28de0 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:03:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", + "digest": "sha256:f7d2a0bb37d8d390b9e187eb46545748a037d43e38716cf5783374b6404f2bb1", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1386, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679" + "files": 1387, + "generated_at_commit": "a8b948018e45f8375d34db67ca96d65d88e0fe99", + "source_tree": "sha256:8cebe384932b84216eca49a49f4ba7833fe6c44a8079557dde38041de6e05de3" }, "owner_lane": "", "provenance": { diff --git a/tests/gates/omega-trace.gate b/tests/gates/omega-trace.gate new file mode 100644 index 000000000..95369d7a0 --- /dev/null +++ b/tests/gates/omega-trace.gate @@ -0,0 +1,23 @@ +# tests/gates/omega-trace.gate +# omega#608: local trace segment format v1 in seeded Omega (seed/trace/segment.om): write, scan, torn-tail +# recovery keeping the valid prefix, CRC-32 per record, and 4 source mutants, built by the committed +# seed/out/omc. No hosted mirror: local gate only. +gate: OMEGA-TRACE +manifest_version: 2 +owner: omega +requires: + - host +inputs: + - seed/trace/ + - seed/out/omc + - seed/out/omc.sha256 + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["trace"] +expects: + exit: 0 + verdict: PASS +timeout: 10m +exactness: EXACT +cache_scope: machine diff --git a/tests/gates/run.sh b/tests/gates/run.sh index 66da8e1a9..c9bd37775 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -327,6 +327,14 @@ case "$step" in obs omc_sha256 "\"$(sha256sum < seed/out/omc | cut -c1-64)\"" sh seed/tilelab/gate.sh ;; + trace) # omega#608: local trace segment (seed/trace/segment.om), built by the committed seed/out/omc + # after its recorded SHA-256 is checked: 71 checks against expected.txt (torn-tail recovery + # keeps N-1 records, CRC/length/sequence damage, header refusals, O_EXCL, O_NOFOLLOW) and + # 4 source mutants (CRC check, torn tail, alignment, O_EXCL) that must each fail their check. + sha256sum -c seed/out/omc.sha256 + obs omc_sha256 "\"$(sha256sum < seed/out/omc | cut -c1-64)\"" + sh seed/trace/gate.sh + ;; native) # omega#663/#664: native .om units built by the committed seed/out/omc after its recorded # SHA-256 is checked. The metadata test must pass and each recorded ECOSYSTEM663 mutant must # exit 1; with native/autodiff664 present, its tape suite (test + 3 compiled mutants) and the