diff --git a/.crumb b/.crumb index f3e51fe46..a592990bd 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": "d157ab7531bcf4bccb9856a64ccc47c84ed70d0e1eb29086ce3485eaf64cf048", + "last_commit": "b3cbec657", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", - "last_commit": "bf54b19fa", + "digest": "c925c6f0bef5efb006043f3878028022d9e4135634557f1305746162e62bbd93", + "last_commit": "b3cbec657", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "digest": "d9914aa350fd18daae8d6ed3b17df61a66476e5f3f92282151d8bbc2c9b6091b", + "last_commit": "b3cbec657", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "digest": "454ec8b81f3b164b135461e5cefdfbf9b5d336604bdd5255a7d0195700091baf", + "last_commit": "b3cbec657", "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:1f892d0d5e95a1fbcc2ce477cb686ac42a352de19684cf09c1597a5dc6ec0079", + "compiled_at": "2026-10-30T16:37:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", + "digest": "sha256:2abf46506fff385273c20f07202aa35fa28a2b827b5176e94891f321ad6cac81", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "files": 17854, + "generated_at_commit": "824b34a1616a9189607f89e3ce179200e6c5c78a", + "source_tree": "sha256:12c2e02a6571d609066dfce9301a41eaee6274060ff3df52622a0c54b9676bc0" }, "owner_lane": "", "provenance": { diff --git a/Makefile b/Makefile index 6b53cd124..005edcb4c 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ SRCS = src/omega_om_units.c src/omega_canonical.c src/omega_validate.c src/omega src/omega_matvec.c src/omega_accelerator.c src/omega_accelerator_world.c \ src/omega_vector.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ src/omega_blackwell_realize.c src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_gates.c src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_gpu_session.c src/omega_gpu_platform.c src/omega_gpu_platform_linux.c src/omega_gpu_fmt.c src/omega_gpu_matmul_api.c src/omega_gpu_elementwise_api.c src/omega_gpu_attention_api.c src/omega_gpu_serving.c src/omega_world_gates.c src/omega_gpu_wait.c \ - src/omega_evidence.c \ + src/omega_evidence.c src/omega_clean_clone.c \ $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c \ tools/omegatool.c # OWN-30B cut 2 (2026-10-13): column windows over a resident bf16 tensor for the MoE path. New file, @@ -209,6 +209,12 @@ test-m19: $(TARGET) test-m19r-qualify: tools/test_m19r_qualify.sh +# Host-only tests of the M18/M19 clean-clone reproduction (src/omega_clean_clone.c): +# OUT_DIR from tests/gates/run.sh, dirty tree, failing nested run, broken candidate. No GPU. +.PHONY: test-clean-clone +test-clean-clone: + PHYSICS_DIR=$(abspath $(PHYSICS_DIR)) tools/test_clean_clone.sh + # Host-only tests of the chipwait campaign runner (tools/chipwait_campaign.sh) # against a stub qualifier. No GPU. .PHONY: test-chipwait-campaign @@ -2438,7 +2444,7 @@ test-vc-bridge: tests/test_omega_vc_bridge.c src/omega_vc_bridge.c src/omega_vc_ # they compile the physics checkout path into the object (-DOMEGA_PHYSICS_DIR), which made the # archive digest depend on where physics was checked out. Without them libomega_gpu.a is # byte-identical for any PHYSICS_DIR and any omega checkout directory. -GPU_API_OBJS = $(filter-out $(OUT_DIR)/omegatool.o $(OUT_DIR)/omega_blackwell_gates.o $(OUT_DIR)/omega_world_gates.o,$(OBJS)) +GPU_API_OBJS = $(filter-out $(OUT_DIR)/omegatool.o $(OUT_DIR)/omega_blackwell_gates.o $(OUT_DIR)/omega_world_gates.o $(OUT_DIR)/omega_clean_clone.o,$(OBJS)) GPU_API_TEST = $(OUT_DIR)/gpu_matmul_api_test GPU_R4_RECEIPT = $(OUT_DIR)/gpu_matmul_r4_receipt $(OUT_DIR)/libomega_gpu.a: $(GPU_API_OBJS) | check-physics-lock diff --git a/README.md b/README.md index 1cfed2960..6bcbff8ab 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,18 @@ make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-realize The full omegatool build (`make`) links the `physics` repository at the commit in `physics.lock`. Some older milestone gate scripts rewrite their receipts in place, so do not run them on a clean checkout you mean to keep; prefer the `make test-*` targets above. Targets that touch the GB10 need the DGX Spark, run one at a time, and are never killed mid-run. The M19 clean-clone gate rebuilds the tree in a temporary directory and runs the milestone gates there; when that nested build or nested run fails, it now prints the tail of its own log to stderr, so a failure names its cause instead of reporting a bare FAIL. CI definitions in `.github/workflows/` list the suites that run on every push. +Host checks on the shared Spark judge, whose 1-minute load average is rarely below 2, keep every +check they had and never turn load into a pass. `tests/runtime/r11_own_hold_test.sh` raises the R11 +load limit for its own runs (`R11_LOAD_LIMIT`, which can only raise it) and judges the quiet-flag hold +decision the program prints; the living run's speed checks are judged there only when the load +average is at most 2. The speed checks (the action-graph 2x speedup in +`tests/runtime/rx_action_graph.c`, workflow fusion) take their median over the repetitions the +machine did not disturb (run-queue delay from schedstat, `tests/runtime/rx_quiet_reps.h`); when too +few are undisturbed the check reports `NOT_RUN` with reason `cpu_busy`, and `tests/gates/run.sh` +reads that refusal from the receipt, runs the rest of the step and ends it NOT_RUN. Omega's serve +cost is the CPU time of the serving thread (`cost_ns` in `src/runtime/rx_omega.c`), not wall-clock +time, and the R15 parity rig gives both sides a fixed cost table (`r15_use_cost_model`). + ## Repository layout `src/` existing core and C compiler awaiting replacement (`src/compiler/`), `src/runtime/` reaction runtime, `src/fabric/` host-only fabric interface, `src/physics0/` Physics Zero apparatus, `spec/` and `docs/` specifications, `tests/` gate suites, `evidence/` content-addressed receipts, `tools/` harnesses, `mk/` make fragments included by the `Makefile`. Also `bench/prime_race/` (Prime Drag Race implementation), `calibration/` (Turing calibration experiments, preregistration and blinding protocol), `research/` (experiments and prototypes) and `doctrine/` (the Milestone 4 doctrine). diff --git a/spec/.crumb b/spec/.crumb index a226ce192..828edea66 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-30T16:33:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", + "digest": "sha256:d157ab7531bcf4bccb9856a64ccc47c84ed70d0e1eb29086ce3485eaf64cf048", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 63, - "generated_at_commit": "a8a6a3d3c47ce797430f045edc5eae11594ba36d", - "source_tree": "sha256:4cb3bb1977c84caacc34366f814d6fe403a2eda7b89b916948d29541675c59bb" + "generated_at_commit": "8d591af9c727dbc1dd02c2ec9988c939d59a378b", + "source_tree": "sha256:c180aa46482da4d8707d6d3a6f26c3755064a16fd8f5c038701b81c08bcc0071" }, "owner_lane": "", "provenance": { diff --git a/spec/action-graph-ir.md b/spec/action-graph-ir.md index c9573125c..61ea8bfb5 100644 --- a/spec/action-graph-ir.md +++ b/spec/action-graph-ir.md @@ -172,7 +172,7 @@ chain. The effect object holds count, last value, an order chain | Claim | How | |---|---| | same semantic result as sequential reference | every run: status, value and evidence of every node, outcome, effect chain | -| lower critical path for parallel graphs | 1 vs 4 workers, same lowered graph, median of 15 runs, pinned to one core class | +| lower critical path for parallel graphs | 1 vs 4 workers, same lowered graph, median of 15 runs the machine did not disturb (run-queue delay from schedstat, `tests/runtime/rx_quiet_reps.h`), pinned to one core class | | zero authority bypass | every commit to a boundary target comes from a lowered boundary reaction; stolen, revoked, forged and tampered cases blocked; compile mints nothing | | zero missing evidence | every evidence node of every successful run has its word | | same causal ancestry | per node, crumb parents inside the run's episode reach exactly the graph's ancestors and the run token | diff --git a/spec/r11-aien-faculty.md b/spec/r11-aien-faculty.md index 01e3318e2..346faf6b7 100644 --- a/spec/r11-aien-faculty.md +++ b/spec/r11-aien-faculty.md @@ -34,7 +34,7 @@ Code: `src/runtime/rx_aien.{c,h}`, plus `omega.reconsider` in | `aien.predict` | `belief` interval count | `prediction` | | `aien.explain` | `prediction` sequence or state | `hypothesis` | | `aien.assess` | `goal` (human), `prediction` state | `assessment` | -| `aien.plan` | `hypothesis` state, `assessment` | `plan`, `memory`, `hypothesis` state | +| `aien.plan` | `hypothesis` sequence or state, `assessment` | `plan`, `memory`, `hypothesis` state | | `omega.reconsider` | `plan`, Omega `selection` | Omega `search` (new epoch) | What AIEN reasons about: Omega's selection is a claim that a realization @@ -50,7 +50,11 @@ costs so much. AIEN checks that claim against what production pays. - **Hypothesis.** For a failed prediction, AIEN looks at what else it observed. If the core class changed since the prediction, the hypothesis is `CORE_CLASS`. Otherwise it is `DRIFT`. A placement change on its own is not - evidence and produces nothing. + evidence and produces nothing. An open `DRIFT` hypothesis is tested by + relearning the same record where it runs; if the body moved to another core + class before that relearn, the relearned prediction turns it into a + `CORE_CLASS` hypothesis about the class the body runs on now, so the drift + question cannot wait forever for a same-class prediction. - **Plan.** One experiment per condition (core class, regime): re-search the regime where the work runs now. `memory` records the conditions AIEN has had explored. A hypothesis about an explored condition becomes `EXHAUSTED`, with diff --git a/spec/r13-living-system.md b/spec/r13-living-system.md index 51b32dd9c..7513199f7 100644 --- a/spec/r13-living-system.md +++ b/spec/r13-living-system.md @@ -80,10 +80,13 @@ cost and is not the promoted realization. The receipt says so. ## Generation -`generation.prepare` checks who wrote each input (selection by `omega.select`, +`generation.prepare` wakes on the selection, the goal and the plan. It checks +who wrote each input (selection by `omega.select`, belief by `aien.experiment`, evidence by the evidence reaction, GPU output by the seat, search by `omega.reconsider`, plan by `aien.plan`, goal from -outside), re-derives the realization identity from the stored bytes, walks the +outside); a selection that lands before the goal (the body researched a new +core class on its own) is declined for want of an author and checked again +when the goal arrives. It re-derives the realization identity from the stored bytes, walks the crumbs selection <- measure <- verdict <- synthesis and GPU output <- ... <- trial 0, and proposes a draft binding: diff --git a/src/.crumb b/src/.crumb index 7c4b83da7..a104525a4 100644 --- a/src/.crumb +++ b/src/.crumb @@ -62,140 +62,140 @@ "children": [ { "digest": "728ab6985dea994eb78a7eb2521384a911492d1c36819c17970a5dc3a8a0c5e2", - "last_commit": "d863780eb", + "last_commit": "7350a61c9", "name": "algebra", "purpose": "Directory src/algebra. Purpose not yet described by a human." }, { "digest": "1881ed1d139a405a777d24d4b26f97bc8405dee0552d6ce21841ce4833560ce2", - "last_commit": "d863780eb", + "last_commit": "834ee93e4", "name": "ans", "purpose": "ANS (Alignment Navigation System), Inertial Alignment v1: frozen reference atoms, drift filter o" }, { "digest": "92c3e2481f7457afd6c7717e6c1a75ebab950ec9114b48025dd137a6edb2975c", - "last_commit": "d863780eb", + "last_commit": "d48ab89e5", "name": "autodiff", "purpose": "M21 OMEGA_AUTODIFF: reverse-mode tape over M20 tensor CPU ops, caller-owned nodes and scratch, p" }, { "digest": "3bd51397fcd28cd54db65c1df72c320883798bc8550779b2b79c8498b28ffb0d", - "last_commit": "d863780eb", + "last_commit": "1edf41a5c", "name": "compiler", "purpose": "Directory src/compiler. Purpose not yet described by a human." }, { "digest": "36a66980895553ae73884798bc09a92141e1aeba5e5068a7d9d62a99bad02548", - "last_commit": "d863780eb", + "last_commit": "3c82389f7", "name": "crumbline", "purpose": "Directory src/crumbline. Purpose not yet described by a human." }, { "digest": "c75df77ddb2bae35ac5e1225a0ae9dcef77b24608775c7b8d02dce1af0ec3ca4", - "last_commit": "d863780eb", + "last_commit": "00f54b6b1", "name": "dual_experiment", "purpose": "DUAL applicability experiment library (ARCH-0031 offline evidence lane): deterministic discrete " }, { "digest": "8856d5162c55cb33997201cd580638f80ea933b46e11c61e1913185d419731d7", - "last_commit": "d863780eb", + "last_commit": "1a147e40f", "name": "estimation", "purpose": "Directory src/estimation. Purpose not yet described by a human." }, { "digest": "391e337c60cb8b2ae549595394482c23717c1757d83747a7446e81cd780750c1", - "last_commit": "d863780eb", + "last_commit": "3108fc2f5", "name": "fabric", "purpose": "Directory src/fabric. Purpose not yet described by a human." }, { "digest": "2d33eb528dafb5954bb027cdd9a7c7923594c177f17181194311155b4e1f40b3", - "last_commit": "d863780eb", + "last_commit": "71c6ff882", "name": "language", "purpose": "Directory src/language. Purpose not yet described by a human." }, { "digest": "cd0551dbfb6fc354741efe9a3ad1808ffaaf6a8d7e9e7345851333d7a721cee0", - "last_commit": "d863780eb", + "last_commit": "6d8d92adc", "name": "osh", "purpose": "osh (Omega-native shell, arch#158) lexer unit: layout list, generator, osh_lex.osc, C reference " }, { "digest": "2b5dd2c64d4bbba8c41471dc1af5a0b00bfc1361a2c680d78b99fb30b5b547fe", - "last_commit": "d863780eb", + "last_commit": "d550b705b", "name": "path", "purpose": "Directory src/path. Purpose not yet described by a human." }, { "digest": "e0b91129cc9c188fc0e47b7f3189a3a9a09f9c55eecd018786794571ffc39aad", - "last_commit": "d863780eb", + "last_commit": "e59633e5e", "name": "physics0", "purpose": "PD-0 hidden-equation benchmark (Physics-0 Discovery Engine cut 1): world, oracle, scorer, ladder" }, { "digest": "8b923fb5dc1de3b04afae043a4770f7b1fb27d959a8f597191ae2556d822a1cf", - "last_commit": "d863780eb", + "last_commit": "61c094113", "name": "polyglot", "purpose": "Directory src/polyglot. Purpose not yet described by a human." }, { "digest": "076f486fdf51e12a26160e7f0bf7686fea611db54216f7fef81367620e7a6bdb", - "last_commit": "d863780eb", + "last_commit": "dd67f6bd7", "name": "reservoir", "purpose": "Ionic-droplet reservoir simulator (omega#440): binary32 fixed-step RK4 of the authors' droplet m" }, { - "digest": "1e400d9b84494347892448fd576be7bf596ef810ed6e88bcd70f7e7d9a6b5746", - "last_commit": "97a960f5c", + "digest": "2318800e5ce3d29e55e4317c7647205b81768f05eff95c7dc7176b07cf43e74e", + "last_commit": "e5404a056", "name": "runtime", "purpose": "Directory src/runtime. Purpose not yet described by a human." }, { "digest": "71502e9ef65e0620b94ea156cef5034e4c97d703d5ea13c489e4b65713014f84", - "last_commit": "97a960f5c", + "last_commit": "5901baa51", "name": "searchtrace", "purpose": "Directory src/searchtrace. Purpose not yet described by a human." }, { "digest": "b82288db7e732d10f954e921ac98c60e19579a3e58118cc12c49230587929ea2", - "last_commit": "ed8de5736", + "last_commit": "", "name": "synapse", "purpose": "Synapse ADR 0003 J1 binary codec port: layout list, generator, syn_codec.osc (A1 WAL records + c" }, { "digest": "9723dd7c18d4e2c22db631680974e1025bccb9c309619424e2f4dfcc43cc7068", - "last_commit": "d863780eb", + "last_commit": "f633e3430", "name": "tensor", "purpose": "M20 OMEGA_TENSOR: immutable tensor semantic layer, views, generation-checked storage, CPU realiz" }, { "digest": "06d9fb18dddf7ab0f8ad02fffd15ce8b80808c77d0904609b6baae83c2b05ce5", - "last_commit": "d863780eb", + "last_commit": "54826a37f", "name": "train", "purpose": "Directory src/train. Purpose not yet described by a human." }, { "digest": "812a7faed07b21e066b732ed596eb0aea609379a2b2af0e8b61dd1ea05bef602", - "last_commit": "d863780eb", + "last_commit": "2564f57a9", "name": "turing", "purpose": "Directory src/turing. Purpose not yet described by a human." }, { "digest": "b2e34b2ea0392059ac30d17e27289b1146e523db60a02ef825edef96036817ab", - "last_commit": "d863780eb", + "last_commit": "40d1ea378", "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:c984296dfa69c462b119296f19a818cb01be259fa16c2e797b2fbe62da37ba1f", + "compiled_at": "2026-10-30T16:33:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", + "digest": "sha256:c925c6f0bef5efb006043f3878028022d9e4135634557f1305746162e62bbd93", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 568, - "generated_at_commit": "2cb1ccb5d3c1a1ce1cb94a7a3dd3c221395c4e15", - "source_tree": "sha256:7f1fef46a27e8baf5cf567bb590d417ede3767c5f07e714d0f0812af0645bb4b" + "files": 570, + "generated_at_commit": "8d591af9c727dbc1dd02c2ec9988c939d59a378b", + "source_tree": "sha256:4fec32c438cf86c5c66391879b213019598f4bd0e41585e7c351930a506cf9ea" }, "owner_lane": "", "provenance": { diff --git a/src/omega_blackwell_gates.c b/src/omega_blackwell_gates.c index 54ec7f769..a94b99898 100644 --- a/src/omega_blackwell_gates.c +++ b/src/omega_blackwell_gates.c @@ -34,6 +34,7 @@ #include #include #include "omega_physics_dir.h" +#include "omega_clean_clone.h" static int m17_gate_count = 0; static int m17_gate_passed = 0; @@ -995,28 +996,12 @@ static bool test_m18_gate16_clean_clone(void) { if (getenv("OMEGA_IN_CLEAN_CLONE") != NULL) { return true; } - /* Copy the repo this omegatool runs from (the code under test), not a - * hardcoded checkout, and pass the PHYSICS_DIR this process resolves at run time - * (omega_physics_dir.h) as an absolute path so the copy in /tmp does not fall back to - * the Makefile default ../physics (= /tmp/physics). Mirrors M19. */ - char physics_dir_resolved[PATH_MAX], physics_err[OMEGA_PHYSICS_ERR_SIZE]; - if (!omega_physics_dir_resolve_pinned(physics_dir_resolved, sizeof(physics_dir_resolved), 0, physics_err, sizeof(physics_err))) { - fprintf(stderr, "%s\n", physics_err); - return false; - } - char command[4608]; - int len = snprintf(command, sizeof(command), - "root=$(git rev-parse --show-toplevel) && " - "rm -rf /tmp/omega_clean_m18 && " - "cp -r \"$root\" /tmp/omega_clean_m18 && " - "cd /tmp/omega_clean_m18 && " - "make OUT_DIR=build clean >/dev/null 2>&1 && " - "make -j OUT_DIR=build PHYSICS_DIR='%s' >/dev/null 2>&1 && " - "OMEGA_IN_CLEAN_CLONE=1 ./build/omegatool --run-m18-gates >/tmp/clean_clone_m18.log 2>&1", - physics_dir_resolved); - if (len < 0 || (size_t)len >= sizeof(command)) return false; - int rc = system(command); - return (rc == 0); + /* Clone the exact revision this omegatool runs from (the code under test) + * into a fresh /tmp directory, build it from scratch at the pinned + * PHYSICS_DIR and rerun the M18 suite there (omega_clean_clone.h). Mirrors + * M19. A dirty tree is refused: a clean clone cannot reproduce it. */ + char clone_sha[41] = {0}; + return omega_clean_clone_run("m18", "--run-m18-gates", clone_sha); } diff --git a/src/omega_clean_clone.c b/src/omega_clean_clone.c new file mode 100644 index 000000000..b545bec25 --- /dev/null +++ b/src/omega_clean_clone.c @@ -0,0 +1,284 @@ +#include "omega_clean_clone.h" +#include "omega_evidence.h" +#include "omega_physics_dir.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +/* How much of a failing step's log reaches stderr. */ +#define CLEAN_CLONE_TAIL_BYTES 6144 + +/* The programs a step may run. The child calls execvp or execv with a literal + * name chosen from this switch, so no program name ever comes from data. */ +enum cc_prog { CC_GIT, CC_MAKE, CC_OMEGATOOL, CC_RM }; + +/* Only letters, digits and / . _ + - pass. make reads PHYSICS_DIR= as a + * variable value, where '$' would be expanded, so anything else is refused. */ +static bool cc_path_is_plain(const char *s) { + if (!s || !*s) return false; + for (const char *p = s; *p; p++) { + char c = *p; + bool ok = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || + c == '/' || c == '.' || c == '_' || c == '+' || c == '-'; + if (!ok) return false; + } + return true; +} + +/* Child side of a step: environment, directory, log, then exec. Never returns. + * Arguments travel as argv entries; no shell parses any path. The log is opened + * by the child after it changes directory, at an absolute path built by us. */ +static void cc_child(enum cc_prog prog, char *const argv[], const char *work_dir, const char *log_path, + bool gates_env) { + unsetenv("OUT_DIR"); + unsetenv("MAKEFLAGS"); + unsetenv("MFLAGS"); + unsetenv("MAKELEVEL"); + if (gates_env && setenv("OMEGA_IN_CLEAN_CLONE", "1", 1) != 0) _exit(127); + if (work_dir && chdir(work_dir) != 0) _exit(127); + int fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0644); + if (fd < 0) _exit(126); + if (dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0) _exit(127); + if (fd > STDERR_FILENO) close(fd); + switch (prog) { + case CC_GIT: execvp("git", argv); break; + case CC_MAKE: execvp("make", argv); break; + case CC_OMEGATOOL: execv("./build/omegatool", argv); break; + case CC_RM: execvp("rm", argv); break; + } + _exit(127); +} + +/* Run git rev-parse HEAD in repo_dir and read the 40-hex sha it prints. */ +static bool clean_clone_head(const char *repo_dir, char out[41]) { + int fds[2]; + if (pipe(fds) != 0) return false; + fflush(NULL); + pid_t pid = fork(); + if (pid < 0) { + close(fds[0]); + close(fds[1]); + return false; + } + if (pid == 0) { + close(fds[0]); + if (dup2(fds[1], STDOUT_FILENO) < 0) _exit(127); + close(fds[1]); + int nul = open("/dev/null", O_WRONLY); + if (nul >= 0) dup2(nul, STDERR_FILENO); + char *argv[] = { "git", "-C", (char *)repo_dir, "rev-parse", "HEAD", NULL }; + execvp("git", argv); + _exit(127); + } + close(fds[1]); + char line[64]; + size_t used = 0; + for (;;) { + ssize_t n = read(fds[0], line + used, sizeof(line) - 1 - used); + if (n < 0 && errno == EINTR) continue; + if (n <= 0) break; + used += (size_t)n; + if (used >= sizeof(line) - 1) break; + } + close(fds[0]); + line[used] = '\0'; + int status = 0; + while (waitpid(pid, &status, 0) < 0) { + if (errno != EINTR) return false; + } + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) return false; + line[strcspn(line, "\r\n")] = '\0'; + if (strlen(line) != 40 || strspn(line, "0123456789abcdef") != 40) return false; + memcpy(out, line, 41); + return true; +} + +/* Print the lines that name the failure (gcc's "file:line:col: error:" lines and + * make's "make: ***" lines), up to a fixed count. make -j keeps printing + * compile commands after the first error, so the tail alone can miss it. */ +#define CLEAN_CLONE_ERROR_LINES 20 +static void clean_clone_print_errors(const char *log_path) { + FILE *f = fopen(log_path, "rb"); + if (!f) return; + char line[1024]; + int shown = 0; + while (shown < CLEAN_CLONE_ERROR_LINES && fgets(line, sizeof line, f)) { + if (strstr(line, ": error") || strstr(line, ": fatal error") || strstr(line, "make: ***")) { + fputs(line, stderr); + if (strchr(line, '\n') == NULL) fputc('\n', stderr); + shown++; + } + } + fclose(f); + if (shown > 0) fprintf(stderr, " (%d error line(s) above; log tail below)\n", shown); +} + +/* Print the last CLEAN_CLONE_TAIL_BYTES of a log to stderr, from a line start. */ +static void clean_clone_print_tail(const char *log_path) { + clean_clone_print_errors(log_path); + FILE *f = fopen(log_path, "rb"); + if (!f) { + fprintf(stderr, " (log %s unreadable)\n", log_path); + return; + } + bool cut = false; + if (fseek(f, 0, SEEK_END) == 0) { + long size = ftell(f); + if (size > CLEAN_CLONE_TAIL_BYTES) { + fseek(f, size - CLEAN_CLONE_TAIL_BYTES, SEEK_SET); + cut = true; + } else { + fseek(f, 0, SEEK_SET); + } + } + char buf[CLEAN_CLONE_TAIL_BYTES + 1]; + size_t n = fread(buf, 1, CLEAN_CLONE_TAIL_BYTES, f); + fclose(f); + buf[n] = '\0'; + const char *start = buf; + if (cut) { + const char *nl = strchr(buf, '\n'); + if (nl) start = nl + 1; + } + if (*start == '\0') { + fprintf(stderr, " (log is empty)\n"); + return; + } + fputs(start, stderr); + if (n > 0 && buf[n - 1] != '\n') fputc('\n', stderr); +} + +static void clean_clone_report(const char *tag, const char *step, const char *why, + const char *dir, const char *log_path) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step %s failed: %s (clone kept at %s)\n", tag, step, why, dir); + if (log_path) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: last lines of %s:\n", tag, log_path); + clean_clone_print_tail(log_path); + } + fflush(stderr); +} + +static bool step_log(char *buf, size_t size, const char *dir, const char *step) { + int n = snprintf(buf, size, "%s/%s.log", dir, step); + return n >= 0 && (size_t)n < size; +} + +/* Run one step with argv, its output in log_path; true when it exits 0. */ +static bool clean_clone_step(const char *tag, const char *step, const char *dir, const char *work_dir, + enum cc_prog prog, char *const argv[], const char *log_path, bool gates_env) { + fflush(NULL); + pid_t pid = fork(); + if (pid < 0) { + clean_clone_report(tag, step, "could not start the step", dir, log_path); + return false; + } + if (pid == 0) cc_child(prog, argv, work_dir, log_path, gates_env); + int status = 0; + while (waitpid(pid, &status, 0) < 0) { + if (errno != EINTR) { + clean_clone_report(tag, step, "could not wait for the step", dir, log_path); + return false; + } + } + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) return true; + char why[96]; + if (WIFEXITED(status) && WEXITSTATUS(status) == 127) + snprintf(why, sizeof why, "exit status 127 (program not found or not runnable)"); + else if (WIFEXITED(status)) + snprintf(why, sizeof why, "exit status %d", WEXITSTATUS(status)); + else if (WIFSIGNALED(status)) + snprintf(why, sizeof why, "killed by signal %d", WTERMSIG(status)); + else + snprintf(why, sizeof why, "wait status 0x%x", (unsigned)status); + clean_clone_report(tag, step, why, dir, log_path); + return false; +} + +bool omega_clean_clone_run(const char *tag, const char *gates_flag, char out_sha[41]) { + char src_sha[41] = {0}; + if (!clean_clone_head(".", src_sha)) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step source_head failed: git rev-parse HEAD in the source tree\n", tag); + return false; + } + if (omega_evidence_tree_dirty()) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step source_clean failed: source tree at %s is dirty " + "(git status --porcelain not empty); a clean clone cannot reproduce it\n", tag, src_sha); + return false; + } + + /* The PHYSICS_DIR this process runs with (omega_physics_dir.h), as an + * absolute path, so the clone in /tmp builds against the same pinned + * physics checkout instead of the Makefile default ../physics. */ + char physics_dir[PATH_MAX], physics_err[OMEGA_PHYSICS_ERR_SIZE]; + if (!omega_physics_dir_resolve_pinned(physics_dir, sizeof(physics_dir), 0, physics_err, sizeof(physics_err))) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step physics_dir failed: %s\n", tag, physics_err); + return false; + } + if (!cc_path_is_plain(physics_dir)) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step physics_dir failed: path %s has characters outside " + "letters, digits and / . _ + - (make would read them)\n", tag, physics_dir); + return false; + } + char pd_arg[PATH_MAX + 16]; + if (snprintf(pd_arg, sizeof pd_arg, "PHYSICS_DIR=%s", physics_dir) >= (int)sizeof pd_arg) return false; + + char dir_template[64]; + int n = snprintf(dir_template, sizeof dir_template, "/tmp/omega_clean_%s_XXXXXX", tag); + if (n < 0 || (size_t)n >= sizeof dir_template) return false; + char *dir = mkdtemp(dir_template); + if (!dir) { + perror("OMEGA_CLEAN_CLONE mkdtemp"); + return false; + } + char checkout[PATH_MAX], log[PATH_MAX]; + n = snprintf(checkout, sizeof checkout, "%s/checkout", dir); + if (n < 0 || (size_t)n >= sizeof checkout) return false; + + if (!step_log(log, sizeof log, dir, "1-clone")) return false; + char *clone_argv[] = { "git", "clone", "--quiet", "--no-hardlinks", ".", checkout, NULL }; + if (!clean_clone_step(tag, "1-clone", dir, NULL, CC_GIT, clone_argv, log, false)) return false; + + if (!step_log(log, sizeof log, dir, "2-checkout")) return false; + char *co_argv[] = { "git", "checkout", "--quiet", "--detach", src_sha, NULL }; + if (!clean_clone_step(tag, "2-checkout", dir, checkout, CC_GIT, co_argv, log, false)) return false; + + char clone_sha[41] = {0}; + if (!clean_clone_head(checkout, clone_sha) || strcmp(clone_sha, src_sha) != 0) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step 2-checkout failed: clone HEAD %s is not the candidate %s " + "(clone kept at %s)\n", tag, clone_sha[0] ? clone_sha : "(unreadable)", src_sha, dir); + return false; + } + + if (!step_log(log, sizeof log, dir, "3-make-clean")) return false; + char *mc_argv[] = { "make", "-C", checkout, "clean", NULL }; + if (!clean_clone_step(tag, "3-make-clean", dir, NULL, CC_MAKE, mc_argv, log, false)) return false; + + if (!step_log(log, sizeof log, dir, "4-make")) return false; + char *mk_argv[] = { "make", "-C", checkout, "-j", pd_arg, NULL }; + if (!clean_clone_step(tag, "4-make", dir, NULL, CC_MAKE, mk_argv, log, false)) return false; + + if (!step_log(log, sizeof log, dir, "5-run-gates")) return false; + char *run_argv[] = { "./build/omegatool", (char *)gates_flag, NULL }; + if (!clean_clone_step(tag, "5-run-gates", dir, checkout, CC_OMEGATOOL, run_argv, log, true)) return false; + + /* The built and qualified checkout must still be exactly the candidate. */ + if (!clean_clone_head(checkout, clone_sha) || strcmp(clone_sha, src_sha) != 0) { + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: step 6-verify-head failed: clone HEAD %s after the run is not " + "the candidate %s (clone kept at %s)\n", tag, clone_sha, src_sha, dir); + return false; + } + + printf(" OMEGA_CLEAN_CLONE %s: candidate %s cloned, built from scratch and %s passed\n", + tag, src_sha, gates_flag); + char *rm_argv[] = { "rm", "-rf", dir, NULL }; + if (!clean_clone_step(tag, "cleanup", dir, NULL, CC_RM, rm_argv, "/dev/null", false)) + fprintf(stderr, "OMEGA_CLEAN_CLONE %s: could not remove %s\n", tag, dir); + memcpy(out_sha, src_sha, 41); + return true; +} diff --git a/src/omega_clean_clone.h b/src/omega_clean_clone.h new file mode 100644 index 000000000..8a45ecbf3 --- /dev/null +++ b/src/omega_clean_clone.h @@ -0,0 +1,28 @@ +#ifndef OMEGA_CLEAN_CLONE_H +#define OMEGA_CLEAN_CLONE_H + +#include + +/* Clean-clone reproduction shared by the M18 and M19 CLEAN_CLONE gates. + * + * Clones the repository this process runs in (cwd, the repo root under make) + * at its exact HEAD into a fresh mkdtemp directory /tmp/omega_clean__XXXXXX, + * builds it from scratch (make clean, then make -j) against the pinned + * PHYSICS_DIR this process resolves, and runs + * `OMEGA_IN_CLEAN_CLONE=1 ./build/omegatool ` inside the clone. + * + * The clone always builds into its own default build/ directory: OUT_DIR, + * MAKEFLAGS, MFLAGS and MAKELEVEL inherited from the calling make (for example + * tests/gates/run.sh exports OUT_DIR=build/step-) are removed, so the + * nested build cannot land somewhere the run step does not look (omega #511 + * moved the gate builds into per-step OUT_DIRs, and the clone then ran a + * ./build/omegatool that was never built). + * + * Refuses a dirty source tree. Returns true only when every step exits 0 and + * the built clone's HEAD equals the source HEAD; out_sha (41 bytes) then holds + * that revision. On failure the failing step, its exit status, its log path + * and the last lines of that log are printed to stderr and the clone + * directory is kept for inspection; on success it is removed. */ +bool omega_clean_clone_run(const char *tag, const char *gates_flag, char out_sha[41]); + +#endif diff --git a/src/omega_world_gates.c b/src/omega_world_gates.c index b78806dad..ed56af9a4 100644 --- a/src/omega_world_gates.c +++ b/src/omega_world_gates.c @@ -33,9 +33,7 @@ #include #include #include -#include -#include -#include "omega_physics_dir.h" +#include "omega_clean_clone.h" static int m19_gate_count = 0; static int m19_gate_passed = 0; @@ -1777,59 +1775,6 @@ static bool test_m19_gate15_zero_libcuda(void) { return true; } - -/* Start one program directly, with an optional working directory, one extra - * environment value, and stdout+stderr sent to log_path. No shell is involved, - * so a path, a commit id or a directory name passed here stays an argument and - * can never become command text. Returns the exit status, or -1 if it did not run. */ -static int m19_run(char *const argv[], const char *dir, const char *log_path, - const char *e1_name, const char *e1_value, - const char *e2_name, const char *e2_value) { - if (!argv || !argv[0]) return -1; - pid_t pid = fork(); - if (pid < 0) return -1; - if (pid == 0) { - if (dir && chdir(dir) != 0) _exit(127); - if (e1_name && e1_value && setenv(e1_name, e1_value, 1) != 0) _exit(127); - if (e2_name && e2_value && setenv(e2_name, e2_value, 1) != 0) _exit(127); - if (log_path) { - int fd = open(log_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd < 0) _exit(127); - if (dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0) _exit(127); - if (fd > STDERR_FILENO) close(fd); - } - execvp(argv[0], argv); - _exit(127); - } - int status = 0; - if (waitpid(pid, &status, 0) < 0) return -1; - if (WIFEXITED(status)) return WEXITSTATUS(status); - return -1; -} -/* Echo the tail of the nested clean-clone log to stderr. The file is read - * directly: building a shell command out of a path is both flagged by static - * analysis and a way for a crafted path to run something unintended. */ -static void m19_echo_log_tail(const char *dir) { - char path[PATH_MAX]; - int n = snprintf(path, sizeof(path), "%s/qualification.log", dir); - if (n < 0 || (size_t)n >= sizeof(path)) return; - FILE *f = fopen(path, "rb"); - if (!f) return; - char buf[2048]; - size_t want = sizeof(buf) - 1; - if (fseek(f, 0, SEEK_END) != 0) { fclose(f); return; } - long end = ftell(f); - if (end < 0) { fclose(f); return; } - long start = end > (long)want ? end - (long)want : 0; - if (fseek(f, start, SEEK_SET) != 0) { fclose(f); return; } - size_t got = fread(buf, 1, want, f); - fclose(f); - if (got == 0) return; - buf[got] = '\0'; - fputs(buf, stderr); - if (buf[got - 1] != '\n') fputc('\n', stderr); -} - /* Gate 16: OMEGA_ACCEL_RESIDENT_CLEAN_CLONE_PASS */ static bool test_m19_gate16_clean_clone(void) { char src_sha[41] = {0}; @@ -1847,63 +1792,10 @@ static bool test_m19_gate16_clean_clone(void) { memcpy(m19_candidate_commit, src_sha, sizeof(m19_candidate_commit)); return true; } - if (omega_evidence_tree_dirty()) { - return false; - } - char clone_template[] = "/tmp/omega_clean_m19_XXXXXX"; - char *clone = mkdtemp(clone_template); - if (!clone) return false; - char checkout[512]; - int cl = snprintf(checkout, sizeof(checkout), "%s/checkout", clone); - if (cl < 0 || (size_t)cl >= sizeof(checkout)) return false; - - /* Resolve the PHYSICS_DIR this process runs with (omega_physics_dir.h), as an - * absolute path, so the nested build (running from a different cwd) - * finds the same pinned physics checkout instead of silently falling - * back to the Makefile's default. */ - char physics_dir_resolved[PATH_MAX], physics_err[OMEGA_PHYSICS_ERR_SIZE]; - if (!omega_physics_dir_resolve_pinned(physics_dir_resolved, sizeof(physics_dir_resolved), 0, physics_err, sizeof(physics_err))) { - fprintf(stderr, "%s\n", physics_err); - return false; - } - - /* OUT_DIR=build on the clone's make: tests/gates/run.sh exports a per-step OUT_DIR - * (omega#511), which the clone would inherit and build into, while the line below runs - * ./build/omegatool. The clone is its own directory, so its default build/ is private. */ - /* Each step is started directly, without a shell. The checkout path, the commit id - * and the physics path are arguments to a program, never words in a command string. */ - char log_path[PATH_MAX]; - int lp = snprintf(log_path, sizeof(log_path), "%s/qualification.log", clone); - if (lp < 0 || (size_t)lp >= sizeof(log_path)) return false; - - char *clone_argv[] = { (char *)"git", (char *)"clone", (char *)"--quiet", - (char *)"--no-hardlinks", (char *)".", checkout, NULL }; - char *clean_argv[] = { (char *)"make", (char *)"OUT_DIR=build", (char *)"clean", NULL }; - char *build_argv[] = { (char *)"make", (char *)"-j", (char *)"OUT_DIR=build", NULL }; - char *gates_argv[] = { (char *)"./build/omegatool", (char *)"--run-m19-gates", NULL }; - - /* No value read from a file goes on a command line. The clone carries the source's own - * head, so the commit id is never passed as an argument; the check further down still - * refuses a clone whose head is not src_sha. The physics path travels in the environment, - * which the Makefile's `PHYSICS_DIR ?= ../physics` picks up. */ - bool nested_ok = m19_run(clone_argv, ".", "/dev/null", NULL, NULL, NULL, NULL) == 0 && - m19_run(clean_argv, checkout, "/dev/null", NULL, NULL, NULL, NULL) == 0 && - m19_run(build_argv, checkout, "/dev/null", - "PHYSICS_DIR", physics_dir_resolved, NULL, NULL) == 0 && - m19_run(gates_argv, checkout, log_path, - "OMEGA_IN_CLEAN_CLONE", "1", NULL, NULL) == 0; - if (!nested_ok) { - /* The nested clone builds and runs into qualification.log. A failure here used to report - * only "[FAIL]" with no reason while the log stayed inside the runner's temp directory. - * Echo the tail to stderr, which the gate runner captures into the evidence record. */ - fprintf(stderr, "M19 gate 16: nested build or nested run failed; tail of %s:\n", log_path); - m19_echo_log_tail(clone); - return false; - } - - /* The built checkout must be exactly the named candidate revision. */ + /* Clone this exact revision into a fresh /tmp directory, build it from + * scratch and rerun the M19 suite there (omega_clean_clone.h). */ char clone_sha[41] = {0}; - if (!m19_git_head(checkout, clone_sha)) return false; + if (!omega_clean_clone_run("m19", "--run-m19-gates", clone_sha)) return false; if (strcmp(clone_sha, src_sha) != 0) return false; memcpy(m19_candidate_commit, src_sha, sizeof(m19_candidate_commit)); diff --git a/src/runtime/.crumb b/src/runtime/.crumb index a82872991..f0b1a508b 100644 --- a/src/runtime/.crumb +++ b/src/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-25T19:38:33Z", + "compiled_at": "2026-10-30T16:33:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:1e400d9b84494347892448fd576be7bf596ef810ed6e88bcd70f7e7d9a6b5746", + "digest": "sha256:2318800e5ce3d29e55e4317c7647205b81768f05eff95c7dc7176b07cf43e74e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 65, - "generated_at_commit": "97a960f5c18fc09b506168c55c10031b3f0cffc3", - "source_tree": "sha256:fc3f521b52b9fddaf86ad8b95b05c8060b03b84dc5117e2655ec37ae03c5323b" + "generated_at_commit": "8d591af9c727dbc1dd02c2ec9988c939d59a378b", + "source_tree": "sha256:e5d832694b77cfe0cf807ff650dadafd699130f559f4195d140bd774f35b6d94" }, "owner_lane": "", "provenance": { diff --git a/src/runtime/rx_aien.c b/src/runtime/rx_aien.c index 59eeb21f1..181219454 100644 --- a/src/runtime/rx_aien.c +++ b/src/runtime/rx_aien.c @@ -51,6 +51,19 @@ static int failure_settled(const RxSnapshotDep *p, const RxSnapshotDep *h) { return 0; } +/* A failed prediction is relearned from fresh intervals when its failure is + * settled, and also while a drift hypothesis for it is open: nothing that + * AIEN knows of changed, so the first test of "this record's cost moved" is + * to learn the same record again where it runs. aien.plan asks for research + * only if the relearned cost really moved (omega #527: a burst under load + * failed the prediction, the cost came back, but the drift plan waited for + * a new record that could not come, so the cost was never confirmed). */ +static int relearns(const RxSnapshotDep *p, const RxSnapshotDep *h) { + if (failure_settled(p, h)) return 1; + return p->field[6] == RX_AIEN_PRED_FAILED && h->field[2] == p->field[0] && + h->field[1] == RX_AIEN_HYP_DRIFT && h->field[7] == RX_AIEN_HYP_OPEN; +} + static int explored(const RxSnapshotDep *mem, uint64_t key) { uint64_t n = mem->field[0] < RX_AIEN_MEMORY_SLOTS ? mem->field[0] : RX_AIEN_MEMORY_SLOTS; for (uint64_t i = 0; i < n; i++) @@ -87,14 +100,15 @@ static int fn_observe(RxCtx *c) { return 0; } /* A prediction about this record failed on this belief and the failure - * is settled (explained, nothing left to try). The belief has served its + * is settled (explained, nothing left to try) or is open drift (see + * relearns). The belief has served its * purpose: relearn what this record costs from fresh intervals. Without * this a failed belief stays failed until a new record exists, and a * later, real change (a core move) could never be noticed. */ const RxSnapshotDep *p = in_of(c, f->o.prediction); const RxSnapshotDep *h = in_of(c, f->o.hypothesis); if (!p || !h) return -1; - if (p->field[1] == epoch && b->field[7] >= f->cfg.misses_to_fail && failure_settled(p, h)) { + if (p->field[1] == epoch && b->field[7] >= f->cfg.misses_to_fail && relearns(p, h)) { put(c, f->o.belief, 2, calls); put(c, f->o.belief, 3, spent); put(c, f->o.belief, 4, 0); @@ -115,6 +129,14 @@ static int fn_observe(RxCtx *c) { if (seen == 0) { /* warm-up interval, discarded */ } else if (seen <= f->cfg.baseline_intervals) { + /* A baseline is a claim that the record costs `mean` within the + * tolerance, so its own intervals must agree within it. One that + * disagrees with the intervals before it starts the baseline again + * from itself: averaging a burst into the mean gives a cost nothing + * pays, and every steady interval after it then misses (R13 under + * load: 16361, 26203, 8370, 7708 ns learned as 14660 ns, then 391 + * intervals at 7.0 to 8.8 us all failed against it). */ + if (seen > 1 && !within(x, mean, f->cfg.tolerance_pct)) seen = 1; mean = (mean * (seen - 1) + x) / seen; } else { miss = within(x, mean, f->cfg.tolerance_pct) ? 0 : miss + 1; @@ -156,7 +178,7 @@ static int fn_predict(RxCtx *c) { * prediction, so the next real change is noticed. */ const RxSnapshotDep *h = in_of(c, f->o.hypothesis); if (!h) return -1; - if (failure_settled(p, h) && b->field[0] == p->field[1] && + if (relearns(p, h) && b->field[0] == p->field[1] && b->field[7] < f->cfg.misses_to_fail) { put(c, f->o.prediction, 0, p->field[0] + 1); put(c, f->o.prediction, 1, b->field[0]); @@ -196,12 +218,34 @@ static int fn_explain(RxCtx *c) { uint64_t pseq = p->field[0], state = p->field[6]; if (pseq == 0) return 0; - /* A later prediction under the hypothesized condition tests it. */ - if (h->field[7] == RX_AIEN_HYP_TESTING && pseq > h->field[2] && p->field[4] == h->field[4]) { + /* A later prediction under the hypothesized condition tests it. A drift + * plan is made on the relearned prediction (aien.plan), so only a later + * one tests a drift hypothesis. */ + uint64_t tested_from = h->field[2] + (h->field[1] == RX_AIEN_HYP_DRIFT); + if (h->field[7] == RX_AIEN_HYP_TESTING && pseq > tested_from && p->field[4] == h->field[4]) { if (state == RX_AIEN_PRED_CONFIRMED) put(c, f->o.hypothesis, 7, RX_AIEN_HYP_SUPPORTED); else if (state == RX_AIEN_PRED_FAILED) put(c, f->o.hypothesis, 7, RX_AIEN_HYP_UNSUPPORTED); return 0; } + /* An open drift hypothesis is tested by relearning the same record where + * it runs (relearns, aien.observe). When the body moved to another core + * class before that relearn, the relearned prediction is about the new + * class and "nothing changed" is no longer the question: the record was + * made on another core class. Left open, the drift hypothesis would wait + * for a same-class prediction that cannot come, and the body would never + * research the class it runs on now (OMEGA-R14-HOST, 2026-10-20). */ + if (h->field[7] == RX_AIEN_HYP_OPEN && h->field[1] == RX_AIEN_HYP_DRIFT && + pseq == h->field[2] + 1 && p->field[4] != h->field[4]) { + put(c, f->o.hypothesis, 0, h->field[0] + 1); + put(c, f->o.hypothesis, 1, RX_AIEN_HYP_CORE_CLASS); + put(c, f->o.hypothesis, 2, pseq); + put(c, f->o.hypothesis, 3, h->field[4]); + put(c, f->o.hypothesis, 4, p->field[4]); + put(c, f->o.hypothesis, 5, h->field[5]); + put(c, f->o.hypothesis, 6, h->field[6]); + put(c, f->o.hypothesis, 7, RX_AIEN_HYP_OPEN); + return 0; + } if (state != RX_AIEN_PRED_FAILED || h->field[2] == pseq) return 0; uint64_t now = pl->field[1], then = p->field[4]; put(c, f->o.hypothesis, 0, h->field[0] + 1); @@ -291,7 +335,20 @@ static int fn_plan(RxCtx *c) { } if (h->field[7] == RX_AIEN_HYP_OPEN) { - if (p->field[0] != h->field[2]) return 0; /* prediction moved on; wait for it */ + if (h->field[1] == RX_AIEN_HYP_DRIFT) { + /* Drift is first tested by relearning the same record (see + * relearns). Research only if the relearned cost really moved; + * if it is back within the tolerance of what the failed + * prediction expected, the failure was a burst, not drift. */ + if (p->field[0] != h->field[2] + 1 || p->field[6] != RX_AIEN_PRED_CONFIRMED || + p->field[4] != h->field[4]) return 0; + if (within(p->field[5], h->field[5], f->cfg.tolerance_pct)) { + put(c, f->o.hypothesis, 7, RX_AIEN_HYP_UNSUPPORTED); + return 0; + } + } else if (p->field[0] != h->field[2]) { + return 0; /* prediction moved on; wait for it */ + } uint64_t regime = p->field[2], cls = h->field[4]; uint64_t key = rx_aien_key(cls, regime); if (explored(m, key)) { @@ -478,10 +535,10 @@ int rx_aien_register(RxAienFaculty *f, const RxAienCaps *caps) { if ((rc = rx_world_add_reaction_keyed(w, f->keys, &b.d, &f->r_assess)) != RX_OK) return rc; begin(&b, "aien.plan", RX_PRIO_LEARNING, fn_plan, f, caps); - trig(&b, f->o.hypothesis, RX_FIELD(7)); + trig(&b, f->o.hypothesis, RX_FIELD(0) | RX_FIELD(7)); /* a new hypothesis, or a state */ trig(&b, f->o.assessment, RX_FIELD(4) | RX_FIELD(0)); rd(&b, f->o.memory); - rd(&b, f->o.prediction); + trig(&b, f->o.prediction, RX_FIELD(0) | RX_FIELD(6)); /* a relearned drift prediction */ rd(&b, f->o.plan); wr(&b, f->o.plan); wr(&b, f->o.memory); diff --git a/src/runtime/rx_aien.h b/src/runtime/rx_aien.h index 0ebf8cc03..9308a8ad1 100644 --- a/src/runtime/rx_aien.h +++ b/src/runtime/rx_aien.h @@ -106,7 +106,8 @@ enum { RX_AIEN_EXP_SUPPORTED = 1, /* every replicate matched its expected valu #define RX_AIEN_MEMORY_SLOTS 7u typedef struct { - uint32_t baseline_intervals; /* intervals averaged into the baseline */ + uint32_t baseline_intervals; /* intervals averaged into the baseline; they must + agree within tolerance_pct or it starts again */ uint32_t tolerance_pct; /* an interval outside +/- this is a miss */ uint32_t misses_to_fail; /* consecutive misses that fail a prediction */ uint32_t confirm_intervals; /* consecutive hits that confirm it */ diff --git a/src/runtime/rx_living.c b/src/runtime/rx_living.c index e9eb33c85..07a9b1667 100644 --- a/src/runtime/rx_living.c +++ b/src/runtime/rx_living.c @@ -659,16 +659,24 @@ int rx_living_register(RxLiving *l, const RxLivingCaps *caps, if ((rc = rx_world_add_reaction_keyed(w, l->keys, &d, &l->r_evidence)) != RX_OK) return rc; base(&d, "generation.prepare", RX_FACULTY_OMEGA, RX_LIVING_PREPARE_SUBJ, fn_candidate, l); - d.n_triggers = 1; + /* Wakes on the selection, and on the goal and plan the proposal must be + * authored by. The body researches a new core class on its own, before + * any goal exists (aien.plan, core-class hypothesis), so a selection can + * land before the goal; prepare then declines for want of an author, and + * that decline must not be final: the goal (or a new plan) arriving runs + * the same check again on the same selection. With the goal and plan as + * plain reads, nothing woke prepare again and the organism never adapted + * (OMEGA-R14-HOST under judge load, 2026-10-20). */ + d.n_triggers = 3; d.triggers[0] = (RxDep){l->omega->o.selection, RX_ALL_FIELDS}; - d.n_reads = 7; + d.triggers[1] = (RxDep){l->aien->o.goal, RX_FIELD(0)}; + d.triggers[2] = (RxDep){l->aien->o.plan, RX_FIELD(0)}; + d.n_reads = 5; d.reads[0] = (RxDep){l->aien->o.experiment_belief, RX_ALL_FIELDS}; d.reads[1] = (RxDep){l->o.evidence, RX_ALL_FIELDS}; d.reads[2] = (RxDep){l->o.candidate, RX_ALL_FIELDS}; - d.reads[3] = (RxDep){l->aien->o.goal, RX_ALL_FIELDS}; - d.reads[4] = (RxDep){l->aien->o.plan, RX_ALL_FIELDS}; - d.reads[5] = (RxDep){l->omega->o.search, RX_ALL_FIELDS}; - d.reads[6] = (RxDep){l->o.output, RX_ALL_FIELDS}; + d.reads[3] = (RxDep){l->omega->o.search, RX_ALL_FIELDS}; + d.reads[4] = (RxDep){l->o.output, RX_ALL_FIELDS}; d.n_writes = 1; d.writes[0] = (RxDep){l->o.candidate, RX_ALL_FIELDS}; d.n_caps = 8; diff --git a/src/runtime/rx_omega.c b/src/runtime/rx_omega.c index 07ed3893a..57440b0ae 100644 --- a/src/runtime/rx_omega.c +++ b/src/runtime/rx_omega.c @@ -56,6 +56,17 @@ static uint64_t now_ns(void) { return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; } +/* What a matvec costs: the time the calling thread spent executing it. + * Serve and measure time their calls with this, so a preemption or a busy + * neighbour on the same core does not count as cost, while the core it runs + * on and the code it runs still do (omega #313, #527). Deadlines stay on + * now_ns. */ +static uint64_t cost_ns(void) { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; +} + static uint64_t id_word(const SemanticId *id, uint32_t i) { uint64_t v = 0; for (uint32_t b = 0; b < 8; b++) v |= (uint64_t)id->bytes[i * 8 + b] << (8 * b); @@ -185,7 +196,7 @@ int rx_omega_store_find(RxOmegaFaculty *f, uint64_t w0, RxOmegaRealization *out) } /* A realization the parent may execute: verified, and named by all 32 bytes. */ -static MatVecFn verified_fn(RxOmegaFaculty *f, const SemanticId *id) { +static MatVecFn verified_fn(RxOmegaFaculty *f, const SemanticId *id, uint32_t *kind) { pthread_mutex_lock(&f->mu); RxOmegaRealization *e = store_find_locked(f, id); MatVecFn fn = NULL; @@ -193,6 +204,7 @@ static MatVecFn verified_fn(RxOmegaFaculty *f, const SemanticId *id) { union { void *p; MatVecFn fn; } u; u.p = e->page; fn = u.fn; + if (kind) *kind = e->kind; e->parent_runs++; } pthread_mutex_unlock(&f->mu); @@ -219,17 +231,20 @@ static int fn_serve(RxCtx *c) { /* Whatever the world currently records for this regime. Never waits. */ MatVecFn fn = NULL; + uint32_t kind = RX_OMEGA_COST_REFERENCE; uint64_t used = 0; if (sel->field[0] != 0 && sel->field[6] == rx_omega_regime(M, N) && sel->field[1] != 0) { SemanticId id; id_from_words(&id, &sel->field[1]); - fn = verified_fn(f, &id); + fn = verified_fn(f, &id, &kind); if (fn) used = sel->field[1]; } - uint64_t t0 = now_ns(); + uint64_t t0 = cost_ns(); if (fn) fn(A, x, y, M, N); else omega_matvec_reference(A, x, y, (uint32_t)M, (uint32_t)N); - uint64_t ns = now_ns() - t0; + uint64_t ns = cost_ns() - t0; + if (f->cfg.cost_ns) + ns = f->cfg.cost_ns(f->cfg.cost_ctx, kind, (uint32_t)M, (uint32_t)N, 1); uint64_t digest = rx_omega_digest(y, (uint32_t)M); free(A); free(x); free(y); @@ -612,14 +627,18 @@ static int fn_verify(RxCtx *c) { #define ROUNDS 7u -static uint64_t time_calls(MatVecFn fn, const uint64_t *A, const uint64_t *x, uint64_t *y, +static uint64_t time_calls(const RxOmegaFaculty *f, MatVecFn fn, uint32_t kind, + const uint64_t *A, const uint64_t *x, uint64_t *y, uint32_t M, uint32_t N, uint32_t iters) { - uint64_t t0 = now_ns(); + uint64_t t0 = cost_ns(); for (uint32_t i = 0; i < iters; i++) { if (fn) fn(A, x, y, M, N); else omega_matvec_reference(A, x, y, M, N); } - return now_ns() - t0; + uint64_t ns = cost_ns() - t0; + if (f->cfg.cost_ns) + ns = f->cfg.cost_ns(f->cfg.cost_ctx, fn ? kind : RX_OMEGA_COST_REFERENCE, M, N, iters); + return ns; } static int fn_measure(RxCtx *c) { @@ -638,7 +657,8 @@ static int fn_measure(RxCtx *c) { SemanticId id; id_from_words(&id, &cand->field[2]); uint64_t cps = 0, rps = 0, state = RX_OMEGA_DECLINED; - MatVecFn fn = v->field[1] == RX_OMEGA_PASSED ? verified_fn(f, &id) : NULL; + uint32_t kind = RX_OMEGA_COST_REFERENCE; + MatVecFn fn = v->field[1] == RX_OMEGA_PASSED ? verified_fn(f, &id, &kind) : NULL; uint32_t M = (uint32_t)s->field[1], N = (uint32_t)s->field[2]; if (fn && shape_ok(M, N)) { uint64_t *A = malloc((size_t)M * N * sizeof(uint64_t)); @@ -651,14 +671,14 @@ static int fn_measure(RxCtx *c) { omega_matvec_reference(A, x, yr, M, N); if (memcmp(y, yr, (size_t)M * sizeof(uint64_t)) == 0) { /* Size one round to about 200 microseconds of the reference. */ - uint64_t one = time_calls(NULL, A, x, yr, M, N, 1); + uint64_t one = time_calls(f, NULL, kind, A, x, yr, M, N, 1); uint32_t iters = one ? (uint32_t)(200000u / one) : 1000u; if (iters < 4) iters = 4; if (iters > 20000) iters = 20000; uint64_t best_c = UINT64_MAX, best_r = UINT64_MAX; for (uint32_t r = 0; r < ROUNDS; r++) { - uint64_t tc = time_calls(fn, A, x, y, M, N, iters); - uint64_t tr = time_calls(NULL, A, x, yr, M, N, iters); + uint64_t tc = time_calls(f, fn, kind, A, x, y, M, N, iters); + uint64_t tr = time_calls(f, NULL, kind, A, x, yr, M, N, iters); if (tc < best_c) best_c = tc; if (tr < best_r) best_r = tr; } @@ -894,6 +914,11 @@ int rx_omega_register(RxOmegaFaculty *f, const RxOmegaCaps *caps) { begin(&b, "omega.select", RX_FACULTY_OMEGA, RX_OMEGA_SUBJ_OMEGA, RX_PRIO_LEARNING, fn_select, f, caps->omega); + /* Every epoch republishes the whole selection, even when the same + * realization wins again: the proposal checks that the identity words + * and the epoch were written by one commit, so unchanged words must + * still carry this epoch's author (OMEGA-R14-HOST, 2026-10-20). */ + b.d.stamp_proposed = true; for (uint32_t k = 0; k < f->cfg.n_slots; k++) trig(&b, w, f->o.measure[k], RX_ALL_FIELDS); if (f->require_experiment_evidence) { b.d.triggers[b.d.n_triggers++] = (RxDep){ f->experiment_evidence, RX_FIELD(0) }; diff --git a/src/runtime/rx_omega.h b/src/runtime/rx_omega.h index bd6c27ede..c35382061 100644 --- a/src/runtime/rx_omega.h +++ b/src/runtime/rx_omega.h @@ -76,7 +76,8 @@ enum { * 4..7 realization id * selection: 0 epoch, 1..4 realization id (zero = reference), 5 ps/call, * 6 regime, 7 reference ps/call - * regime = (M << 32) | N. */ + * regime = (M << 32) | N. Every ns and ps above is the executing thread's CPU + * time (CLOCK_THREAD_CPUTIME_ID), not wall-clock time. */ enum { RX_OMEGA_SYNTHESIZED = 1 }; enum { RX_OMEGA_PASSED = 1, RX_OMEGA_REFUSED = 2 }; enum { RX_OMEGA_MEASURED = 1, RX_OMEGA_DECLINED = 2 }; @@ -119,8 +120,16 @@ typedef struct { uint64_t hot_ns; uint32_t margin_pct; /* a realization must beat the reference by this */ uint32_t sandbox_ms; + /* Test only (R15 SEQ parity): when set, the cost of `calls` matvec calls + * replaces the wall-clock time measured around them, in serve and in + * measure. The calls still run. kind is the realization kind, or + * RX_OMEGA_COST_REFERENCE for the reference. NULL measures, as always. */ + uint64_t (*cost_ns)(void *ctx, uint32_t kind, uint32_t M, uint32_t N, uint64_t calls); + void *cost_ctx; } RxOmegaConfig; +#define RX_OMEGA_COST_REFERENCE UINT32_MAX + typedef struct { RxObjRef request, demand, result, search, selection; RxObjRef candidate[RX_OMEGA_SLOTS]; diff --git a/tests/.crumb b/tests/.crumb index 5fbfcb29c..fd3bc0fa1 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -110,206 +110,206 @@ "children": [ { "digest": "2c1deaaa1bae6257789749edde641df61413250fe91ce6aa61a99dfb3b271306", - "last_commit": "d863780eb", + "last_commit": "28911be7a", "name": "algebra", "purpose": "Directory tests/algebra. Purpose not yet described by a human." }, { "digest": "63f086b68bb9ffc032cbd74931309ab34df3c8c341b57935e5db43d8bf475800", - "last_commit": "d863780eb", + "last_commit": "834ee93e4", "name": "ans", "purpose": "Tests 1-10 for ANS (docs/ans/INERTIAL_ALIGNMENT_SPEC_V1.md): freeze/digest, hostile reference mu" }, { "digest": "7b69a19958c5a5f55bba4fbc33bc6f26423358efd46311b0eacfe83bb665d4c1", - "last_commit": "450bbefd4", + "last_commit": "1b0e2968c", "name": "brownian", "purpose": "Directory tests/brownian. Purpose not yet described by a human." }, { "digest": "1cd97575b2b10d9313ca0df4997391612056754778bb2851bf052c146144f15e", - "last_commit": "d863780eb", + "last_commit": "30bb116cc", "name": "canonicalization", "purpose": "Directory tests/canonicalization. Purpose not yet described by a human." }, { "digest": "088f526f8cae115209dd0162f28669812483ce5c926e41e8810dada1eefcb81a", - "last_commit": "450bbefd4", + "last_commit": "1edf41a5c", "name": "compiler", "purpose": "Directory tests/compiler. Purpose not yet described by a human." }, { "digest": "9e372cfc9747befacdcf31bc8643356aaff861e81ee6640b4866170be67b5e6c", - "last_commit": "d863780eb", + "last_commit": "28b87934b", "name": "constraints", "purpose": "Directory tests/constraints. Purpose not yet described by a human." }, { "digest": "87a3efa5cd0aefa7821046f9a31594bfa0a109e95005a1e12f40c99a1bc6cd3d", - "last_commit": "d863780eb", + "last_commit": "49abb0247", "name": "crumbline", "purpose": "Directory tests/crumbline. Purpose not yet described by a human." }, { "digest": "10aa3424eded7768fee0bae0eedd062b9deac3279d2e5721439fd024493bc42b", - "last_commit": "d863780eb", + "last_commit": "00f54b6b1", "name": "dual_experiment", "purpose": "Tests for the DUAL applicability experiment: determinism (same seed, byte-identical results dige" }, { "digest": "758dde696afa847d9347fad76b0c4935e968f8af4551f0f9810ec2a37ad9847a", - "last_commit": "d863780eb", + "last_commit": "c819b3762", "name": "effect", "purpose": "Directory tests/effect. Purpose not yet described by a human." }, { "digest": "23e559d13ff664995baca31dc157a8cf5a860615f3ecb07a9a40fe4626b57ae3", - "last_commit": "d863780eb", + "last_commit": "1a147e40f", "name": "estimation", "purpose": "Directory tests/estimation. Purpose not yet described by a human." }, { "digest": "b7b6391caf653c76707a21f9969126abcbc730d1243259219225fdb9bc0084e0", - "last_commit": "d863780eb", + "last_commit": "3108fc2f5", "name": "fabric", "purpose": "Directory tests/fabric. Purpose not yet described by a human." }, { "digest": "defc52a44ea0f65ba5de3468de786148ba58d292ffa217fb95629a28a569a977", - "last_commit": "d863780eb", + "last_commit": "28b87934b", "name": "identity", "purpose": "Directory tests/identity. Purpose not yet described by a human." }, { "digest": "6ba43d622b712a4215767cab29425016f29cce4b28eb9e4961fc67fd20e9d765", - "last_commit": "d863780eb", + "last_commit": "4f55f45ed", "name": "language", "purpose": "Directory tests/language. Purpose not yet described by a human." }, { "digest": "54f43a3416595ff5d4e64bd12afe013359e706651c39c78e2896a5799638d263", - "last_commit": "d863780eb", + "last_commit": "30bb116cc", "name": "malformed", "purpose": "Directory tests/malformed. Purpose not yet described by a human." }, { "digest": "a03a4dd9a72f7b449342e562f6d9df1a3348fb03fb640b662956caf163dcd7e9", - "last_commit": "d863780eb", + "last_commit": "40d1ea378", "name": "numeric_native", "purpose": "Simulated M16 driver for numeric resource-lifecycle tests. No device execution or numeric parity" }, { "digest": "d958af5413726ddc48a47721800d9766939129f480b26492332ba094577837cb", - "last_commit": "d863780eb", + "last_commit": "6d8d92adc", "name": "osh", "purpose": "osh lexer host driver, vendored aien-protocols PR#16 draft vectors (5ae5292)" }, { "digest": "65e84051bb8dc00b180c6b06bec58103773785eebd6d6c69c9783de5fd0e2ba9", - "last_commit": "450bbefd4", + "last_commit": "d550b705b", "name": "path", "purpose": "Directory tests/path. Purpose not yet described by a human." }, { "digest": "51f14936b27d3d21379cf05ea1b6b532cf3175a40844dac85f023a61e7a0912c", - "last_commit": "d863780eb", + "last_commit": "5901baa51", "name": "physics0", "purpose": "PD-0 gates: world self-test, oracle calibration, learner L0/L1/NULL, mutations, OSC differential" }, { "digest": "c8524317c751fa8f464cabc31b760cef262abba822f1843482a02e239daa81b3", - "last_commit": "d863780eb", + "last_commit": "61c094113", "name": "polyglot", "purpose": "Directory tests/polyglot. Purpose not yet described by a human." }, { "digest": "6569e2cd6dbf6f792edb5d83bf0715df9dece42ca7bd9b3a291535de0492d3aa", - "last_commit": "d863780eb", + "last_commit": "3c82389f7", "name": "program", "purpose": "Directory tests/program. Purpose not yet described by a human." }, { "digest": "c549b5b82fd026d664b35e4b1a5d7fd2aaafa13b60b541cfbba87d7522517b1d", - "last_commit": "d863780eb", + "last_commit": "6fdc4c33a", "name": "r16_inventory", "purpose": "Directory tests/r16_inventory. Purpose not yet described by a human." }, { "digest": "855bd23e4c526fb49eeb430c4ea5967d3f2f9da3a5b3aa3ec9dae5b814b11a21", - "last_commit": "d863780eb", + "last_commit": "46b9cad0d", "name": "r16_negative", "purpose": "Directory tests/r16_negative. Purpose not yet described by a human." }, { "digest": "f21be04969cbf51de17118c4f81b103f712db56fd517a1f12dd0d3ac4ff3afe4", - "last_commit": "d863780eb", + "last_commit": "44d8c06c3", "name": "r16_surface", "purpose": "Directory tests/r16_surface. Purpose not yet described by a human." }, { "digest": "b0ba3448394d5f27958c38b7233ae389e5e437e327f0859749a774fb252d6b02", - "last_commit": "d863780eb", + "last_commit": "40d1ea378", "name": "realize", "purpose": "Directory tests/realize. Purpose not yet described by a human." }, { "digest": "157018d66de5bfd149015654cf0bda1346a9cfcefe5fd552c1d54859cd9ece81", - "last_commit": "d863780eb", + "last_commit": "30bb116cc", "name": "relations", "purpose": "Directory tests/relations. Purpose not yet described by a human." }, { "digest": "e5f68362c083510e34c41f65de3ba2d553eac8a52fbc3e4cc1f69314eac9cc32", - "last_commit": "d863780eb", + "last_commit": "dd67f6bd7", "name": "reservoir", "purpose": "Reservoir tests (omega#440): Gate 1 simulator and readout checks against an independent binary64" }, { - "digest": "10d19641e4bb5b435ec6363d4ea7d3c1596af47d97b86f4de35d6ae57770241e", - "last_commit": "45f7d7691", + "digest": "7698d6d30ff6158217268586a3c4ce404466b5f020249daf635ad0fa3e0e6d62", + "last_commit": "ef4f5656c", "name": "runtime", "purpose": "Directory tests/runtime. Purpose not yet described by a human." }, { "digest": "467652c09505ecbd82d96a5e0e7ea24b19d9216cfd1dad7c60fa8258e47594c0", - "last_commit": "d863780eb", + "last_commit": "5ae192a43", "name": "searchtrace", "purpose": "Directory tests/searchtrace. Purpose not yet described by a human." }, { "digest": "e69616ad471704066a86bf2796776301179eada5c0aa36a7166b9aca788619f4", - "last_commit": "ed8de5736", + "last_commit": "", "name": "synapse", "purpose": "J1 parity driver for syn_codec.osc against the sealed Rust A1 corpus (aien-dev/synapse j1-codec-" }, { "digest": "5c97916fbf20310eff2e502c526337cb093e912cb48f18d44b0345ed8a3c3240", - "last_commit": "d863780eb", + "last_commit": "54826a37f", "name": "train", "purpose": "Directory tests/train. Purpose not yet described by a human." }, { "digest": "7679bd1c49c7e89d8c26ccf8dfb91478f4e6e2f584745806fa8d26061dbdbb9c", - "last_commit": "d863780eb", + "last_commit": "2564f57a9", "name": "turing", "purpose": "Directory tests/turing. Purpose not yet described by a human." }, { "digest": "930fcb9ce348c604424e5380796a77c3586a835b43d42b504325c36b12d166d7", - "last_commit": "450bbefd4", + "last_commit": "fed4f0775", "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:77f9f2803697bf4c4f41cf45411ef6f546f9f11f6fb3910d8f150a060d9e2d89", + "compiled_at": "2026-10-30T16:33:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", + "digest": "sha256:d9914aa350fd18daae8d6ed3b17df61a66476e5f3f92282151d8bbc2c9b6091b", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1386, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679" + "files": 1388, + "generated_at_commit": "8d591af9c727dbc1dd02c2ec9988c939d59a378b", + "source_tree": "sha256:1ea2c49e5d1cfd5d6e3ce83c50c43226dc9b9a0758d8b0062809b95378bb2bd8" }, "owner_lane": "", "provenance": { diff --git a/tests/gates/run.sh b/tests/gates/run.sh index 66da8e1a9..c220aa043 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -82,6 +82,38 @@ receipt() { } gates_pass() { grep -E 'TOTAL GATES: [0-9]+ \| PASSED: [0-9]+ \| FAILED: 0' "$1" && ! grep -E 'FAILED: [1-9]' "$1"; } +# speed : a speed test (tests/runtime/rx_quiet_reps.h) that found +# the machine too busy to time ends with `AIEN-OBS not_run_reason "cpu_busy"` and exit 77; make reports +# any failing recipe as 2, so the refusal is read from the test's own receipt for this step: "failures": 0 +# and the gate word NOT_RUN, which the test writes only when nothing it judged failed. Then the step goes +# on, so every other check is still judged, and ends NOT_RUN (exit 77) only if nothing else failed. +# Anything else is the failure it was. A passing run gets the receipt check it always had. +BUSY=0 +speed() { + local target="$1" file="$2" word="$3" rc=0 r f bad=1 + make "$target" || rc=$? + if [ "$rc" -eq 0 ]; then + receipt "$file" '"failures": 0,' '"candidate_bound": true,' "\"$word\": \"PASS\"" + return + fi + # Every receipt of that name written during this step must say so; any other one keeps the failure. + r="$(find build/qual-runs -name "$file" -type f -newer "$STEP_MARK")" + if [ -n "$r" ]; then + bad=0 + while IFS= read -r f; do + grep -q '"failures": 0,' "$f" && grep -q '"candidate_bound": true,' "$f" && + grep -q "\"$word\": \"NOT_RUN\"" "$f" || bad=1 + done <<< "$r" + fi + if [ "$bad" = 0 ]; then + echo "run.sh: $target: machine too busy to time (cpu_busy); not judged, the rest of the step runs" >&2 + printf '%s\n' "$r" | xargs sha256sum + BUSY=1 + return 0 + fi + return "$rc" +} + case "$step" in crumb-verify) # Hosted crumb.yml builds the crumb tool from the aien-architecture commit in crumb.lock. @@ -213,18 +245,23 @@ case "$step" in pin physics-src-6d7cf0d physics 6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf export PHYSICS_COMMIT=6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf PHYSICS_DIR="$PINS/physics-src-6d7cf0d" aienos_pin; set -o pipefail; mkdir -p build - make test-r3 test-r7 test-r16-operator-authority-misuse test-r8 test-r9 test-r12 test-rx-emergency test-action-graph test-state-projection test-capability-query test-capability-graph test-skillroute-compose test-semantic-comm test-cognitive-routing test-sem-incremental test-cortex test-jspace-prod test-composition test-composition-attach-asan test-composition-gate test-fabric test-fabric-living | tee build/rx-host-reference.log + # The hosted job runs these as one make line; the speed test test-action-graph is taken out (speed, + # above) so a busy machine is a refusal and the targets after it still run, in the same order. + # All test output also goes to build/rx-host-reference.log, so a step that hits its time limit + # leaves a record of the test that was running. speed runs in this shell (BUSY), so its output + # reaches the log through a process substitution, not a pipe. + make test-r3 test-r7 test-r16-operator-authority-misuse test-r8 test-r9 test-r12 test-rx-emergency | tee build/rx-host-reference.log + speed test-action-graph rx_action_graph_receipt.json OMEGA_ACTION_GRAPH_IR_PASS > >(tee -a build/rx-host-reference.log) + make test-state-projection test-capability-query test-capability-graph test-skillroute-compose test-semantic-comm test-cognitive-routing test-sem-incremental test-cortex test-jspace-prod test-composition test-composition-attach-asan test-composition-gate test-fabric test-fabric-living | tee -a build/rx-host-reference.log make test-machine-identity | tee -a build/rx-host-reference.log make test-effect-cap64 | tee build/effect-cap64.log 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,' 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"' - make test-workflow-fusion - receipt rx_workflow_fusion_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_WORKFLOW_FUSION_PASS": "PASS"' + speed test-workflow-fusion rx_workflow_fusion_receipt.json OMEGA_WORKFLOW_FUSION_PASS make test-typed-results receipt rx_typed_results_receipt.json '"failures": 0,' '"candidate_bound": true,' '"OMEGA_TYPED_RESULT_CONSTRAINTS_PASS": "PASS"' make test-costmodel @@ -237,6 +274,7 @@ case "$step" in tools/rx_host_receipts.sh heartbeat "$r" tools/rx_host_receipts.sh native "$native" "$OMEGA_CANDIDATE_COMMIT" tools/rx_host_receipts.sh generation "$generation" "$OMEGA_CANDIDATE_COMMIT" + if [ "$BUSY" = 1 ]; then obs not_run_reason '"cpu_busy"'; exit 77; fi ;; faculty-arm) pin physics-src-6d7cf0d physics 6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf diff --git a/tests/r15_energy_preflight_test.sh b/tests/r15_energy_preflight_test.sh index 2e5f28263..30e6446e3 100644 --- a/tests/r15_energy_preflight_test.sh +++ b/tests/r15_energy_preflight_test.sh @@ -33,7 +33,7 @@ EL=$(sed -n 's/^static const char \*const k_elabel\[[A-Z_0-9]*\] = {\(.*\)};/\1/ PL=$(sed -n 's/^static const char \*const k_plabel\[[A-Z_0-9]*\] = {\(.*\)};/\1/p' $C | tr -d '" ' | tr , ' ') [ "$(echo $EL | wc -w)" = 5 ] && [ "$(echo $PL | wc -w)" = 5 ] || { echo "[-] cannot read label tables from $C"; exit 1; } check() { # name expected-exit expected-text - out=$(R15_HWMON_ROOT="$W/$1" "$T" energy-preflight 2>&1); rc=$? + out=$(R15_HWMON_ROOT="$W/$1" "$T" energy-preflight 2>&1); rc=$?; : > "$W/$1.stop" # the preflight has returned: stop this case's background writer if [ "$rc" = "$2" ] && printf '%s\n' "$out" | grep -Fq -- "$3"; then echo "[+] $1: exit $rc" else echo "[-] $1: exit $rc (want $2), output: $out"; fail=$((fail + 1)); fi } @@ -42,9 +42,15 @@ mk() { # case: a complete, valid-looking reader tree (static counters) i=1; for l in $EL; do echo "$l" > "$H/energy${i}_label"; echo 5000000000 > "$H/energy${i}_input"; echo 0 > "$H/energy${i}_overflow_raw"; i=$((i + 1)); done i=1; for l in $PL; do echo "$l" > "$H/power${i}_label"; echo 20000000 > "$H/power${i}_input"; i=$((i + 1)); done } -# advance : package counter rises 0.5 J then 1 J in the background while the preflight samples +# advance : the package counter keeps rising (0.5 J every 20 ms) in the background until check() +# has run the preflight, so the three samples see a moving counter however slow the preflight is to start. +# The old writer stepped twice (50 ms and 150 ms) and then stopped; under the Spark judge, which runs ~21 gates at once, +# the preflight's own startup (bash, sed over r15_measure.c, label reads) took longer than 150 ms, every sample read the +# final value and "valid" failed with "package counter did not advance over 3 samples (5001100000 uJ)" (omega#508 judge +# run 2026-10-16 13:09Z; reproduced 6/15 on the host under 20 busy loops, 0/15 with this writer). Capped at 1500 steps +# (30 s, 750 J) so it always ends on its own; the cap keeps every fixture below the headroom and wrap thresholds. put() { echo "$2" > "$1.tmp" && mv "$1.tmp" "$1"; } # atomic, so the preflight never reads a half-written file -advance() { ( sleep 0.05; put "$W/$1/hwmon1/energy1_input" $(( $2 + 500000 )); sleep 0.1; put "$W/$1/hwmon1/energy1_input" $(( $2 + 1000000 )) ) & } +advance() { ( v=$2; k=0; while [ ! -e "$W/$1.stop" ] && [ $k -lt 1500 ]; do v=$((v + 500000)); put "$W/$1/hwmon1/energy1_input" $v; k=$((k + 1)); sleep 0.02; done ) & } mkdir -p "$W/absent/hwmon0"; echo acpitz > "$W/absent/hwmon0/name"; check absent 5 "reason=absent" mkdir -p "$W/empty"; check empty 5 "reason=absent" mk substitute; echo nvml > "$W/substitute/hwmon1/name"; check substitute 5 "reason=absent" @@ -75,7 +81,7 @@ R15_UPTIME_FILE="$W/wrapped-uptime" R15_ENERGY_PREFLIGHT_SLEEP=0.08 check wrappe mk nouptime; advance nouptime 5000000000; R15_UPTIME_FILE="$W/does-not-exist" R15_ENERGY_PREFLIGHT_SLEEP=0.08 check nouptime 5 "uptime"; wait # a decrease on any channel (not only package) invalidates the reader mk decr3; echo 5000000000 > "$W/decr3/hwmon1/energy1_input" -( k=0; while [ $k -lt 60 ]; do put "$W/decr3/hwmon1/energy3_input" $((5000000000 - k * 1000)); k=$((k + 1)); sleep 0.01; done ) & # steadily falling cpu_p counter +( k=0; while [ ! -e "$W/decr3.stop" ] && [ $k -lt 3000 ]; do put "$W/decr3/hwmon1/energy3_input" $((5000000000 - k * 1000)); k=$((k + 1)); sleep 0.01; done ) & # steadily falling cpu_p counter until check() returns (cap 30 s) advance decr3 5000000000 R15_ENERGY_PREFLIGHT_SLEEP=0.08 check decr3 5 "energy3 counter went backwards" wait diff --git a/tests/runtime/.crumb b/tests/runtime/.crumb index 9dce17c38..7aa6b000b 100644 --- a/tests/runtime/.crumb +++ b/tests/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-26T08:13:25Z", + "compiled_at": "2026-10-30T16:33:41Z", "compiler": "crumb-compile/1", - "digest": "sha256:10d19641e4bb5b435ec6363d4ea7d3c1596af47d97b86f4de35d6ae57770241e", + "digest": "sha256:7698d6d30ff6158217268586a3c4ce404466b5f020249daf635ad0fa3e0e6d62", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 70, - "generated_at_commit": "45f7d76919042ef821cca9ccc75c2bbf7183f712", - "source_tree": "sha256:6d63521e1c1f8eea1bf172d18bde2e6f4fc7c084e9506bc1cc088f8b9ff339d6" + "files": 71, + "generated_at_commit": "8d591af9c727dbc1dd02c2ec9988c939d59a378b", + "source_tree": "sha256:57937942601ede99dc6749e06fe3435f3520226cf426e85e530d24eb0cf0f05b" }, "owner_lane": "", "provenance": { diff --git a/tests/runtime/r11_own_hold_test.sh b/tests/runtime/r11_own_hold_test.sh index 98a3bfcab..fc874c64d 100755 --- a/tests/runtime/r11_own_hold_test.sh +++ b/tests/runtime/r11_own_hold_test.sh @@ -15,23 +15,72 @@ # limitations under the License. # R11 living run inside its own quiet hold (tests/runtime/rx_r11_aien.c -# quiet_flag_is_mine). With a fake HOME whose ~/workspace/.spark-quiet carries -# hold=q1-abc: no QUIETLOCK_HOLD, a prefix and an extension of the id must all -# refuse the living run because of that flag (someone else's measurement); -# QUIETLOCK_HOLD=q1-abc must not be refused because of the flag. The binary also -# skips the living run on a 1-minute load above 2 (other_load), which is the -# normal state of the shared Spark while the judge runs gates in parallel, so a -# refusal for load is not the hold logic under test and is not counted here. +# quiet_flag_state / quiet_flag_is_mine). With a fake HOME whose +# ~/workspace/.spark-quiet carries hold=q1-abc: no QUIETLOCK_HOLD, a prefix and +# an extension of the id must all be refused because of the flag (someone +# else's measurement); QUIETLOCK_HOLD=q1-abc must be let through to the living +# run. +# +# What is judged, and what is not. The program also refuses the living run +# when the machine is loaded (1-minute load average above 2). That is a second, +# unrelated reason, and on the shared Spark judge it is always true, so it +# used to hide the answer this test is about. The test therefore raises that +# limit for its own runs (R11_LOAD_LIMIT; it can only raise it) and reads +# the two decisions the program prints and takes: +# "quiet flag: " +# "[*] living run: ..." (printed when the living run starts) +# Refused cases: the flag line must say another measurement's hold, the reason +# given must be the flag, and the living run must not start. Own-hold case: the +# flag line must say this run's own hold and the living run must start. +# The physical verdict of that living run (its speed checks) is judged here +# only when the machine was calm when it began (1-minute load average <= 2, +# the condition the living run is specified for): then "checks N failures 0" +# is required, exactly as before. On a loaded machine its verdict is printed +# and not judged. Measured at load 25 with Omega's CPU-time clock (cost_ns), +# the living run still failed 4 of 40 runs (AIEN acting on a preempted +# interval), so the load limit is a real property of the living run, not noise +# in this test. A loaded machine is never a pass for that part; it is simply +# not this test's question, and test-r11 runs it where the machine is calm. # usage: r11_own_hold_test.sh B=${1:?rx_r11_aien_test binary}; H=$(mktemp -d); fail=0 trap 'rm -rf "$H"' EXIT mkdir -p "$H/workspace" echo "other quietlock X start=2026-10-05T00:00:00Z expected_end=2099-01-01T00:00:00Z pid=1 hold=q1-abc" > "$H/workspace/.spark-quiet" +FLAG_WHY='holds ~/workspace/.spark-quiet' for hold in "" q1-ab q1-abcd q1-abc; do - out=$(HOME=$H QUIETLOCK_HOLD=$hold "$B" 2>&1) - if printf '%s\n' "$out" | grep -Fq "an R15 timed measurement holds ~/workspace/.spark-quiet"; then got=refused; else got=ran; fi - if [ "$hold" = q1-abc ]; then want=ran; else want=refused; fi - printf '%s\n' "$out" | grep -Eq '^checks [0-9]+ failures 0$' || { got="$got+failures"; } + calm=$(awk '{ if ($1 <= 2.0) print "yes"; else print "no" }' /proc/loadavg) + out=$(HOME=$H QUIETLOCK_HOLD=$hold R11_LOAD_LIMIT=1000000 "$B" 2>&1) + flag=$(printf '%s\n' "$out" | sed -n 's/^quiet flag: //p' | head -n 1) + printf '%s\n' "$out" | grep -Fq '[*] living run:' && started=yes || started=no + printf '%s\n' "$out" | grep -Fq "$FLAG_WHY" && why_flag=yes || why_flag=no + if [ "$hold" = q1-abc ]; then + # let through: the flag is ours, the flag is not the reason, the living run starts + if [ "$flag" = "this run's own hold" ] && [ "$why_flag" = no ] && [ "$started" = yes ]; then + got=ran + else + got="refused or not started (flag='$flag', flag reason $why_flag, started $started)" + fi + want=ran + else + # refused because of the flag: it says so, gives it as the reason, and does not start + if [ "$flag" = "another measurement's hold" ] && [ "$why_flag" = yes ] && [ "$started" = no ]; then + got=refused + else + got="not refused by the flag (flag='$flag', flag reason $why_flag, started $started)" + fi + want=refused + fi + if [ "$got" = "$want" ] && [ "$want" = ran ]; then + line=$(printf '%s\n' "$out" | grep -E '^checks [0-9]+ failures [0-9]+$' | tail -n 1) + if [ "$calm" = yes ]; then + case "$line" in + "checks "*" failures 0") ;; + *) got="ran, but the calm-machine verdict was '$line', want failures 0" ;; + esac + else + echo "[~] hold='$hold': machine loaded, living run verdict not judged here ('$line'); test-r11 judges it on a calm machine" + fi + fi if [ "$got" = "$want" ]; then echo "[+] hold='$hold': $got"; else echo "[-] hold='$hold': $got, want $want"; fail=$((fail + 1)); fi done echo "failures $fail"; [ "$fail" = 0 ] diff --git a/tests/runtime/rx_action_graph.c b/tests/runtime/rx_action_graph.c index f04cc2a48..199abaaab 100644 --- a/tests/runtime/rx_action_graph.c +++ b/tests/runtime/rx_action_graph.c @@ -45,6 +45,7 @@ #include #include #include +#include "rx_quiet_reps.h" enum { SUBJ_EXTERNAL = 100, ISSUER = 3, SUBJ_PLAN = 61, SUBJ_OTHER = 62 }; @@ -810,9 +811,12 @@ static void t_effects(void) { static void t_parallel(void) { printf("[*] parallel graph: critical path\n"); - const uint32_t reps = 15; + /* 15 undisturbed repetitions per leg (rx_quiet_reps.h), at most 60 times + * as many attempts. */ + const uint32_t reps = 15, attempts = 15 * 60; uint64_t times[2][32]; - uint32_t workers[2] = { 1, 4 }; + uint32_t workers[2] = { 1, 4 }, kept[2] = { 0, 0 }, tried[2] = { 0, 0 }; + int delay_known = 1; AgReport rep; for (uint32_t k = 0; k < 2; k++) { Env e; @@ -827,14 +831,29 @@ static void t_parallel(void) { CHECK(res.outcome == AG_RUN_SUCCESS && res.value[node_of_kind(&g, AG_SKILL)] == 7 + 500 * 3 + 40 * 6 + 7 * 9 + 3 * 12, "combine = 7 + 3*500 + 6*40 + 9*7 + 12*3"); - for (uint32_t i = 0; i < reps; i++) { + for (uint32_t i = 0; i < attempts && kept[k] < reps; i++) { reference(&e, &g, 2 + i); - int64_t ext = run(&e, &L, 2 + i, &res, ×[k][i]); + uint64_t ns = 0; + int64_t d0 = rx_run_delay_ns(); + int64_t ext = run(&e, &L, 2 + i, &res, &ns); + int64_t d1 = rx_run_delay_ns(); compare(&e, &g, &res, &g_ref, "parallel"); if (i == 0) ancestry(&e, &L, ext, "parallel"); + tried[k]++; + if (d0 < 0 || d1 < 0) delay_known = 0; + if (rx_quiet_rep(d0 < 0 || d1 < 0 ? -1 : d1 - d0, ns)) times[k][kept[k]++] = ns; } env_stop(&e); } + printf(" undisturbed repetitions: 1 worker %u of %u, %u workers %u of %u (%s)\n", kept[0], + tried[0], workers[1], kept[1], tried[1], + delay_known ? "run-queue delay from schedstat" : "schedstat missing: every repetition counts"); + if (kept[0] < reps || kept[1] < reps) { + fprintf(stderr, " machine too busy to time the parallel graph: %u and %u of %u undisturbed " + "repetitions in %u attempts\n", kept[0], kept[1], reps, attempts); + rx_busy_refuse("parallel graph timing (speedup, beats the sequential sum)"); + return; + } for (uint32_t k = 0; k < 2; k++) for (uint32_t i = 1; i < reps; i++) for (uint32_t j = i; j > 0 && times[k][j - 1] > times[k][j]; j--) { @@ -1237,6 +1256,11 @@ static void binary_digest(char out[65]) { for (int i = 0; i < 32; i++) sprintf(out + i * 2, "%02x", d[i]); } +static int judged_pass(void) { + return g_fail == 0 && R.bypass == 0 && R.evidence_missing == 0 && R.ancestry_mismatch == 0 && + R.det_mismatch == 0 && R.aegis_mints_during_compile == 0; +} + static void write_receipt(void) { char path[512]; if (omega_evidence_path("ACTION_GRAPH/rx_action_graph_receipt.json", path, sizeof path) != 0) return; @@ -1254,8 +1278,6 @@ static void write_receipt(void) { struct utsname u; memset(&u, 0, sizeof u); uname(&u); - int pass = g_fail == 0 && R.bypass == 0 && R.evidence_missing == 0 && R.ancestry_mismatch == 0 && - R.det_mismatch == 0 && R.aegis_mints_during_compile == 0; fprintf(fp, "{\n" " \"schema\": \"OMEGA_ACTION_GRAPH_IR_V1\",\n" @@ -1304,7 +1326,7 @@ static void write_receipt(void) { (unsigned long long)R.opt_crumbs_before, (unsigned long long)R.opt_crumbs_after, (unsigned long long)R.opt_ns_before, (unsigned long long)R.opt_ns_after, R.bypass, R.authority_blocked_crumbs, R.aegis_mints_during_compile, R.aegis_mints_after_approval, - pass ? "PASS" : "FAIL"); + rx_busy_verdict(judged_pass())); fclose(fp); printf("receipt: %s\n", path); } @@ -1333,5 +1355,5 @@ int main(void) { R.evidence_checked, R.evidence_missing, R.bypass); printf("checks %d failures %d\n", g_checks, g_fail); write_receipt(); - return g_fail ? 1 : 0; + return rx_busy_exit(g_fail, judged_pass()); } diff --git a/tests/runtime/rx_quiet_reps.h b/tests/runtime/rx_quiet_reps.h new file mode 100644 index 000000000..2ab310abd --- /dev/null +++ b/tests/runtime/rx_quiet_reps.h @@ -0,0 +1,107 @@ +/* Speed checks on a shared machine: keep only the repetitions the machine did + * not disturb. + * + * A stopwatch check compares wall times. On the Spark other jobs share the + * cores, and a run whose threads sat runnable without a core (the kernel's + * run-queue delay) is longer by time the code under test never asked for. + * That delay is measured, not guessed: /proc/self/task//schedstat field 2 + * is the time each thread of this process has spent runnable but waiting for + * a CPU (Documentation/scheduler/sched-stats.rst, "time spent waiting on a + * runqueue"). A repetition whose threads waited more than the allowance below + * is set aside and run again; the check then takes the same statistic (the + * median) with the same threshold over undisturbed repetitions only. + * + * Nothing is loosened: the work, the statistic and the threshold are the + * ones the check always had. A real slowdown is in every repetition, + * undisturbed ones included, so it still fails. When too few repetitions are + * undisturbed within the attempt budget the check is refused and says why + * (rx_busy_refuse below: NOT_RUN cpu_busy, never a pass). Where schedstat is missing every + * repetition counts (the old behaviour) and the output says so. + */ +#ifndef RX_QUIET_REPS_H +#define RX_QUIET_REPS_H + +#include +#include +#include + +/* Allowance: run-queue delay summed over all threads of the process during + * one repetition, at most RX_QUIET_FLOOR_NS plus RX_QUIET_PERMILLE of the + * repetition's wall time. The floor covers waking an idle worker (a few + * microseconds per hand-off on an idle core). */ +#define RX_QUIET_FLOOR_NS 50000ull +#define RX_QUIET_PERMILLE 20ull + +/* Sum of run-queue delay (ns) over every thread of this process; -1 when the + * kernel does not report it. */ +static inline int64_t rx_run_delay_ns(void) { + DIR *d = opendir("/proc/self/task"); + if (!d) return -1; + int64_t sum = 0; + int seen = 0; + struct dirent *de; + while ((de = readdir(d))) { + if (de->d_name[0] < '0' || de->d_name[0] > '9') continue; + char path[288]; + snprintf(path, sizeof path, "/proc/self/task/%s/schedstat", de->d_name); + FILE *fp = fopen(path, "r"); + if (!fp) continue; + unsigned long long on_cpu = 0, waited = 0; + if (fscanf(fp, "%llu %llu", &on_cpu, &waited) == 2) { + sum += (int64_t)waited; + seen = 1; + } + fclose(fp); + } + closedir(d); + return seen ? sum : -1; +} + +/* Whether a repetition of `wall_ns` whose threads waited `delay_ns` for a + * core counts. delay < 0 (not reported) always counts. */ +static inline int rx_quiet_rep(int64_t delay_ns, uint64_t wall_ns) { + if (delay_ns < 0) return 1; + return (uint64_t)delay_ns <= RX_QUIET_FLOOR_NS + wall_ns * RX_QUIET_PERMILLE / 1000ull; +} + +/* A check that found the machine too busy to time is a refusal, not a + * failure: nothing was measured, so nothing is judged, and the checks that + * need that measurement are not judged either. The program then ends with + * the local judge's "could not run" contract (aien-test SELF_NOT_RUN_EXIT): + * stdout line `AIEN-OBS not_run_reason "cpu_busy"` and exit 77, a retryable + * NOT_RUN, never a pass. Any real failure anywhere in the run wins: the exit + * is then 1, whatever was refused. */ +#define RX_NOT_RUN_EXIT 77 + +static inline unsigned *rx_busy_refusals(void) { + static unsigned n; + return &n; +} + +/* Record one refusal; `what` names the measurement that was not taken. */ +static inline void rx_busy_refuse(const char *what) { + (*rx_busy_refusals())++; + fprintf(stderr, " NOT RUN %s (cpu_busy): checks that need this measurement are not judged\n", what); +} + +/* The program's exit status from its failure count and `pass`, everything + * else its receipt judges: a refusal never covers a check judged false. */ +static inline int rx_busy_exit(int failures, int pass) { + if (failures) return 1; + if (*rx_busy_refusals()) { + if (!pass) return 1; + printf("AIEN-OBS not_run_reason \"cpu_busy\"\n"); + fflush(stdout); + return RX_NOT_RUN_EXIT; + } + return 0; +} + +/* A receipt's gate word: FAIL when `pass` (everything judged) is false, + * NOT_RUN when a measurement was refused, else PASS. */ +static inline const char *rx_busy_verdict(int pass) { + if (!pass) return "FAIL"; + return *rx_busy_refusals() ? "NOT_RUN" : "PASS"; +} + +#endif diff --git a/tests/runtime/rx_r11_aien.c b/tests/runtime/rx_r11_aien.c index beb6f9a72..7a61627a9 100644 --- a/tests/runtime/rx_r11_aien.c +++ b/tests/runtime/rx_r11_aien.c @@ -42,6 +42,7 @@ #include "sha256.h" #include +#include #include #include #include @@ -404,7 +405,8 @@ static void t_core_class(void) { } static void t_drift(void) { - printf("[*] a failure with nothing else changed is drift; a second failure refutes it\n"); + printf("[*] a failure with nothing else changed is drift: relearned first, researched only " + "if the cost moved; a second failure refutes it\n"); Env e; CHECK(envA_start(&e) == 0, "setup"); RxAienFaculty *a = &e.a; @@ -415,11 +417,20 @@ static void t_drift(void) { windows(&e, 2, 9000, 0xAA); CHECK(fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_DRIFT && fld(&e, a->o.hypothesis, 3) == P1 && fld(&e, a->o.hypothesis, 4) == P1, "drift hypothesis"); - CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_DRIFT, "drift plan"); + CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_OPEN && fld(&e, a->o.plan, 0) == 0, + "drift researched before the record was relearned"); + /* The same record, learned again where it runs: the cost really moved. */ + windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 9000, 0xAA); + CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && + fld(&e, a->o.prediction, 5) == 9000, "relearned prediction"); + CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_DRIFT && + fld(&e, a->o.plan, 4) == fld(&e, a->o.hypothesis, 0), "drift plan"); + CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, "hypothesis state %llu", + (unsigned long long)fld(&e, a->o.hypothesis, 7)); record(&e, 2, 0xBB); windows(&e, 1 + a->cfg.baseline_intervals, 9000, 0xBB); windows(&e, 2, 15000, 0xBB); - CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED, + CHECK(fld(&e, a->o.prediction, 0) == 3 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED, "second prediction"); CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_UNSUPPORTED, "hypothesis state %llu", (unsigned long long)fld(&e, a->o.hypothesis, 7)); @@ -427,6 +438,120 @@ static void t_drift(void) { env_stop(&e); } +/* Seen in R13 under whole-machine load (omega #527): a burst failed the + * prediction with nothing changed, then the cost came back. The drift plan + * went out at once and its research could not run before the goal, so the + * failed prediction was never relearned and the incumbent cost never + * confirmed. Drift is now tested by relearning first: a cost back where it + * was refutes it, with no research. A real change later is still noticed. */ +static void t_drift_burst_refuted(void) { + printf("[*] a burst that passes is refuted by relearning: no research, a later move is noticed\n"); + Env e; + CHECK(envA_start(&e) == 0, "setup"); + RxAienFaculty *a = &e.a; + place(&e, P1); + window(&e, 5000, 0); /* production runs before any record exists */ + record(&e, 1, 0xAA); + confirm_at(&e, 5000, 0xAA); + windows(&e, 2, 9000, 0xAA); /* the burst */ + CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_FAILED && + fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_DRIFT, "the burst was not noticed"); + windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 5100, 0xAA); + CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && + fld(&e, a->o.prediction, 5) == 5100, "not relearned: seq %llu state %llu cost %llu", + (unsigned long long)fld(&e, a->o.prediction, 0), (unsigned long long)fld(&e, a->o.prediction, 6), + (unsigned long long)fld(&e, a->o.prediction, 5)); + CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_UNSUPPORTED, "hypothesis state %llu", + (unsigned long long)fld(&e, a->o.hypothesis, 7)); + CHECK(fld(&e, a->o.plan, 0) == 0 && fld(&e, a->o.memory, 0) == 0, "researched a burst"); + place(&e, P2); + windows(&e, 2, 2000, 0xAA); + CHECK(fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_CORE_CLASS && + fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING && + fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, + "the move was not planned"); + check_only_reactive(&e); + env_stop(&e); +} + +/* R13 under load: baseline intervals 16361, 26203, 8370, 7708 ns averaged to + * 14660 ns, a cost no interval paid. A baseline interval that disagrees with + * the ones before it by more than the tolerance starts the baseline again. */ +/* Seen in R14 under whole-machine load (OMEGA-R14-HOST, 2026-10-20): a burst + * failed the incumbent's prediction on the A725 cores (drift, open, to be + * relearned), then the body moved to the X925 cores before the relearn. The + * relearned prediction was about the new class, so the drift question was + * moot; left open it waited forever for a same-class prediction, and the body + * never researched the class it ran on, even with a goal it already met. */ +static void t_drift_moved(void) { + printf("[*] a drift hypothesis whose relearn lands on another core class becomes a core-class " + "hypothesis and a plan for that class\n"); + Env e; + CHECK(envA_start(&e) == 0, "setup"); + RxAienFaculty *a = &e.a; + uint64_t R = rx_aien_regime(REG_M, REG_N); + place(&e, P1); + window(&e, 5000, 0); /* production runs before any record exists */ + record(&e, 1, 0xAA); + confirm_at(&e, 5000, 0xAA); + windows(&e, 2, 9000, 0xAA); /* a burst: drift, open, relearn pending */ + CHECK(fld(&e, a->o.hypothesis, 0) == 1 && fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_DRIFT && + fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_OPEN, "drift hypothesis"); + /* The body moves before the record is relearned. */ + place(&e, P2); + CHECK(settle(&e) == RX_OK, "settle"); + windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 4000, 0xAA); + CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 4) == P2 && + fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED && fld(&e, a->o.prediction, 5) == 4000, + "relearned on the new class: prediction %llu class %llx state %llu cost %llu", + (unsigned long long)fld(&e, a->o.prediction, 0), (unsigned long long)fld(&e, a->o.prediction, 4), + (unsigned long long)fld(&e, a->o.prediction, 6), (unsigned long long)fld(&e, a->o.prediction, 5)); + CHECK(fld(&e, a->o.hypothesis, 0) == 2 && fld(&e, a->o.hypothesis, 1) == RX_AIEN_HYP_CORE_CLASS && + fld(&e, a->o.hypothesis, 2) == 2 && fld(&e, a->o.hypothesis, 3) == P1 && + fld(&e, a->o.hypothesis, 4) == P2, + "core-class hypothesis: seq %llu kind %llu prediction %llu then %llx now %llx", + (unsigned long long)fld(&e, a->o.hypothesis, 0), (unsigned long long)fld(&e, a->o.hypothesis, 1), + (unsigned long long)fld(&e, a->o.hypothesis, 2), (unsigned long long)fld(&e, a->o.hypothesis, 3), + (unsigned long long)fld(&e, a->o.hypothesis, 4)); + CHECK(fld(&e, a->o.hypothesis, 7) == RX_AIEN_HYP_TESTING, "hypothesis state %llu", + (unsigned long long)fld(&e, a->o.hypothesis, 7)); + CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 1) == RX_AIEN_ACT_RESEARCH && + fld(&e, a->o.plan, 2) == R && fld(&e, a->o.plan, 3) == P2 && fld(&e, a->o.plan, 4) == 2 && + fld(&e, a->o.plan, 5) == RX_AIEN_WHY_CORE_CLASS, + "plan for the class the body runs on: seq %llu class %llx why %llu", + (unsigned long long)fld(&e, a->o.plan, 0), (unsigned long long)fld(&e, a->o.plan, 3), + (unsigned long long)fld(&e, a->o.plan, 5)); + CHECK(fld(&e, a->o.memory, 0) == 1 && fld(&e, a->o.memory, 1) == rx_aien_key(P2, R), "memory"); + env_stop(&e); +} + +static void t_baseline_must_agree(void) { + printf("[*] a burst inside the baseline restarts it; the prediction is what production pays\n"); + Env e; + CHECK(envA_start(&e) == 0, "setup"); + RxAienFaculty *a = &e.a; + place(&e, P1); + window(&e, 5000, 0); /* production runs before any record exists */ + record(&e, 1, 0xAA); + window(&e, 5000, 0xAA); /* warm-up */ + window(&e, 5000, 0xAA); + window(&e, 12000, 0xAA); /* the burst */ + windows(&e, a->cfg.baseline_intervals - 1, 5000, 0xAA); + CHECK(fld(&e, a->o.prediction, 0) == 0, "predicted from a baseline that disagrees with itself"); + window(&e, 5000, 0xAA); + CHECK(fld(&e, a->o.prediction, 0) == 1 && fld(&e, a->o.prediction, 5) == 5000, + "prediction %llu expects %llu ns", (unsigned long long)fld(&e, a->o.prediction, 0), + (unsigned long long)fld(&e, a->o.prediction, 5)); + windows(&e, a->cfg.confirm_intervals, 5000, 0xAA); + CHECK(fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "not confirmed"); + /* A steady, slower cost is learned at what it is. */ + record(&e, 2, 0xBB); + confirm_at(&e, 9000, 0xBB); + CHECK(fld(&e, a->o.prediction, 0) == 2 && fld(&e, a->o.prediction, 5) == 9000 && + fld(&e, a->o.prediction, 6) == RX_AIEN_PRED_CONFIRMED, "a steady slower cost was not learned"); + env_stop(&e); +} + /* Seen on GB10 in R15 (2026-09-28): production jitter on A725 failed the * prediction twice with nothing changed; the drift research found nothing and * the failure was settled. The prediction then stayed FAILED, so the later @@ -442,7 +567,9 @@ static void t_settled_failure_relearns(void) { window(&e, 5000, 0); /* production runs before any record exists */ record(&e, 1, 0xAA); confirm_at(&e, 5000, 0xAA); - windows(&e, 2, 9000, 0xAA); /* jitter: drift hypothesis, drift plan */ + windows(&e, 2, 9000, 0xAA); /* jitter: drift hypothesis */ + windows(&e, 2 + a->cfg.baseline_intervals + a->cfg.confirm_intervals, 9000, 0xAA); + /* relearned: the cost stays moved, so a drift plan */ CHECK(fld(&e, a->o.plan, 0) == 1 && fld(&e, a->o.plan, 5) == RX_AIEN_WHY_DRIFT, "drift plan"); record(&e, 2, 0xAA); /* the research kept the same realization */ windows(&e, 1 + a->cfg.baseline_intervals, 9000, 0xAA); @@ -684,15 +811,44 @@ static int quiet_flag_is_mine(const char *flag) { return 0; } +/* Whose measurement holds the quiet flag? Decided before and apart from the + * host load, so a loaded machine can never hide this answer: main prints it + * and tests/runtime/r11_own_hold_test.sh reads it. */ +enum { QUIET_FLAG_NONE, QUIET_FLAG_OWN, QUIET_FLAG_OTHER }; +static int quiet_flag_state(void) { + const char *home = getenv("HOME"); + char flag[512], real_flag[PATH_MAX], real_home[PATH_MAX]; + if (!home || !home[0]) return QUIET_FLAG_NONE; + snprintf(flag, sizeof flag, "%s/workspace/.spark-quiet", home); + /* The flag must resolve to a file inside $HOME (symlinks and ".." are + * resolved first). A flag that is missing or lies outside home is no flag. */ + if (!realpath(flag, real_flag) || !realpath(home, real_home)) return QUIET_FLAG_NONE; + size_t hn = strlen(real_home); + if (strncmp(real_flag, real_home, hn) != 0 || real_flag[hn] != '/') return QUIET_FLAG_NONE; + return quiet_flag_is_mine(real_flag) ? QUIET_FLAG_OWN : QUIET_FLAG_OTHER; +} + +/* The 1-minute load average above which the living run is not started. + * R11_LOAD_LIMIT raises it (tests/runtime/r11_own_hold_test.sh does, to see + * the quiet-flag decision on a busy judge); it can never lower it, so the + * override cannot make a run pass that the default would refuse. */ +#define R11_LOAD_LIMIT_DEFAULT 2.0 +static double load_limit(void) { + const char *v = getenv("R11_LOAD_LIMIT"); + if (v && v[0]) { + char *end = NULL; + double d = strtod(v, &end); + if (end != v && *end == '\0' && d > R11_LOAD_LIMIT_DEFAULT) return d; + } + return R11_LOAD_LIMIT_DEFAULT; +} + /* A timed phase measures this host. When an R15 timed measurement is * running (its quiet flag exists or an R15 program is alive) or the machine * is already loaded, the numbers would describe the other work, so the * living run is not started. Same test as rx_plan_reuse.c. */ -static int other_load(char *why, size_t n) { - const char *home = getenv("HOME"); - char flag[512]; - snprintf(flag, sizeof flag, "%s/workspace/.spark-quiet", home ? home : ""); - if (access(flag, F_OK) == 0 && !quiet_flag_is_mine(flag)) { +static int other_load(int flag_state, char *why, size_t n) { + if (flag_state == QUIET_FLAG_OTHER) { snprintf(why, n, "an R15 timed measurement holds ~/workspace/.spark-quiet"); return 1; } @@ -722,8 +878,8 @@ static int other_load(char *why, size_t n) { if (fscanf(f, "%lf", &load) != 1) load = 0; fclose(f); } - if (load > 2.0) { - snprintf(why, n, "1-minute load average %.2f is above 2", load); + if (load > load_limit()) { + snprintf(why, n, "1-minute load average %.2f is above %.0f", load, load_limit()); return 1; } return 0; @@ -1026,13 +1182,20 @@ int main(void) { t_steady_and_outlier(); t_core_class(); t_drift(); + t_drift_burst_refuted(); + t_drift_moved(); + t_baseline_must_agree(); t_settled_failure_relearns(); t_goal(); t_authority(); #if defined(__aarch64__) find_core_classes(); char why[128]; - if (g_nx > 0 && g_na > 0 && other_load(why, sizeof why)) { + int flag_state = quiet_flag_state(); + printf("quiet flag: %s\n", flag_state == QUIET_FLAG_NONE ? "none" + : flag_state == QUIET_FLAG_OWN ? "this run's own hold" + : "another measurement's hold"); + if (g_nx > 0 && g_na > 0 && other_load(flag_state, why, sizeof why)) { snprintf(g_b_skip_buf, sizeof g_b_skip_buf, "SKIPPED-LOADED: %s", why); g_b_skip = g_b_skip_buf; printf("[-] SKIPPED-LOADED: living run not started: %s\n", why); diff --git a/tests/runtime/rx_r13_living.c b/tests/runtime/rx_r13_living.c index a390362be..0609534eb 100644 --- a/tests/runtime/rx_r13_living.c +++ b/tests/runtime/rx_r13_living.c @@ -14,12 +14,16 @@ * limitations under the License. */ - /* Timing sensitivity (omega #313 item 1): `target` is 55 percent of the incumbent cost AIEN confirmed - * on the old core class, and `final_expected` is the cost AIEN later confirmed on the new one. Both - * are wall-clock (CLOCK_MONOTONIC) measurements taken at different times, so CPU contention that - * slows the second more than the first can miss the goal. The check is deliberately unchanged: a - * CPU-time or repeat-and-median variant needs the measurement in src/runtime (rx_omega.c, rx_aien.c) - * changed, which is outside this test program and a separate, declared change. */ + /* Timing sensitivity (omega #313 item 1, #527): `target` is 55 percent of the incumbent cost AIEN + * confirmed on the old core class, and `final_expected` is the cost AIEN later confirmed on the new + * one. Both are measured on this machine, as the CPU time the serving thread spent in the matvec + * (rx_omega.c cost_ns). Wall-clock time counted a preemption or a busy neighbour as cost: on a + * loaded host a slow interval failed AIEN's prediction before the goal, or tipped Omega's first + * selection, and the episode could not start. The checks are unchanged. + * The production windows (AIEN, Omega, GPU experiment, promotion barrier) are held open until + * production commits (seat_watch, barrier_watch): under whole-machine load the host episode is + * shorter than a starved producer's wait for a CPU, and counting the commits that happened to + * land in it measured the scheduler (omega #598 c2dd2a0d: AIEN=0 Omega=0 GPU=0 at load 70). */ /* R13: one world; after the goal, only production requests and observation. */ #include "runtime/rx_living.h" #include "runtime/rx_resident_gpu.h" @@ -114,6 +118,13 @@ typedef struct { int op_gate_held, op_restored, ready; atomic_ullong op_halt_since, op_halt_total; /* ns; stopped time is not run time */ atomic_int op_shutdown, op_teardown; + /* POSITIVE: what production did while the promotion barrier was held + * (barrier_watch, on the store executor). */ + uint64_t barrier_calls, barrier_commits, barrier_wait_ns; + /* Seat results the transport accepted into the world; POSITIVE: what + * production did while the transport held the experiment after the first + * one (seat_watch, on the acceptor thread). */ + uint64_t accepted, seat_calls, seat_commits, seat_wait_ns; } Rig; static int g_stage; typedef struct { @@ -756,6 +767,57 @@ static void *producer_main(void *arg) { return NULL; } +/* The store calls this on its executor inside the promotion barrier: the + * barrier lock is held and the candidate is closing, after the candidate is + * written and before the root flips (as R15 G7 does). It waits until + * production has committed three more requests, at most 3 s (under the + * producer's 5 s request limit, so a stop is reported here). Without it the + * window is as long as the barrier's disk work, and on a tmpfs state + * directory (the judge's /tmp) that is about 0.35 ms: whether a request + * lands in it measured the scheduler, not the barrier. A barrier that stops + * production cannot pass: nothing commits while it is held, the wait runs + * out, and the check finds fewer than three. (A request stuck behind such a + * stop commits the moment it ends, before the promotion crumb, so the + * window count alone could not see it.) It reads one counter, takes no lock. */ +static void barrier_watch(const char *dir, void *ctx) { + (void)dir; + Rig *r = ctx; + const uint64_t *commits = &r->w.reactions[r->omega.r_serve].commits; + uint64_t c0 = __atomic_load_n(commits, __ATOMIC_RELAXED), t0 = now_ns(); + while (__atomic_load_n(commits, __ATOMIC_RELAXED) < c0 + 3 && + now_ns() - t0 < 3000000000ull) + pause_us(50); + r->barrier_calls++; + r->barrier_commits = __atomic_load_n(commits, __ATOMIC_RELAXED) - c0; + r->barrier_wait_ns = now_ns() - t0; +} + +/* The seat transport calls this once, after it accepted the first trial's + * result and before it moves the next claim, so the experiment (and with it + * AIEN's plan and Omega's search, which wait on its evidence) is held in + * flight until production has committed three more requests, at most 3 s of + * run time (an operator stop pauses the bound as it pauses production). On + * the host the whole episode from goal to candidate runs on the executor in + * less time than a starved producer waits for a CPU under whole-machine load, + * so whether a request landed in the AIEN, Omega or GPU window measured the + * scheduler, not the faculties. An episode that stops production while it + * runs cannot pass: nothing commits while it is held, the wait runs out, and + * the check finds fewer than three. It reads one counter, takes no lock. */ +static void seat_watch(Rig *r) { + const uint64_t *commits = &r->w.reactions[r->omega.r_serve].commits; + uint64_t c0 = __atomic_load_n(commits, __ATOMIC_RELAXED), t0 = run_clock(r); + int64_t waited = 0; + while (__atomic_load_n(commits, __ATOMIC_RELAXED) < c0 + 3 && + !atomic_load(&r->acceptor_stop)) { + waited = (int64_t)(run_clock(r) - t0); /* a stop in flight can read low */ + if (waited >= 3000000000ll) break; + pause_us(50); + } + r->seat_calls++; + r->seat_commits = __atomic_load_n(commits, __ATOMIC_RELAXED) - c0; + r->seat_wait_ns = waited > 0 ? (uint64_t)waited : 0; +} + static int start_producer(Rig *r) { atomic_store(&r->producer_stop, 0); if (pthread_create(&r->producer, NULL, producer_main, r) != 0) return -1; @@ -866,11 +928,13 @@ static uint64_t production_between(Rig *r, uint64_t lo, uint64_t hi) { static int progress(Rig *r) { #ifdef R13_SILICON int rc = rx_resident_accept(&r->w); + if (rc == RX_OK) r->accepted++; return rc == RX_ERR_NOT_FOUND || rc == RX_OK || rc == RX_ERR_HALTED ? 0 : rc; #else int rc = rx_resident_seat_step(&r->w); if (rc == 1) { rc = rx_resident_accept(&r->w); + if (rc == RX_OK) r->accepted++; return rc == RX_ERR_HALTED ? 0 : rc; } return rc < 0 && rc != RX_ERR_HALTED ? rc : 0; @@ -882,6 +946,7 @@ static void *acceptor_main(void *arg) { while (!atomic_load(&r->acceptor_stop)) { int rc = progress(r); if (rc != 0) atomic_store(&r->acceptor_error, rc); + if (r->mode == POSITIVE && r->accepted == 1 && !r->seat_calls) seat_watch(r); pause_us(1000); } return NULL; @@ -1077,7 +1142,18 @@ static int run(Rig *r, int mode) { } /* Production is a workload of its own, already running when the goal * arrives. From here this thread only observes. */ + /* A burst that passes is refuted by AIEN relearning the record; a cost + * that really moved before the goal is researched as drift, so the + * episode below is no longer the goal's alone. Say so: it is a real + * slowdown of this machine, not a fault of the episode. */ + if (with_aien && field(r, r->aien.o.plan, 0) != 0 && + field(r, r->aien.o.plan, 5) == RX_AIEN_WHY_DRIFT) + fprintf(stderr, "R13 note (mode %d): the incumbent cost moved before the goal (AIEN " + "expected %llu ns, saw %llu ns, relearned %llu ns) and AIEN asked for drift " + "research\n", mode, U(field(r, r->aien.o.hypothesis, 5)), + U(field(r, r->aien.o.hypothesis, 6)), U(incumbent_ns)); if (start_producer(r) != 0) FAIL("producer"); + if (mode == POSITIVE) rx_gen_set_disk_hook(r->gen, barrier_watch, r); /* The environment changes (the body now runs on the X925 cores) and the * human states the goal. After this, the harness only serves and reads. */ if (move_threads(&x) <= 0 || publish_placement(r, CLASS_X925) != 0 || @@ -1292,7 +1368,15 @@ static int run(Rig *r, int mode) { uint64_t during_gpu = production_between(r, gpu_input, evidence); uint64_t before_promotion = production_between(r, goal_crumb, promotion); /* The R9 barrier runs inside generation.promote. Production that committed - * between the candidate and its promotion shows it is not a global stop. */ + * between the candidate and its promotion shows it is not a global stop. + * In POSITIVE the barrier is held until production commits (barrier_watch), + * so a live production always lands in this window; the watch must have run + * once, inside that barrier, and seen three commits while it was held. + * The same for the AIEN, Omega and GPU windows: the seat transport holds + * the experiment after its first trial until production commits + * (seat_watch), and that hold lies inside all three (the input's field 2 + * is written once, before the first claim; the evidence closes the last). + * The hold must have run once and seen three commits. */ uint64_t during_promotion = production_between(r, candidate, promotion); printf("R13 costs: incumbent %llu ns, target %llu ns, selected %llu ps, reference on new " "cores %llu ps, AIEN now expects %llu ns, goal status %llu\n", @@ -1303,18 +1387,21 @@ static int run(Rig *r, int mode) { if (final_status != RX_AIEN_GOAL_MET || final_expected > target || field(r, r->aien.o.prediction, 1) != field(r, r->living.o.inforce, 0)) FAIL("AIEN's belief does not show the goal met under the new generation"); - int need_gpu_overlap = 0; -#ifdef R13_SILICON - need_gpu_overlap = 1; /* the processor stand-in runs the add instantly */ -#endif - if (mode == POSITIVE && (!during_aien || !during_omega || - (need_gpu_overlap && !during_gpu) || !before_promotion || - !during_promotion)) + if (mode == POSITIVE && (!during_aien || !during_omega || !during_gpu || + !before_promotion || !during_promotion || + r->seat_calls != 1 || r->seat_commits < 3 || + r->barrier_calls != 1 || r->barrier_commits < 3)) FAIL("production intervals: AIEN=%llu Omega=%llu GPU=%llu before promotion=%llu " - "during promotion=%llu", + "during promotion=%llu (seat hold: %llu calls, %llu commits in %llu us; " + "barrier watch: %llu calls, %llu commits in %llu us)", (unsigned long long)during_aien, (unsigned long long)during_omega, (unsigned long long)during_gpu, (unsigned long long)before_promotion, - (unsigned long long)during_promotion); + (unsigned long long)during_promotion, (unsigned long long)r->seat_calls, + (unsigned long long)r->seat_commits, + (unsigned long long)(r->seat_wait_ns / 1000u), + (unsigned long long)r->barrier_calls, + (unsigned long long)r->barrier_commits, + (unsigned long long)(r->barrier_wait_ns / 1000u)); const RxCrumb *gpu_c = rx_world_crumb(&r->w, gpu); #ifdef R13_SILICON if (!r->seat || !gpu_c || gpu_c->worker != RX_SEAT_BLACKWELL) diff --git a/tests/runtime/rx_r14_recovery.c b/tests/runtime/rx_r14_recovery.c index 4a4d6a31a..e38306dad 100644 --- a/tests/runtime/rx_r14_recovery.c +++ b/tests/runtime/rx_r14_recovery.c @@ -87,6 +87,8 @@ typedef struct { int crash_step; /* R9 crash point (F, first process) */ int seat; /* start the resident GB10 seat (silicon build only) */ const char *gen_dir; /* reuse an R9 store (F restart); else a new one */ + int goal_after_research; /* adapt(): the goal arrives only after the body's own + research of the new cores has selected (A semantic) */ } Opts; typedef struct { @@ -903,9 +905,13 @@ static uint64_t crumbs_of(Rig *r, uint32_t reaction, RxCrumbKind kind, int reaso * R13's episode: production confirms the incumbent on the A725 cores, the * body moves to the X925 cores, a human goal arrives, and the organism adapts * by itself (plan, search, GPU experiment, belief, selection, R9 promotion). - * Production runs on its own thread from the goal on and keeps running. */ + * Production runs on its own thread from the move on and keeps running. The + * body also researches the new core class on its own, with no goal yet + * (AIEN's core-class hypothesis): with goal_after_research the goal is + * published only after that research has selected, so a selection older + * than the goal must still be proposed and promoted. */ typedef struct { - uint64_t goal_crumb, served_at_goal, served_at_promotion, gen_before, gen_after; + uint64_t goal_crumb, served_at_move, served_at_promotion, gen_before, gen_after; uint64_t promotion_crumb; int promoted; } Episode; @@ -926,8 +932,27 @@ static int adapt(Rig *r, Episode *ep) { uint64_t lineage = 0; rx_gen_active(r->gen, &ep->gen_before, &lineage); if (start_producer(r) != 0) return -6; + uint64_t sel_before = field(r, r->omega.o.selection, 0); + uint64_t declined_before = __atomic_load_n(&r->living.refusals, __ATOMIC_ACQUIRE); if (move_threads(&x) <= 0 || publish_placement(r, CLASS_X925) != 0) return -7; - ep->served_at_goal = served(r); + /* Production is counted from the move on, as before the goal was made + * late: every refusal (the late-goal decline included) comes after it. */ + ep->served_at_move = served(r); + if (r->opt.goal_after_research) { + /* The body researches the new core class by itself, selects, and + * generation.prepare declines that selection for want of a goal. The + * goal is published only after that decline has been recorded. */ + limit = now_ns() + 60000000000ull; + while (now_ns() < limit && + (field(r, r->omega.o.selection, 0) <= sel_before || + __atomic_load_n(&r->living.refusals, __ATOMIC_ACQUIRE) <= declined_before)) { + if (atomic_load(&r->producer_error)) return -9; + pause_us(200); + } + if (field(r, r->omega.o.selection, 0) <= sel_before || + __atomic_load_n(&r->living.refusals, __ATOMIC_ACQUIRE) <= declined_before) + return -12; + } if (publish_goal(r, target) != 0) return -8; ep->goal_crumb = rx_world_explain(&r->w, r->aien.o.goal, 0); limit = now_ns() + 90000000000ull; @@ -961,18 +986,22 @@ typedef struct { unsigned gap_us; int live; atomic_int error; + atomic_uint idle; /* turns sat out because pause was set */ } Driver; static void *driver_main(void *arg) { Driver *d = arg; Rig *r = d->r; while (!atomic_load(&d->stop)) { - if (!atomic_load(&d->pause)) + if (atomic_load(&d->pause)) { + atomic_fetch_add(&d->idle, 1); + } else { for (uint32_t k = 0; k < r->opt.lanes; k++) { if (d->quota && r->lane_sent[k] >= d->quota) continue; if (lane_done(r, k) != r->lane_sent[k]) continue; if (lane_submit(r, k) != 0) atomic_store(&d->error, 1); } + } pause_us((int)d->gap_us); } return NULL; @@ -988,6 +1017,22 @@ static int driver_start(Driver *d, Rig *r, uint64_t quota, unsigned gap_us) { return 0; } +/* Park the driver: returns once it has seen the pause from the top of its + * loop, so a turn that was already inside the submit loop when the pause was + * set has finished. Only after that is lanes_sent a count the caller can + * wait for; sampling it earlier lets late submits reach the seat unseen. + * -1 if the driver never parked within ms. */ +static int driver_pause(Driver *d, int ms) { + atomic_store(&d->pause, 1); + unsigned idle0 = atomic_load(&d->idle); + uint64_t t = now_ns(); + while (atomic_load(&d->idle) == idle0) { + if (now_ns() - t > (uint64_t)ms * 1000000ull) return -1; + pause_us(200); + } + return 0; +} + static void driver_stop(Driver *d) { if (!d->live) return; atomic_store(&d->stop, 1); @@ -1120,6 +1165,9 @@ static int scenario_a_case(int defect, uint32_t want, const char *label, Result if (!r) return -1; Opts o = opts(); o.defect = defect; + /* The semantic case lets the body research the new cores on its own and + * publishes the goal after that selection; the others publish it at once. */ + o.goal_after_research = defect == RX_OMEGA_DEFECT_SKIP_REMAINDER; int rc = start(r, &o); CHECK(rc == 0, "A %s: setup failed at stage %d", label, g_stage); Episode ep; @@ -1181,14 +1229,14 @@ static int scenario_a_case(int defect, uint32_t want, const char *label, Result } pthread_mutex_unlock(&r->omega.mu); CHECK(lies == 0, "A %s: %u verified store entries do not match their bytes", label, lies); - uint64_t during = ep.served_at_promotion - ep.served_at_goal; + uint64_t during = ep.served_at_promotion - ep.served_at_move; CHECK(during > 0, "A %s: production stopped while the candidate was refused", label); Result sub; memset(&sub, 0, sizeof sub); finish(r, &sub, 100); if (first) { *res = sub; - res->prod_before = ep.served_at_goal; + res->prod_before = ep.served_at_move; res->prod_during = during; res->gen_before = ep.gen_before; res->fault_observed = 1; @@ -1994,8 +2042,7 @@ static void scenario_e(void) { Driver dv; CHECK(driver_start(&dv, r, 0, 300) == 0, "E: driver"); CHECK(wait_lanes(r, 3 * LANES, 30000) == 0, "E: lanes never produced"); - atomic_store(&dv.pause, 1); - pause_us(2000); + CHECK(driver_pause(&dv, 30000) == 0, "E: the driver did not park"); CHECK(wait_lanes(r, lanes_sent(r), 30000) == 0, "E: lanes did not go idle"); res->prod_before = served(r); uint32_t seat_gen0 = r->w.seat_generation; @@ -2035,8 +2082,8 @@ static void scenario_e(void) { else pause_us(500); } #endif - CHECK(claimed && held, "E: the seat did not hold the lane claim (claimed %d held %d)", claimed, - held); + CHECK(claimed && held, "E: the seat did not hold the lane claim (claimed %d held %d, lanes in flight %llu)", + claimed, held, U(lanes_sent(r) - lanes_done(r))); uint64_t mem_held = r->w.used_memory; OmegaSharedWorldRing *c2g = (OmegaSharedWorldRing *)(r->w.coherent + rx_world_off_c2g()); OmegaSharedWorldDesc old = c2g->slots[seq & c2g->mask]; diff --git a/tests/runtime/rx_r15_parity.c b/tests/runtime/rx_r15_parity.c index e7b140155..a209790c0 100644 --- a/tests/runtime/rx_r15_parity.c +++ b/tests/runtime/rx_r15_parity.c @@ -30,9 +30,18 @@ * evidence, AIEN's belief, generation identity, the in-force realization * and the authority outcome. Gated on each side: goal MET, crumbs verify, * no crumb overflow, no illegal transition, no wrong result, no use of a - * realization not in force, and no lost trigger. Measured costs are printed - * and not compared; the detector that reads them is configured (see main) - * so that host timing noise cannot change a compared plan field. + * realization not in force, and no lost trigger. + * + * Both sides see the same costs: the rig gives Omega a fixed cost table + * (r15_use_cost_model) in place of wall-clock time, while the work itself + * still runs. Measured time differed between the two sides of a pair, and + * under machine load it crossed AIEN's and Omega's thresholds on one side + * only (a 20% miss read as drift opened an extra search; an X925 cost over + * the target left the goal UNMET), so a pair could differ for reasons that + * are not orchestration. With equal cost inputs any difference is the + * orchestration's. Costs are printed and not compared; the detector that + * reads them is also configured (see main) so that host timing noise cannot + * change a compared plan field. * * R15_PARITY_PAIRS (default 5) sets the number of pairs. * Exit status 0 = SEQ_SEMANTIC_PARITY PASS. @@ -118,7 +127,7 @@ static int run_side(R15Config c, uint64_t target, R15Outcome *o, char *first, si static void print_side_tag(const char *side, const R15Outcome *o, const char *tag) { printf(" %-5s%s goal status %llu, plan action %llu reason %llu, epoch %llu, " "selected %016llx (verdict %llu), evidence %llu/%llu trials, belief %llu, " - "generation %llu -> %llu, in force %016llx; measured: incumbent %llu ns, " + "generation %llu -> %llu, in force %016llx; costs: incumbent %llu ns, " "selected %llu ps, reference %llu ps, served %llu, crumbs %llu\n", side, tag, U(o->goal_status), U(o->plan_action), U(o->plan_reason), U(o->selection_epoch), U(o->selection_id[0]), U(o->selected_verdict), U(o->evidence[4]), U(o->evidence[3]), @@ -179,7 +188,8 @@ int main(void) { printf("R15 SEQ parity: processor stand-in seat (host)\n"); #endif /* Diagnostic only (not the gate): R15_PARITY_REPEAT=: - * runs n episodes of one configuration and reports each outcome. */ + * runs n episodes of one configuration and reports each outcome, with + * measured (wall-clock) costs. */ const char *rep = getenv("R15_PARITY_REPEAT"); if (rep) { R15Config c = strncmp(rep, "SEQ", 3) == 0 ? R15_SEQ @@ -201,7 +211,9 @@ int main(void) { printf("R15 repeat %s: %d of %d failed\n", r15_config_name(c), bad, n); return bad ? 1 : 0; } - /* AIEN's drift detector reads Omega's wall-clock serve costs. Under host + r15_use_cost_model(1); + /* AIEN's drift detector reads Omega's serve costs; without the cost model + * above they are wall-clock. Under host * load one side can see two consecutive intervals outside the tolerance, * fail its prediction, and research the regime because of DRIFT (plan * reason 2, condition A725, no goal) where the other side researches diff --git a/tests/runtime/rx_r15_rig.c b/tests/runtime/rx_r15_rig.c index 12e5bde45..23188aae8 100644 --- a/tests/runtime/rx_r15_rig.c +++ b/tests/runtime/rx_r15_rig.c @@ -78,6 +78,36 @@ static uint64_t field(R15Rig *r, RxObjRef ref, uint32_t i) { return rx_world_read(&r->w, ref, &o) == RX_OK ? o.field[i] : UINT64_MAX; } +/* Fixed matvec cost per call in ns, by core class and realization kind + * (0..3, then the reference; any other kind is priced as the reference): + * Omega's own measure of each kind on this GB10, unloaded, 2026-10-19. On + * A725 quad4 is inside the 10% margin, so the first search keeps the + * reference; on X925 quad4 wins and its cost is under 55% of the A725 + * incumbent, so the goal is MET. */ +static const uint64_t k_model_ns[2][5] = { + {13300, 11100, 11300, 6060, 6200}, /* A725 */ + {4900, 4400, 4900, 2700, 4600}, /* X925 */ +}; + +static int g_cost_model; + +void r15_use_cost_model(int on) { g_cost_model = on; } + +/* X925 costs apply once the episode's goal is in the world. The goal is + * published after the X925 placement, so the cost change is tied to a world + * event, not to when the episode's thread gets to run: a thread paused + * between steps cannot open a window of X925 costs under the A725 + * placement, or of A725 costs in the X925 search. The goal is read live, so + * the one demand window spanning the goal mixes both costs; it can only add + * a miss to the A725 prediction, which the X925 costs fail anyway. A failed + * read counts as X925. */ +static uint64_t model_cost(void *ctx, uint32_t kind, uint32_t M, uint32_t N, uint64_t calls) { + R15Rig *r = ctx; + (void)M; (void)N; /* the rig serves one shape, R15_M x R15_N */ + uint32_t cls = field(r, r->aien.o.goal, 0) != 0; + return calls * k_model_ns[cls][kind < 4 ? kind : 4]; +} + static const RxSnapshotDep *snapshot(RxCtx *c, RxObjRef ref) { for (uint32_t i = 0; i < c->n_in; i++) if (c->in[i].obj.id == ref.id) return &c->in[i]; @@ -337,6 +367,10 @@ int r15_start_with(R15Rig *r, R15Config config, const uint32_t *fixture_subjects RxOmegaConfig oc; rx_omega_default_config(&oc); oc.hot_calls = 64; oc.hot_ns = 200000; oc.margin_pct = 10; + if (g_cost_model) { + oc.cost_ns = model_cost; + oc.cost_ctx = r; + } if (rx_omega_create_objects(&r->omega, &r->w, &oc) != RX_OK) return -1; r->omega.keys = &r->keys_omega; RxAienConfig ac; diff --git a/tests/runtime/rx_r15_rig.h b/tests/runtime/rx_r15_rig.h index 04a93d8e5..2d9ad9623 100644 --- a/tests/runtime/rx_r15_rig.h +++ b/tests/runtime/rx_r15_rig.h @@ -177,6 +177,12 @@ int r15_placement(R15Rig *r, uint32_t cls); /* Confine every thread of the process to one core class. */ int r15_move_class(uint32_t cls); const char *r15_config_name(R15Config c); +/* Rigs started after this call (on = 1) give Omega a fixed cost table in + * place of wall-clock time for serve and measure, so every rig sees the same + * costs whatever the machine's load. The SEQ parity gate uses it for its + * detector controls and pairs; every other rig user (G7, the R15 harness, + * R16 negative) keeps measured costs (default off). */ +void r15_use_cost_model(int on); /* Reactions whose last activation read an older version of a trigger field * than the one now in the world (changes after the build baseline), in a diff --git a/tests/runtime/rx_workflow_fusion.c b/tests/runtime/rx_workflow_fusion.c index 70d13cd86..2bb6e47e1 100644 --- a/tests/runtime/rx_workflow_fusion.c +++ b/tests/runtime/rx_workflow_fusion.c @@ -56,6 +56,7 @@ #include #include #include +#include "rx_quiet_reps.h" enum { SUBJ_EXTERNAL = 100, ISSUER = 3, SUBJ_PLAN = 61, SUBJ_PROPOSER = 71, SUBJ_PROMOTER = 72 }; @@ -83,6 +84,8 @@ enum { MS_COMPILED = 101, MS_HYBRID, MS_LEARNED, MS_HARDWARE, MS_POISONED, MS_PA static int g_checks; static int g_fail; +/* Measurements refused as too busy to time (rx_quiet_reps.h). */ +static int g_untimed_compiled, g_untimed_parallel, g_untimed_poisoned; #define CHECK(cond, ...) do { \ g_checks++; \ @@ -1049,34 +1052,68 @@ static int cmp_u64(const void *a, const void *b) { /* 41 interleaved runs per leg at 4 workers: reactions that computed per * run, crumbs per run, median latency, CPU time, outcomes. */ -static void measure(AgMetaSkill *m, uint32_t goal, AgFusionMeasure *ms, int with_energy, const char *what) { +/* 1 when measured; 0 when the machine was too busy to time it (a refusal, + * rx_quiet_reps.h): nothing was measured and nothing that needs it is judged. */ +static int measure(AgMetaSkill *m, uint32_t goal, AgFusionMeasure *ms, int with_energy, const char *what) { Pair *p = &g_pair; CHECK(pair_start(p, goal, m, 4) == 0, "%s: pair", what); memset(ms, 0, sizeof *ms); AgResult ro, rf; for (uint64_t r = 1; r <= 3; r++) pair_run(p, r, a_value(r), &ro, &rf, NULL, NULL, 0); enum { RUNS = 41 }; + /* RUNS undisturbed pairs (rx_quiet_reps.h): a pair counts only when + * neither leg's threads waited for a core, at most 60 attempts per pair. + * Every attempt is still checked for the same outcome on both legs. */ + enum { ATTEMPTS = RUNS * 60 }; uint64_t ns_o[RUNS], ns_f[RUNS], cpu_o = 0, cpu_f = 0, cr_o = 0, cr_f = 0, cm_o = 0, cm_f = 0; - for (uint64_t i = 0; i < RUNS; i++) { - uint64_t id = 10 + i, a = a_value(id); + uint32_t kept = 0, tried = 0; + int delay_known = 1; + for (uint64_t i = 0; i < ATTEMPTS && kept < RUNS; i++) { + uint64_t id = 10 + i, a = a_value(id), t_o = 0, t_f = 0; set_inputs(&p->o, a, id); set_inputs(&p->f, a, id); uint64_t c0 = p->o.w.n_crumbs, t0 = cpu_ns(); - run(&p->o, &p->lo, id, &ro, &ns_o[i]); - cpu_o += cpu_ns() - t0; - cr_o += p->o.w.n_crumbs - c0; - cm_o += commits_between(&p->o, c0, p->o.w.n_crumbs); + int64_t d0 = rx_run_delay_ns(); + run(&p->o, &p->lo, id, &ro, &t_o); + int64_t d1 = rx_run_delay_ns(); + uint64_t u_o = cpu_ns() - t0, k_o = p->o.w.n_crumbs - c0; + uint64_t m_o = commits_between(&p->o, c0, p->o.w.n_crumbs); c0 = p->f.w.n_crumbs; t0 = cpu_ns(); - run(&p->f, &p->lf, id, &rf, &ns_f[i]); - cpu_f += cpu_ns() - t0; - cr_f += p->f.w.n_crumbs - c0; - cm_f += commits_between(&p->f, c0, p->f.w.n_crumbs); + int64_t d2 = rx_run_delay_ns(); + run(&p->f, &p->lf, id, &rf, &t_f); + int64_t d3 = rx_run_delay_ns(); + uint64_t u_f = cpu_ns() - t0, k_f = p->f.w.n_crumbs - c0; + uint64_t m_f = commits_between(&p->f, c0, p->f.w.n_crumbs); + tried++; + CHECK(ro.outcome == rf.outcome, "%s: attempt %u: outcomes differ", what, tried); + if (d0 < 0 || d1 < 0 || d2 < 0 || d3 < 0) delay_known = 0; + if (!rx_quiet_rep(delay_known ? d1 - d0 : -1, t_o) || + !rx_quiet_rep(delay_known ? d3 - d2 : -1, t_f)) + continue; + ns_o[kept] = t_o; + ns_f[kept] = t_f; + kept++; + cpu_o += u_o; + cr_o += k_o; + cm_o += m_o; + cpu_f += u_f; + cr_f += k_f; + cm_f += m_f; ms->ok_before += ro.outcome == AG_RUN_SUCCESS; ms->failed_before += ro.outcome == AG_RUN_FAILURE; ms->ok_after += rf.outcome == AG_RUN_SUCCESS; ms->failed_after += rf.outcome == AG_RUN_FAILURE; } + printf(" %s: undisturbed pairs %u of %u (%s)\n", what, kept, tried, + delay_known ? "run-queue delay from schedstat" : "schedstat missing: every pair counts"); + if (kept < RUNS) { + fprintf(stderr, " %s: machine too busy to time: %u of %u undisturbed pairs in %u attempts\n", + what, kept, RUNS, (unsigned)ATTEMPTS); + rx_busy_refuse(what); + pair_stop(p); + return 0; + } qsort(ns_o, RUNS, sizeof ns_o[0], cmp_u64); qsort(ns_f, RUNS, sizeof ns_f[0], cmp_u64); ms->runs = RUNS; @@ -1105,28 +1142,36 @@ static void measure(AgMetaSkill *m, uint32_t goal, AgFusionMeasure *ms, int with "(+/- %.1f) uJ, performance cores %.1f -> %.1f (+/- %.1f) uJ", ms->energy_uj_before, ms->energy_uj_after, ms->energy_noise_uj, cpu_mean(0), cpu_mean(1), cpu_noise()); printf("\n"); + return 1; } static void t_measure(void) { printf("[*] measurement: original and fused side by side\n"); if (MC.state != AG_MS_VERIFIED) return; unpublished_refused(&MC, "verified"); - measure(&MC, GOAL_EFFECT, &R.m_compiled, 1, "compiled"); - CHECK(rx_fusion_accept_measure(&MC, &R.m_compiled, 50) == 0 && MC.state == AG_MS_MEASURED, - "compiled accepted: fewer reactions, not slower, same outcomes"); + /* A refused measurement (machine too busy to time) leaves its MetaSkill + * verified and unmeasured: the acceptance below, and for the compiled one + * the canary, promotion and use that follow it, are not judged. */ + g_untimed_compiled = !measure(&MC, GOAL_EFFECT, &R.m_compiled, 1, "compiled"); + if (!g_untimed_compiled) + CHECK(rx_fusion_accept_measure(&MC, &R.m_compiled, 50) == 0 && MC.state == AG_MS_MEASURED, + "compiled accepted: fewer reactions, not slower, same outcomes"); R.m_compiled = MC.measure; - measure(&MH, GOAL_EFFECT, &R.m_hybrid, 0, "hybrid"); - rx_fusion_accept_measure(&MH, &R.m_hybrid, 50); + if (measure(&MH, GOAL_EFFECT, &R.m_hybrid, 0, "hybrid")) { + rx_fusion_accept_measure(&MH, &R.m_hybrid, 50); + CHECK(MH.state == AG_MS_MEASURED, "hybrid accepted"); + } R.m_hybrid = MH.measure; R.hybrid_state = MH.state; - CHECK(MH.state == AG_MS_MEASURED, "hybrid accepted"); - measure(&MP, GOAL_PARALLEL, &R.m_parallel, 0, "parallel"); - CHECK(rx_fusion_accept_measure(&MP, &R.m_parallel, 50) != 0 && MP.state == AG_MS_SLOWER, - "parallel fragment refused: fusing it serializes independent work (%.0f -> %.0f us)", - R.m_parallel.median_ns_before / 1e3, R.m_parallel.median_ns_after / 1e3); + g_untimed_parallel = !measure(&MP, GOAL_PARALLEL, &R.m_parallel, 0, "parallel"); + if (!g_untimed_parallel) { + CHECK(rx_fusion_accept_measure(&MP, &R.m_parallel, 50) != 0 && MP.state == AG_MS_SLOWER, + "parallel fragment refused: fusing it serializes independent work (%.0f -> %.0f us)", + R.m_parallel.median_ns_before / 1e3, R.m_parallel.median_ns_after / 1e3); + CHECK(rx_fusion_canary(&MP, 0, 1) == AG_FUSION_E_STATE, "a slower MetaSkill cannot enter canary"); + } R.parallel_state = MP.state; R.m_parallel = MP.measure; - CHECK(rx_fusion_canary(&MP, 0, 1) == AG_FUSION_E_STATE, "a slower MetaSkill cannot enter canary"); unpublished_refused(&MC, "measured"); } @@ -1170,7 +1215,11 @@ static void t_canary(void) { R.poisoned_verified = MQ.state == AG_MS_VERIFIED; CHECK(MQ.state == AG_MS_VERIFIED, "poisoned hybrid passes verification (the entry is never generated)"); AgFusionMeasure mq; - measure(&MQ, GOAL_EFFECT, &mq, 0, "poisoned hybrid"); + g_untimed_poisoned = !measure(&MQ, GOAL_EFFECT, &mq, 0, "poisoned hybrid"); + if (g_untimed_poisoned) { /* unmeasured: its canary and quarantine are not judged */ + unpublished_refused(&MC, "canary-passed"); + return; + } rx_fusion_accept_measure(&MQ, &mq, 50); CHECK(pair_start(p, GOAL_EFFECT, &MQ, 4) == 0, "pair"); /* The divergence here is the point; it is kept out of the fusion totals. */ @@ -1210,6 +1259,10 @@ static char g_store_dir[64]; static void t_promote(void) { printf("[*] promotion through the generation barrier, then publication\n"); + if (g_untimed_compiled) { /* never measured, so never canary-passed */ + printf(" not judged: the compiled MetaSkill was not measured (cpu_busy)\n"); + return; + } static Env e; CHECK(env_start(&e, 1) == 0, "env"); strcpy(g_store_dir, "/tmp/rx-fusion-XXXXXX"); @@ -1226,9 +1279,11 @@ static void t_promote(void) { uint64_t active0 = 0, lineage0 = 0; CHECK(rx_gen_active(store, &active0, &lineage0) == RX_GEN_OK, "store has an active generation"); - CHECK(rx_fusion_promote(&MQ, store, SUBJ_PROPOSER, &req, native_auth, &ac) == AG_FUSION_E_STATE, - "quarantined MetaSkill cannot be promoted"); - R.poisoned_promote_refused = 1; + if (!g_untimed_poisoned) { + CHECK(rx_fusion_promote(&MQ, store, SUBJ_PROPOSER, &req, native_auth, &ac) == AG_FUSION_E_STATE, + "quarantined MetaSkill cannot be promoted"); + R.poisoned_promote_refused = 1; + } int rc = rx_fusion_promote(&MC, store, SUBJ_PROPOSER, &req, native_auth, &ac); R.promote_refused_no_right = rc == RX_GEN_ERR_AUTHORITY && MC.state == AG_MS_CANARY_PASSED; CHECK(R.promote_refused_no_right, "promotion without the promote right refused (%d)", rc); @@ -1520,6 +1575,18 @@ static void measure_json(FILE *fp, const char *name, const AgFusionMeasure *m, i fprintf(fp, "}%s\n", last ? "" : ","); } +/* Everything judged held. A refused measurement takes out only the states + * that need it: the compiled chain (canary, promotion, publication, and the + * poisoned hybrid's canary, which runs after it), the parallel refusal, the + * poisoned quarantine. */ +static int judged_pass(void) { + return g_fail == 0 && R.bypass == 0 && R.evidence_missing == 0 && R.ancestry_mismatch == 0 && + R.eq_mismatch == 0 && R.cross_mismatch == 0 && R.steps_mismatch == 0 && R.det_mismatch == 0 && + R.tamper_caught == R.tamper_cases && (g_untimed_compiled || MC.state == AG_MS_PUBLISHED) && + (g_untimed_parallel || R.parallel_state == AG_MS_SLOWER) && + (g_untimed_compiled || g_untimed_poisoned || R.poisoned_state == AG_MS_QUARANTINED); +} + static void write_receipt(void) { char path[512]; if (omega_evidence_path("WORKFLOW_FUSION/rx_workflow_fusion_receipt.json", path, sizeof path) != 0) return; @@ -1536,10 +1603,6 @@ static void write_receipt(void) { struct utsname u; memset(&u, 0, sizeof u); uname(&u); - int pass = g_fail == 0 && R.bypass == 0 && R.evidence_missing == 0 && R.ancestry_mismatch == 0 && - R.eq_mismatch == 0 && R.cross_mismatch == 0 && R.steps_mismatch == 0 && R.det_mismatch == 0 && - R.tamper_caught == R.tamper_cases && MC.state == AG_MS_PUBLISHED && - R.parallel_state == AG_MS_SLOWER && R.poisoned_state == AG_MS_QUARANTINED; static const char *kinds[4] = { "compiled", "hybrid", "learned", "hardware" }; fprintf(fp, "{\n" @@ -1624,7 +1687,7 @@ static void write_receipt(void) { R.fused_nodes_before, R.fused_nodes_after, R.eq_runs, R.eq_nodes, R.eq_mismatch, R.cross_runs, R.cross_mismatch, R.steps_checked, R.steps_mismatch, R.evidence_checked, R.evidence_missing, R.ancestry_nodes, R.ancestry_mismatch, R.det_mismatch, R.bypass, R.n3_blocked_original, - R.n3_blocked_fused, R.n3_meta_auth_exact, pass ? "PASS" : "FAIL"); + R.n3_blocked_fused, R.n3_meta_auth_exact, rx_busy_verdict(judged_pass())); fclose(fp); printf("receipt: %s\n", path); } @@ -1647,5 +1710,5 @@ int main(void) { R.steps_mismatch, R.ancestry_nodes, R.ancestry_mismatch, R.bypass); printf("checks %d failures %d\n", g_checks, g_fail); write_receipt(); - return g_fail ? 1 : 0; + return rx_busy_exit(g_fail, judged_pass()); } diff --git a/tests/test_clean_clone_driver.c b/tests/test_clean_clone_driver.c new file mode 100644 index 000000000..529c6fec0 --- /dev/null +++ b/tests/test_clean_clone_driver.c @@ -0,0 +1,20 @@ +/* Driver for tools/test_clean_clone.sh: runs omega_clean_clone_run (the M18 and + * M19 CLEAN_CLONE reproduction) from the cwd with the given omegatool flag. + * Host only when the flag names a host-only suite (the self-test uses + * --run-m6-gates). Prints CLEAN_CLONE_OK and exits 0 only on success. */ +#include "omega_clean_clone.h" +#include + +int main(int argc, char **argv) { + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 2; + } + char sha[41] = {0}; + if (!omega_clean_clone_run("selftest", argv[1], sha)) { + printf("CLEAN_CLONE_FAIL\n"); + return 1; + } + printf("CLEAN_CLONE_OK %s\n", sha); + return 0; +} diff --git a/tools/.crumb b/tools/.crumb index e9e4932b5..6e9f72d20 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -62,14 +62,14 @@ } ], "children_root": "sha256:8d3d3b952374b3b72e667521f07bf028c4c02bcefff772ad1a71cfff3e5266f2", - "compiled_at": "2026-10-30T11:28:28Z", + "compiled_at": "2026-10-30T16:37:50Z", "compiler": "crumb-compile/1", - "digest": "sha256:308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", + "digest": "sha256:454ec8b81f3b164b135461e5cefdfbf9b5d336604bdd5255a7d0195700091baf", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 298, - "generated_at_commit": "a8a6a3d3c47ce797430f045edc5eae11594ba36d", - "source_tree": "sha256:acd1f1b0080968db950791b4eb2dce39bb0289dc0c2e8794bfc7449023446105" + "files": 299, + "generated_at_commit": "824b34a1616a9189607f89e3ce179200e6c5c78a", + "source_tree": "sha256:0459e3684b7e5accecfbb905b66b5557128489e493eabed86a88533f9435c897" }, "owner_lane": "", "provenance": { diff --git a/tools/test_clean_clone.sh b/tools/test_clean_clone.sh new file mode 100755 index 000000000..0281f428a --- /dev/null +++ b/tools/test_clean_clone.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# test_clean_clone.sh -- tests of the clean-clone reproduction shared by the M18 +# and M19 CLEAN_CLONE gates (src/omega_clean_clone.c). Host only (no GPU): the +# nested run is the host-only M6 suite. Needs PHYSICS_DIR at the physics.lock pin +# (absolute). Run: make test-clean-clone PHYSICS_DIR= +# +# Works on a scratch clone of HEAD so the caller's tree may be dirty: +# 1. OUT_DIR exported the way tests/gates/run.sh does (omega #511) still builds +# and runs the clone (the root cause of the 2026-10-19 OMEGA-M19 failures); +# 2. a dirty source tree is refused before anything is cloned; +# 3. a nested gate run that fails is reported with its step and log tail; +# 4. a candidate commit that does not build is reported at the make step with +# the compiler error in the tail. +set -u +HERE=$(cd -P "$(dirname "$0")/.." && pwd) +: "${PHYSICS_DIR:?set PHYSICS_DIR to the pinned physics checkout}" +PHYSICS_DIR=$(cd "$PHYSICS_DIR" && pwd) || exit 1 +export PHYSICS_DIR +TMP=$(mktemp -d /tmp/omega-clean-clone-test.XXXXXX) +trap 'rm -rf "$TMP" /tmp/omega_clean_selftest_*' EXIT +fails=0 +ok() { echo " [PASS] $1"; } +bad() { echo " [FAIL] $1"; fails=$((fails + 1)); } +check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; } + +src=$TMP/src +git clone --quiet --no-hardlinks "$HERE" "$src" || exit 1 +git -C "$src" checkout --quiet --detach "$(git -C "$HERE" rev-parse HEAD)" || exit 1 +sha=$(git -C "$src" rev-parse HEAD) +drv=$TMP/driver +cc -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -I"$src/src" -I"$PHYSICS_DIR/nvrm" \ + -I"$PHYSICS_DIR/m16" -o "$drv" "$src/tests/test_clean_clone_driver.c" "$src/src/omega_clean_clone.c" \ + "$src/src/omega_evidence.c" "$src/src/omega_om_units.c" || { echo "FAIL: cannot build driver"; exit 1; } +run() { (cd "$src" && "$drv" "$@" >"$TMP/out" 2>"$TMP/err"); } + +echo "1. OUT_DIR exported like tests/gates/run.sh" +check "clone built and nested M6 run passed" '(export OUT_DIR=build/step-chip-test-m19; run --run-m6-gates)' +check " bound to the exact candidate" 'grep -qx "CLEAN_CLONE_OK $sha" "$TMP/out"' +check " clone directory removed on success" '! ls -d /tmp/omega_clean_selftest_* >/dev/null 2>&1' + +echo "2. dirty source tree" +touch "$src/untracked-mutant" +check "dirty tree refused" '! run --run-m6-gates' +check " says why" 'grep -q "step source_clean failed: source tree at $sha is dirty" "$TMP/err"' +check " nothing cloned" '! ls -d /tmp/omega_clean_selftest_* >/dev/null 2>&1' +rm -f "$src/untracked-mutant" + +echo "3. nested gate run fails" +check "failing nested run refused" '! run --no-such-gates' +check " names the step and exit status" 'grep -q "step 5-run-gates failed: exit status 1" "$TMP/err"' +check " prints the log tail" 'grep -q "last lines of /tmp/omega_clean_selftest_.*/5-run-gates.log" "$TMP/err"' +rm -rf /tmp/omega_clean_selftest_* + +echo "4. candidate that does not build" +printf '#error clean-clone-mutant\n' >> "$src/src/omega_vector.c" +git -C "$src" -c user.name=Test -c user.email=test@example.invalid commit -qam "mutant: does not build" +bsha=$(git -C "$src" rev-parse HEAD) +check "broken candidate refused" '! run --run-m6-gates' +check " names the make step" 'grep -q "step 4-make failed: exit status" "$TMP/err"' +check " tail shows the compiler error" 'grep -q "clean-clone-mutant" "$TMP/err"' +check " candidate was the new commit" '[ "$bsha" != "$sha" ]' +rm -rf /tmp/omega_clean_selftest_* + +if [ "$fails" -ne 0 ]; then echo "test-clean-clone: FAIL ($fails)"; exit 1; fi +echo "test-clean-clone: PASS"