diff --git a/.crumb b/.crumb index 9d624ad99..3cff505d6 100644 --- a/.crumb +++ b/.crumb @@ -82,7 +82,7 @@ }, { "digest": "c126b5b07a5cd9f114bfd9de1ea7d088170990eda3a25efa21037b6c11177748", - "last_commit": "5347f13", + "last_commit": "f87194f", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, @@ -93,8 +93,8 @@ "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "6613e15a29e55246a9939492011b26ec53c87eef79764f87ef6eecc7d46f8e54", - "last_commit": "b56e89b", + "digest": "8babd67d29ceef6b2600e4eae0e9f9430b3d21f4812aa691504f3e129f929388", + "last_commit": "f66cda3", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -105,15 +105,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:b5a33e5ae3a85e66c3a93c5d56135626685c4ce66bbe9a89250dba6316414d54", - "compiled_at": "2026-10-05T04:01:50Z", + "children_root": "sha256:2fd8f6d4d5ff872407a7b5a2b126eb9a02fb83d4d58e682da852f201b6dfe558", + "compiled_at": "2026-10-05T04:09:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:d447d4052063e5a4585318d406fd1ee8d799306d3ffdfd350aca2ef55225c59f", + "digest": "sha256:eb3fc6b98e0154c55ce7d0113e27627714e586b0872fe630b1f36a57d24e8387", "evidence_files": 1733, "evidence_root": "sha256:0b92d15f30b595de70a79ce6c93f76d3b90cbb8bb113f4bcd543fd4787e47532", "files": 3499, - "generated_at_commit": "5347f1309fb0f489d55e3005c9b529ea386ff9d2", - "source_tree": "sha256:f52d2cf1433ff7fb07e21bc4370ab24130fce04d1be625c73ff29b509ec27221" + "generated_at_commit": "c76f205d29fdcd3d466ec98705f0a210772de35f", + "source_tree": "sha256:822474ccfb69c3707e094244a40c31039b37b9c9177a6a52f23a0670200cb675" }, "owner_lane": "", "provenance": { diff --git a/tests/.crumb b/tests/.crumb index 9a82dabeb..e473aeae7 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -253,8 +253,8 @@ "purpose": "Directory tests/relations. Purpose not yet described by a human." }, { - "digest": "f49db08f5e2f8ad20c9e10f7eaaa27e7f264b6bfc17e4d4fad16e60eb1495f1d", - "last_commit": "3a3144d", + "digest": "35716e4886e855c8dd0aa92bdb95d3c12b9fa7c3f0427293531e0c6f39c10dea", + "last_commit": "519f53e", "name": "runtime", "purpose": "Directory tests/runtime. Purpose not yet described by a human." }, @@ -283,15 +283,15 @@ "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], - "children_root": "sha256:0a4e348cf355e1fa5924f9c76a460d1d49bc285687b134365ef0fb9dab4f0855", - "compiled_at": "2026-10-05T03:24:21Z", + "children_root": "sha256:f41a548c1ae9abe8a9e71e6609852343b4f435a229a0cb9ad2765fe189c08275", + "compiled_at": "2026-10-05T04:06:25Z", "compiler": "crumb-compile/1", - "digest": "sha256:6613e15a29e55246a9939492011b26ec53c87eef79764f87ef6eecc7d46f8e54", + "digest": "sha256:8babd67d29ceef6b2600e4eae0e9f9430b3d21f4812aa691504f3e129f929388", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", "files": 791, - "generated_at_commit": "b544d81db1f8d576685a8de19add13c7c59b052a", - "source_tree": "sha256:a55b39ff19e82f59a9fbd00005a43310011cad05be3b789d94e8a9a69d916349" + "generated_at_commit": "519f53e49d3a260923aa02c84e1d13a5653a2c05", + "source_tree": "sha256:6b3a366fd6e87768e83c61253478cb4c2cccab42e844c1cb8fb00373f3a66236" }, "owner_lane": "", "provenance": { diff --git a/tests/runtime/.crumb b/tests/runtime/.crumb index 867d1c133..a24aeb96e 100644 --- a/tests/runtime/.crumb +++ b/tests/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T18:12:40Z", + "compiled_at": "2026-10-05T04:03:03Z", "compiler": "crumb-compile/1", - "digest": "sha256:f49db08f5e2f8ad20c9e10f7eaaa27e7f264b6bfc17e4d4fad16e60eb1495f1d", + "digest": "sha256:35716e4886e855c8dd0aa92bdb95d3c12b9fa7c3f0427293531e0c6f39c10dea", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 52, - "generated_at_commit": "cb7cc216147664549484fcca8e8ceadbd6f6cdbf", - "source_tree": "sha256:cc6b64472b5dadb93de40b9efbe2ca53931138d538323a2683b79d9fe3ec2df4" + "generated_at_commit": "e5593ae488fcb9038557a4317a07faa7625649a3", + "source_tree": "sha256:3d30b46c9f76993c8e7ce621a230484c23179800c3433c2a59fb737788addf54" }, "owner_lane": "", "provenance": { diff --git a/tests/runtime/rx_compose_test.c b/tests/runtime/rx_compose_test.c index 793db21a3..4761555fe 100644 --- a/tests/runtime/rx_compose_test.c +++ b/tests/runtime/rx_compose_test.c @@ -59,6 +59,35 @@ static void reset_c(void) { static int ref_eq(JsBranchRef a, JsBranchRef b) { return a.id == b.id && a.gen == b.gen; } static int noop_fn(RxCtx *x) { (void)x; return 0; } +/* Staged (never-committed) J-Space branches still held in memory. */ +static uint32_t staged_branches(const JsSpace *s) { + uint32_t n = 0; + for (uint32_t i = 0; i < s->n_branches; i++) n += s->branches[i] && s->branches[i]->staged; + return n; +} + +/* Cleanup in process, before any close or reopen (L7-LIVING): every + * candidate branch the run forked and did not commit is reclaimed and no + * staged branch survives. A run that did not move the World also leaves + * exactly one live branch (the state's) and promotes nothing. */ +static void check_cleanup(const char *what, const RxcResult *o, uint32_t promotions_before) { + int moved = !ref_eq(rx_compose_state(&g_c), o->old_ref); + for (uint32_t k = 0; k < RXC_K; k++) { + if (!o->cand_ref[k].id && !o->cand_ref[k].gen) continue; + if (moved && ref_eq(o->cand_ref[k], rx_compose_state(&g_c))) continue; + CHECK(js_branch_check(&g_c.js, o->cand_ref[k]) == JS_ERR_STALE, + "%s: candidate %u reclaimed in process", what, k); + } + CHECK(staged_branches(&g_c.js) == 0, "%s: no staged branch survives (%u)", what, + staged_branches(&g_c.js)); + if (!moved) { + CHECK(fx_live_branches(&g_c.js) == 1, "%s: one live branch in process (%u)", what, + fx_live_branches(&g_c.js)); + CHECK(fx_count(&g_c.cx, CX_K_PROMOTION, UINT64_MAX) == promotions_before, + "%s: nothing promoted", what); + } +} + /* Reference run: what OLD and NEW are for input 5 in a fresh directory. */ static struct { JsBranchRef old_ref, new_ref, cand[RXC_K]; @@ -91,6 +120,7 @@ static void t_reference(void) { CHECK(js_branch_info(&g_c.js, o.new_ref, &bi) == JS_OK && !bi.staged && bi.owner == 0, "winner sealed, no owner"); CHECK(fx_live_branches(&g_c.js) == 1, "one live branch"); + check_cleanup("reference", &o, 0); /* cleanup after success */ R.old_ref = s0; R.new_ref = o.new_ref; R.cand[0] = o.cand_ref[0]; @@ -179,6 +209,7 @@ static void fault_case(int point, int crash, uint32_t k) { : point == RXC_FP_CORTEX ? RXC_OUT_RECORD_FAILED : RXC_OUT_NOT_COMMITTED; CHECK(o.outcome == want, "%s: outcome %d want %d", what, o.outcome, want); CHECK(g_c.test.fault_hit, "%s: fault fired", what); + check_cleanup(what, &o, 0); fx_close(&g_fx, &g_c); } reset_c(); @@ -232,6 +263,7 @@ static void t_no_winner(void) { cx_payload(&g_c.cx, ev)[RXC_EP_PASSMASK] == 0, "evidence: no winner, nothing passed"); for (uint32_t k = 0; k < RXC_K; k++) CHECK(js_branch_check(&g_c.js, o.cand_ref[k]) == JS_ERR_STALE, "candidate %u reclaimed", k); + check_cleanup("no winner", &o, 0); fx_close(&g_fx, &g_c); reset_c(); CHECK(fx_open(&g_fx, &g_c, d, 1) == RX_OK, "reopen"); @@ -251,6 +283,7 @@ static void t_authority(void) { CHECK(fx_run(&g_fx, &g_c, 5, &o) == RX_OK && o.outcome == RXC_OUT_NOT_COMMITTED, "rogue run not committed (%d)", o.outcome); CHECK(ref_eq(rx_compose_state(&g_c), R.old_ref), "state untouched"); + check_cleanup("rogue", &o, 0); /* cleanup after a refusal */ /* The refusal is on the record. */ uint32_t refused = 0; for (uint64_t id = 1; id <= g_c.cx.n; id++) { diff --git a/tests/runtime/rx_r13_living.c b/tests/runtime/rx_r13_living.c index 25511d49e..ad8e2db82 100644 --- a/tests/runtime/rx_r13_living.c +++ b/tests/runtime/rx_r13_living.c @@ -1202,6 +1202,24 @@ static int revoke_cap(Rig *r, RxCapRef cap) { return aienos_cap_revoke(r->admin, office, (AienosCapRef){cap.cap_id, cap.generation}); } +/* Cleanup after a run inside the living World, checked before any close + * (L7-LIVING): every candidate branch the run forked and did not commit is + * reclaimed, no staged branch survives, and exactly one branch is live (the + * superseded one is released after a commit; nothing new after a refusal). */ +static int compose_cleanup_ok(RxCompose *c, const RxcResult *o) { + JsBranchRef s = rx_compose_state(c); + for (uint32_t k = 0; k < RXC_K; k++) { + JsBranchRef b = o->cand_ref[k]; + if (!b.id && !b.gen) continue; + if (b.id == s.id && b.gen == s.gen) continue; + if (js_branch_check(&c->js, b) != JS_ERR_STALE) return 0; + } + uint32_t staged = 0; + for (uint32_t i = 0; i < c->js.n_branches; i++) + staged += c->js.branches[i] && c->js.branches[i]->staged; + return staged == 0 && fx_live_branches(&c->js) == 1; +} + #define CFAIL(...) do { fprintf(stderr, "R13 composition: "); fprintf(stderr, __VA_ARGS__); \ fputc('\n', stderr); goto out; } while (0) @@ -1244,6 +1262,8 @@ static int composition_phase(Rig *r) { if (js_branch_check(&c->js, o.cand_ref[1]) != JS_ERR_STALE) CFAIL("loser not reclaimed"); JsBranchInfo bi; if (js_branch_info(&c->js, o.new_ref, &bi) != JS_OK || bi.staged) CFAIL("winner not sealed"); + if (!compose_cleanup_ok(c, &o)) + CFAIL("cleanup after commit: branch left (live %u)", fx_live_branches(&c->js)); if (!o.cx_candidate[0] || !o.cx_candidate[1] || !o.cx_evidence || !o.cx_promotion || !o.cx_admission[1]) CFAIL("composition record incomplete"); g->alternatives = o.n_alternatives; @@ -1290,7 +1310,8 @@ static int composition_phase(Rig *r) { c->test.rogue_candidate = 0; now = rx_compose_state(c); g->rogue_refused = rc == RX_OK && o.outcome == RXC_OUT_NOT_COMMITTED && - now.id == first.id && now.gen == first.gen; + now.id == first.id && now.gen == first.gen && + compose_cleanup_ok(c, &o); /* cleanup after a refusal */ if (!g->rogue_refused) CFAIL("rogue candidate (rc %d outcome %d)", rc, o.outcome); /* Replay: close (the living World stays up), attach again on the same @@ -1323,7 +1344,8 @@ static int composition_phase(Rig *r) { now = rx_compose_state(c); g->stale_commit_outcome = rc == RX_OK ? o.outcome : rc; g->stale_commit_refused = rc == RX_OK && o.outcome != RXC_OUT_COMMITTED && - now.id == second.id && now.gen == second.gen; + now.id == second.id && now.gen == second.gen && + compose_cleanup_ok(c, &o); /* cleanup after a refusal */ if (!g->stale_commit_refused) CFAIL("revoked commit right still wrote (rc %d outcome %d)", rc, o.outcome); /* Outside input under a revoked capability is refused at the World. */