omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
GitHub aien-dev/omega-mv#200 (code only)
Apply it
git checkout -b patch-1bbc108f9edd7eff 32ad8a51cea78182ef64dc05a2065005cf92678d curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/1bbc108f9edd7eff.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
200
ce10fceacbbc4e93a7f9f5bc463fa4d675e8cba9
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":200,"url":"https://github.com/aien-dev/omega-mv/pull/200","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:45Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/Makefile b/Makefile index ac5036b68..96f828de6 100644 --- a/Makefile +++ b/Makefile @@ -1568,6 +1568,25 @@ print-composition-gate-bin: .PHONY: test-composition test-composition-gate test-composition-attach-asan composition-gate-bin print-composition-gate-bin +# C4 (Convergence plan item 4): requalification of the local runtime with +# interruption and recovery (crash at every stage boundary, SIGKILL sweep, on-disk +# corruption). Test build only (crash points). Receipt: tools/c4_requal.sh. +RX_C4_REQUAL = $(OUT_DIR)/rx_c4_requal + +$(RX_C4_REQUAL): $(RX_COMPOSE_DEPS) tests/runtime/rx_c4_requal.c | $(OUT_DIR) + $(CC) $(CFLAGS) $(AIEN_TEST_FLAGS) -pthread -o $@ $(RX_COMPOSE_SRCS) tests/runtime/rx_c4_requal.c \ + $(RX_COMPOSE_LINK) + +test-c4-requal: $(RX_C4_REQUAL) + ./$(RX_C4_REQUAL) $(OUT_DIR)/c4_requal_receipt.json + +c4-requal-bin: $(RX_C4_REQUAL) + +print-c4-requal-bin: + @echo $(RX_C4_REQUAL) + +.PHONY: test-c4-requal c4-requal-bin print-c4-requal-bin + # COMPOSITION-2 GPU tier: the same 14-step gate with both Skills executed on # the GB10 through the sovereign M16 native path (no CUDA); see # tests/runtime/rx_compose_gpu_skill.h. A chip run: take the quiet flag and diff --git a/src/runtime/rx_compose.c b/src/runtime/rx_compose.c index 4a5f6b3c0..c201fe39c 100644 --- a/src/runtime/rx_compose.c +++ b/src/runtime/rx_compose.c @@ -305,6 +305,22 @@ static uint64_t latest_before(CxStore *s, uint32_t slot, uint32_t cls, uint32_t return cx_latest(s, RXC_CX_SUBJECT(slot), before > 1 ? before - 1 : 0, &f); } +/* C4: 1 if a Cortex promotion names a winner claim whose branch is `packed_ref`. + * A promotion is written only after its state is durable (settle order), so a + * promoted state that J-Space no longer holds is a regressed checkpoint, not a + * crash window: recovery must refuse it rather than roll it back. */ +static int state_ref_promoted(const CxStore *s, uint64_t packed_ref) { + for (uint64_t id = 1; id <= s->n; id++) { + const CxObject *o = cx_get(s, id); + if (!o || o->kind != CX_K_PROMOTION) continue; + const CxObject *claim = cx_get(s, o->links[0]); + if (!claim || claim->kind != CX_K_CANDIDATE) continue; + const uint64_t *pl = payload_of(s, claim->id, RXC_CP_WORDS); + if (pl && pl[RXC_CP_REF] == packed_ref) return 1; + } + return 0; +} + static int has_admission(CxStore *s, uint64_t tag, uint64_t link0) { const CxIdList *l = &s->by_subject[RXC_STATE_SUBJECT]; for (uint32_t i = 0; i < l->n; i++) { @@ -519,6 +535,10 @@ static int recover(RxCompose *c) { if (!o || o->id <= chosen) continue; if (o->kind != CX_K_ENTITY_CREATED && o->kind != CX_K_EXEC_COMMIT) continue; if (has_admission(s, RXC_ADMIT_ROLLBACK, o->id)) continue; + { + const uint64_t *pp = payload_of(s, o->id, CX_WREC_WORDS); + if (pp && state_ref_promoted(s, pp[CX_WREC_FIELD0 + RXC_S_REF])) return RX_ERR_REPLAY; + } const uint64_t *p = payload_of(s, o->id, CX_WREC_WORDS); uint64_t ap[RXC_AP_WORDS] = { p ? p[CX_WREC_FIELD0 + RXC_S_REF] : 0, p ? p[CX_WREC_FIELD0 + RXC_S_GOAL] : 0, RXC_NONE }; @@ -535,6 +555,12 @@ static int recover(RxCompose *c) { } if (!chosen) { /* Genesis: drop anything durable, root seeded by the machine identity. */ + /* C4: a lost or emptied Cortex journal must not silently reset a World + * whose J-Space holds committed history. The genesis root is one unit; + * every committed goal derives more. Durable history with no state + * record is refused, never overwritten with a fresh genesis. */ + for (uint32_t b = 0; b < c->js.n_branches; b++) + if (c->js.branches[b] && c->js.branches[b]->n_units > 1) return RX_ERR_REPLAY; for (uint32_t b = 0; b < c->js.n_branches; b++) if (c->js.branches[b]) js_branch_release(&c->js, b); uint32_t root; diff --git a/tests/runtime/rx_c4_requal.c b/tests/runtime/rx_c4_requal.c new file mode 100644 index 000000000..210d0a5ef --- /dev/null +++ b/tests/runtime/rx_c4_requal.c @@ -0,0 +1,684 @@ +/* + * rx_c4_requal.c -- C4 local-runtime requalification, interruption and recovery. + * + * ONE repeatable task: the verified-scale ledger. Three goals (inputs 5, 6, 7) + * each go through the whole COMPOSITION-2 path in one World: + * World -> J-Space (fork two staged branches) -> AEGIS (contract check, + * one candidate deliberately breaks the contract) -> World commit (seal) + * -> settle -> Cortex (claims, evidence, promotion), durable on disk. + * The committed state after each goal is a signature (World state ref, J-Space + * content digest, state result, Cortex promotion count, chain verified, exactly + * one live branch). The baseline run records the signature after goal 0..3. + * + * Injections (each in a fresh directory): + * crash : fault point p (one per stage boundary) x goal g: the child exits + * at the point (test-build hook), the parent reopens. + * kill : the child runs the whole task, the parent SIGKILLs it after a + * delay (a sweep across the run), the parent reopens. + * corrupt : the finished directory is damaged (truncate, flip a byte, zero + * fill, delete, append junk) in the Cortex journal, in every + * J-Space file, and in machine.id, then reopened; plus a foreign + * machine identity, and a single-byte flip sweep of the J-Space + * checkpoint, machine.id and (every 7th byte of) the journal. + * Acceptance, written before the run: + * crash/kill : reopen succeeds and the signature equals exactly one baseline + * signature (crash: the one the point implies); the task then + * resumes from it and reaches the baseline final signature, also + * after one more close/reopen. + * corrupt : reopen REFUSES (nonzero, repeatable); or the damage is + * detected when the state is read (J-Space corrupt error); or + * the state and every Cortex record equal the pristine reopen + * (UNCHANGED, benign damage); or a torn-looking tail was cut and + * re-completed with a visible RECOVERED admission and the same + * state and promotions (REPAIRED_VISIBLY). Anything else is a + * silent divergence and FAILS. + * + * Needs -DAIEN_TEST_BUILD=1 (crash points). usage: rx_c4_requal <receipt.json> + */ +#include "rx_compose_fixture.h" + +#include <dirent.h> +#include <stdarg.h> +#include <errno.h> +#include <fcntl.h> +#include <ftw.h> +#include <signal.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <time.h> +#include <unistd.h> + +#ifndef RXC_TEST_HOOKS +#error "rx_c4_requal needs -DAIEN_TEST_BUILD=1" +#endif + +#define NGOAL 3 +static const uint64_t GOALS[NGOAL] = { 5, 6, 7 }; + +static Fx g_fx; +static RxCompose g_c; +static char g_base[128]; + +typedef struct { + int ok; /* chain verified, one live branch, digest readable */ + int digest_rc; /* js_branch_content_digest result */ + JsBranchRef ref; + uint8_t dg[32]; + uint64_t result; + uint32_t promos; + uint64_t nrec; + uint32_t radm; /* RECOVERED admissions: records re-completed after a torn tail */ + uint8_t rec[32]; /* Cortex record digest (all records, timing excluded) */ +} Sig; +static Sig BASE[NGOAL + 1]; +static uint8_t REOPEN_REC[32]; /* record digest after ONE reopen of the pristine finished directory */ +static uint64_t REOPEN_NREC; /* and its record count */ + +typedef struct { + char name[96]; + char klass[24]; /* RECOVERED / REFUSED / DETECTED_ON_READ / UNCHANGED / DIVERGED / FAULT_NOT_FIRED */ + int pass; + char detail[200]; +} Case; +#define MAXCASE 400 +static Case g_case[MAXCASE]; +static int g_ncase; + +static int rm_one(const char *p, const struct stat *sb, int fl, struct FTW *w) { + (void)sb; (void)fl; (void)w; + return remove(p); +} +static void rmtree(const char *p) { nftw(p, rm_one, 16, FTW_DEPTH | FTW_PHYS); } + +static void reset_hooks(void) { + g_c.test.fault_point = RXC_FP_NONE; + g_c.test.fault_crash = 0; + g_c.test.fault_k = 0; + g_c.test.rogue_candidate = 0; +} + +static int sig_eq(const Sig *a, const Sig *b) { + /* The branch ref (slot id, generation) is an allocator artifact that differs + * after a crash; the state is its content digest, the World result and the + * Cortex promotion count. */ + return a->result == b->result && + a->promos == b->promos && memcmp(a->dg, b->dg, 32) == 0; +} + +/* Which fields of a differ from b (for failure details). */ +static void sig_diff(const Sig *a, const Sig *b, char *buf, size_t n) { + snprintf(buf, n, "ref %u/%u vs %u/%u; result %llu vs %llu; promos %u vs %u; digest %s; ok=%d", + a->ref.id, a->ref.gen, b->ref.id, b->ref.gen, (unsigned long long)a->result, + (unsigned long long)b->result, a->promos, b->promos, + memcmp(a->dg, b->dg, 32) ? "differs" : "same", a->ok); +} + +static void sig_take(RxCompose *c, Sig *s) { + memset(s, 0, sizeof *s); + s->ref = rx_compose_state(c); + s->digest_rc = js_branch_content_digest(&c->js, s->ref.id, s->dg); + RxObject so; + memset(&so, 0, sizeof so); + rx_world_read(&c->w, c->state, &so); + s->result = so.field[RXC_S_RESULT]; + s->promos = fx_count(&c->cx, CX_K_PROMOTION, UINT64_MAX); + rx_compose_record_digest(&c->cx, s->rec); + s->nrec = c->cx.n; + s->radm = fx_count(&c->cx, CX_K_ADMISSION, RXC_ADMIT_RECOVERED); + s->ok = cx_verify_chain(&c->cx) == CX_OK && fx_live_branches(&c->js) == 1 && s->digest_rc == JS_OK; +} + +static int open_dir(const char *d) { + memset(&g_c, 0, sizeof g_c); + return fx_open(&g_fx, &g_c, d, 1); +} + +/* Index j of the baseline signature equal to s, or -1. */ +static int match_base(const Sig *s) { + for (int j = 0; j <= NGOAL; j++) + if (s->ok && sig_eq(s, &BASE[j])) return j; + return -1; +} + +static void add_case(const char *name, const char *klass, int pass, const char *fmt, ...) { + if (g_ncase >= MAXCASE) { fprintf(stderr, "too many cases\n"); exit(2); } + Case *c = &g_case[g_ncase++]; + snprintf(c->name, sizeof c->name, "%s", name); + snprintf(c->klass, sizeof c->klass, "%s", klass); + c->pass = pass; + va_list ap; + va_start(ap, fmt); + vsnprintf(c->detail, sizeof c->detail, fmt, ap); + va_end(ap); +} + +/* Baseline: run the whole task once in `d`, filling sig[]. */ +static int run_task(const char *d, Sig *sig) { + if (open_dir(d) != RX_OK) return -1; + sig_take(&g_c, &sig[0]); + for (int i = 0; i < NGOAL; i++) { + RxcResult o; + fx_a_bad = 1; + int rc = fx_run(&g_fx, &g_c, GOALS[i], &o); + fx_a_bad = 0; + if (rc != RX_OK || o.outcome != RXC_OUT_COMMITTED || o.result != GOALS[i] * 3 + 1) { + fx_close(&g_fx, &g_c); + return -2; + } + sig_take(&g_c, &sig[i + 1]); + } + fx_close(&g_fx, &g_c); + return 0; +} + +/* After a recovery landed on baseline index j: finish the task from goal j, + * check the final signature, close, reopen, check again. Returns 1 on success. */ +static int resume_and_check(const char *d, int j, char *why, size_t wn) { + for (int i = j; i < NGOAL; i++) { + RxcResult o; + fx_a_bad = 1; + int rc = fx_run(&g_fx, &g_c, GOALS[i], &o); + fx_a_bad = 0; + if (rc != RX_OK || o.outcome != RXC_OUT_COMMITTED) { + snprintf(why, wn, "resume goal %d rc=%d outcome=%d", i, rc, o.outcome); + fx_close(&g_fx, &g_c); + return 0; + } + } + Sig f; + sig_take(&g_c, &f); + fx_close(&g_fx, &g_c); + if (!f.ok || !sig_eq(&f, &BASE[NGOAL])) { + { char dd[160]; sig_diff(&f, &BASE[NGOAL], dd, sizeof dd); snprintf(why, wn, "final differs: %.150s", dd); } + return 0; + } + if (open_dir(d) != RX_OK) { snprintf(why, wn, "second reopen failed"); return 0; } + sig_take(&g_c, &f); + fx_close(&g_fx, &g_c); + if (!f.ok || !sig_eq(&f, &BASE[NGOAL])) { snprintf(why, wn, "second reopen differs"); return 0; } + return 1; +} + +/* Reopen after an interruption; acceptance: recovered signature is baseline + * index `expect` (-1 = any index), then resume reaches the baseline final. */ +static void recover_case(const char *name, const char *d, int expect) { + char why[200] = ""; + int rc = open_dir(d); + if (rc != RX_OK) { + add_case(name, "REFUSED", 0, "interruption must be recoverable, open rc=%d", rc); + return; + } + Sig s; + sig_take(&g_c, &s); + int j = match_base(&s); + if (j < 0) { + fx_close(&g_fx, &g_c); + { char dd[160]; sig_diff(&s, &BASE[0], dd, sizeof dd); add_case(name, "DIVERGED", 0, "matches no baseline; vs genesis: %s", dd); } + return; + } + if (expect >= 0 && j != expect) { + fx_close(&g_fx, &g_c); + add_case(name, "DIVERGED", 0, "recovered to baseline %d, implied %d", j, expect); + return; + } + if (!resume_and_check(d, j, why, sizeof why)) { + add_case(name, "DIVERGED", 0, "%s", why); + return; + } + add_case(name, "RECOVERED", 1, "recovered to baseline %d, resumed to final, 2nd reopen equal", j); +} + +static const char *fp_name[RXC_FP_END] = { "none", "before_fork", "candidate", "before_commit", + "after_validation", "seal", "reclaim", "cortex" }; + +static void mkcasedir(char *out, size_t n, const char *leaf) { + snprintf(out, n, "%s/%s", g_base, leaf); + rmtree(out); +} + +static void crash_case(int point, int g) { + char d[200], name[96], leaf[64]; + snprintf(name, sizeof name, "crash/%s/goal%d", fp_name[point], g); + snprintf(leaf, sizeof leaf, "crash_%d_%d", point, g); + mkcasedir(d, sizeof d, leaf); + fflush(NULL); + pid_t pid = fork(); + if (pid == 0) { + if (open_dir(d) != RX_OK) _exit(2); + for (int i = 0; i < g; i++) { + RxcResult o; + fx_a_bad = 1; + int rc = fx_run(&g_fx, &g_c, GOALS[i], &o); + fx_a_bad = 0; + if (rc != RX_OK || o.outcome != RXC_OUT_COMMITTED) _exit(4); + } + reset_hooks(); + g_c.test.fault_point = point; + g_c.test.fault_crash = 1; + g_c.test.fault_k = 0; + RxcResult o; + fx_a_bad = 1; + fx_run(&g_fx, &g_c, GOALS[g], &o); + _exit(3); /* fault did not fire */ + } + int st = 0; + waitpid(pid, &st, 0); + if (!(WIFEXITED(st) && WEXITSTATUS(st) == RXC_CRASH_EXIT)) { + add_case(name, "FAULT_NOT_FIRED", 0, "child status %d", WIFEXITED(st) ? WEXITSTATUS(st) : -1); + rmtree(d); + return; + } + recover_case(name, d, point == RXC_FP_CORTEX ? g + 1 : g); + rmtree(d); +} + +static double now_s(void) { + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return t.tv_sec + t.tv_nsec * 1e-9; +} + +static void child_full_run(const char *d) { + Sig tmp[NGOAL + 1]; + _exit(run_task(d, tmp) == 0 ? 0 : 5); +} + +static void kill_sweep(int n) { + char d[200]; + mkcasedir(d, sizeof d, "kill_t"); + fflush(NULL); + double t0 = now_s(); + pid_t pid = fork(); + if (pid == 0) child_full_run(d); + int st; + waitpid(pid, &st, 0); + double T = now_s() - t0; + rmtree(d); + for (int i = 0; i < n; i++) { + char name[96], leaf[64]; + snprintf(name, sizeof name, "kill/sigkill@%d_of_%d", i + 1, n); + snprintf(leaf, sizeof leaf, "kill_%d", i); + mkcasedir(d, sizeof d, leaf); + fflush(NULL); + pid = fork(); + if (pid == 0) child_full_run(d); + double delay = T * 1.1 * (i + 1) / n; + struct timespec ts = { (time_t)delay, (long)((delay - (time_t)delay) * 1e9) }; + nanosleep(&ts, NULL); + kill(pid, SIGKILL); + waitpid(pid, &st, 0); + /* A child that already finished is a valid (complete) case. */ + recover_case(name, d, -1); + rmtree(d); + } +} + +/* ---- corruption of a finished directory ---------------------------------- */ + +typedef enum { OP_TRUNC_BY, OP_TRUNC_TO, OP_TRUNC_HALF, OP_FLIP_MID, OP_FLIP_FIRST, OP_FLIP_LAST, + OP_ZERO_TAIL, OP_DELETE, OP_APPEND_JUNK, OP_FLIP_PM, OP_FLIP_ABS } Op; +static const char *op_name[] = { "truncate_by", "truncate_to", "truncate_half", "flip_mid", + "flip_first", "flip_last", "zero_tail", "delete", "append_junk", "flip_permille", "flip_byte" }; + +static int apply_op(const char *path, Op op, long arg) { + struct stat sb; + if (stat(path, &sb) != 0) return -1; + off_t n = sb.st_size; + if (op == OP_DELETE) return unlink(path); + int fd = open(path, O_RDWR); + if (fd < 0) return -1; + int rc = 0; + uint8_t b; + switch (op) { + case OP_TRUNC_BY: rc = ftruncate(fd, n > arg ? n - arg : 0); break; + case OP_TRUNC_TO: rc = ftruncate(fd, arg); break; + case OP_TRUNC_HALF: rc = ftruncate(fd, n / 2); break; + case OP_FLIP_MID: case OP_FLIP_FIRST: case OP_FLIP_LAST: case OP_FLIP_PM: case OP_FLIP_ABS: { + off_t at = op == OP_FLIP_MID ? n / 2 : op == OP_FLIP_FIRST ? 0 : op == OP_FLIP_PM ? n * arg / 1000 : op == OP_FLIP_ABS ? arg : n - 1; + if (n == 0 || pread(fd, &b, 1, at) != 1) { rc = -1; break; } + b ^= 0x40; + rc = pwrite(fd, &b, 1, at) == 1 ? 0 : -1; + break; + } + case OP_ZERO_TAIL: { + uint8_t z[64] = { 0 }; + off_t at = n > 64 ? n - 64 : 0; + rc = pwrite(fd, z, n > 64 ? 64 : (size_t)n, at) >= 0 ? 0 : -1; + break; + } + case OP_APPEND_JUNK: { + uint8_t j[64]; + for (int i = 0; i < 64; i++) j[i] = (uint8_t)(0xA5 ^ i); + rc = pwrite(fd, j, sizeof j, n) == (ssize_t)sizeof j ? 0 : -1; + break; + } + default: rc = -1; + } + if (rc == 0) fsync(fd); + close(fd); + return rc; +} + +/* Open a damaged finished directory and classify what happened. Returns 1 if + * acceptable (refused stably, detected on read, or nothing committed changed). */ +static int classify_dir(const char *d, const char **klass, char *detail, size_t dn) { + int rc = open_dir(d); + if (rc != RX_OK) { + int rc2 = open_dir(d); /* a refusal must be stable */ + if (rc2 == RX_OK) fx_close(&g_fx, &g_c); + *klass = "REFUSED"; + snprintf(detail, dn, "open rc=%d, again rc=%d", rc, rc2); + return rc2 == rc; + } + Sig s; + sig_take(&g_c, &s); + fx_close(&g_fx, &g_c); + if (s.digest_rc != JS_OK) { + *klass = "DETECTED_ON_READ"; + snprintf(detail, dn, "open ok, state read refused (js rc=%d)", s.digest_rc); + return 1; + } + if (s.ok && sig_eq(&s, &BASE[NGOAL]) && memcmp(s.rec, REOPEN_REC, 32) == 0) { + *klass = "UNCHANGED"; + snprintf(detail, dn, "open ok, state and every Cortex record equal the committed final state"); + return 1; + } + /* A flip that makes a record look torn gets the log cut there; recovery repairs + * it by re-completing the composition records and leaves a RECOVERED admission + * as visible evidence. Same state and promotions, bounded record count. */ + if (s.ok && sig_eq(&s, &BASE[NGOAL]) && s.radm >= 1 && s.nrec >= REOPEN_NREC && s.nrec <= REOPEN_NREC + 2) { + *klass = "REPAIRED_VISIBLY"; + snprintf(detail, dn, "torn-looking tail cut and re-completed: state and promotions equal, %u RECOVERED admission(s), records %llu vs %llu", + s.radm, (unsigned long long)s.nrec, (unsigned long long)REOPEN_NREC); + return 1; + } + *klass = "DIVERGED"; + snprintf(detail, dn, "open ok but state or Cortex records differ from the committed final state (j=%d result=%llu promos=%u ok=%d records=%llu vs pristine-reopen %llu)", + match_base(&s), (unsigned long long)s.result, s.promos, s.ok, (unsigned long long)s.nrec, + (unsigned long long)REOPEN_NREC); + return 0; +} + +static void corrupt_case(const char *rel, Op op, long arg) { + char d[200], name[128], path[400], detail[220]; + const char *klass; + if (op == OP_TRUNC_BY || op == OP_TRUNC_TO || op == OP_FLIP_PM || op == OP_FLIP_ABS) snprintf(name, sizeof name, "corrupt/%s/%s_%ld", rel, op_name[op], arg); + else snprintf(name, sizeof name, "corrupt/%s/%s", rel, op_name[op]); + mkcasedir(d, sizeof d, "corrupt"); + Sig tmp[NGOAL + 1]; + if (run_task(d, tmp) != 0) { add_case(name, "DIVERGED", 0, "could not build the finished directory"); return; } + snprintf(path, sizeof path, "%s/%s", d, rel); + /* A torn Cortex tail is what a crash leaves; classify_dir accepts it only as + * REPAIRED_VISIBLY. Every other damage must leave every record byte-identical + * or be refused. */ + if (apply_op(path, op, arg) != 0) { + add_case(name, "NOT_APPLICABLE", 1, "operation not applicable (file is empty or absent in this task)"); + rmtree(d); + return; + } + int ok = classify_dir(d, &klass, detail, sizeof detail); + add_case(name, klass, ok, "%s", detail); + rmtree(d); +} + +/* Exhaustive single-byte sweep of one file: flip every `stride`-th byte (each + * from a pristine copy of the directory), reopen, classify. One summary case. */ +typedef struct { char rel[300]; uint8_t *b; size_t n; } Snap; +static int snap_dir(const char *d, Snap *s, int max) { + static const char *fixed[] = { "machine.id", "cortex.cx" }; + char names[16][300]; + int k = 0; + for (size_t i = 0; i < 2; i++) snprintf(names[k++], sizeof names[0], "%s", fixed[i]); + char jd[260]; + snprintf(jd, sizeof jd, "%s/jspace", d); + DIR *dir = opendir(jd); + struct dirent *e; + while (dir && (e = readdir(dir)) && k < 14) + if (e->d_name[0] != '.') snprintf(names[k++], sizeof names[0], "jspace/%.200s", e->d_name); + if (dir) closedir(dir); + int ns = 0; + for (int i = 0; i < k && ns < max; i++) { + char p[600]; + snprintf(p, sizeof p, "%.200s/%.290s", d, names[i]); + struct stat sb; + if (stat(p, &sb) != 0) continue; + FILE *f = fopen(p, "rb"); + if (!f) continue; + s[ns].b = malloc(sb.st_size ? (size_t)sb.st_size : 1); + s[ns].n = fread(s[ns].b, 1, sb.st_size, f); + fclose(f); + snprintf(s[ns].rel, sizeof s[ns].rel, "%.290s", names[i]); + ns++; + } + return ns; +} +static void restore_dir(const char *d, const Snap *s, int ns) { + for (int i = 0; i < ns; i++) { + char p[600]; + snprintf(p, sizeof p, "%.200s/%.290s", d, s[i].rel); + FILE *f = fopen(p, "wb"); + if (!f) continue; + fwrite(s[i].b, 1, s[i].n, f); + fclose(f); + } +} +static void byte_sweep(const char *rel, size_t stride) { + char d[200], name[128], path[600], detail[220]; + snprintf(name, sizeof name, "sweep/%s/flip_every_%zu_bytes", rel, stride); + mkcasedir(d, sizeof d, "sweep"); + Sig tmp[NGOAL + 1]; + if (run_task(d, tmp) != 0) { add_case(name, "DIVERGED", 0, "could not build the finished directory"); return; } + Snap snap[16]; + int ns = snap_dir(d, snap, 16); + snprintf(path, sizeof path, "%s/%s", d, rel); + struct stat sb; + if (stat(path, &sb) != 0 || sb.st_size == 0) { + add_case(name, "NOT_APPLICABLE", 1, "file is empty or absent in this task"); + } else { + size_t n = (size_t)sb.st_size; + unsigned refused = 0, detected = 0, unchanged = 0, diverged = 0, tried = 0; + char first_bad[120] = ""; + for (size_t i = 0; i < n; i += stride) { + restore_dir(d, snap, ns); + if (apply_op(path, OP_FLIP_ABS, (long)i) != 0) continue; + const char *klass; + int ok = classify_dir(d, &klass, detail, sizeof detail); + tried++; + if (!ok) { diverged++; if (getenv("C4_VERBOSE")) fprintf(stderr, "sweep divergence at %zu: %s\n", i, detail); if (!first_bad[0]) snprintf(first_bad, sizeof first_bad, "first at offset %zu", i); } + else if (!strcmp(klass, "REFUSED")) refused++; + else if (!strcmp(klass, "DETECTED_ON_READ")) detected++; + else unchanged++; + } + add_case(name, diverged ? "DIVERGED" : "SWEEP", diverged == 0, + "%zu-byte file, %u flips: refused %u, detected on read %u, unchanged (benign) %u, silent divergence %u %s", + n, tried, refused, detected, unchanged, diverged, first_bad); + } + for (int i = 0; i < ns; i++) free(snap[i].b); + rmtree(d); +} + +static void corrupt_all(void) { + static const struct { Op op; long arg; } cx_ops[] = { + { OP_TRUNC_BY, 1 }, { OP_TRUNC_BY, 40 }, { OP_TRUNC_BY, 400 }, { OP_TRUNC_HALF, 0 }, + { OP_TRUNC_TO, 0 }, { OP_TRUNC_TO, 24 }, { OP_FLIP_FIRST, 0 }, { OP_FLIP_MID, 0 }, + { OP_FLIP_LAST, 0 }, { OP_ZERO_TAIL, 0 }, { OP_APPEND_JUNK, 0 }, { OP_DELETE, 0 }, + { OP_FLIP_PM, 125 }, { OP_FLIP_PM, 250 }, { OP_FLIP_PM, 375 }, { OP_FLIP_PM, 625 }, + { OP_FLIP_PM, 750 }, { OP_FLIP_PM, 875 } }; + for (size_t i = 0; i < sizeof cx_ops / sizeof cx_ops[0]; i++) + corrupt_case("cortex.cx", cx_ops[i].op, cx_ops[i].arg); + static const struct { Op op; long arg; } mid_ops[] = { { OP_FLIP_FIRST, 0 }, { OP_DELETE, 0 } }; + for (size_t i = 0; i < 2; i++) corrupt_case("machine.id", mid_ops[i].op, mid_ops[i].arg); + /* every J-Space file in a finished directory */ + char d[200], jd[260]; + mkcasedir(d, sizeof d, "corrupt_list"); + Sig tmp[NGOAL + 1]; + if (run_task(d, tmp) != 0) { add_case("corrupt/jspace/list", "DIVERGED", 0, "no directory"); return; } + snprintf(jd, sizeof jd, "%s/jspace", d); + char names[16][256]; + int nn = 0; + DIR *dir = opendir(jd); + struct dirent *e; + while (dir && (e = readdir(dir)) && nn < 16) + if (e->d_name[0] != '.') snprintf(names[nn++], sizeof names[0], "%.200s", e->d_name); + if (dir) closedir(dir); + rmtree(d); + static const struct { Op op; long arg; } js_ops[] = { + { OP_TRUNC_HALF, 0 }, { OP_TRUNC_BY, 1 }, { OP_TRUNC_TO, 0 }, { OP_FLIP_FIRST, 0 }, + { OP_FLIP_MID, 0 }, { OP_FLIP_LAST, 0 }, { OP_ZERO_TAIL, 0 }, { OP_DELETE, 0 }, + { OP_FLIP_ABS, 20 }, { OP_FLIP_ABS, 70 }, { OP_FLIP_ABS, 100 }, { OP_FLIP_ABS, 130 }, + { OP_FLIP_PM, 125 }, { OP_FLIP_PM, 250 }, { OP_FLIP_PM, 375 }, { OP_FLIP_PM, 625 }, + { OP_FLIP_PM, 750 }, { OP_FLIP_PM, 875 } }; + for (int f = 0; f < nn; f++) + for (size_t i = 0; i < sizeof js_ops / sizeof js_ops[0]; i++) { + char rel[300]; + snprintf(rel, sizeof rel, "jspace/%.200s", names[f]); + corrupt_case(rel, js_ops[i].op, js_ops[i].arg); + } +} + +/* A directory made on one machine is refused by another identity, and the + * refusal changes nothing (the owner still opens it and sees the final state). */ +static void identity_case(void) { + char d[200]; + mkcasedir(d, sizeof d, "identity"); + Sig tmp[NGOAL + 1]; + if (run_task(d, tmp) != 0) { add_case("identity/foreign_machine", "DIVERGED", 0, "no directory"); return; } + AienMachineId mine = g_fx.self; + g_fx.self = fx_mid(2); + int rc = open_dir(d); + g_fx.self = mine; + if (rc == RX_OK) fx_close(&g_fx, &g_c); + Sig s; + int rc2 = open_dir(d); + int same = 0; + if (rc2 == RX_OK) { sig_take(&g_c, &s); fx_close(&g_fx, &g_c); same = s.ok && sig_eq(&s, &BASE[NGOAL]); } + add_case("identity/foreign_machine", rc == RX_ERR_IDENTITY ? "REFUSED" : "DIVERGED", + rc == RX_ERR_IDENTITY && same, "foreign open rc=%d (want %d), owner reopen same=%d", rc, + RX_ERR_IDENTITY, same); + rmtree(d); +} + +/* Stale J-Space: put back the J-Space checkpoint from after goal `k` while the + * Cortex journal (and machine.id) are from after the last goal. Cortex has + * already promoted the later goals, which only happens after their state is + * durable, so a checkpoint that lost them is not a crash window: it must be + * refused, never silently rolled back. */ +static void stale_case(int k) { + char d[200], name[96]; + snprintf(name, sizeof name, "stale/jspace_checkpoint_from_after_goal%d", k); + mkcasedir(d, sizeof d, "stale"); + Snap snap[16]; + int ns = 0; + if (open_dir(d) != RX_OK) { add_case(name, "DIVERGED", 0, "open failed"); return; } + for (int pass = 0; pass < 2; pass++) { + for (int i = pass ? k : 0; i < (pass ? NGOAL : k); i++) { + RxcResult o; + fx_a_bad = 1; + int rc = fx_run(&g_fx, &g_c, GOALS[i], &o); + fx_a_bad = 0; + if (rc != RX_OK || o.outcome != RXC_OUT_COMMITTED) { fx_close(&g_fx, &g_c); add_case(name, "DIVERGED", 0, "setup goal %d failed", i); rmtree(d); return; } + } + fx_close(&g_fx, &g_c); + if (pass == 0) { + ns = snap_dir(d, snap, 16); + if (open_dir(d) != RX_OK) { add_case(name, "DIVERGED", 0, "reopen failed"); return; } + } + } + int nj = 0; + for (int i = 0; i < ns; i++) + if (!strncmp(snap[i].rel, "jspace/", 7)) snap[nj++] = snap[i]; + restore_dir(d, snap, nj); + int rc = open_dir(d); + if (rc != RX_OK) { + int rc2 = open_dir(d); + if (rc2 == RX_OK) fx_close(&g_fx, &g_c); + add_case(name, "REFUSED", rc2 == rc, "open rc=%d, again rc=%d", rc, rc2); + } else { + Sig s; + sig_take(&g_c, &s); + fx_close(&g_fx, &g_c); + char dd[160]; + sig_diff(&s, &BASE[NGOAL], dd, sizeof dd); + add_case(name, "DIVERGED", 0, "promoted goals silently rolled back (state matches baseline %d of %d); vs final: %.100s", + match_base(&s), NGOAL, dd); + } + rmtree(d); +} + +static void jstr(FILE *f, const char *s) { + fputc('"', f); + for (; *s; s++) { + if (*s == '"' || *s == '\\') fputc('\\', f); + fputc(*s, f); + } + fputc('"', f); +} + +int main(int argc, char **argv) { + if (argc != 2) { fprintf(stderr, "usage: %s <receipt.json>\n", argv[0]); return 2; } + snprintf(g_base, sizeof g_base, "/tmp/rx_c4_requal.XXXXXX"); + if (!mkdtemp(g_base)) { perror("mkdtemp"); return 2; } + if (fx_init(&g_fx) != 0) { fprintf(stderr, "fixture init failed\n"); return 2; } + + /* Baseline, twice: must be deterministic and fully committed. */ + char d0[200], d1[200]; + mkcasedir(d0, sizeof d0, "base0"); + mkcasedir(d1, sizeof d1, "base1"); + Sig B1[NGOAL + 1]; + int b0 = run_task(d0, BASE), b1 = run_task(d1, B1); + int base_ok = b0 == 0 && b1 == 0; + for (int i = 0; base_ok && i <= NGOAL; i++) + base_ok = BASE[i].ok && sig_eq(&BASE[i], &B1[i]) && (i == 0 || !sig_eq(&BASE[i], &BASE[i - 1])); + add_case("baseline/two_runs_identical_signatures", "BASELINE", base_ok, "rc=%d,%d", b0, b1); + /* Baseline reopen after clean close names the final state. */ + Sig rb; + int rr = open_dir(d0); + int reopen_ok = 0; + if (rr == RX_OK) { sig_take(&g_c, &rb); fx_close(&g_fx, &g_c); reopen_ok = rb.ok && sig_eq(&rb, &BASE[NGOAL]); memcpy(REOPEN_REC, rb.rec, 32); REOPEN_NREC = rb.nrec; } + add_case("baseline/close_reopen_same_state", "BASELINE", reopen_ok, "rc=%d", rr); + rmtree(d0); + rmtree(d1); + + if (base_ok) { + for (int g = 0; g < NGOAL; g++) + for (int p = RXC_FP_BEFORE_FORK; p < RXC_FP_END; p++) crash_case(p, g); + kill_sweep(24); + corrupt_all(); + identity_case(); + for (int k = 1; k < NGOAL; k++) stale_case(k); + byte_sweep("jspace/jspace.meta", 1); + byte_sweep("cortex.cx", 7); + byte_sweep("machine.id", 1); + } + + int npass = 0, nfail = 0, nna = 0; + for (int i = 0; i < g_ncase; i++) nna += strcmp(g_case[i].klass, "NOT_APPLICABLE") == 0; + for (int i = 0; i < g_ncase; i++) g_case[i].pass ? npass++ : nfail++; + FILE *f = fopen(argv[1], "w"); + if (!f) { perror(argv[1]); return 2; } + fprintf(f, "{\n \"task\": \"verified-scale ledger: goals 5,6,7, result = 3*input+1, Skill A breaks the contract\",\n"); + fprintf(f, " \"stages\": \"World -> J-Space -> AEGIS verify -> World commit/seal -> settle -> Cortex\",\n"); + fprintf(f, " \"baseline_final\": {\"result\": %llu, \"promotions\": %u},\n", + (unsigned long long)BASE[NGOAL].result, BASE[NGOAL].promos); + fprintf(f, " \"cases\": %d, \"pass\": %d, \"fail\": %d, \"not_applicable\": %d,\n \"verdict\": \"%s\",\n \"results\": [\n", g_ncase, npass, + nfail, nna, nfail == 0 && base_ok ? "PASS" : "FAIL"); + for (int i = 0; i < g_ncase; i++) { + fprintf(f, " {\"name\": "); + jstr(f, g_case[i].name); + fprintf(f, ", \"class\": \"%s\", \"result\": \"%s\", \"detail\": ", g_case[i].klass, + g_case[i].pass ? "PASS" : "FAIL"); + jstr(f, g_case[i].detail); + fprintf(f, "}%s\n", i + 1 < g_ncase ? "," : ""); + } + fprintf(f, " ]\n}\n"); + fclose(f); + for (int i = 0; i < g_ncase; i++) + if (!g_case[i].pass || getenv("C4_VERBOSE")) + printf("%s %-52s %-17s %s\n", g_case[i].pass ? "ok " : "FAIL", g_case[i].name, + g_case[i].klass, g_case[i].detail); + printf("C4 requalification (interruption+recovery): %d cases, %d pass, %d fail: %s\n", g_ncase, npass, nfail, + nfail == 0 && base_ok ? "PASS" : "FAIL"); + fx_free(&g_fx); + rmtree(g_base); + return nfail == 0 && base_ok ? 0 : 1; +} diff --git a/tools/c4_requal.sh b/tools/c4_requal.sh new file mode 100755 index 000000000..141bd8fc3 --- /dev/null +++ b/tools/c4_requal.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# C4 requalification gate: the complete local runtime (World -> J-Space -> +# AEGIS/FORGE verify -> commit -> Cortex) on one machine, one repeatable task, +# with interruption and recovery. Refuses a dirty tree, builds and runs the +# committed source, stores a receipt named by its content hash: +# evidence/C4-REQUAL/<sha256-of-receipt>.json +# The receipt carries the commit of every repo of the candidate (and whether it +# matches the CAND-0 manifest in aien-architecture), the executable digests, +# the 14-step COMPOSITION-2 gate verdict, every injection case, and (with +# --mutants) the recovery-check mutant results. +# usage: tools/c4_requal.sh [--mutants] +# Env: MAKE_ARGS (e.g. AIENOS_LOCK_REPO=...), C4_SC_DIR, C4_PROTO_DIR, C4_ARCH_DIR. +set -eu +want_mut=0 +[ "${1:-}" = "--mutants" ] && want_mut=1 +root=$(git rev-parse --show-toplevel) +cd "$root" +if [ -n "$(git status --porcelain --untracked-files=normal)" ]; then + echo "c4_requal: working tree is dirty; commit first" >&2 + git status --short >&2 + exit 2 +fi +commit=$(git rev-parse HEAD) +sc_dir=${C4_SC_DIR:-$HOME/workspace/aien-sovereign-core} +proto_dir=${C4_PROTO_DIR:-$HOME/workspace/aien-protocols} +arch_dir=${C4_ARCH_DIR:-$HOME/workspace/aien-architecture} +head_of() { git -C "$1" rev-parse origin/main 2>/dev/null || echo unknown; } +aienos_pin=$(head -n 1 aienos.lock) +sc_head=$(head_of "$sc_dir"); proto_head=$(head_of "$proto_dir"); arch_head=$(head_of "$arch_dir") + +# CAND-0 pins (aien-architecture qualification/candidates/CAND-0.toml on origin/main). +cand=$(git -C "$arch_dir" show origin/main:qualification/candidates/CAND-0.toml 2>/dev/null || true) +cand_status=$(printf '%s\n' "$cand" | sed -n 's/^status *= *"\(.*\)"/\1/p' | head -n 1) +pin() { printf '%s\n' "$cand" | sed -n "s/^$1 *= *\"\([0-9a-f]\{40\}\)\".*/\1/p" | head -n 1; } +c_omega=$(pin omega); c_aienos=$(pin aienos); c_sc=$(pin aien-sovereign-core) +c_proto=$(pin aien-protocols); c_arch=$(pin aien-architecture) +m() { [ -n "$2" ] && [ "$1" = "$2" ] && echo true || echo false; } + +make ${MAKE_ARGS:-} c4-requal-bin composition-gate-bin >/dev/null +bin=$(make -s ${MAKE_ARGS:-} print-c4-requal-bin) +gbin=$(make -s ${MAKE_ARGS:-} print-composition-gate-bin) +work=$(mktemp -d /tmp/c4req.XXXXXX) +trap 'rm -rf "$work"' EXIT +set +e +"./$gbin" "$commit" "$work/composition.json" >"$work/composition.out" 2>&1 +gstatus=$? +"./$bin" "$work/injection.json" >"$work/injection.out" 2>&1 +istatus=$? +mut_status=0 +if [ $want_mut -eq 1 ]; then + tools/c4_requal_mutants.sh "$work/mutants.json" >"$work/mutants.out" 2>&1 + mut_status=$? +fi +set -e +[ -s "$work/injection.json" ] || { echo "c4_requal: no injection receipt" >&2; cat "$work/injection.out" >&2; exit 2; } +gverdict=$(sed -n 's/.*"verdict": "\([A-Z]*\)".*/\1/p' "$work/composition.json" | head -n 1) +iverdict=$(sed -n 's/.*"verdict": "\([A-Z]*\)".*/\1/p' "$work/injection.json" | head -n 1) +verdict=PASS +[ "$gstatus" -eq 0 ] && [ "$gverdict" = PASS ] || verdict=FAIL +[ "$istatus" -eq 0 ] && [ "$iverdict" = PASS ] || verdict=FAIL +[ "$mut_status" -eq 0 ] || verdict=FAIL +bsha=$(sha256sum "$bin" | cut -d' ' -f1); gsha=$(sha256sum "$gbin" | cut -d' ' -f1) +binding=NOT_BOUND +if [ "$cand_status" = frozen ] && [ "$(m "$commit" "$c_omega")" = true ] && [ "$(m "$aienos_pin" "$c_aienos")" = true ]; then binding=BOUND; fi +indent() { sed 's/^/ /' "$1"; } +tmp="$work/receipt.json" +{ + printf '{\n "schema": "C4RequalReceiptV1",\n "gate": "C4-REQUAL",\n "verdict": "%s",\n' "$verdict" + printf ' "date_utc": "%s",\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" + printf ' "env_class": "host CPU on the Spark (no chip, no QEMU, no network)",\n' + printf ' "machine": {"host": "%s", "arch": "%s", "kernel": "%s"},\n' "$(hostname)" "$(uname -m)" "$(uname -r)" + printf ' "tree_dirty": false,\n' + printf ' "repos": {\n' + printf ' "omega": {"commit": "%s", "exercised": true, "cand0_pin": "%s", "matches_cand0": %s},\n' "$commit" "$c_omega" "$(m "$commit" "$c_omega")" + printf ' "aienos": {"commit": "%s", "source": "omega aienos.lock (capability authority library built from this commit)", "exercised": true, "cand0_pin": "%s", "matches_cand0": %s},\n' "$aienos_pin" "$c_aienos" "$(m "$aienos_pin" "$c_aienos")" + printf ' "aien-sovereign-core": {"commit": "%s", "source": "origin/main of local clone at run time", "exercised": false, "cand0_pin": "%s", "matches_cand0": %s},\n' "$sc_head" "$c_sc" "$(m "$sc_head" "$c_sc")" + printf ' "aien-protocols": {"commit": "%s", "source": "origin/main of local clone at run time", "exercised": false, "cand0_pin": "%s", "matches_cand0": %s},\n' "$proto_head" "$c_proto" "$(m "$proto_head" "$c_proto")" + printf ' "aien-architecture": {"commit": "%s", "source": "origin/main of local clone at run time", "exercised": false, "cand0_pin": "%s", "matches_cand0": %s}\n' "$arch_head" "$c_arch" "$(m "$arch_head" "$c_arch")" + printf ' },\n' + printf ' "candidate": {"id": "CAND-0", "manifest_status": "%s", "binding": "%s", "note": "binding is BOUND only when CAND-0 is frozen and the omega and aienos commits match; this run is evidence for the listed commits, not a candidate qualification"},\n' "${cand_status:-unreadable}" "$binding" + printf ' "executables": {"rx_c4_requal": "%s", "rx_composition_gate": "%s", "build": "make c4-requal-bin composition-gate-bin (c4 binary is a test build, -DAIEN_TEST_BUILD=1; the composition gate binary is the production build)"},\n' "$bsha" "$gsha" + printf ' "composition_gate": {"verdict": "%s", "exit": %s},\n' "$gverdict" "$gstatus" + printf ' "known_gaps": [\n' + printf ' "FORGE is not on the composed path: the Skills are CPU procedures; omega_forge_realize has no caller in src/runtime (GPU tier uses the m16 native path, not FORGE)",\n' + printf ' "aien-sovereign-core and aien-protocols are not exercised by this chain",\n' + printf ' "Cortex owner is unresolved (three implementations); this gate qualifies omega rx_cortex only",\n' + printf ' "Fabric and remote J-Space do not exist; local only",\n' + printf ' "J-Space spill file is empty in this task, so corruption of spilled data is not exercised",\n' + printf ' "power-loss durability (fsync ordering on real media) is not tested; crashes are process exits and SIGKILL"\n' + printf ' ],\n' + printf ' "injection":\n' + indent "$work/injection.json" + if [ $want_mut -eq 1 ]; then printf ' ,\n "mutants":\n'; indent "$work/mutants.json"; else printf ' ,\n "mutants": null\n'; fi + printf '}\n' +} > "$tmp" +sum=$(sha256sum "$tmp" | cut -d' ' -f1) +mkdir -p evidence/C4-REQUAL +out="evidence/C4-REQUAL/$sum.json" +cp "$tmp" "$out" +chmod 0644 "$out" +cat "$work/injection.out" | tail -n 5 +[ $want_mut -eq 1 ] && tail -n 2 "$work/mutants.out" +echo "receipt: $out" +echo "verdict: $verdict (omega $commit, binding $binding)" +[ "$verdict" = PASS ] diff --git a/tools/c4_requal_mutants.sh b/tools/c4_requal_mutants.sh new file mode 100755 index 000000000..eccbdd000 --- /dev/null +++ b/tools/c4_requal_mutants.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# C4 mutant check: each mutant weakens one recovery check in a COPY of the +# runtime, rebuilds the C4 harness against it and runs it. A mutant is KILLED +# when the harness fails (exit nonzero, FAIL cases listed), SURVIVED when it +# still passes (a recovery check no test bites on), ERROR when it did not build +# or the edit did not apply. Exit 0 only if every mutant is KILLED. +# usage: tools/c4_requal_mutants.sh [out.json] +# Extra make args via MAKE_ARGS (e.g. AIENOS_LOCK_REPO=...). +set -u +root=$(git rev-parse --show-toplevel) +out=${1:-"$root/build/c4_mutants.json"} +auth=$(ls -d "$root"/build/aienos-authority/*/ 2>/dev/null | head -n 1) +[ -n "$auth" ] || { echo "run 'make test-c4-requal' first (builds the authority library)" >&2; exit 2; } +phys=${PHYSICS_DIR:-$(cd "$root/../physics" && pwd)} +work=$(mktemp -d /tmp/c4mut.XXXXXX) +trap 'rm -rf "$work"' EXIT + +# id~file~sed expression~what the original check does +MUTANTS=' +M01~src/runtime/rx_compose.c~s/ || !aien_mid_equal(&stored, self))/ || 0)/~machine identity must match the stored one +M02~src/runtime/rx_compose.c~s/n_units > 1) return RX_ERR_REPLAY;/n_units > 100000) return RX_ERR_REPLAY;/~refuse durable history when the Cortex journal has no state record +M03~src/runtime/rx_compose.c~s/if (cx_verify_chain(&c->cx) != CX_OK) { cx_close(&c->cx); return RX_ERR_REPLAY; }/;/~Cortex hash chain verified at open~redundant: at open the chain value is rebuilt from the stored record digests (rx_cortex.c chain_step in append at line 166) and cx_verify_chain recomputes the same digests the per-record load check (M09) already enforces, so alone it adds nothing; M13 removes both and is KILLED. Candidate equivalent mutant, UNVERIFIED +M04~src/runtime/rx_compose.c~s/js_branch_info(&c->js, r, &bi) == JS_OK \&\& !bi.staged/js_branch_info(\&c->js, r, \&bi) == JS_OK/~recovered state branch must be sealed, not staged~redundant: no injection can leave a staged branch in the durable checkpoint (staged branches are never persisted, rx_compose.h recovery note), candidate equivalent mutant, UNVERIFIED +M05~src/runtime/rx_compose.c~s/if (!o || o->id <= chosen) continue;/continue;/~answer newer, non-durable state records with a rollback admission +M06~src/runtime/rx_compose.c~s/for (uint32_t i = l->n; i-- > 0;) {/for (uint32_t i = 0; i < l->n; i++) {/~choose the NEWEST durable state record +M07~src/runtime/rx_compose.c~s/if (n < 0) return RX_ERR_REPLAY;/(void)n;/~an interrupted composition record that cannot be completed refuses~gap: no injection leaves a composition record that cannot be completed +M08~src/runtime/rx_compose.c~s/int n = compose_records(c, S, V, NULL, 0, \&tmp);/int n = 0; (void)S; (void)V; (void)tmp;/~complete every interrupted composition record at open +M09~src/runtime/rx_cortex.c~s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (CX_R_FIXED + n), 32) != 0) {/if (0) {/~each journal record digest is checked at load +M10~src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint body digest~redundant: header digest, body digest and the restore-time content check overlap; each alone is covered by the others and by structural validation +M11~src/runtime/rx_jspace.c~s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint header digest~redundant: header digest, body digest and the restore-time content check overlap; each alone is covered by the others and by structural validation +M12~src/runtime/rx_compose.c~s/if (js_space_commit(&c->js) != JS_OK) return RX_ERR_REPLAY;/;/~recovered state is made durable before the World starts +M13~src/runtime/rx_compose.c,src/runtime/rx_cortex.c~s/if (cx_verify_chain(&c->cx) != CX_OK) { cx_close(&c->cx); return RX_ERR_REPLAY; }/;/@@s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (CX_R_FIXED + n), 32) != 0) {/if (0) {/~Cortex integrity (both the load digest and the chain check removed) +M14~src/runtime/rx_jspace.c,src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint integrity (header and body digests both removed)~gap: with every J-Space integrity digest removed all 820 single-byte flips of the task checkpoint are still refused structurally or benign, so the digests are not shown to bite +M15~src/runtime/rx_jspace.c,src/runtime/rx_jspace.c,src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(chk, r->content, 32)) { s->stats.corrupt_restores++; return JS_ERR_CORRUPT; }/;/~J-Space integrity, all three layers (header digest, body digest, restore-time content check) removed~gap: with every J-Space integrity digest removed all 820 single-byte flips of the task checkpoint are still refused structurally or benign, so the digests are not shown to bite +M16~src/runtime/rx_compose.c~s/if (pp \&\& state_ref_promoted(s, pp\[CX_WREC_FIELD0 + RXC_S_REF\])) return RX_ERR_REPLAY;/(void)pp; (void)state_ref_promoted;/~refuse a J-Space checkpoint that lost a state Cortex already promoted +' +n=0; killed=0; survived=0; err=0 +printf '{\n "mutants": [\n' > "$out" +first=1 +echo "$MUTANTS" | while IFS="~" read -r id file expr what redund; do + [ -n "$id" ] || continue + if [ -n "${ONLY:-}" ]; then case " $ONLY " in *" $id "*) ;; *) continue;; esac; fi + dir="$work/$id" + mkdir -p "$dir/build" + (cd "$root" && cp -r src tests tools Makefile mk aienos.lock physics.lock "$dir/" 2>/dev/null) + mkdir -p "$dir/build/aienos-authority" + cp -r "$auth" "$dir/build/aienos-authority/$(basename "$auth")" + files=$(echo "$file" | tr ',' ' ') + before=$(for f in $files; do sha256sum "$dir/$f"; done | sha256sum) + i=1 + for f in $files; do + e=$(echo "$expr" | awk -F'@@' -v n=$i '{print $n}') + sed -i "$e" "$dir/$f"; i=$((i+1)) + done + after=$(for f in $files; do sha256sum "$dir/$f"; done | sha256sum) + if [ "$before" = "$after" ]; then status=ERROR; note="edit did not apply" + else + log="$work/$id.log" + if ! (cd "$dir" && nice -n 10 make PHYSICS_DIR="$phys" ${MAKE_ARGS:-} c4-requal-bin >"$log" 2>&1); then + status=ERROR; note="build failed: $(grep -m1 -E "error:|Error " "$log" | cut -c1-120)" + else + (cd "$dir" && ./build/rx_c4_requal "$dir/r.json") >"$log.run" 2>&1 + rc=$? + nf=$(grep -c '^FAIL' "$log.run") + if [ $rc -ne 0 ] && [ "$nf" -gt 0 ]; then status=KILLED; note="$nf failing case(s), first: $(grep -m1 '^FAIL' "$log.run" | cut -c6-70)" + elif [ $rc -ne 0 ]; then status=KILLED; note="harness exit $rc (crash or abort)" + else + case "$redund" in + redundant:*) status=SURVIVED_REDUNDANT; note="$redund" ;; + gap:*) status=SURVIVED_GAP; note="$redund" ;; + *) status=SURVIVED; note="harness still PASS, no justification recorded" ;; + esac + fi + fi + fi + echo "$id $status $what ($note)" >&2 + [ $first -eq 1 ] || printf ',\n' >> "$out" + first=0 + printf ' {"id": "%s", "file": "%s", "checks": "%s", "status": "%s", "note": "%s"}' "$id" "$file" "$what" "$status" "$(echo "$note" | tr -d '"\\')" >> "$out" + rm -rf "$dir" +done +printf '\n ]\n}\n' >> "$out" +k=$(grep -c '"status": "KILLED"' "$out"); t=$(grep -c '"status"' "$out") +r=$(grep -c '"status": "SURVIVED_REDUNDANT"' "$out"); g=$(grep -c '"status": "SURVIVED_GAP"' "$out") +echo "mutants: $t total, $k killed, $r survived as redundant, $g survived as test gaps (receipt $out)" +# Fail on any unjustified survivor or build/edit error. +[ $((k + r + g)) -eq "$t" ]