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

GitHub aien-dev/omega-mv#947 (code only)

closed derived 04050de5bf6da2f1 #947

Imported from GitHub aien-dev/omega-mv#947 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 62d1d0d668f897386a0e311374f8dbcc5c32dde8 · Head 436ceaae8cda642def8808ee17404a6bf58cc3f2

github-advanced-security[bot] commented on tests/visor/test_visor_evidence.c line 68 on 2026-10-30 15:02 UTC

CodeQL / File created without restricting permissions

A file may be created here with mode 0666, which would make it world-writable.

Show more details

github-advanced-security[bot] commented on tests/visor/test_visor_evidence.c line 68 on 2026-10-30 15:02 UTC

github-advanced-security[bot] reviewed (COMMENTED) on 2026-10-30 15:02 UTC

Apply it

git checkout -b patch-04050de5bf6da2f1 62d1d0d668f897386a0e311374f8dbcc5c32dde8
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/04050de5bf6da2f1.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
947
436ceaae8cda642def8808ee17404a6bf58cc3f2
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":947,"url":"https://github.com/aien-dev/omega-mv/pull/947","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:26Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index f3e51fe46..7aa85b7f7 100644
--- a/.crumb
+++ b/.crumb
@@ -71,39 +71,39 @@
           "purpose": "Directory research. Purpose not yet described by a human."
         },
         {
-          "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986",
-          "last_commit": "a8a6a3d3c",
+          "digest": "81e06ef5a9bc757dd9f43dcbf79966faadc98bbc9e88000cb514e667fdffaac5",
+          "last_commit": "52c62d6c4",
           "name": "spec",
           "purpose": "Directory spec. Purpose not yet described by a human."
         },
         {
-          "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7",
-          "last_commit": "bf54b19fa",
+          "digest": "4f9bac5138ef312b575ec54c6a6a9f1c5bb614c45a65f5a6e8332cb2f35158a9",
+          "last_commit": "52c62d6c4",
           "name": "src",
           "purpose": "Directory src. Purpose not yet described by a human."
         },
         {
-          "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
-          "last_commit": "a8a6a3d3c",
+          "digest": "1047173bf3d1a1e2108a265ee1c9229c49a41adc03b80c2004ac46bd7deaacbf",
+          "last_commit": "52c62d6c4",
           "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:73cd1ea53d22c1aa94995ff8dcfd905039854dbffade4196f1a8aaf4d27e370c",
+      "compiled_at": "2026-10-30T16:09:29Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6",
+      "digest": "sha256:28bbabf888d62915b3f6b6b382c4e23a7ea223c6ddd5cef93add095665a56630",
       "evidence_files": 12622,
       "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9",
       "files": 17849,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed"
+      "generated_at_commit": "52c62d6c439c65614ad6c298a80c677efdc602fd",
+      "source_tree": "sha256:9e9122f03b43f304dd9de3b6c9cf36af7456976642b2ca9ab118a400cdc12ba7"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/spec/.crumb b/spec/.crumb
index a226ce192..b4f8c19d5 100644
--- a/spec/.crumb
+++ b/spec/.crumb
@@ -20,14 +20,14 @@
         }
       ],
       "children_root": "sha256:6834a3241647d3a098283d4eafedbdb1428dfa4d834f9ed5f22025b6d2303093",
-      "compiled_at": "2026-10-30T11:28:28Z",
+      "compiled_at": "2026-10-30T14:45:45Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986",
+      "digest": "sha256:81e06ef5a9bc757dd9f43dcbf79966faadc98bbc9e88000cb514e667fdffaac5",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 63,
-      "generated_at_commit": "a8a6a3d3c47ce797430f045edc5eae11594ba36d",
-      "source_tree": "sha256:4cb3bb1977c84caacc34366f814d6fe403a2eda7b89b916948d29541675c59bb"
+      "generated_at_commit": "62d1d0d668f897386a0e311374f8dbcc5c32dde8",
+      "source_tree": "sha256:17f479115f894bd08492c4eec39ae1c6ea1dba519d0032154a583de4a8d7350c"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/spec/omega-incremental-semantics.md b/spec/omega-incremental-semantics.md
index bed781dab..34cc448bd 100644
--- a/spec/omega-incremental-semantics.md
+++ b/spec/omega-incremental-semantics.md
@@ -205,6 +205,12 @@ measurement and not a quiet-machine R15 qualification.
 | `HOST_PASS_ENERGY_UNMEASURED` | Everything passes on a host with no energy counter, such as CI. |
 | `FAIL` | Anything else. |
 
+The host gate (`tests/gates/run.sh rx-host-reference`) requires the value that
+matches the machine: `PASS` on a host whose hwmon exposes the `aien_spbm`
+package energy counter, `HOST_PASS_ENERGY_UNMEASURED` on a host without it. It
+records which one as the observation `incremental_semantics_verdict`.
+`PASS_UNBOUND` and `FAIL` fail the gate on every host (omega-mv#404 item 2).
+
 ## Limits
 
 - Functions must be pure over their declared inputs. The engine cannot see an
diff --git a/src/.crumb b/src/.crumb
index 7c4b83da7..c8ef04d18 100644
--- a/src/.crumb
+++ b/src/.crumb
@@ -181,21 +181,21 @@
           "purpose": "Directory src/turing. Purpose not yet described by a human."
         },
         {
-          "digest": "b2e34b2ea0392059ac30d17e27289b1146e523db60a02ef825edef96036817ab",
+          "digest": "e832df528a0a0992e817f879c5b7df52c33b8445f30fc2743e5c0fa5ad6e6b2a",
           "last_commit": "d863780eb",
           "name": "visor",
           "purpose": "Directory src/visor. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:2f729945214be989a74d7c2064ae4ba3c2deb52ebea3f334b459198a7bd032ed",
-      "compiled_at": "2026-10-30T02:49:13Z",
+      "children_root": "sha256:e3f39dc892d911707fbbe59b17ac924bd1274a869b640eccda4d854487217887",
+      "compiled_at": "2026-10-30T14:45:45Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7",
+      "digest": "sha256:4f9bac5138ef312b575ec54c6a6a9f1c5bb614c45a65f5a6e8332cb2f35158a9",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 568,
-      "generated_at_commit": "2cb1ccb5d3c1a1ce1cb94a7a3dd3c221395c4e15",
-      "source_tree": "sha256:7f1fef46a27e8baf5cf567bb590d417ede3767c5f07e714d0f0812af0645bb4b"
+      "generated_at_commit": "62d1d0d668f897386a0e311374f8dbcc5c32dde8",
+      "source_tree": "sha256:a9900b022cce3448fba3563860e9162e14babf5f6adda90a8e0fe38dd76c4413"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/src/visor/.crumb b/src/visor/.crumb
index da9ff4e44..2f79d006a 100644
--- a/src/visor/.crumb
+++ b/src/visor/.crumb
@@ -14,20 +14,20 @@
       "children": [
         {
           "digest": "a3579edee497773e4bfa2486863dad01e27bad9e0f393cf2697a6783d059b4b0",
-          "last_commit": "dc7c1304",
+          "last_commit": "d863780eb",
           "name": "rx",
           "purpose": "Directory src/visor/rx. Purpose not yet described by a human."
         }
       ],
       "children_root": "sha256:9078572eab3bdd92914cafdc865c5f2786a04189f1f9596f7d3351ed77d53336",
-      "compiled_at": "2026-10-24T04:15:18Z",
+      "compiled_at": "2026-10-30T14:45:45Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:b2e34b2ea0392059ac30d17e27289b1146e523db60a02ef825edef96036817ab",
+      "digest": "sha256:e832df528a0a0992e817f879c5b7df52c33b8445f30fc2743e5c0fa5ad6e6b2a",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 21,
-      "generated_at_commit": "dc7c1304c038f49db3b121d5a5e27d7bcab5bf6c",
-      "source_tree": "sha256:a76a2bc6e0bf9b3ab4a7be87598be5067ac3e05284e99bf5a923072790cfc1f3"
+      "generated_at_commit": "62d1d0d668f897386a0e311374f8dbcc5c32dde8",
+      "source_tree": "sha256:d1f9cfbc57c6d5b0ee3103f405c814eeed0887c3316e02913e608b4ab11b319f"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/src/visor/visor_evidence.c b/src/visor/visor_evidence.c
index f7170c77c..7b9561ba2 100644
--- a/src/visor/visor_evidence.c
+++ b/src/visor/visor_evidence.c
@@ -457,10 +457,56 @@ int visor_evidence_load(const char *path, VisorEvidenceRecord *out) {
 /* ------------------------------------------------------------------ */
 /* Directory walk (sorted, deterministic)                              */
 /* ------------------------------------------------------------------ */
-#define VISOR_EVIDENCE_MAX_FILES 1024
-static char g_paths[VISOR_EVIDENCE_MAX_FILES][256];
-static size_t g_npaths;
-static bool g_paths_overflow;
+/* The kept set never depends on readdir order (omega-mv#404): below the cap every regular
+ * file is kept; past it the list is a max-heap on strcmp and a later path replaces the
+ * largest kept one when it sorts before it, so the scan keeps exactly the g_max_files
+ * smallest paths of the tree, whatever order the filesystem returned them in. */
+typedef char VisorPath[256];
+static VisorPath *g_paths;
+static size_t g_npaths, g_paths_alloc;
+static size_t g_max_files = VISOR_EVIDENCE_MAX_FILES;
+static bool g_paths_overflow, g_paths_oom;
+
+size_t visor_evidence_set_max_files(size_t cap) {
+    size_t prev = g_max_files;
+    g_max_files = cap ? cap : VISOR_EVIDENCE_MAX_FILES;
+    return prev;
+}
+
+static void heap_sift_down(size_t i) {
+    for (;;) {
+        size_t l = 2 * i + 1, r = l + 1, m = i;
+        if (l < g_npaths && strcmp(g_paths[l], g_paths[m]) > 0) m = l;
+        if (r < g_npaths && strcmp(g_paths[r], g_paths[m]) > 0) m = r;
+        if (m == i) return;
+        VisorPath t;
+        memcpy(t, g_paths[i], sizeof(t));
+        memcpy(g_paths[i], g_paths[m], sizeof(t));
+        memcpy(g_paths[m], t, sizeof(t));
+        i = m;
+    }
+}
+
+static void keep_path(const VisorPath p) {
+    if (g_npaths < g_max_files) {
+        if (g_npaths == g_paths_alloc) {
+            size_t n = g_paths_alloc ? g_paths_alloc * 2 : 1024;
+            if (n > g_max_files) n = g_max_files;
+            VisorPath *q = realloc(g_paths, n * sizeof(*q));
+            if (!q) { g_paths_oom = true; return; }
+            g_paths = q;
+            g_paths_alloc = n;
+        }
+        memcpy(g_paths[g_npaths++], p, sizeof(VisorPath));
+        if (g_npaths == g_max_files)
+            for (size_t i = g_npaths / 2; i-- > 0;) heap_sift_down(i);
+        return;
+    }
+    g_paths_overflow = true;
+    if (strcmp(p, g_paths[0]) >= 0) return;            /* sorts after every kept path */
+    memcpy(g_paths[0], p, sizeof(VisorPath));
+    heap_sift_down(0);
+}
 
 static void walk(const char *dir, int depth) {
     if (depth > 8) return;
@@ -469,15 +515,14 @@ static void walk(const char *dir, int depth) {
     struct dirent *e;
     while ((e = readdir(d)) != NULL) {
         if (e->d_name[0] == '.') continue;
-        char p[256];
+        VisorPath p;
         int w = snprintf(p, sizeof(p), "%s%s%s", dir, dir[strlen(dir) - 1] == '/' ? "" : "/", e->d_name);
         if (w < 0 || (size_t)w >= sizeof(p)) { g_paths_overflow = true; continue; }
         struct stat st;
         if (lstat(p, &st) != 0) continue;
         if (S_ISDIR(st.st_mode)) { walk(p, depth + 1); continue; }
         if (!S_ISREG(st.st_mode)) continue;               /* symlinks and devices are not followed */
-        if (g_npaths >= VISOR_EVIDENCE_MAX_FILES) { g_paths_overflow = true; continue; }
-        memcpy(g_paths[g_npaths++], p, sizeof(p));
+        keep_path(p);
     }
     closedir(d);
 }
@@ -489,8 +534,10 @@ static int collect(const char *root) {
     if (!root || !root[0] || stat(root, &st) != 0 || !S_ISDIR(st.st_mode)) return -1;
     g_npaths = 0;
     g_paths_overflow = false;
+    g_paths_oom = false;
     walk(root, 0);
-    qsort(g_paths, g_npaths, sizeof(g_paths[0]), cmp_path);
+    if (g_paths_oom) return -1;                        /* fail closed: a dropped path could hide evidence */
+    if (g_npaths) qsort(g_paths, g_npaths, sizeof(g_paths[0]), cmp_path);
     return 0;
 }
 
diff --git a/src/visor/visor_evidence.h b/src/visor/visor_evidence.h
index c421a4d72..ca19b1cae 100644
--- a/src/visor/visor_evidence.h
+++ b/src/visor/visor_evidence.h
@@ -51,6 +51,9 @@
 #define VISOR_EVIDENCE_MAX_ITEMS 16
 #define VISOR_EVIDENCE_MAX_UNPARSED_PATHS 8
 #define VISOR_EVIDENCE_MAX_FILE_BYTES (256u * 1024u)
+/* Walk cap: regular files kept per scan. Past it the scan keeps the lexicographically
+ * smallest paths (never the first ones readdir returned) and sets truncated. */
+#define VISOR_EVIDENCE_MAX_FILES ((size_t)131072)
 
 typedef enum {
     VISOR_QUAL_UNKNOWN, VISOR_QUAL_SIMULATED, VISOR_QUAL_HOST, VISOR_QUAL_QEMU, VISOR_QUAL_SILICON
@@ -89,8 +92,12 @@ typedef struct {
 
 const char *visor_qual_scope_name(VisorQualScope s);
 
-/* All receipts under root, depth-first, sorted by path. -1 if root unreadable. */
+/* All receipts under root, depth-first, sorted by path. -1 if root unreadable or the
+ * path list cannot be allocated. */
 int visor_evidence_scan(const char *evidence_root, VisorEvidenceView *out);
+/* Sets the walk cap (0 restores VISOR_EVIDENCE_MAX_FILES); returns the previous cap.
+ * Tests lower it to prove the cap keeps the same files for any readdir order. */
+size_t visor_evidence_set_max_files(size_t cap);
 /* Receipts whose bytes mention the id's 64-hex form (semantic, realization or
  * machine id, any nesting). count==0 means "no evidence" and returns 0. */
 int visor_evidence_for_id(const char *evidence_root, const SemanticId *id, VisorEvidenceView *out);
diff --git a/tests/.crumb b/tests/.crumb
index 5fbfcb29c..1e7f84237 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -295,21 +295,21 @@
           "purpose": "Directory tests/turing. Purpose not yet described by a human."
         },
         {
-          "digest": "930fcb9ce348c604424e5380796a77c3586a835b43d42b504325c36b12d166d7",
-          "last_commit": "450bbefd4",
+          "digest": "aad47a6f37231afcd415798fcd7f18cbcb541066bb958c09d44cb755ce385057",
+          "last_commit": "52c62d6c4",
           "name": "visor",
           "purpose": "Directory tests/visor. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902",
-      "compiled_at": "2026-10-30T12:31:50Z",
+      "children_root": "sha256:44a3884f0aa7799c2253e6dec8010192506737f5a796371a77c14b5c4a715372",
+      "compiled_at": "2026-10-30T16:09:29Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
+      "digest": "sha256:1047173bf3d1a1e2108a265ee1c9229c49a41adc03b80c2004ac46bd7deaacbf",
       "evidence_files": 16,
       "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a",
       "files": 1386,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679"
+      "generated_at_commit": "52c62d6c439c65614ad6c298a80c677efdc602fd",
+      "source_tree": "sha256:7b459a687f91ba6dfe2758a6a4a4a3134d2e79174bbc82335b61a0765a4d8f7c"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/tests/gates/run.sh b/tests/gates/run.sh
index 66da8e1a9..5dc7421e6 100755
--- a/tests/gates/run.sh
+++ b/tests/gates/run.sh
@@ -219,7 +219,13 @@ case "$step" in
     grep -q '^OMEGA_EFFECT_CAP64_PASS$' build/effect-cap64.log
     receipt omega_state_projection_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_STATE_PROJECTION_PASS": "PASS"'
     receipt rx_action_graph_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_ACTION_GRAPH_IR_PASS": "PASS"'
-    receipt omega_incremental_semantics_receipt.json '"OMEGA_INCREMENTAL_SEMANTICS_PASS": "HOST_PASS_ENERGY_UNMEASURED"' '"false_hits": 0,'
+    # omega-mv#404 item 2: PASS means the package energy counter (hwmon aien_spbm, found by the
+    # same name-prefix test rx_sem_incremental uses) measured the work; HOST_PASS_ENERGY_UNMEASURED
+    # means this host has no such counter. The verdict must match this host; PASS_UNBOUND and FAIL
+    # never pass. Which one ran is recorded as an observation.
+    if grep -qs '^aien_spbm' /sys/class/hwmon/*/name; then inc_verdict=PASS; else inc_verdict=HOST_PASS_ENERGY_UNMEASURED; fi
+    receipt omega_incremental_semantics_receipt.json "\"OMEGA_INCREMENTAL_SEMANTICS_PASS\": \"$inc_verdict\"" '"false_hits": 0,'
+    obs incremental_semantics_verdict "\"$inc_verdict\""
     receipt rx_capability_query_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_CAPABILITY_QUERY_PASS": "PASS"'
     receipt rx_semantic_comm_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_SEMANTIC_COMMUNICATION_PASS": "PASS"'
     receipt rx_cognitive_routing_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_COGNITIVE_ROUTING_PASS": "PASS"'
diff --git a/tests/visor/.crumb b/tests/visor/.crumb
index 910ea0dc3..100f1ed3b 100644
--- a/tests/visor/.crumb
+++ b/tests/visor/.crumb
@@ -22,7 +22,7 @@
       "children": [
         {
           "digest": "ece775b7c58ff8eec6dea09e286cfd56d3a7ca90a999b3ecc16fa249897622cb",
-          "last_commit": "992a8e254",
+          "last_commit": "450bbefd4",
           "name": "qualification",
           "purpose": "Directory tests/visor/qualification. Purpose not yet described by a human."
         },
@@ -34,14 +34,14 @@
         }
       ],
       "children_root": "sha256:5960bc1ab045c3674cf58dba97f8441009b83ba3ebd9923f96beb6a935b2fb39",
-      "compiled_at": "2026-10-25T21:57:22Z",
+      "compiled_at": "2026-10-30T16:09:29Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:930fcb9ce348c604424e5380796a77c3586a835b43d42b504325c36b12d166d7",
+      "digest": "sha256:aad47a6f37231afcd415798fcd7f18cbcb541066bb958c09d44cb755ce385057",
       "evidence_files": 8,
       "evidence_root": "sha256:a2c4aaddc14ed3b6aae059061c23683b4ccf0562046ec883b40f14014fbce670",
       "files": 33,
-      "generated_at_commit": "992a8e254658cecb2ca9e1eb74cf42c85d9e6816",
-      "source_tree": "sha256:4e26044777a6b15f32d0706f33745521b921d09a42bb2a7f4b8dbd854aca777a"
+      "generated_at_commit": "52c62d6c439c65614ad6c298a80c677efdc602fd",
+      "source_tree": "sha256:36e04d5c3143e545af718d5b3fcf0777969327b2a369c5b569d03c85cce3ea57"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/tests/visor/test_visor_evidence.c b/tests/visor/test_visor_evidence.c
index 49cafcc29..b2a35fa96 100644
--- a/tests/visor/test_visor_evidence.c
+++ b/tests/visor/test_visor_evidence.c
@@ -16,8 +16,13 @@
 
 /* Lane 4: visor_evidence tests (fixtures + read-only pass over the real evidence/ tree).
  * Run from the repo root. Prints "PASS n/n" on success. */
+#include <dirent.h>
+#include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "omega_canonical.h"
 #include "visor_evidence.h"
@@ -39,6 +44,126 @@ static const VisorEvidenceRecord *find(const VisorEvidenceView *view, const char
     return NULL;
 }
 
+/* --- omega-mv#404: a tree larger than the old 1024-file cap, built twice with the same
+ * names in opposite creation orders. tmpfs lists entries by creation order (newest first on
+ * Linux 7.0), so the two trees hand the walker opposite readdir orders; the note line prints
+ * where readdir put zzz_last_receipt.json in each. The view must be the same for both. --- */
+#define BIG_TXT 1500
+#define BIG_FILES (BIG_TXT + 2)
+static const char *const big_receipts[2] = {"a_first_receipt.json", "zzz_last_receipt.json"};
+static char receipt_bytes[65536];
+static size_t receipt_len;
+
+static int big_name(int k, char *out, size_t n) {   /* k-th name in ascending order */
+    if (k == 0) return snprintf(out, n, "%s", big_receipts[0]);
+    if (k == BIG_FILES - 1) return snprintf(out, n, "%s", big_receipts[1]);
+    return snprintf(out, n, "f%04d.txt", k - 1);
+}
+
+static int build_big_tree(const char *dir, int descending) {
+    if (mkdir(dir, 0700) != 0) return -1;
+    for (int i = 0; i < BIG_FILES; ++i) {
+        char name[64], p[512];
+        big_name(descending ? BIG_FILES - 1 - i : i, name, sizeof(name));
+        snprintf(p, sizeof(p), "%s/%s", dir, name);
+        /* Owner-only, never through an existing file or link (CodeQL world-writable-file-creation). */
+        int fd = open(p, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600);
+        if (fd < 0) return -1;
+        FILE *f = fdopen(fd, "wb");
+        if (!f) { close(fd); return -1; }
+        int json = strstr(name, ".json") != NULL;
+        size_t w = json ? fwrite(receipt_bytes, 1, receipt_len, f) : fwrite("not a receipt\n", 1, 14, f);
+        if (fclose(f) != 0 || w != (json ? receipt_len : 14)) return -1;
+    }
+    return 0;
+}
+
+static void remove_big_tree(const char *dir) {
+    for (int i = 0; i < BIG_FILES; ++i) {
+        char name[64], p[512];
+        big_name(i, name, sizeof(name));
+        snprintf(p, sizeof(p), "%s/%s", dir, name);
+        unlink(p);
+    }
+    rmdir(dir);
+}
+
+static long readdir_pos(const char *dir, const char *name) {
+    DIR *d = opendir(dir);
+    if (!d) return -1;
+    long i = 0, at = -1;
+    struct dirent *e;
+    while ((e = readdir(d)) != NULL) {
+        if (e->d_name[0] == '.') continue;
+        if (strcmp(e->d_name, name) == 0) at = i;
+        ++i;
+    }
+    closedir(d);
+    return at;
+}
+
+static int same_view(const VisorEvidenceView *a, const VisorEvidenceView *b, size_t ra, size_t rb) {
+    if (a->scanned != b->scanned || a->matched != b->matched || a->count != b->count ||
+        a->unparsed != b->unparsed || a->truncated != b->truncated || a->unparsed_listed != b->unparsed_listed)
+        return 0;
+    for (size_t i = 0; i < a->count; ++i)
+        if (strcmp(a->items[i].path + ra, b->items[i].path + rb) != 0 ||
+            strcmp(a->items[i].receipt_id, b->items[i].receipt_id) != 0) return 0;
+    for (size_t i = 0; i < a->unparsed_listed; ++i)
+        if (strcmp(a->unparsed_paths[i] + ra, b->unparsed_paths[i] + rb) != 0) return 0;
+    return 1;
+}
+
+static void check_large_tree(void) {
+    FILE *f = fopen(FIX "/HOST/host_run_receipt.json", "rb");
+    receipt_len = f ? fread(receipt_bytes, 1, sizeof(receipt_bytes), f) : 0;
+    if (f) fclose(f);
+    CHECK(receipt_len > 0 && receipt_len < sizeof(receipt_bytes), "large tree: receipt fixture read");
+
+    /* Fixed bases only: no directory from the environment reaches the scanner (CodeQL path-injection). */
+    struct stat st;
+    const char *base = stat("/dev/shm", &st) == 0 && S_ISDIR(st.st_mode) && access("/dev/shm", W_OK) == 0
+                           ? "/dev/shm" : "/tmp";
+    char root[512], asc[600], desc[600];
+    snprintf(root, sizeof(root), "%s/visor-evidence-404-XXXXXX", base);
+    if (!mkdtemp(root)) { CHECK(0, "large tree: mkdtemp"); return; }
+    snprintf(asc, sizeof(asc), "%s/asc", root);
+    snprintf(desc, sizeof(desc), "%s/desc", root);
+    CHECK(build_big_tree(asc, 0) == 0 && build_big_tree(desc, 1) == 0, "large tree: built");
+    fprintf(stderr, "note: %s: %s at readdir position %ld (asc) and %ld (desc) of %d\n", base, big_receipts[1],
+            readdir_pos(asc, big_receipts[1]), readdir_pos(desc, big_receipts[1]), BIG_FILES);
+    size_t ra = strlen(asc), rb = strlen(desc);
+
+    /* Default cap: every file is scanned in both trees. */
+    CHECK(visor_evidence_scan(asc, &v) == 0 && visor_evidence_scan(desc, &v2) == 0, "large tree: scan rc");
+    CHECK(v.scanned == BIG_FILES && v.matched == 2 && v.count == 2 && v.unparsed == BIG_TXT && !v.truncated,
+          "large tree: every file scanned, both receipts found, not truncated");
+    CHECK(v.count == 2 && strstr(v.items[0].path, big_receipts[0]) && strstr(v.items[1].path, big_receipts[1]),
+          "large tree: receipts in path order");
+    CHECK(same_view(&v, &v2, ra, rb), "large tree: same view for opposite readdir orders");
+
+    /* The old cap (1024) applied to the same trees: the kept files are the 1024 smallest paths,
+     * so a_first is kept and zzz_last is not, in both orders. */
+    size_t prev = visor_evidence_set_max_files(1024);
+    CHECK(visor_evidence_scan(asc, &v) == 0 && visor_evidence_scan(desc, &v2) == 0, "capped: scan rc");
+    CHECK(v.scanned == 1024 && v.truncated && v.matched == 1 && v.count == 1 && v.unparsed == 1023 &&
+          strstr(v.items[0].path, big_receipts[0]), "capped: smallest 1024 paths kept, truncated");
+    CHECK(v.unparsed_listed == VISOR_EVIDENCE_MAX_UNPARSED_PATHS && strstr(v.unparsed_paths[0], "/f0000.txt") &&
+          strstr(v.unparsed_paths[VISOR_EVIDENCE_MAX_UNPARSED_PATHS - 1], "/f0007.txt"), "capped: first unparsed paths");
+    CHECK(same_view(&v, &v2, ra, rb), "capped: same view for opposite readdir orders");
+    SemanticId aid;
+    memset(aid.bytes, 0xaa, sizeof(aid.bytes));
+    CHECK(visor_evidence_for_id(asc, &aid, &v) == 0 && visor_evidence_for_id(desc, &aid, &v2) == 0 &&
+          v.count == 1 && v.truncated && same_view(&v, &v2, ra, rb), "capped: for_id same view for both orders");
+    visor_evidence_set_max_files(0);
+    CHECK(prev == VISOR_EVIDENCE_MAX_FILES && visor_evidence_set_max_files(0) == VISOR_EVIDENCE_MAX_FILES,
+          "cap restored to default");
+
+    remove_big_tree(asc);
+    remove_big_tree(desc);
+    CHECK(rmdir(root) == 0, "large tree: removed");
+}
+
 int main(void) {
     /* --- scan fixtures --- */
     CHECK(visor_evidence_scan(FIX, &v) == 0, "scan fixtures rc");
@@ -115,6 +240,8 @@ int main(void) {
     CHECK(visor_evidence_format_json(&v, js, sizeof(js)) > 0 && js[0] == '{' && strstr(js, "\"scope\":\"QEMU\""), "json");
     CHECK(visor_evidence_format_text(&v, txt_b, 32) == -1, "truncation fails closed");
 
+    check_large_tree();
+
     /* --- real evidence/ tree, read-only: format coverage and no upgrade --- */
     if (visor_evidence_scan("evidence", &v) == 0) {
         CHECK(v.scanned >= 70 && v.count == VISOR_EVIDENCE_MAX_ITEMS && v.truncated && v.matched >= 50,