Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-mv/patches/e9dd3a2128bd27e0
# 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
Sign in to star 1 stars 0 watching
About Files History Releases Proposed changes Issues For developers
## GitHub aien-dev/omega-mv#300 (code only)
closed derived `e9dd3a2128bd27e0` #300
Imported from GitHub aien-dev/omega-mv#300 (code only)
GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).
Base `38a6a569b1263bf6ae6fc33fc06a726d8582ff74` · Head `e9f05389c47ab5466850bf6a4c5b6cca062b6ee3`
### Apply it
```
git checkout -b patch-e9dd3a2128bd27e0 38a6a569b1263bf6ae6fc33fc06a726d8582ff74
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/e9dd3a2128bd27e0.patch | git am
```
Raw patch (mbox) · Diff
### Provenance
This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:
```
github-import 1
aien-dev/omega-mv
300
e9f05389c47ab5466850bf6a4c5b6cca062b6ee3
```
```
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":300,"url":"https://github.com/aien-dev/omega-mv/pull/300","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:13Z","metadata":"unavailable","state_derived":true}
```
### Changes
```
diff --git a/.crumb b/.crumb
index 46e28cb9a..6beba73bb 100644
--- a/.crumb
+++ b/.crumb
@@ -52,7 +52,7 @@
},
{
"digest": "01a9aa128e136ecccdaca33b6babef24d4011a95c2ca1a5dd839d84e2841ce3d",
- "last_commit": "8fd3afe",
+ "last_commit": "38a6a56",
"name": "docs",
"purpose": "Directory docs. Purpose not yet described by a human."
},
@@ -64,7 +64,7 @@
},
{
"digest": "7a280ae41e1051f14529ab2c8b2749f4712ea37df87254fd90bfbc3e1bba2048",
- "last_commit": "4c8a6a6",
+ "last_commit": "38a6a56",
"name": "mk",
"purpose": "Directory mk. Purpose not yet described by a human."
},
@@ -81,39 +81,39 @@
"purpose": "Directory research. Purpose not yet described by a human."
},
{
- "digest": "5c3c94a89860afb94180166af2bd48740aa17408cd611a2c937490260cabcfe7",
- "last_commit": "80ca5d4",
+ "digest": "1fe9f5f262e772c89bd39bd9b35748472d6b61b6762ce975b48990403df03ffb",
+ "last_commit": "984aa1e",
"name": "spec",
"purpose": "Directory spec. Purpose not yet described by a human."
},
{
- "digest": "9d41b28b5097bcd6375ec285de5ce215bed31cf06816fa34adb0dd529e46cd54",
- "last_commit": "f1da160",
+ "digest": "a6297bff3c4d142fa966c7d8817366e17505f4f0c1a1f97903813606a95d3f36",
+ "last_commit": "984aa1e",
"name": "src",
"purpose": "Directory src. Purpose not yet described by a human."
},
{
- "digest": "09c803a2d62bcda0b85e84c70399d270bda18d335e77270c58567746abf1f173",
- "last_commit": "f1da160",
+ "digest": "a7f97a1cd886fa4dfb2f66b766c2948200d0858dc26788d65682ab1c8a4646a5",
+ "last_commit": "420a0ff",
"name": "tests",
"purpose": "Directory tests. Purpose not yet described by a human."
},
{
- "digest": "39a4a935c81a9ba2a047be53e745857892c48a9c9e17f5f166e037d36f7a28b6",
- "last_commit": "8fd3afe",
+ "digest": "cc003d272b6b0ba376a8fa7eb4f05a51041c945677ebe6eedcdccaaa929b6545",
+ "last_commit": "a6d0d52",
"name": "tools",
"purpose": "Directory tools. Purpose not yet described by a human."
}
],
- "children_root": "sha256:bc9f475ac36f9249b2ad2b117425648b2af81a459f7ea945124342166cb0a62f",
- "compiled_at": "2026-10-05T16:48:41Z",
+ "children_root": "sha256:246188c8b3a9f92e4cd14d0d07750f277a32effe8426165d4188ee2fbc158e2e",
+ "compiled_at": "2026-10-05T17:22:20Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:5772ef67488f0a92f58a6c01a47ac228d4cbaf0513df141d039ac7bd64f8db70",
+ "digest": "sha256:3225ee84ee211888dd44c080b2290112357d11ca67457525095c442fbe948d25",
"evidence_files": 2773,
"evidence_root": "sha256:9b7e635d548d619fa71619fe08c4e37fc207feeb04bf6f9c6b0faa7ea4c3a533",
- "files": 4573,
- "generated_at_commit": "678ed89f7b0213130c92d20d481bf429414772e2",
- "source_tree": "sha256:aa10fa3437a5fb46adc9b934de2c4c077f152094409b92378c3261b10c803ed0"
+ "files": 4576,
+ "generated_at_commit": "420a0ff7d7fe6c6f473c01e9871012609aafd0de",
+ "source_tree": "sha256:826cdc8cdf5339fc4ed06bd59c4037ec7dec1c2066aa9fad20676d1fb186ca13"
},
"owner_lane": "",
"provenance": {
diff --git a/.github/workflows/rx-host.yml b/.github/workflows/rx-host.yml
index 5ba3bd358..9427d5721 100644
--- a/.github/workflows/rx-host.yml
+++ b/.github/workflows/rx-host.yml
@@ -82,7 +82,7 @@ jobs:
PHYSICS_DIR: ${{ github.workspace }}/physics-src
AIENOS_R7_DIR: ${{ github.workspace }}/aienos-src
AIENOS_COMMIT: ${{ steps.aienos.outputs.sha }}
- run: make test-r3 test-r7 test-r8 test-r9 test-r12 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
+ run: make test-r3 test-r7 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
- name: Canonical machine identity (M20)
run: make test-machine-identity
- name: Effect capability generations are 64-bit end to end (OMEGA_EFFECT_CAP64)
diff --git a/Makefile b/Makefile
index 63b91a436..51b294b61 100644
--- a/Makefile
+++ b/Makefile
@@ -456,6 +456,25 @@ $(RX_R12_TEST): $(RX_R12_SRCS) src/runtime/rx_caproot.h src/runtime/rx_world.h \
test-r12: $(RX_R12_TEST)
./$(RX_R12_TEST)
+# R16 G6 operator emergency stop (spec/r16-operator-emergency-stop.md). Host only,
+# real capability root: authority refusals, in-flight and racing stops, the
+# generation store under a stop, the durable mark across a restart, and resume.
+# The mutant script then removes each guard in turn from a temporary copy and
+# requires the test to fail against every one. The resident-seat case lives in
+# test-r12 (t_emergency_stop, native AIENOS authority).
+RX_EMERGENCY_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c \
+ src/runtime/rx_generation.c src/sha256.c tests/runtime/rx_emergency.c
+RX_EMERGENCY_TEST = $(OUT_DIR)/rx_emergency_test
+
+$(RX_EMERGENCY_TEST): $(RX_EMERGENCY_SRCS) src/runtime/rx_caproot.h src/runtime/rx_world.h \
+ src/runtime/rx_generation.h src/runtime/rx_caller.h | $(OUT_DIR)
+ $(CC) $(CFLAGS) -pthread -o $@ $(RX_EMERGENCY_SRCS) -lm
+
+.PHONY: test-rx-emergency
+test-rx-emergency: $(RX_EMERGENCY_TEST)
+ ./$(RX_EMERGENCY_TEST)
+ CC="$(CC)" bash tests/runtime/rx_emergency_mutants.sh
+
# R10: Omega as a resident realization faculty. Omega's native AArch64 matvec
# realizations become ready from cost evidence, are verified in a sandbox,
# measured, and recorded; production picks the record up. AArch64 hosts only.
diff --git a/spec/.crumb b/spec/.crumb
index ac4d8d817..22e9530b8 100644
--- a/spec/.crumb
+++ b/spec/.crumb
@@ -20,14 +20,14 @@
}
],
"children_root": "sha256:6834a3241647d3a098283d4eafedbdb1428dfa4d834f9ed5f22025b6d2303093",
- "compiled_at": "2026-10-05T05:37:18Z",
+ "compiled_at": "2026-10-05T16:20:56Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:5c3c94a89860afb94180166af2bd48740aa17408cd611a2c937490260cabcfe7",
+ "digest": "sha256:1fe9f5f262e772c89bd39bd9b35748472d6b61b6762ce975b48990403df03ffb",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "files": 55,
- "generated_at_commit": "cb06d081901c03063945a99ffed1c58d33397e9c",
- "source_tree": "sha256:6c716fd2c2200a60b46da440e371c4c40bc37a73bcad211b1ed24bb27ccfe9ca"
+ "files": 56,
+ "generated_at_commit": "3aa6d80ad1c169b5ad605801ad6ef79d3902ecfd",
+ "source_tree": "sha256:cc4a5aa85651a7ea0e37341db9bba9000d093c770dbe11ce5adfc8ea84f637e1"
},
"owner_lane": "",
"provenance": {
diff --git a/spec/r16-operator-emergency-stop.md b/spec/r16-operator-emergency-stop.md
new file mode 100644
index 000000000..58d37b0d6
--- /dev/null
+++ b/spec/r16-operator-emergency-stop.md
@@ -0,0 +1,180 @@
+# R16 G6: operator emergency stop (contract)
+
+Status: runtime control IMPLEMENTED and host-tested. G6 item
+`operator_emergency_controls_passing` stays **MISSING_IMPLEMENTATION**: the
+production R13 program does not wire the control (no `rx_world_set_halt_dir`
+call, no operator entry point), so no operator can reach it on the candidate,
+and no silicon run exercises a stop. See "Not done" at the end.
+
+Source: `src/runtime/rx_world.c` (`rx_world_emergency_stop`,
+`rx_world_emergency_resume`, `rx_world_set_halt_dir`, `rx_world_halt_status`),
+`src/runtime/rx_generation.c` (`rx_gen_promote` mark check),
+`src/runtime/rx_world.h` (contract comment). Tests: `make test-rx-emergency`
+(`tests/runtime/rx_emergency.c` plus `tests/runtime/rx_emergency_mutants.sh`) and
+`make test-r12` (`t_emergency_stop` in `tests/runtime/rx_r12_resident.c`).
+
+## 1. What it is
+
+One deterministic operator control over a running reaction world: **stop**
+(nothing new commits, nothing from outside publishes, no generation is proposed
+or promoted) and **resume** (the world continues from exactly the state it held,
+and the work the stop refused runs again). ADR 0016 §57: "Do not remove
+deterministic operator control." This is that control for the R16 world. It is
+not a kill switch for the process and not a rollback: the world's state is kept,
+not changed.
+
+## 2. Authority
+
+A stop or resume is accepted only when all three hold, checked under the world
+lock in this order:
+
+1. **Caller credential.** `subject` is enrolled (`rx_world_enroll_caller`) and
+ `cred` passes the constant-time caller check (absent, unknown, revoked, stale
+ and forged credentials are refused: `RX_ERR_IDENTITY`). This holds whether or
+ not the world has bound its callers.
+2. **Not a reaction.** `subject` is not the subject of any reaction ever added to
+ the world: no reaction can stop or resume the world it runs in
+ (`RX_ERR_AUTHORITY`). ADR 0016 I9: intelligence cannot promote itself past
+ authority policy; the same applies to pausing or un-pausing.
+3. **Capability.** `cap` is a live capability for `subject` on
+ `RX_WORLD_RES_CONTROL` (0x906) with right `RX_WORLD_RIGHT_HALT`, validated by
+ the world's authority (rx_caproot or the native AIENOS authority). The right
+ is `RX_RIGHT_EPOCH`: privileged, never delegable. The right that may void every
+ capability may also pause the world. Wrong right, wrong resource, another
+ subject's capability or a revoked capability: `RX_ERR_AUTHORITY`.
+
+Authority is never a boolean anyone can set (ADR 0016 §57, "Do not encode
+authority as editable booleans"). `w->halted` is the world's *state*, written
+only by the two authorized calls and by restart restoration (§4). Every refused
+attempt leaves the world digest, the crumb log and the stop state unchanged (E1).
+A forged resume is refused before the world says whether it is stopped (E1).
+
+## 3. What a stop does
+
+Taken under `mu` then `callers_mu` (the C7 order), so work already committing
+finishes first, and nothing lands between the check and the state change.
+
+| Path | Under a stop | Evidence |
+|---|---|---|
+| Workers | take no work (`worker_main` waits); resume broadcasts | E3, mutant M2 |
+| An activation computing when the stop lands | its result is refused at commit: CANCELLED, `RX_ERR_HALTED`, crumb; it is re-armed and runs again on resume, committing exactly once | E3, mutant M1 |
+| Outside publication (`rx_world_publish_external`) | refused, `RX_ERR_HALTED`, world unchanged | E2, E4, mutant M3 |
+| Resident seat result (`rx_resident_accept`) | not published: the output window is re-projected from the world, the activation ends CANCELLED and runs again on resume; the claim closes | R12 `t_emergency_stop` (manual mutant: removing the guard fails 5 checks) |
+| Object create and retire (`rx_world_create`, `rx_world_retire`) | refused, `RX_ERR_HALTED`, world unchanged (digest, crumbs) | E7, mutants M11, M12 |
+| Sequential activation (`rx_world_seq_activate_timed_locked`) | refused, `RX_ERR_HALTED` | code review only |
+| Caller check (`rx_world_caller_check_fn`) | refuses with `RX_CALLER_ERR_HALTED` (CHECK and HOLD; RELEASE unaffected) | E5, mutant M4 |
+| Generation store bound to the world | `rx_gen_propose` / `rx_gen_promote` refuse with `RX_GEN_ERR_HALTED`; a promotion is re-checked after its HOLD, right before the flip, so a stop during its live barrier or its disk writes refuses it; active generation unchanged in memory and on disk | E5 |
+
+A refused activation is not spent: it does not count toward the reaction's
+episode activation budget, so a reaction woken by another reaction's commit is
+not quarantined by its own refusal and does run on resume (E7, mutant M10; the
+same correction on the seat-result path is in code, covered by no test that sets
+a budget).
+
+A second stop answers `RX_HALT_ALREADY` and changes nothing (E2). A resume of a
+running world answers `RX_HALT_NOT_STOPPED`, with no crumb (E1).
+
+The stop is in force in memory **before** any disk work (mutant M9). Under racing
+publishers and two operators, the crumb log never shows an EXTERNAL or COMMIT
+between a STOP and its RESUME, each accepted stop has exactly one STOP crumb,
+and the chain verifies (E4).
+
+## 4. Durability and restart
+
+With `rx_world_set_halt_dir(w, dir)` set (normally the generation store's
+directory):
+
+* A stop writes `
/OPERATOR_HALT`: a fixed text record (`aien-operator-halt
+ v1`, seq, subject, capability, reason, time, the STOP crumb id) followed by
+ `sha256 ` over every byte before it. Written to a partial file, fsynced,
+ renamed, directory fsynced. If the write fails, the stop still holds in memory
+ and `durable` < 0 reports the errno (never hidden); `durable` = 0 means no
+ directory was set (E2).
+* A world that starts over a directory holding the mark starts **stopped**
+ (`restored`, STOP crumb). A mark that does not verify (one byte changed) or
+ cannot be read also starts it stopped (`RX_ERR_TORN` / `RX_ERR_IO`): the mark
+ fails closed (E6, mutant M7).
+* A mark that is not a regular file (a symlink, dangling or not, a FIFO, a
+ directory) is never followed or blocked on: it is read with `O_NOFOLLOW |
+ O_NONBLOCK` and reported `RX_ERR_TORN`, so the world starts stopped, and the
+ store (which tests for any entry with `lstat`) agrees. Resume keeps a record and
+ removes the entry, so the store is never blocked for good (E7, mutant M13).
+* A generation store refuses promotion while the mark exists, even when it is
+ not bound to any world (`RX_GEN_ERR_HALTED`; an unreadable directory is
+ `RX_GEN_ERR_IO`) (E6, mutant M6). It checks its *own* directory, on entry
+ and again right before the flip; an unbound store over a directory other than
+ the world's halt directory does not see the mark. Set the halt directory to the
+ store's directory.
+* Resume first writes the sealed resumed record
+ `OPERATOR_HALT.resumed..`: the original bytes, then `resumed_by`,
+ `resume_cap` and `resume_t_ns`, then a new seal. It is linked in without
+ overwriting anything, and only then is the mark removed. If either step fails,
+ resume returns `RX_ERR_IO` and the world **stays stopped** (E6, mutant M8).
+
+The mark is the durable stop *state*. The canonical evidence is the crumb log
+(OPERATOR_STOP and OPERATOR_RESUME crumbs, with the resume caused by its stop),
+per ADR 0016 §57 "Do not use text logs as canonical evidence". These two kinds
+have no Cortex kind and are not linked into Cortex (`rx_cortex_record.c`).
+
+## 5. ADR 0016 invariants
+
+| Invariant | How the stop keeps it |
+|---|---|
+| I2 stale generations cannot mutate current state | a refused activation re-runs on resume against the state *then*; the seat result path re-projects from the world |
+| I4 revoked authority cannot execute | a revoked control capability or caller is refused (E1); the stop adds a refusal, never a permission |
+| I6 concurrent publication cannot create torn objects | a stop is taken under the world lock; a commit either finishes before it or is refused whole (E3, E4) |
+| I7 causal history for meaningful committed changes | STOP and RESUME are crumbs; refused activations leave CANCELLED crumbs with `RX_ERR_HALTED` |
+| I8 generation recovery produces a coherent world | no promotion completes under a stop, including one already past its barrier (E5); restart restores the stop (E6) |
+| I11 GPU failure cannot destroy durable identity | a seat result under a stop is dropped and re-projected, never half-published (R12 `t_emergency_stop`) |
+| I15 irreversible effects remain attributable | every stop, resume and refusal names its subject, capability and reason |
+
+## 6. Tests and what they prove
+
+`make test-rx-emergency` (host CPU, real rx_caproot authority, worker pool,
+generation store; built with the normal flags; E1 to E6 in the file header):
+
+* E1 refusals: seven refused stops, each with its code, nothing changed.
+* E2/E3: stop, second stop, refused publication, in-flight refusal, queued work
+ not taken, resume, each activation commits exactly once.
+* E4 race: four workers, two operators, publishers; crumb-log ordering.
+* E5 promotion under a stop (live barrier and disk-write windows), proposal
+ refused, control promotion after resume.
+* E6 durable mark, restart, torn mark, unbound store, read-only directory resume.
+ The read-only case is skipped when the test runs as root (root ignores the
+ permission).
+* E7 budget: a stop while a downstream reaction computes, budget 1; object
+ create and retire under a stop; a dangling symlink mark.
+* `rx_emergency_mutants.sh`: thirteen single-guard mutants (M1 to M13 above),
+ each applied to a temporary copy; the test must fail against every one (at
+ least one failed check, not a crash or a timeout) and pass against the
+ unmutated copy. A mutant whose pattern does not match exactly once fails the
+ script.
+
+`make test-r12` `t_emergency_stop` (native AIENOS authority, resident seat
+stand-in): a seat result that lands after the stop is refused, canonical B and
+B's window keep the world's value, the dependent does not run, no claim is posted
+under the stop; after resume the seat runs again and B = X + Y, C = X + Y + 1.
+
+## 7. Not done (why the G6 item stays MISSING_IMPLEMENTATION)
+
+1. **Production wiring.** The production R13 program
+ (`tests/runtime/rx_r13_living.c`) does not set a halt directory and exposes no
+ operator entry point. An operator console needs a design for how the
+ operator's credential and control capability reach a running program; that
+ design is not written. The G6 item names `rx_world_set_halt_dir` in the R13
+ program as a required symbol, so it reads MISSING until that lands.
+2. **Silicon.** No silicon run exercises a stop. The resident-seat case runs on
+ the R12 host stand-in only.
+3. **Mark authenticity.** The seal is an unkeyed sha256: it detects a damaged
+ mark, not a forged one. A forged mark can only stop the world (fail closed).
+ Removing the mark while no world runs bypasses the restart restoration;
+ protecting the directory is the operating system's job and is not tested
+ here.
+4. **Outside executors.** A stop does not reach a durable executor already
+ performing an effect outside the world. Its result is not published until
+ resume, and the effect stays attributable through its crumbs.
+5. **Sequential activation** under a stop is refused in code but has no test.
+6. **Disk work under the locks.** The stop writes its mark (fsync included) while
+ holding the world lock and the caller lock. The stop is already in force in
+ memory; a slow disk delays readers and caller checks for that time, never the
+ stop itself.
diff --git a/src/.crumb b/src/.crumb
index 103fd2f05..b2cb5e0a0 100644
--- a/src/.crumb
+++ b/src/.crumb
@@ -133,8 +133,8 @@
"purpose": "Directory src/polyglot. Purpose not yet described by a human."
},
{
- "digest": "779e416daad95fc928a9217a06a2897d29930df83b61423d2496fb71f7c42355",
- "last_commit": "3a3144d",
+ "digest": "5a156b88f82413a6284d324d7bf457ec583fe0d4fa07dec1f77d56b3b0652606",
+ "last_commit": "984aa1e",
"name": "runtime",
"purpose": "Directory src/runtime. Purpose not yet described by a human."
},
@@ -169,15 +169,15 @@
"purpose": "Directory src/visor. Purpose not yet described by a human."
}
],
- "children_root": "sha256:607467f8ea6e425bf33f7a0df65a411055a569e302b8127ab84822a0b4559109",
- "compiled_at": "2026-10-05T15:05:28Z",
+ "children_root": "sha256:2b11d37dbb5a168332b53d9a69df44685353241048839d3fc79d027c26070e13",
+ "compiled_at": "2026-10-05T17:01:01Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:9d41b28b5097bcd6375ec285de5ce215bed31cf06816fa34adb0dd529e46cd54",
+ "digest": "sha256:a6297bff3c4d142fa966c7d8817366e17505f4f0c1a1f97903813606a95d3f36",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 406,
- "generated_at_commit": "ac6bab5691d3297993ad7312e3288a61da99696a",
- "source_tree": "sha256:824136a8c53295f02679785e2ad5d2e1c81ada069c8a5e94ae0ce8c4c658e1a1"
+ "generated_at_commit": "714835409175f776b4a5630d892cf9383ba43b44",
+ "source_tree": "sha256:737cbd6bf1488606ef40aaa86391d377c3624e555e3fa80aa7d52d2bd862774a"
},
"owner_lane": "",
"provenance": {
diff --git a/src/runtime/.crumb b/src/runtime/.crumb
index 2a30739d3..e2eda9026 100644
--- a/src/runtime/.crumb
+++ b/src/runtime/.crumb
@@ -7,14 +7,14 @@
"generated": {
"children": [],
"children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "compiled_at": "2026-10-04T18:12:40Z",
+ "compiled_at": "2026-10-05T16:20:56Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:779e416daad95fc928a9217a06a2897d29930df83b61423d2496fb71f7c42355",
+ "digest": "sha256:5a156b88f82413a6284d324d7bf457ec583fe0d4fa07dec1f77d56b3b0652606",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 59,
- "generated_at_commit": "cb7cc216147664549484fcca8e8ceadbd6f6cdbf",
- "source_tree": "sha256:2f806e4c07c8f93a4e613c242c515990f8193fdafd41f8ba85e30bcc5f795393"
+ "generated_at_commit": "3aa6d80ad1c169b5ad605801ad6ef79d3902ecfd",
+ "source_tree": "sha256:2d2b7c349981d00df339d8b28dda8d9720b5e558646e608fe19aa63406a8cd80"
},
"owner_lane": "",
"provenance": {
diff --git a/src/runtime/rx_caller.h b/src/runtime/rx_caller.h
index d971819a0..c3165cd6f 100644
--- a/src/runtime/rx_caller.h
+++ b/src/runtime/rx_caller.h
@@ -51,6 +51,8 @@ typedef struct {
#define RX_CALLER_ERR_EXISTS -7 /* subject already enrolled */
#define RX_CALLER_ERR_ENTROPY -8 /* getrandom failed */
#define RX_CALLER_ERR_FULL -9 /* enrollment table full (RX_CALLER_MAX) */
+#define RX_CALLER_ERR_HALTED -10 /* operator emergency stop in force (rx_world_caller_check_fn):
+ RX_GEN_ERR_HALTED at the R9 boundary, not an identity fault */
/* What a caller check does (RxGenCallerFn, rx_world_caller_check_fn).
* HOLD is the full check that, when it passes, keeps the enrollment table
diff --git a/src/runtime/rx_cortex_record.c b/src/runtime/rx_cortex_record.c
index e83e3350d..bb6fd3e87 100644
--- a/src/runtime/rx_cortex_record.c
+++ b/src/runtime/rx_cortex_record.c
@@ -64,6 +64,9 @@ static uint64_t subject_in(const CortexLink *l, const RxObjRef *ref) {
/* One crumb into one link. Called with the world mutex held. */
static void record_link(CortexLink *l, const RxWorld *w, const RxCrumb *k) {
+ /* An operator stop or resume (R16 G6) is about no World object and has no
+ * Cortex kind; its evidence is the crumb log and the durable halt mark. */
+ if (k->kind == RX_CRUMB_OPERATOR_STOP || k->kind == RX_CRUMB_OPERATOR_RESUME) return;
const RxObjRef *ref = k->n_outputs ? &k->outputs[0].obj
: k->n_inputs ? &k->inputs[0].obj : NULL;
uint64_t subject = subject_in(l, ref);
diff --git a/src/runtime/rx_generation.c b/src/runtime/rx_generation.c
index 49b83a86e..0dec4d94c 100644
--- a/src/runtime/rx_generation.c
+++ b/src/runtime/rx_generation.c
@@ -775,6 +775,23 @@ int rx_gen_read_blob(const RxGenStore *store, uint64_t id, const char *name, uin
return RX_GEN_OK;
}
+/* A bound caller check that refused: an operator stop (R16 G6) is reported as
+ * such, every other refusal is an identity fault. */
+static int caller_refusal(int crc) {
+ return crc == RX_CALLER_ERR_HALTED ? RX_GEN_ERR_HALTED : RX_GEN_ERR_IDENTITY;
+}
+
+/* R16 G6: the durable mark of an operator stop in the store directory. 0 none,
+ * RX_GEN_ERR_HALTED present, RX_GEN_ERR_IO when it cannot be told (refuse). */
+static int halt_marked(const RxGenStore *store) {
+ char p[512];
+ if (snprintf(p, sizeof p, "%s/%s", store->dir, RX_GEN_HALT_MARK) >= (int)sizeof p)
+ return RX_GEN_ERR_IO;
+ struct stat st;
+ if (lstat(p, &st) == 0) return RX_GEN_ERR_HALTED;
+ return errno == ENOENT ? 0 : RX_GEN_ERR_IO;
+}
+
int rx_gen_bind_authority(RxGenStore *store, RxGenCallerFn caller, void *caller_ctx,
RxGenAuthFn auth, void *auth_ctx) {
if (!store || !caller || !auth) return RX_GEN_ERR_ARG;
@@ -796,8 +813,10 @@ int rx_gen_propose_as(RxGenStore *store, uint32_t proposer, const RxCallerCred *
const RxGenDraft *draft, uint64_t *out_id) {
if (!store || !draft || !out_id) return RX_GEN_ERR_ARG;
/* R16 C5: the proposer is who the credential says, or nobody. */
- if (store_bound(store) && store->caller(store->caller_ctx, proposer, cred, RX_CALLER_OP_CHECK) != 0)
- return RX_GEN_ERR_IDENTITY;
+ if (store_bound(store)) {
+ int crc = store->caller(store->caller_ctx, proposer, cred, RX_CALLER_OP_CHECK);
+ if (crc != 0) return caller_refusal(crc);
+ }
if (draft->n_objects > RX_GEN_MAX_OBJECTS) return RX_GEN_ERR_ARG;
if (draft->n_objects && !draft->objects) return RX_GEN_ERR_ARG;
Candidate *slot = NULL;
@@ -895,8 +914,10 @@ int rx_gen_add_work_as(RxGenStore *store, uint32_t subject, const RxCallerCred *
uint64_t candidate, const RxGenWork *work) {
if (!store || !work) return RX_GEN_ERR_ARG;
/* R16 C7: on a bound store the caller is who the credential says. */
- if (store_bound(store) && store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK) != 0)
- return RX_GEN_ERR_IDENTITY;
+ if (store_bound(store)) {
+ int crc = store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK);
+ if (crc != 0) return caller_refusal(crc);
+ }
Candidate *c = find_cand(store, candidate);
if (!c) return RX_GEN_ERR_ARG;
if (c->closing) return RX_GEN_ERR_CLOSING;
@@ -920,8 +941,10 @@ int rx_gen_finish_work(RxGenStore *store, uint64_t candidate, uint64_t work_id)
int rx_gen_finish_work_as(RxGenStore *store, uint32_t subject, const RxCallerCred *cred,
uint64_t candidate, uint64_t work_id) {
if (!store) return RX_GEN_ERR_ARG;
- if (store_bound(store) && store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK) != 0)
- return RX_GEN_ERR_IDENTITY;
+ if (store_bound(store)) {
+ int crc = store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK);
+ if (crc != 0) return caller_refusal(crc);
+ }
Candidate *c = find_cand(store, candidate);
if (!c) return RX_GEN_ERR_ARG;
for (uint32_t i = 0; i < c->n_work; i++) {
@@ -1016,11 +1039,14 @@ int rx_gen_promote(RxGenStore *store, const RxPromotionRequest *request, RxGenAu
* the runtime issued for it; and a bound store validates the promotion
* right with its own authority, never the caller's callback. */
if (store_bound(store)) {
- if (store->caller(store->caller_ctx, request->subject, &request->caller, RX_CALLER_OP_CHECK) != 0)
- return RX_GEN_ERR_IDENTITY;
+ int crc = store->caller(store->caller_ctx, request->subject, &request->caller, RX_CALLER_OP_CHECK);
+ if (crc != 0) return caller_refusal(crc);
auth = store->bound_auth;
auth_ctx = store->bound_auth_ctx;
}
+ /* R16 G6: no promotion while an operator stop is in force, bound or not. */
+ int halted = halt_marked(store);
+ if (halted != 0) return halted;
if (!auth) return RX_GEN_ERR_ARG;
Candidate *c = find_cand(store, request->candidate_id);
if (!c) return RX_GEN_ERR_ARG;
@@ -1156,12 +1182,17 @@ int rx_gen_promote(RxGenStore *store, const RxPromotionRequest *request, RxGenAu
* and lock-free: by contract no bind races an in-flight promotion. */
int recheck = store_bound(store);
if (recheck) {
- if (store->caller(store->caller_ctx, request->subject, &request->caller, RX_CALLER_OP_HOLD) != 0) {
- rc = RX_GEN_ERR_IDENTITY;
+ int crc = store->caller(store->caller_ctx, request->subject, &request->caller, RX_CALLER_OP_HOLD);
+ if (crc != 0) {
+ rc = caller_refusal(crc);
goto done;
}
held = 1;
}
+ /* R16 G6: a stop taken during the disk writes. A bound store holds the
+ * caller check, so no world stop lands between here and the flip. */
+ rc = halt_marked(store);
+ if (rc != RX_GEN_OK) goto done;
rc = commit_file(store, active_path, pointer, sizeof pointer, RX_CRASH_DURING_ROOT_FLIP);
if (rc == RX_GEN_OK) {
store->phases.flip_ns = monotonic_ns();
diff --git a/src/runtime/rx_generation.h b/src/runtime/rx_generation.h
index 812ef19ed..a20301a05 100644
--- a/src/runtime/rx_generation.h
+++ b/src/runtime/rx_generation.h
@@ -30,6 +30,12 @@
#define RX_GEN_ERR_VERIFY -48
#define RX_GEN_ERR_IO -49
#define RX_GEN_ERR_IDENTITY -50 /* caller credential absent, forged, stale or revoked */
+#define RX_GEN_ERR_HALTED -51 /* an operator emergency stop is in force (world or durable mark) */
+
+/* Durable mark of an operator emergency stop (R16 G6), written by the world into
+ * its halt directory (rx_world_set_halt_dir), the store directory. While it exists
+ * the store promotes nothing, bound or not. */
+#define RX_GEN_HALT_MARK "OPERATOR_HALT"
#define RX_GEN_MAX_OBJECTS 32u
#define RX_GEN_MAX_WORK 16u
diff --git a/src/runtime/rx_world.c b/src/runtime/rx_world.c
index 75ef0d125..d5a711ca1 100644
--- a/src/runtime/rx_world.c
+++ b/src/runtime/rx_world.c
@@ -4,13 +4,18 @@
#include "rx_world.h"
#include "rx_argus.h"
#include "sha256.h"
+#include "rx_generation.h" /* RX_GEN_HALT_MARK */
#include
+#include
+#include
#include
#include
#include
#include
+#include
#include
+#include
/* ---- helpers ------------------------------------------------------------ */
@@ -115,6 +120,8 @@ const char *rx_crumb_kind_name(RxCrumbKind k) {
case RX_CRUMB_RETIRE: return "RETIRE";
case RX_CRUMB_QUARANTINE: return "QUARANTINE";
case RX_CRUMB_CANCELLED: return "CANCELLED";
+ case RX_CRUMB_OPERATOR_STOP: return "OPERATOR_STOP";
+ case RX_CRUMB_OPERATOR_RESUME: return "OPERATOR_RESUME";
default: return "?";
}
}
@@ -876,12 +883,284 @@ int rx_world_caller_check_fn(void *world, uint32_t subject, const RxCallerCred *
return RX_CALLER_OK;
}
pthread_mutex_lock(&w->callers_mu);
+ /* R16 G6: under an operator stop a bound generation store neither
+ * proposes nor promotes. halted is written under callers_mu too. */
+ if (w->halted) {
+ pthread_mutex_unlock(&w->callers_mu);
+ return RX_CALLER_ERR_HALTED;
+ }
int rc = caller_check_locked(w, subject, cred);
/* HOLD: a pass keeps the table locked until RELEASE (no revocation). */
if (op != RX_CALLER_OP_HOLD || rc != RX_CALLER_OK) pthread_mutex_unlock(&w->callers_mu);
return rc;
}
+/* ---- R16 G6 operator emergency stop (spec/r16-operator-emergency-stop.md) ---- */
+
+static void stamp_cap(RxWorld *w, RxCrumb *k, uint32_t i, RxCapRef ref);
+
+static uint64_t realtime_ns(void) {
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
+}
+
+/* Caller holds mu and callers_mu. The credential, then the subject (no
+ * reaction ever added to this world runs under it), then the capability. */
+static int halt_authorize(RxWorld *w, uint32_t subject, const RxCallerCred *cred, RxCapRef cap) {
+ if (caller_check_locked(w, subject, cred) != RX_CALLER_OK) return RX_ERR_IDENTITY;
+ for (uint32_t i = 0; i < w->n_reactions; i++)
+ if (w->reactions[i].desc.subject == subject) return RX_ERR_AUTHORITY;
+ if (rx_world_validate_cap(w, cap, subject, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT, NULL)
+ != RX_CAP_OK)
+ return RX_ERR_AUTHORITY;
+ return RX_OK;
+}
+
+/* The mark's text: fixed lines, then "sha256 " over every byte before it. */
+static int halt_record(const RxHaltStatus *h, char *buf, size_t cap) {
+ int n = snprintf(buf, cap,
+ "aien-operator-halt v1\nseq %llu\nsubject %u\ncap %u %llu\nreason %d\n"
+ "t_ns %llu\ncrumb %llu\n",
+ (unsigned long long)h->seq, h->subject, h->cap.cap_id,
+ (unsigned long long)h->cap.generation,
+ (int)h->reason, (unsigned long long)h->t_ns, (unsigned long long)h->crumb);
+ return n > 0 && (size_t)n < cap ? n : -1;
+}
+
+static int seal_append(char *buf, size_t len, size_t cap) {
+ uint8_t d[32];
+ sha256_ctx c;
+ sha256_init(&c);
+ sha256_update(&c, (const uint8_t *)buf, len);
+ sha256_final(&c, d);
+ if (len + 8 + 64 + 2 > cap) return -1;
+ memcpy(buf + len, "sha256 ", 7);
+ for (int i = 0; i < 32; i++) snprintf(buf + len + 7 + 2 * i, 3, "%02x", d[i]);
+ buf[len + 71] = '\n';
+ buf[len + 72] = 0;
+ return (int)len + 72;
+}
+
+static int fsync_dir(const char *dir) {
+ int fd = open(dir, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (fd < 0) return -errno;
+ int rc = fsync(fd) == 0 ? 0 : -errno;
+ close(fd);
+ return rc;
+}
+
+/* Write `buf` to dir/name durably (temporary file, fsync, rename, fsync dir).
+ * With excl, an existing dir/name is never replaced (link, not rename). */
+static int durable_write(const char *dir, const char *name, const char *buf, size_t len, bool excl) {
+ char tmp[512], dst[512];
+ if (snprintf(tmp, sizeof tmp, "%s/%s.partial", dir, name) >= (int)sizeof tmp ||
+ snprintf(dst, sizeof dst, "%s/%s", dir, name) >= (int)sizeof dst)
+ return -ENAMETOOLONG;
+ int fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
+ if (fd < 0) return -errno;
+ size_t off = 0;
+ while (off < len) {
+ ssize_t n = write(fd, buf + off, len - off);
+ if (n < 0 && errno == EINTR) continue;
+ if (n <= 0) { int e = n < 0 ? errno : EIO; close(fd); unlink(tmp); return -e; }
+ off += (size_t)n;
+ }
+ if (fsync(fd) != 0) { int e = errno; close(fd); unlink(tmp); return -e; }
+ close(fd);
+ if (excl) {
+ if (link(tmp, dst) != 0) { int e = errno; unlink(tmp); return -e; }
+ unlink(tmp);
+ } else if (rename(tmp, dst) != 0) {
+ int e = errno; unlink(tmp); return -e;
+ }
+ return fsync_dir(dir);
+}
+
+static int halt_mark_write(const RxWorld *w) {
+ if (!w->halt_dir[0]) return 0;
+ char buf[512];
+ int n = halt_record(&w->halt, buf, sizeof buf);
+ if (n < 0 || (n = seal_append(buf, (size_t)n, sizeof buf)) < 0) return -EOVERFLOW;
+ int rc = durable_write(w->halt_dir, RX_GEN_HALT_MARK, buf, (size_t)n, false);
+ return rc == 0 ? 1 : rc;
+}
+
+/* Read dir/OPERATOR_HALT. 0 absent, 1 read and its seal holds (h filled),
+ * RX_ERR_TORN present but unreadable as a sealed record, RX_ERR_IO cannot tell. */
+static int halt_mark_read(const char *dir, RxHaltStatus *h, char *raw, size_t cap, size_t *raw_len) {
+ char path[512];
+ if (snprintf(path, sizeof path, "%s/%s", dir, RX_GEN_HALT_MARK) >= (int)sizeof path)
+ return RX_ERR_IO;
+ raw[0] = 0;
+ *raw_len = 0;
+ /* Never follow a link or block on a FIFO under the world locks: a mark that
+ * is not a regular file is damaged (TORN: the world stays stopped, and resume
+ * keeps a record and removes it, so the store is never blocked for good). */
+ int fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK);
+ if (fd < 0) return errno == ENOENT ? 0 : errno == ELOOP ? RX_ERR_TORN : RX_ERR_IO;
+ struct stat st;
+ if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) {
+ close(fd);
+ return RX_ERR_TORN;
+ }
+ ssize_t n = read(fd, raw, cap - 1);
+ close(fd);
+ if (n < 0) return RX_ERR_IO;
+ raw[n] = 0;
+ *raw_len = (size_t)n;
+ RxHaltStatus r;
+ memset(&r, 0, sizeof r);
+ unsigned long long seq, t, crumb, cgen;
+ unsigned subject, cid;
+ int reason, used = 0;
+ if (sscanf(raw, "aien-operator-halt v1\nseq %llu\nsubject %u\ncap %u %llu\nreason %d\n"
+ "t_ns %llu\ncrumb %llu\n%n",
+ &seq, &subject, &cid, &cgen, &reason, &t, &crumb, &used) != 7 || used <= 0)
+ return RX_ERR_TORN;
+ char want[600];
+ memcpy(want, raw, (size_t)used);
+ if (seal_append(want, (size_t)used, sizeof want) < 0 || strcmp(want, raw) != 0)
+ return RX_ERR_TORN;
+ r.seq = seq; r.subject = subject; r.cap.cap_id = cid; r.cap.generation = cgen;
+ r.reason = reason; r.t_ns = t; r.crumb = crumb;
+ *h = r;
+ return 1;
+}
+
+static uint64_t halt_crumb(RxWorld *w, RxCrumbKind kind, RxCapRef cap, int32_t reason,
+ uint64_t parent) {
+ RxCrumb k;
+ memset(&k, 0, sizeof k);
+ k.kind = kind;
+ k.reaction = UINT32_MAX;
+ k.faculty = RX_FACULTY_EXTERNAL;
+ k.worker = UINT32_MAX;
+ k.n_caps = 1;
+ stamp_cap(w, &k, 0, cap);
+ add_parent(&k, parent);
+ k.reason = reason;
+ k.t_start_ns = now_ns();
+ k.t_end_ns = k.t_start_ns;
+ return crumb_append(w, &k);
+}
+
+int rx_world_set_halt_dir(RxWorld *w, const char *dir) {
+ if (!w || !dir || !dir[0] || strlen(dir) >= sizeof w->halt_dir) return RX_ERR_ARG;
+ pthread_mutex_lock(&w->mu);
+ pthread_mutex_lock(&w->callers_mu);
+ snprintf(w->halt_dir, sizeof w->halt_dir, "%s", dir);
+ RxHaltStatus h;
+ char raw[600];
+ size_t raw_len = 0;
+ int rc = halt_mark_read(dir, &h, raw, sizeof raw, &raw_len);
+ if (rc == 0 && w->halted) {
+ w->halt.durable = halt_mark_write(w); /* a stop taken before the directory was set */
+ } else if (rc != 0 && !w->halted) {
+ /* A stop outlives the process: the world starts stopped. A mark that
+ * cannot be read or verified still stops it (unknown is not "go"). */
+ if (rc != 1) {
+ memset(&h, 0, sizeof h);
+ h.reason = rc;
+ }
+ h.halted = true;
+ h.restored = true;
+ h.durable = 1;
+ h.refused = w->halt.refused;
+ h.crumb = halt_crumb(w, RX_CRUMB_OPERATOR_STOP, h.cap, h.reason, 0);
+ w->halt = h;
+ w->halted = true;
+ }
+ pthread_mutex_unlock(&w->callers_mu);
+ pthread_mutex_unlock(&w->mu);
+ return rc;
+}
+
+int rx_world_emergency_stop(RxWorld *w, uint32_t subject, const RxCallerCred *cred,
+ RxCapRef cap, int32_t reason, RxHaltStatus *out) {
+ if (!w) return RX_ERR_ARG;
+ /* mu then callers_mu (R16 C7 order): a commit or seat result holds mu from
+ * its checks to its publish, and a promotion holds callers_mu (HOLD) across
+ * its flip, so each finishes before the stop or sees it. */
+ pthread_mutex_lock(&w->mu);
+ pthread_mutex_lock(&w->callers_mu);
+ int rc = halt_authorize(w, subject, cred, cap);
+ if (rc == RX_OK && w->halted) rc = RX_HALT_ALREADY;
+ if (rc == RX_OK) {
+ RxHaltStatus h;
+ memset(&h, 0, sizeof h);
+ h.halted = true;
+ h.seq = w->halt.seq + 1;
+ h.subject = subject;
+ h.cap = cap;
+ h.reason = reason;
+ h.t_ns = realtime_ns();
+ h.refused = w->halt.refused;
+ h.crumb = halt_crumb(w, RX_CRUMB_OPERATOR_STOP, cap, reason, 0);
+ w->halt = h;
+ w->halted = true; /* in force before any disk work */
+ w->halt.durable = halt_mark_write(w);
+ }
+ if (out) *out = w->halt;
+ pthread_mutex_unlock(&w->callers_mu);
+ pthread_mutex_unlock(&w->mu);
+ return rc;
+}
+
+int rx_world_emergency_resume(RxWorld *w, uint32_t subject, const RxCallerCred *cred,
+ RxCapRef cap, RxHaltStatus *out) {
+ if (!w) return RX_ERR_ARG;
+ pthread_mutex_lock(&w->mu);
+ pthread_mutex_lock(&w->callers_mu);
+ int rc = halt_authorize(w, subject, cred, cap);
+ if (rc == RX_OK && !w->halted) rc = RX_HALT_NOT_STOPPED;
+ if (rc == RX_OK && w->halt_dir[0]) {
+ /* The stop record is kept, never deleted: its bytes, then the resume,
+ * sealed together under a name no later resume can take; only then is
+ * the mark removed. Any failure leaves the world stopped. */
+ RxHaltStatus disk;
+ char raw[600];
+ size_t raw_len = 0;
+ int mr = halt_mark_read(w->halt_dir, &disk, raw, sizeof raw, &raw_len);
+ if (mr == RX_ERR_IO) rc = RX_ERR_IO;
+ else if (mr != 0) {
+ char buf[1200], name[160];
+ uint64_t t = realtime_ns();
+ int n = snprintf(buf, sizeof buf, "%s%sresumed_by %u\nresume_cap %u %llu\nresume_t_ns %llu\n",
+ raw, raw_len && raw[raw_len - 1] != '\n' ? "\n" : "", subject,
+ cap.cap_id, (unsigned long long)cap.generation, (unsigned long long)t);
+ if (n < 0 || (size_t)n >= sizeof buf || (n = seal_append(buf, (size_t)n, sizeof buf)) < 0)
+ rc = RX_ERR_IO;
+ snprintf(name, sizeof name, "%s.resumed.%llu.%llu", RX_GEN_HALT_MARK,
+ (unsigned long long)w->halt.seq, (unsigned long long)t);
+ if (rc == RX_OK && durable_write(w->halt_dir, name, buf, (size_t)n, true) != 0)
+ rc = RX_ERR_IO;
+ char mark[512];
+ snprintf(mark, sizeof mark, "%s/%s", w->halt_dir, RX_GEN_HALT_MARK);
+ if (rc == RX_OK && (unlink(mark) != 0 || fsync_dir(w->halt_dir) != 0)) rc = RX_ERR_IO;
+ }
+ }
+ if (rc == RX_OK) {
+ halt_crumb(w, RX_CRUMB_OPERATOR_RESUME, cap, 0, w->halt.crumb);
+ w->halted = false;
+ w->halt.halted = false;
+ w->halt.restored = false;
+ pthread_cond_broadcast(&w->work_cv);
+ }
+ if (out) *out = w->halt;
+ pthread_mutex_unlock(&w->callers_mu);
+ pthread_mutex_unlock(&w->mu);
+ return rc;
+}
+
+void rx_world_halt_status(RxWorld *w, RxHaltStatus *out) {
+ if (!w || !out) return;
+ pthread_mutex_lock(&w->mu);
+ *out = w->halt;
+ out->halted = w->halted;
+ pthread_mutex_unlock(&w->mu);
+}
+
static int validate_caps(const RxWorld *w, const RxReactionDesc *d, int *first_err) {
/* R16 C5: the subject the capabilities are checked against is the one
* this reaction was admitted under, and that admission still stands. */
@@ -1548,6 +1827,24 @@ static void run_one(RxWorld *w, uint32_t rid, uint32_t worker) {
return;
}
+ /* R16 G6 operator emergency stop: the stop was taken while this
+ * activation computed. Nothing it proposed is published; it runs again
+ * on resume, against the state then (rearm keeps its admission path). */
+ if (w->halted) {
+ set_state(w, r, RX_CANCELLED);
+ k.kind = RX_CRUMB_CANCELLED;
+ k.reason = RX_ERR_HALTED;
+ k.t_end_ns = now_ns();
+ crumb_append(w, &k);
+ w->halt.refused++;
+ /* A refused activation is not spent: it must not count toward the
+ * episode budget, or the re-run could be quarantined instead. */
+ if (r->episode_activations) r->episode_activations--;
+ r->rearm = true;
+ end_activation(w, rid);
+ return;
+ }
+
set_state(w, r, RX_PUBLISHING);
/* 1. Versioned reads still valid? */
bool stale = false;
@@ -1688,7 +1985,8 @@ static void *worker_main(void *arg) {
#if RX_ARGUS
int argus_parked = 0;
#endif
- while (!w->stopping && !pop_ready(w, &rid)) {
+ /* R16 G6: under an operator stop no work is taken; resume broadcasts. */
+ while (!w->stopping && (w->halted || !pop_ready(w, &rid))) {
#if RX_ARGUS
/* ARGUS: before the first wait of a park, flush this worker's use table
* and publish idle. The flush touches only this thread's own ARGUS slot,
@@ -1870,6 +2168,11 @@ void rx_world_destroy(RxWorld *w) {
int rx_world_create(RxWorld *w, uint32_t type, RxPersist persist, uint64_t resource,
const uint64_t init[RX_MAX_FIELDS], RxObjRef *out) {
pthread_mutex_lock(&w->mu);
+ if (w->halted) { /* R16 G6: nothing new commits under a stop */
+ w->halt.refused++;
+ pthread_mutex_unlock(&w->mu);
+ return RX_ERR_HALTED;
+ }
for (uint32_t i = 0; i < RX_MAX_OBJECTS; i++) {
RxObject *o = &w->objects[i];
if (o->live) continue;
@@ -1917,6 +2220,11 @@ int rx_world_create(RxWorld *w, uint32_t type, RxPersist persist, uint64_t resou
int rx_world_retire(RxWorld *w, RxObjRef ref) {
pthread_mutex_lock(&w->mu);
+ if (w->halted) { /* R16 G6: nothing new commits under a stop */
+ w->halt.refused++;
+ pthread_mutex_unlock(&w->mu);
+ return RX_ERR_HALTED;
+ }
if (!ref_live(w, ref)) {
pthread_mutex_unlock(&w->mu);
return RX_ERR_STALE_GEN;
@@ -2120,6 +2428,11 @@ int rx_world_add_reaction_keyed(RxWorld *w, const RxCallerKeyring *keys,
int64_t rx_world_publish_external(RxWorld *w, RxCapRef cap, const RxMutation *muts, uint32_t n) {
if (!muts || n == 0 || n > RX_MAX_MUTATIONS) return RX_ERR_ARG;
pthread_mutex_lock(&w->mu);
+ if (w->halted) { /* R16 G6: nothing outside publishes */
+ w->halt.refused++;
+ pthread_mutex_unlock(&w->mu);
+ return RX_ERR_HALTED;
+ }
for (uint32_t i = 0; i < n; i++) {
if (!ref_live(w, muts[i].obj)) { pthread_mutex_unlock(&w->mu); return RX_ERR_STALE_GEN; }
int rc = rx_world_validate_cap(w, cap, w->external_subject,
@@ -2233,6 +2546,25 @@ int rx_resident_accept(RxWorld *w) {
add_parent(&k, a->field_writer[1]);
}
+ /* R16 G6 operator emergency stop: a seat result that lands while the
+ * world is stopped is not published. The image is re-projected from the
+ * world, the activation ends CANCELLED and runs again on resume. */
+ if (w->halted) {
+ if (o->placed) rx_coherent_project(w, id);
+ if (r->state == RX_RUNNING) set_state(w, r, RX_CANCELLED);
+ k.kind = RX_CRUMB_CANCELLED;
+ k.reason = RX_ERR_HALTED;
+ k.t_end_ns = now_ns();
+ crumb_append(w, &k);
+ r->resident_seat = false;
+ w->stats.resident_closed++;
+ w->halt.refused++;
+ if (r->episode_activations) r->episode_activations--; /* not spent */
+ r->rearm = true;
+ end_activation(w, (uint32_t)rid);
+ pthread_mutex_unlock(&w->mu);
+ return RX_ERR_HALTED;
+ }
if (tr != RX_OK) {
if (o->placed) rx_coherent_project(w, id);
seat_fail(w, (uint32_t)rid, &k, RX_CRUMB_REJECTED, tr);
@@ -2432,6 +2764,7 @@ int rx_world_seq_activate_timed_locked(RxWorld *w, uint32_t rid, uint64_t cause,
if (!w || !w->sequential || rid >= w->n_reactions) return RX_ERR_ARG;
RxReaction *r = &w->reactions[rid];
if (r->state != RX_DORMANT || r->removed) return RX_ERR_ARG; /* removed: never demanded */
+ if (w->halted) return RX_ERR_HALTED; /* R16 G6 operator emergency stop */
r->seq_pending = false;
demand(w, rid, cause); /* R6 budgets and quarantine, unchanged */
if (!r->seq_pending) return 0;
diff --git a/src/runtime/rx_world.h b/src/runtime/rx_world.h
index 85f594731..5743a3e22 100644
--- a/src/runtime/rx_world.h
+++ b/src/runtime/rx_world.h
@@ -99,8 +99,13 @@ typedef enum {
RX_CRUMB_NOOP, /* ran, proposed no change: fixed point */
RX_CRUMB_RETIRE,
RX_CRUMB_QUARANTINE, /* an R6 limit stopped this reaction; reason names it */
- RX_CRUMB_CANCELLED /* HD-09: ran past its declared deadline; nothing
- published; reason RX_ERR_DEADLINE */
+ RX_CRUMB_CANCELLED, /* HD-09: ran past its declared deadline; nothing
+ published; reason RX_ERR_DEADLINE, or
+ RX_ERR_HALTED when an operator stop refused it */
+ /* R16 G6 operator emergency control (spec/r16-operator-emergency-stop.md):
+ * reaction UINT32_MAX, caps[0] the operator's control capability. */
+ RX_CRUMB_OPERATOR_STOP, /* a stop took effect; reason = the operator's code */
+ RX_CRUMB_OPERATOR_RESUME /* a stopped world resumed; parent = its stop */
} RxCrumbKind;
/* Which R6 limit engaged (reason of a QUARANTINE crumb). */
@@ -127,6 +132,8 @@ enum { RX_CONTAIN_BUDGET = 1, RX_CONTAIN_OSCILLATION, RX_CONTAIN_LIVELOCK,
#define RX_ERR_BINDING -28 /* a bound field's external reference was refused (COMPOSITION-2) */
#define RX_ERR_BUSY -29 /* the reaction still has work pending (rx_world_remove_reaction) */
#define RX_ERR_DEADLINE -30 /* the logical tick passed the declared deadline (RX_CRUMB_CANCELLED) */
+#define RX_ERR_HALTED -31 /* operator emergency stop in force (RX_CRUMB_CANCELLED) */
+#define RX_ERR_IO -32 /* an operator-stop mark could not be read or retired */
/* Reaction notices carried in the frozen 128-byte descriptor.
* The older transform request/result values stay in the frozen layout and
@@ -510,6 +517,20 @@ typedef int (*RxAuthValidateFn)(const void *ctx, RxCapRef ref, uint32_t subject,
uint64_t resource, uint32_t rights, RxCapEntry *out);
typedef int (*RxAuthInspectFn)(const void *ctx, RxCapRef ref, RxCapEntry *out);
+/* State of the R16 G6 operator emergency stop (rx_world_halt_status). */
+typedef struct {
+ bool halted;
+ bool restored; /* this stop was read back from the durable mark */
+ uint64_t seq; /* stops taken (a restored stop keeps its number) */
+ uint32_t subject; /* operator of the stop in force or last lifted */
+ RxCapRef cap; /* the control capability that operator presented */
+ int32_t reason; /* the operator's reason code */
+ uint64_t crumb; /* its OPERATOR_STOP crumb (0 if the log was full) */
+ uint64_t t_ns; /* CLOCK_REALTIME of the stop */
+ int durable; /* 1 mark on disk; 0 no halt dir; < 0 -errno of the write */
+ uint64_t refused; /* activations, publications, seat results, creates and retires refused */
+} RxHaltStatus;
+
/* Durable recorder (M20 Cortex). Called with the world mutex held, once per
* crumb, after the crumb is in the log; it reads the world and must not call
* back into it. It cannot veto or fail the commit it records. The one
@@ -641,6 +662,13 @@ typedef struct RxWorld {
uint64_t caller_generation; /* last generation issued */
bool callers_bound; /* one way: set once, never cleared */
+ /* R16 G6 operator emergency stop (spec/r16-operator-emergency-stop.md).
+ * Written under mu and callers_mu together, so either lock reads it.
+ * No worker takes work and nothing publishes while it is set. */
+ bool halted;
+ RxHaltStatus halt;
+ char halt_dir[384]; /* durable mark directory; "" = none */
+
/* M20 durable recorder (rx_world_set_recorder); at most one. */
RxRecordFn recorder;
RxRecordReleaseFn recorder_release;
@@ -772,6 +800,31 @@ int rx_world_revoke_caller(RxWorld *w, uint32_t subject, const RxCallerCred *cr
int rx_world_check_caller(RxWorld *w, uint32_t subject, const RxCallerCred *cred);
int rx_world_caller_check_fn(void *world, uint32_t subject, const RxCallerCred *cred, int op);
+/* ---- R16 G6 operator emergency stop (spec/r16-operator-emergency-stop.md) ----
+ * Authority: the caller credential of `subject` (rx_world_enroll_caller) AND a
+ * capability for `subject` on RX_WORLD_RES_CONTROL carrying RX_WORLD_RIGHT_HALT,
+ * validated by the world's authority. A subject any registered reaction runs
+ * under is refused: no reaction can stop or resume the world it runs in.
+ * Stop: no worker takes work, a computed activation is refused at its commit
+ * (CANCELLED, RX_ERR_HALTED) and re-run on resume, outside publications and
+ * seat results are refused, object create and retire are refused, and the
+ * caller check refuses so a bound generation store neither proposes nor
+ * promotes. A refused activation does not count toward the episode budget. Work already committing
+ * finishes first (the stop waits for the world lock). A durable mark is
+ * written when a halt directory is set; the stop takes effect even if that
+ * write fails (`durable` < 0 says so). Never call with mu held. */
+#define RX_WORLD_RES_CONTROL 0x906ull /* the world's control resource */
+#define RX_WORLD_RIGHT_HALT RX_RIGHT_EPOCH /* the right that may void every
+ capability may also pause the world */
+#define RX_HALT_ALREADY 1 /* stop: already stopped, nothing changed */
+#define RX_HALT_NOT_STOPPED 2 /* resume: not stopped, nothing changed */
+int rx_world_set_halt_dir(RxWorld *w, const char *dir);
+int rx_world_emergency_stop(RxWorld *w, uint32_t subject, const RxCallerCred *cred,
+ RxCapRef cap, int32_t reason, RxHaltStatus *out);
+int rx_world_emergency_resume(RxWorld *w, uint32_t subject, const RxCallerCred *cred,
+ RxCapRef cap, RxHaltStatus *out);
+void rx_world_halt_status(RxWorld *w, RxHaltStatus *out);
+
/* A stimulus from outside the organism (sensor, human input). Requires a
* capability for (external_subject, object resource, WRITE). Returns the
* causal id of the EXTERNAL crumb, or a negative error. */
diff --git a/tests/.crumb b/tests/.crumb
index f550e209e..b34e8a0ed 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -229,8 +229,8 @@
"purpose": "Directory tests/r16_inventory. Purpose not yet described by a human."
},
{
- "digest": "bcbd86e0fc80826cf66b7c2bbd71b6eab93c539313dbd042f30f3bb1fd3c5659",
- "last_commit": "e798fb7",
+ "digest": "000c487afa8f600842eff25a22a671afb5e29b26845105405de9542a21b70746",
+ "last_commit": "420a0ff",
"name": "r16_negative",
"purpose": "Directory tests/r16_negative. Purpose not yet described by a human."
},
@@ -253,8 +253,8 @@
"purpose": "Directory tests/relations. Purpose not yet described by a human."
},
{
- "digest": "471d1ac8ecb149b58ee57d6f9b8e17ac59f21935f83fd6d6281fdc2a057b0678",
- "last_commit": "57e0e5f",
+ "digest": "d48420b3eb071836762debb1f1eed6febb4b0b27bf0379175e2a2d4451b70358",
+ "last_commit": "984aa1e",
"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:5931b109ad80c3fe8f2a1d88ca77be3b288a5b3c61334e07eb278b329d36504c",
- "compiled_at": "2026-10-05T16:20:55Z",
+ "children_root": "sha256:741af2870f086e5e556c26f1007a78ffc1ed055f1f515d8d3712e92b7e209be8",
+ "compiled_at": "2026-10-05T17:22:20Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:09c803a2d62bcda0b85e84c70399d270bda18d335e77270c58567746abf1f173",
+ "digest": "sha256:a7f97a1cd886fa4dfb2f66b766c2948200d0858dc26788d65682ab1c8a4646a5",
"evidence_files": 11,
"evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2",
- "files": 804,
- "generated_at_commit": "bfe4be858d65d5441ee98434945db8fe816dfeff",
- "source_tree": "sha256:68a1ac1a9d06f6619ffa123b22d767a69a8bc0b3b3f80d1dfad29a2ea0f53dd4"
+ "files": 806,
+ "generated_at_commit": "420a0ff7d7fe6c6f473c01e9871012609aafd0de",
+ "source_tree": "sha256:da58c8c1ee12613db888c753ddf8243437b941b2c8d5aa351e2a8a4beae92592"
},
"owner_lane": "",
"provenance": {
diff --git a/tests/r16_negative/.crumb b/tests/r16_negative/.crumb
index 56b37ebce..50b644e02 100644
--- a/tests/r16_negative/.crumb
+++ b/tests/r16_negative/.crumb
@@ -7,14 +7,14 @@
"generated": {
"children": [],
"children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "compiled_at": "2026-10-05T15:04:25Z",
+ "compiled_at": "2026-10-05T17:22:20Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:bcbd86e0fc80826cf66b7c2bbd71b6eab93c539313dbd042f30f3bb1fd3c5659",
+ "digest": "sha256:000c487afa8f600842eff25a22a671afb5e29b26845105405de9542a21b70746",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 1,
- "generated_at_commit": "509fc2f2a20331b9c950fbc495b4fffb0a9825a6",
- "source_tree": "sha256:9b33cab85ea4c1600c98617d009e0257f303bf7e94f7ae8a81f8c949d2b5d2a7"
+ "generated_at_commit": "420a0ff7d7fe6c6f473c01e9871012609aafd0de",
+ "source_tree": "sha256:752bd899e0045807d5f8ee2ecbbfe258a03bf2bd43a5a1704e0b5635a05c4695"
},
"owner_lane": "",
"provenance": {
diff --git a/tests/r16_negative/mutate.sh b/tests/r16_negative/mutate.sh
index 4c7801db7..4e0076edd 100755
--- a/tests/r16_negative/mutate.sh
+++ b/tests/r16_negative/mutate.sh
@@ -169,10 +169,9 @@ mutant id_revoke_needs_credential $W 1 'if (rc == RX_CALLER_OK) {' 'if (rc == RX
mutant id_enroll_closed $W 1 \
'if (w->callers_bound) { rc = RX_CALLER_ERR_CLOSED; goto out; }' '(void)0;'
mutant id_promote $G 1 \
- 'if (store->caller(store->caller_ctx, request->subject, &request->caller, RX_CALLER_OP_CHECK) != 0)' 'if (0)'
+ 'int crc = store->caller(store->caller_ctx, request->subject, &request->caller, RX_CALLER_OP_CHECK);' 'int crc = 0;'
mutant id_propose $G 1 \
- 'if (store_bound(store) && store->caller(store->caller_ctx, proposer, cred, RX_CALLER_OP_CHECK) != 0)' \
- 'if (0 && store_bound(store) && store->caller(store->caller_ctx, proposer, cred, RX_CALLER_OP_CHECK) != 0)'
+ 'int crc = store->caller(store->caller_ctx, proposer, cred, RX_CALLER_OP_CHECK);' 'int crc = 0; (void)proposer; (void)cred;'
mutant id_bound_authority $G 1 'auth = store->bound_auth;' '(void)0;'
# R16 C7: outside review of C5/C6. Each removes one fix; spec C7 names the probe.
@@ -188,11 +187,9 @@ mutant c7_mutate_object_bound $G 1 \
mutant c7_set_evidence_bound $G 2 \
'if (store_bound(store)) return RX_GEN_ERR_IDENTITY;' '(void)0;'
mutant c7_add_work_credential $G 1 \
- 'if (store_bound(store) && store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK) != 0)' \
- 'if (0 && store_bound(store) && store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK) != 0)'
+ 'int crc = store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK);' 'int crc = 0; (void)subject; (void)cred;'
mutant c7_finish_work_credential $G 2 \
- 'if (store_bound(store) && store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK) != 0)' \
- 'if (0 && store_bound(store) && store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK) != 0)'
+ 'int crc = store->caller(store->caller_ctx, subject, cred, RX_CALLER_OP_CHECK);' 'int crc = 0; (void)subject; (void)cred;'
mutant c7_add_work_state $G 1 'if (!starts_open) return RX_GEN_ERR_ARG;' '(void)starts_open;'
echo "R16 G4 mutants: $total total, $killed killed, $survived survived, $broken broken"
diff --git a/tests/r16_qualify/run.sh b/tests/r16_qualify/run.sh
index 04cbafb66..e2b3b0b2b 100755
--- a/tests/r16_qualify/run.sh
+++ b/tests/r16_qualify/run.sh
@@ -224,6 +224,8 @@ g6_good_logs() {
g6log r7_native.log "native authority matched the linux oracle"
g6log r12_host.log "checks 40 failures 0"
g6log r12_silicon.log "checks 40 failures 0 silicon 1"
+ g6log rx_emergency.log "RX_EMERGENCY_STOP: PASS (0 failures; host CPU, real caproot authority)
+RX_EMERGENCY_MUTANTS: PASS"
g6log r13_host.log "R13 gate: R13_LIVING_SYSTEM=HOST_PASS_NON_SILICON"
g6log r14_host.log "R14 gate: R14_LIVING_RECOVERY=HOST_PASS_NON_SILICON"
g6log r14_silicon.log "R14 gate: R14_LIVING_RECOVERY=PASS"
@@ -375,6 +377,20 @@ check "G6 receipt is valid JSON (jq)" 'jq -e . "$R" >/dev/null'
check "G6 receipt: twelve items, twelve different basis texts" '[ "$(jq "[.g6_items[].basis] | unique | length" "$R")" = 12 ] && [ "$(jq ".g6_items | length" "$R")" = 12 ]'
check "G6 receipt: proxy mappings say PROXY, emergency item says MISSING_IMPLEMENTATION" '[ "$(jq "[.g6_items[] | select(.basis | startswith(\"PROXY\"))] | length" "$R")" -ge 5 ] && jq -e ".g6_items[] | select(.item==\"operator_emergency_controls_passing\") | .basis | startswith(\"MISSING_IMPLEMENTATION\")" "$R" >/dev/null'
check "G6 receipt: seat kill hook is not an item symbol" '! jq -e ".g6_items[].implementation[] | select(.symbol==\"rx_gpu_seat_kill\")" "$R" >/dev/null'
+check "G6 emergency item: runtime symbols defined, production wiring absent, RX_EMERGENCY cited" 'jq -e ".g6_items[] | select(.item==\"operator_emergency_controls_passing\") | (.implementation[] | select(.symbol==\"rx_world_emergency_stop\") | .defined == true) and (.implementation[] | select(.symbol==\"rx_world_set_halt_dir\") | .defined == false) and (.tests[] | select(.name==\"RX_EMERGENCY\") | .status == \"PASS\" and .target == \"test-rx-emergency\")" "$R" >/dev/null'
+g6log rx_emergency.log "RX_EMERGENCY_STOP: PASS (0 failures; host CPU, real caproot authority)"
+out=$(G6Q)
+check "G6 emergency test without the mutant pass line: test FAIL in the receipt, item still MISSING_IMPLEMENTATION, G6 never PASS" '! echo "$out" | grep -q "G6=PASS" && [ "$(g6_item operator_emergency_controls_passing)" = MISSING_IMPLEMENTATION ] && jq -e ".g6_items[] | select(.item==\"operator_emergency_controls_passing\") | .tests[] | select(.name==\"RX_EMERGENCY\") | .status == \"FAIL\"" "$R" >/dev/null'
+g6log rx_emergency.log "RX_EMERGENCY_MUTANTS: PASS"
+out=$(G6Q)
+check "G6 emergency test without the stop pass line: test FAIL in the receipt" 'jq -e ".g6_items[] | select(.item==\"operator_emergency_controls_passing\") | .tests[] | select(.name==\"RX_EMERGENCY\") | .status == \"FAIL\"" "$R" >/dev/null'
+g6log rx_emergency.log "RX_EMERGENCY_STOP: PASS (0 failures; host CPU, real caproot authority)
+RX_EMERGENCY_MUTANTS: PASS" 1
+out=$(G6Q)
+check "G6 emergency test exit 1 with both pass lines: test FAIL in the receipt" 'jq -e ".g6_items[] | select(.item==\"operator_emergency_controls_passing\") | .tests[] | select(.name==\"RX_EMERGENCY\") | .status == \"FAIL\"" "$R" >/dev/null'
+g6log rx_emergency.log "RX_EMERGENCY_STOP: PASS (0 failures; host CPU, real caproot authority)
+RX_EMERGENCY_MUTANTS: PASS"
+out=$(G6Q)
rm -rf "$G"
# 9. the script holds no literal for observed fields and does not touch tracked evidence
diff --git a/tests/runtime/.crumb b/tests/runtime/.crumb
index 97f120cca..cc3061976 100644
--- a/tests/runtime/.crumb
+++ b/tests/runtime/.crumb
@@ -7,14 +7,14 @@
"generated": {
"children": [],
"children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "compiled_at": "2026-10-05T15:00:18Z",
+ "compiled_at": "2026-10-05T17:01:01Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:471d1ac8ecb149b58ee57d6f9b8e17ac59f21935f83fd6d6281fdc2a057b0678",
+ "digest": "sha256:d48420b3eb071836762debb1f1eed6febb4b0b27bf0379175e2a2d4451b70358",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
- "files": 55,
- "generated_at_commit": "a386d65ed193a02dccac444de3fd3224c96162b4",
- "source_tree": "sha256:cceeea5f8ce01092b50ea98d6a52b12762de66d2b649c5635a6cdaafcbdc1894"
+ "files": 57,
+ "generated_at_commit": "714835409175f776b4a5630d892cf9383ba43b44",
+ "source_tree": "sha256:c6436bd74923307a6393b12f66beaf3df51e0671b1a1d219cc670cc6fcde9268"
},
"owner_lane": "",
"provenance": {
diff --git a/tests/runtime/rx_emergency.c b/tests/runtime/rx_emergency.c
new file mode 100644
index 000000000..301f011e5
--- /dev/null
+++ b/tests/runtime/rx_emergency.c
@@ -0,0 +1,798 @@
+/*
+ * R16 G6 operator emergency stop (spec/r16-operator-emergency-stop.md).
+ *
+ * Real authority (the rx_caproot root process), real caller credentials, a
+ * worker pool and a generation store. Every case states what must hold:
+ *
+ * E1 refusals no credential, a forged credential, another subject's
+ * capability, the wrong right, the wrong resource, a revoked
+ * capability, and a reaction's own subject holding a valid
+ * control capability: each refused with its code; the world
+ * digest, the crumb count and the halt state are unchanged.
+ * E2 stop an authorized stop takes effect at once (OPERATOR_STOP crumb
+ * naming the capability and the reason); a second stop answers
+ * RX_HALT_ALREADY and changes nothing; outside publication is
+ * refused (RX_ERR_HALTED) and changes nothing.
+ * E3 in flight a stop taken while a reaction computes: its result is not
+ * published (CANCELLED, RX_ERR_HALTED), work queued behind it is
+ * not taken; on resume both run and each commits exactly once.
+ * E4 race publishers and two operators racing stop/resume: in the crumb
+ * log no EXTERNAL or COMMIT lies between a STOP and its RESUME,
+ * each accepted stop has exactly one STOP crumb, every refused
+ * publication returned RX_ERR_HALTED, and the chain verifies.
+ * E5 promotion a stop during a promotion's live barrier and during its disk
+ * writes refuses that promotion (RX_GEN_ERR_HALTED, active
+ * generation unchanged in memory and on disk); a proposal under
+ * a stop is refused; after resume the same promoter promotes.
+ * E6 durable the stop writes a sealed mark; a new world over the same
+ * directory starts stopped (restored); a mark with one byte
+ * changed still stops it (RX_ERR_TORN); an unbound store will not
+ * promote while the mark exists; resume keeps the stop record in
+ * a sealed OPERATOR_HALT.resumed.* file and removes the mark; a
+ * resume that cannot retire the mark leaves the world stopped.
+ * E7 budget a stop while R3 (woken by another reaction's commit) computes,
+ * with an activation budget of 1: the refused activation does not
+ * spend the budget, R3 is not quarantined and runs on resume;
+ * object create and retire are refused under the stop and change
+ * nothing; a symlink mark stops a new world (TORN) and resume
+ * removes it.
+ *
+ * Host only, CPU only. Exit 0 = PASS.
+ */
+#include "runtime/rx_caproot.h"
+#include "runtime/rx_generation.h"
+#include "runtime/rx_world.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define U(x) ((unsigned long long)(x))
+
+static int g_fail;
+static void check(int ok, const char *what) {
+ printf("%s %s\n", ok ? "[+]" : "[-]", what);
+ if (!ok) g_fail++;
+}
+
+enum { RES_E = 0x710, RES_O = 0x711, RES_Q = 0x712 };
+enum { SUBJ_EXT = 9001, SUBJ_R = 9002, SUBJ_R2 = 9003, SUBJ_R3 = 9004, OP = 9100, OP2 = 9101, INTRUDER = 9102 };
+
+/* ---- gate: R parks in its function until released ------------------------- */
+static struct {
+ pthread_mutex_t mu;
+ pthread_cond_t cv;
+ int armed, armed3, inside, go;
+} g = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0, 0 };
+static int g_with_r3; /* setup adds R3, a reaction woken by R's commit (E7) */
+
+typedef struct {
+ RxCapRoot root;
+ RxCapAdmin admin;
+ RxWorld w;
+ RxObjRef e, o, q;
+ uint32_t id_r, id_r2, id_r3;
+ RxCapRef c_ext, c_op, c_op2;
+ RxCallerCred cr_op, cr_op2, cr_intr, cr_r, cr_r2, cr_r3;
+} Env;
+
+static int fn_r(RxCtx *c) {
+ Env *e = c->user;
+ pthread_mutex_lock(&g.mu);
+ if (g.armed) {
+ g.inside = 1;
+ pthread_cond_broadcast(&g.cv);
+ while (!g.go) pthread_cond_wait(&g.cv, &g.mu);
+ g.go = 0;
+ g.inside = 0;
+ g.armed = 0;
+ }
+ pthread_mutex_unlock(&g.mu);
+ c->n_out = 1;
+ c->out[0] = (RxMutation){ e->o, 0, c->in[0].field[0] + 1 };
+ return 0;
+}
+
+static int fn_r2(RxCtx *c) {
+ Env *e = c->user;
+ c->n_out = 1;
+ c->out[0] = (RxMutation){ e->q, 0, c->in[0].field[1] * 10 };
+ return 0;
+}
+
+/* R3: woken by R's commit on O (an internal cause, so its episode budget is not
+ * reset by the wake), held in its function when armed3 is set. */
+static int fn_r3(RxCtx *c) {
+ Env *e = c->user;
+ pthread_mutex_lock(&g.mu);
+ if (g.armed3) {
+ g.inside = 1;
+ pthread_cond_broadcast(&g.cv);
+ while (!g.go) pthread_cond_wait(&g.cv, &g.mu);
+ g.go = 0;
+ g.inside = 0;
+ g.armed3 = 0;
+ }
+ pthread_mutex_unlock(&g.mu);
+ c->n_out = 1;
+ c->out[0] = (RxMutation){ e->q, 1, c->in[0].field[0] * 100 };
+ return 0;
+}
+
+static RxCapRef mint(Env *e, uint32_t subject, uint64_t resource, uint32_t rights) {
+ RxCapMint m;
+ memset(&m, 0, sizeof m);
+ m.issuer = 1;
+ m.subject = subject;
+ m.resource = resource;
+ m.rights = rights;
+ m.parent = (RxCapRef){ UINT32_MAX, 0 };
+ m.authority = rx_capadmin_office(&e->admin);
+ RxCapRef r = { UINT32_MAX, 0 };
+ if (rx_capadmin_mint(&e->admin, &m, &r) != RX_CAP_OK) fprintf(stderr, "mint failed\n");
+ return r;
+}
+
+static RxObjRef mkobj(Env *e, uint64_t resource) {
+ uint64_t init[RX_MAX_FIELDS] = { 0 };
+ RxObjRef r = { UINT32_MAX, 0 };
+ rx_world_create(&e->w, 1, RX_PERSIST_RESIDENT, resource, init, &r);
+ return r;
+}
+
+static int setup(Env *e, uint32_t workers, uint64_t crumb_cap) {
+ memset(e, 0, sizeof *e);
+ if (rx_caproot_start(&e->root, &e->admin) != RX_CAP_OK) return -1;
+ if (rx_world_init(&e->w, &e->root, workers, crumb_cap) != RX_OK) return -1;
+ e->w.external_subject = SUBJ_EXT;
+ e->e = mkobj(e, RES_E);
+ e->o = mkobj(e, RES_O);
+ e->q = mkobj(e, RES_Q);
+ e->c_ext = mint(e, SUBJ_EXT, RES_E, RX_RIGHT_WRITE);
+ e->c_op = mint(e, OP, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT);
+ e->c_op2 = mint(e, OP2, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT);
+ if (rx_world_enroll_caller(&e->w, OP, &e->cr_op) != RX_CALLER_OK ||
+ rx_world_enroll_caller(&e->w, OP2, &e->cr_op2) != RX_CALLER_OK ||
+ rx_world_enroll_caller(&e->w, INTRUDER, &e->cr_intr) != RX_CALLER_OK ||
+ rx_world_enroll_caller(&e->w, SUBJ_R, &e->cr_r) != RX_CALLER_OK ||
+ rx_world_enroll_caller(&e->w, SUBJ_R2, &e->cr_r2) != RX_CALLER_OK)
+ return -1;
+ RxReactionDesc d;
+ memset(&d, 0, sizeof d);
+ d.name = "estop.r";
+ d.faculty = RX_FACULTY_OMEGA;
+ d.subject = SUBJ_R;
+ d.caller = e->cr_r;
+ d.priority = RX_PRIO_FOREGROUND;
+ d.fn = fn_r;
+ d.user = e;
+ d.triggers[d.n_triggers++] = (RxDep){ e->e, RX_FIELD(0) };
+ d.writes[d.n_writes++] = (RxDep){ e->o, RX_FIELD(0) };
+ d.caps[d.n_caps++] = (RxCapNeed){ mint(e, SUBJ_R, RES_E, RX_RIGHT_READ), RES_E, RX_RIGHT_READ };
+ d.caps[d.n_caps++] = (RxCapNeed){ mint(e, SUBJ_R, RES_O, RX_RIGHT_WRITE), RES_O, RX_RIGHT_WRITE };
+ if (rx_world_add_reaction(&e->w, &d, &e->id_r) != RX_OK) return -1;
+ memset(&d, 0, sizeof d);
+ d.name = "estop.r2";
+ d.faculty = RX_FACULTY_AIEN;
+ d.subject = SUBJ_R2;
+ d.caller = e->cr_r2;
+ d.priority = RX_PRIO_FOREGROUND;
+ d.fn = fn_r2;
+ d.user = e;
+ d.triggers[d.n_triggers++] = (RxDep){ e->e, RX_FIELD(1) };
+ d.writes[d.n_writes++] = (RxDep){ e->q, RX_FIELD(0) };
+ d.caps[d.n_caps++] = (RxCapNeed){ mint(e, SUBJ_R2, RES_E, RX_RIGHT_READ), RES_E, RX_RIGHT_READ };
+ d.caps[d.n_caps++] = (RxCapNeed){ mint(e, SUBJ_R2, RES_Q, RX_RIGHT_WRITE), RES_Q, RX_RIGHT_WRITE };
+ if (rx_world_add_reaction(&e->w, &d, &e->id_r2) != RX_OK) return -1;
+ if (g_with_r3) {
+ if (rx_world_enroll_caller(&e->w, SUBJ_R3, &e->cr_r3) != RX_CALLER_OK) return -1;
+ memset(&d, 0, sizeof d);
+ d.name = "estop.r3";
+ d.faculty = RX_FACULTY_AIEN;
+ d.subject = SUBJ_R3;
+ d.caller = e->cr_r3;
+ d.priority = RX_PRIO_FOREGROUND;
+ d.fn = fn_r3;
+ d.user = e;
+ d.triggers[d.n_triggers++] = (RxDep){ e->o, RX_FIELD(0) };
+ d.writes[d.n_writes++] = (RxDep){ e->q, RX_FIELD(1) };
+ d.caps[d.n_caps++] = (RxCapNeed){ mint(e, SUBJ_R3, RES_O, RX_RIGHT_READ), RES_O, RX_RIGHT_READ };
+ d.caps[d.n_caps++] = (RxCapNeed){ mint(e, SUBJ_R3, RES_Q, RX_RIGHT_WRITE), RES_Q, RX_RIGHT_WRITE };
+ if (rx_world_add_reaction(&e->w, &d, &e->id_r3) != RX_OK) return -1;
+ }
+ if (rx_world_bind_callers(&e->w) != RX_OK) return -1;
+ return 0;
+}
+
+static void teardown(Env *e) {
+ rx_world_destroy(&e->w);
+ rx_caproot_stop(&e->root, &e->admin);
+}
+
+static uint64_t field(Env *e, RxObjRef r) {
+ RxObject o;
+ if (rx_world_read(&e->w, r, &o) != RX_OK) return UINT64_MAX;
+ return o.field[0];
+}
+
+static int64_t publish(Env *e, uint32_t f, uint64_t v) {
+ RxMutation m = { e->e, f, v };
+ return rx_world_publish_external(&e->w, e->c_ext, &m, 1);
+}
+
+static uint64_t crumbs(Env *e) {
+ pthread_mutex_lock(&e->w.mu);
+ uint64_t n = e->w.n_crumbs;
+ pthread_mutex_unlock(&e->w.mu);
+ return n;
+}
+
+static void digest(Env *e, uint8_t out[32]) { rx_world_digest(&e->w, out); }
+
+static uint64_t reaction_commits(Env *e, uint32_t rid) {
+ uint64_t n = 0;
+ pthread_mutex_lock(&e->w.mu);
+ for (uint64_t i = 0; i < e->w.n_crumbs; i++)
+ if (e->w.crumbs[i].kind == RX_CRUMB_COMMIT && e->w.crumbs[i].reaction == rid) n++;
+ pthread_mutex_unlock(&e->w.mu);
+ return n;
+}
+
+static int wait_inside(void) {
+ for (int i = 0; i < 5000; i++) {
+ pthread_mutex_lock(&g.mu);
+ int in = g.inside;
+ pthread_mutex_unlock(&g.mu);
+ if (in) return 0;
+ usleep(1000);
+ }
+ return -1;
+}
+
+static void gate_release(void) {
+ pthread_mutex_lock(&g.mu);
+ g.go = 1;
+ pthread_cond_broadcast(&g.cv);
+ pthread_mutex_unlock(&g.mu);
+}
+
+/* Bounded wait until reaction rid has `want` commits (5 s). */
+static int wait_commits(Env *e, uint32_t rid, uint64_t want) {
+ for (int i = 0; i < 5000; i++) {
+ if (reaction_commits(e, rid) >= want) return 0;
+ usleep(1000);
+ }
+ return -1;
+}
+
+static int stop(Env *e, uint32_t subj, const RxCallerCred *cr, RxCapRef cap, int32_t why) {
+ return rx_world_emergency_stop(&e->w, subj, cr, cap, why, NULL);
+}
+static int resume(Env *e, uint32_t subj, const RxCallerCred *cr, RxCapRef cap) {
+ return rx_world_emergency_resume(&e->w, subj, cr, cap, NULL);
+}
+static bool halted(Env *e) {
+ RxHaltStatus h;
+ rx_world_halt_status(&e->w, &h);
+ return h.halted;
+}
+
+/* ---- E1 refusals ----------------------------------------------------------- */
+static void e1_refusals(Env *e) {
+ uint8_t d0[32], d1[32];
+ digest(e, d0);
+ uint64_t n0 = crumbs(e);
+ RxCallerCred forged = e->cr_op;
+ forged.secret[0] ^= 1;
+ RxCapRef wrong_right = mint(e, OP, RX_WORLD_RES_CONTROL, RX_RIGHT_WRITE);
+ RxCapRef wrong_res = mint(e, OP, RES_O, RX_WORLD_RIGHT_HALT);
+ RxCapRef of_r = mint(e, SUBJ_R, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT);
+ RxCapRef revoked = mint(e, OP, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT);
+ check(rx_capadmin_revoke(&e->admin, rx_capadmin_office(&e->admin), revoked) == RX_CAP_OK,
+ "E1 setup: a control capability revoked by the office");
+ struct { const char *what; uint32_t subj; const RxCallerCred *cr; RxCapRef cap; int want; } t[] = {
+ { "no credential", OP, NULL, e->c_op, RX_ERR_IDENTITY },
+ { "forged credential", OP, &forged, e->c_op, RX_ERR_IDENTITY },
+ { "enrolled intruder presenting the operator's capability", INTRUDER, &e->cr_intr, e->c_op,
+ RX_ERR_AUTHORITY },
+ { "operator with the wrong right on the control resource", OP, &e->cr_op, wrong_right,
+ RX_ERR_AUTHORITY },
+ { "operator with the halt right on another resource", OP, &e->cr_op, wrong_res,
+ RX_ERR_AUTHORITY },
+ { "operator with a revoked control capability", OP, &e->cr_op, revoked, RX_ERR_AUTHORITY },
+ { "a reaction's subject with a valid control capability", SUBJ_R, &e->cr_r, of_r,
+ RX_ERR_AUTHORITY },
+ };
+ for (size_t i = 0; i < sizeof t / sizeof t[0]; i++) {
+ char what[200];
+ int rc = stop(e, t[i].subj, t[i].cr, t[i].cap, 7);
+ snprintf(what, sizeof what, "E1 stop refused: %s (rc %d, want %d)", t[i].what, rc, t[i].want);
+ check(rc == t[i].want, what);
+ }
+ check(!halted(e), "E1 the world is still running after every refused stop");
+ digest(e, d1);
+ check(memcmp(d0, d1, 32) == 0 && crumbs(e) == n0,
+ "E1 refused stops changed neither the world digest nor the crumb log");
+ check(resume(e, OP, &forged, e->c_op) == RX_ERR_IDENTITY,
+ "E1 a forged resume is refused before 'not stopped' is told");
+ check(resume(e, OP, &e->cr_op, e->c_op) == RX_HALT_NOT_STOPPED,
+ "E1 an authorized resume of a running world answers RX_HALT_NOT_STOPPED");
+ check(crumbs(e) == n0, "E1 the not-stopped resume left no crumb");
+ check(publish(e, 1, 4) > 0 && wait_commits(e, e->id_r2, 1) == 0 && field(e, e->q) == 40,
+ "E1 control: the world still publishes and reacts (R2 wrote 4*10)");
+}
+
+/* ---- E2 stop and E3 in flight ------------------------------------------------ */
+static void e2_e3(Env *e) {
+ /* E3 first half: R is computing when the stop lands; R2's wake is queued
+ * behind it on the single worker. */
+ pthread_mutex_lock(&g.mu);
+ g.armed = 1;
+ pthread_mutex_unlock(&g.mu);
+ uint64_t r_before = reaction_commits(e, e->id_r), r2_before = reaction_commits(e, e->id_r2);
+ check(publish(e, 0, 41) > 0, "E3 setup: publish E.f0 = 41 (wakes R)");
+ check(wait_inside() == 0, "E3 setup: R is computing, held in its function");
+ check(publish(e, 1, 5) > 0, "E3 setup: publish E.f1 = 5 (wakes R2, queued: one worker)");
+
+ uint64_t n0 = crumbs(e);
+ RxHaltStatus h;
+ int rc = rx_world_emergency_stop(&e->w, OP, &e->cr_op, e->c_op, 77, &h);
+ check(rc == RX_OK && h.halted && h.seq == 1 && h.subject == OP && h.reason == 77,
+ "E2 an authorized stop takes effect (seq 1, operator, reason 77)");
+ const RxCrumb *k = rx_world_crumb(&e->w, h.crumb);
+ check(k && k->kind == RX_CRUMB_OPERATOR_STOP && k->caps[0].cap_id == e->c_op.cap_id &&
+ k->caps[0].generation == e->c_op.generation && k->reason == 77 &&
+ k->reaction == UINT32_MAX,
+ "E2 OPERATOR_STOP crumb names the control capability and the reason");
+ check(h.durable == 0, "E2 no halt directory: durable = 0 (said, not hidden)");
+ uint64_t n1 = crumbs(e);
+ check(n1 == n0 + 1, "E2 the stop added exactly one crumb");
+ check(stop(e, OP2, &e->cr_op2, e->c_op2, 78) == RX_HALT_ALREADY && crumbs(e) == n1,
+ "E2 a second stop (another operator) answers RX_HALT_ALREADY, no crumb");
+ rx_world_halt_status(&e->w, &h);
+ check(h.seq == 1 && h.subject == OP && h.reason == 77, "E2 the second stop changed nothing");
+ uint8_t d0[32], d1[32];
+ digest(e, d0);
+ check(publish(e, 0, 999) == RX_ERR_HALTED, "E2 outside publication refused: RX_ERR_HALTED");
+ digest(e, d1);
+ check(memcmp(d0, d1, 32) == 0 && crumbs(e) == n1, "E2 the refused publication changed nothing");
+
+ /* R finishes computing under the stop. */
+ uint64_t o_before = field(e, e->o);
+ gate_release();
+ int cancelled = 0;
+ for (int i = 0; i < 5000 && !cancelled; i++) {
+ pthread_mutex_lock(&e->w.mu);
+ for (uint64_t j = n1; j < e->w.n_crumbs; j++)
+ if (e->w.crumbs[j].kind == RX_CRUMB_CANCELLED && e->w.crumbs[j].reaction == e->id_r &&
+ e->w.crumbs[j].reason == RX_ERR_HALTED)
+ cancelled = 1;
+ pthread_mutex_unlock(&e->w.mu);
+ if (!cancelled) usleep(1000);
+ }
+ check(cancelled, "E3 the activation computed under the stop ended CANCELLED, RX_ERR_HALTED");
+ usleep(50000);
+ check(field(e, e->o) == o_before && reaction_commits(e, e->id_r) == r_before,
+ "E3 nothing it computed was published (O unchanged, no COMMIT)");
+ check(reaction_commits(e, e->id_r2) == r2_before,
+ "E3 R2's queued wake was not taken while stopped (50 ms)");
+ rx_world_halt_status(&e->w, &h);
+ check(h.refused == 2, "E3 refused count = 2 (one publication, one activation)");
+
+ check(resume(e, OP2, &e->cr_op2, e->c_op2) == RX_OK,
+ "E2 another authorized operator resumes");
+ rx_world_halt_status(&e->w, &h);
+ const RxCrumb *rk = rx_world_crumb(&e->w, e->w.n_crumbs);
+ int found = 0;
+ pthread_mutex_lock(&e->w.mu);
+ for (uint64_t j = n1; j < e->w.n_crumbs; j++) {
+ const RxCrumb *c = &e->w.crumbs[j];
+ if (c->kind != RX_CRUMB_OPERATOR_RESUME) continue;
+ for (uint32_t p = 0; p < c->n_parents; p++) found |= c->parents[p] == n1;
+ found &= c->caps[0].cap_id == e->c_op2.cap_id;
+ }
+ pthread_mutex_unlock(&e->w.mu);
+ (void)rk;
+ check(!h.halted && found, "E2 OPERATOR_RESUME crumb: parent = the stop, cap = the resumer's");
+ check(wait_commits(e, e->id_r, r_before + 1) == 0 && wait_commits(e, e->id_r2, r2_before + 1) == 0,
+ "E3 on resume the cancelled activation and the queued wake both ran");
+ usleep(50000);
+ check(field(e, e->o) == 42 && field(e, e->q) == 50, "E3 their results: O = 41+1, Q = 5*10");
+ check(reaction_commits(e, e->id_r) == r_before + 1 && reaction_commits(e, e->id_r2) == r2_before + 1,
+ "E3 each committed exactly once");
+}
+
+/* ---- E4 race ----------------------------------------------------------------- */
+typedef struct {
+ Env *e;
+ atomic_int run;
+ atomic_long ok, halted_rc, other_rc;
+ atomic_long stops_ok, resumes_ok, stop_other, resume_other;
+} Race;
+
+static void *publisher(void *a) {
+ Race *r = a;
+ uint64_t v = 100;
+ while (atomic_load(&r->run) && atomic_load(&r->ok) < 60000) {
+ int64_t rc = publish(r->e, (uint32_t)(v & 1), v);
+ if (rc > 0) atomic_fetch_add(&r->ok, 1);
+ else if (rc == RX_ERR_HALTED) atomic_fetch_add(&r->halted_rc, 1);
+ else atomic_fetch_add(&r->other_rc, 1);
+ v++;
+ }
+ return NULL;
+}
+
+typedef struct { Race *r; uint32_t subj; RxCallerCred *cr; RxCapRef cap; int n; } Op;
+static void *operator_thread(void *a) {
+ Op *o = a;
+ for (int i = 0; i < o->n; i++) {
+ int rc = stop(o->r->e, o->subj, o->cr, o->cap, 100 + i);
+ if (rc == RX_OK) atomic_fetch_add(&o->r->stops_ok, 1);
+ else if (rc != RX_HALT_ALREADY) atomic_fetch_add(&o->r->stop_other, 1);
+ usleep(200);
+ rc = resume(o->r->e, o->subj, o->cr, o->cap);
+ if (rc == RX_OK) atomic_fetch_add(&o->r->resumes_ok, 1);
+ else if (rc != RX_HALT_NOT_STOPPED) atomic_fetch_add(&o->r->resume_other, 1);
+ usleep(100);
+ }
+ return NULL;
+}
+
+static void e4_race(Env *e) {
+ uint64_t n0 = crumbs(e);
+ Race r;
+ memset(&r, 0, sizeof r);
+ r.e = e;
+ atomic_store(&r.run, 1);
+ pthread_t p[2], o[2];
+ Op o1 = { &r, OP, &e->cr_op, e->c_op, 300 }, o2 = { &r, OP2, &e->cr_op2, e->c_op2, 300 };
+ for (int i = 0; i < 2; i++) pthread_create(&p[i], NULL, publisher, &r);
+ pthread_create(&o[0], NULL, operator_thread, &o1);
+ pthread_create(&o[1], NULL, operator_thread, &o2);
+ pthread_join(o[0], NULL);
+ pthread_join(o[1], NULL);
+ atomic_store(&r.run, 0);
+ for (int i = 0; i < 2; i++) pthread_join(p[i], NULL);
+ if (halted(e)) resume(e, OP, &e->cr_op, e->c_op);
+ rx_world_wait_quiescent(&e->w, 5000);
+
+ long stops = 0, resumes = 0, inside_bad = 0, stop_in_stop = 0, resume_outside = 0;
+ int in = 0;
+ pthread_mutex_lock(&e->w.mu);
+ for (uint64_t j = n0; j < e->w.n_crumbs; j++) {
+ const RxCrumb *c = &e->w.crumbs[j];
+ if (c->kind == RX_CRUMB_OPERATOR_STOP) { stops++; stop_in_stop += in; in = 1; }
+ else if (c->kind == RX_CRUMB_OPERATOR_RESUME) { resumes++; resume_outside += !in; in = 0; }
+ else if (in && (c->kind == RX_CRUMB_EXTERNAL || c->kind == RX_CRUMB_COMMIT)) inside_bad++;
+ }
+ uint64_t overflow = e->w.stats.crumb_overflow;
+ pthread_mutex_unlock(&e->w.mu);
+ char what[240];
+ snprintf(what, sizeof what,
+ "E4 race: %ld publications ok, %ld refused HALTED, %ld other; %ld stops, %ld resumes",
+ (long)atomic_load(&r.ok), (long)atomic_load(&r.halted_rc), (long)atomic_load(&r.other_rc),
+ stops, resumes);
+ check(atomic_load(&r.ok) > 0 && atomic_load(&r.halted_rc) > 0 && atomic_load(&r.other_rc) == 0,
+ what);
+ check(overflow == 0, "E4 the crumb log did not overflow (every event is in it)");
+ check(inside_bad == 0, "E4 no EXTERNAL or COMMIT crumb between a STOP and its RESUME");
+ check(stop_in_stop == 0 && resume_outside == 0, "E4 STOP and RESUME strictly alternate");
+ check(stops == atomic_load(&r.stops_ok) && resumes == atomic_load(&r.resumes_ok) + (stops > atomic_load(&r.resumes_ok) ? 1 : 0),
+ "E4 one STOP crumb per accepted stop, one RESUME per accepted resume");
+ check(atomic_load(&r.stop_other) == 0 && atomic_load(&r.resume_other) == 0,
+ "E4 every stop/resume answer was OK, ALREADY or NOT_STOPPED");
+ uint64_t checked = 0;
+ check(rx_world_verify_crumbs(&e->w, &checked) == 0, "E4 the crumb chain verifies");
+}
+
+/* ---- E5 promotion -------------------------------------------------------------- */
+enum { PROP = 9200, PRO = 9201 };
+static int auth_any(void *c, uint32_t id, uint64_t gen, uint32_t s, uint64_t res, uint32_t rights) {
+ (void)c; (void)id; (void)gen; (void)s; (void)res; (void)rights;
+ return 0;
+}
+
+typedef struct { Env *e; int rc, fired; } StopNow;
+static void stop_live(void *ctx) {
+ StopNow *s = ctx;
+ if (s->fired++) return;
+ s->rc = stop(s->e, OP, &s->e->cr_op, s->e->c_op, 501);
+}
+static void stop_disk(const char *dir, void *ctx) { (void)dir; stop_live(ctx); }
+
+static void e5_promotion(void) {
+ Env e;
+ check(setup(&e, 1, 1u << 16) == 0, "E5 setup: second world");
+ /* A fresh world: the store's proposer and promoter are its callers. The
+ * world above is bound already; this one enrolls them before binding. */
+ teardown(&e);
+ memset(&e, 0, sizeof e);
+ RxCallerCred prop, pro;
+ char dir[64];
+ RxGenStore *gs = NULL;
+ int ok = rx_caproot_start(&e.root, &e.admin) == RX_CAP_OK &&
+ rx_world_init(&e.w, &e.root, 1, 1u << 12) == RX_OK;
+ if (ok) {
+ e.c_op = mint(&e, OP, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT);
+ ok = rx_world_enroll_caller(&e.w, OP, &e.cr_op) == RX_CALLER_OK &&
+ rx_world_enroll_caller(&e.w, PROP, &prop) == RX_CALLER_OK &&
+ rx_world_enroll_caller(&e.w, PRO, &pro) == RX_CALLER_OK &&
+ rx_world_bind_callers(&e.w) == RX_OK &&
+ mkdtemp(strcpy(dir, "/tmp/rx-estop-gen-XXXXXX")) &&
+ rx_gen_open(dir, &gs) == RX_GEN_OK &&
+ rx_gen_bind_authority(gs, rx_world_caller_check_fn, &e.w, auth_any, NULL) == RX_GEN_OK;
+ }
+ check(ok, "E5 setup: world with operator, proposer, promoter; bound generation store");
+ if (!ok) return;
+ static const uint8_t ev[] = "estop";
+ RxGenObject obj = { 1, 1, { 0 } };
+ RxGenDraft gd;
+ memset(&gd, 0, sizeof gd);
+ gd.proofs_ok = 1;
+ gd.n_objects = 1;
+ gd.objects = &obj;
+ gd.evidence = ev;
+ gd.evidence_len = sizeof ev - 1;
+ for (int v = 0; v < 2; v++) {
+ const char *where = v == 0 ? "live barrier" : "disk writes";
+ uint64_t cand = 0, a0 = 0, l0 = 0, a1 = 0, l1 = 0;
+ int prc = rx_gen_propose_as(gs, PROP, &prop, &gd, &cand);
+ rx_gen_active(gs, &a0, &l0);
+ StopNow s = { &e, -99, 0 };
+ RxPromotionRequest req = { cand, PRO, 1, 1, RX_GEN_RES_PROMOTION, RX_GEN_RIGHT_PROMOTE, pro };
+ if (v == 1) rx_gen_set_disk_hook(gs, stop_disk, &s);
+ int rc = prc != RX_GEN_OK ? prc
+ : rx_gen_promote(gs, &req, NULL, NULL, NULL, NULL, v == 0 ? stop_live : NULL,
+ v == 0 ? &s : NULL);
+ if (v == 1) rx_gen_set_disk_hook(gs, NULL, NULL);
+ rx_gen_active(gs, &a1, &l1);
+ RxRecoveryRecord d;
+ memset(&d, 0, sizeof d);
+ rx_gen_recover(dir, &d);
+ char what[200];
+ snprintf(what, sizeof what, "E5 stop during the %s: stop rc %d, promote rc %d (want %d)",
+ where, s.rc, rc, RX_GEN_ERR_HALTED);
+ check(prc == RX_GEN_OK && s.rc == RX_OK && rc == RX_GEN_ERR_HALTED, what);
+ check(a1 == a0 && d.active_id == a0, "E5 active generation unchanged, in memory and on disk");
+ uint64_t c2 = 0;
+ check(rx_gen_propose_as(gs, PROP, &prop, &gd, &c2) == RX_GEN_ERR_HALTED,
+ "E5 a proposal under the stop is refused: RX_GEN_ERR_HALTED");
+ check(resume(&e, OP, &e.cr_op, e.c_op) == RX_OK, "E5 operator resumes");
+ }
+ uint64_t cand = 0, a1 = 0, l1 = 0;
+ int prc = rx_gen_propose_as(gs, PROP, &prop, &gd, &cand);
+ RxPromotionRequest req = { cand, PRO, 1, 1, RX_GEN_RES_PROMOTION, RX_GEN_RIGHT_PROMOTE, pro };
+ int rc = prc == RX_GEN_OK ? rx_gen_promote(gs, &req, NULL, NULL, NULL, NULL, NULL, NULL) : prc;
+ rx_gen_active(gs, &a1, &l1);
+ check(rc == RX_GEN_OK && a1 == cand, "E5 control: after resume the same promoter promotes");
+ rx_gen_close(gs);
+ teardown(&e);
+ char cmd[128];
+ snprintf(cmd, sizeof cmd, "rm -rf '%s'", dir);
+ if (system(cmd) != 0) fprintf(stderr, "cleanup of %s failed\n", dir);
+}
+
+/* ---- E6 durable ------------------------------------------------------------------ */
+static int read_file(const char *path, char *buf, size_t cap) {
+ int fd = open(path, O_RDONLY);
+ if (fd < 0) return -1;
+ ssize_t n = read(fd, buf, cap - 1);
+ close(fd);
+ if (n < 0) return -1;
+ buf[n] = 0;
+ return (int)n;
+}
+
+static int count_resumed(const char *dir, char *name, size_t cap) {
+ DIR *d = opendir(dir);
+ if (!d) return -1;
+ int n = 0;
+ struct dirent *de;
+ while ((de = readdir(d)))
+ if (strncmp(de->d_name, RX_GEN_HALT_MARK ".resumed.", strlen(RX_GEN_HALT_MARK) + 9) == 0) {
+ n++;
+ snprintf(name, cap, "%s", de->d_name);
+ }
+ closedir(d);
+ return n;
+}
+
+static void e6_durable(void) {
+ char dir[64], mark[160], raw[600];
+ check(mkdtemp(strcpy(dir, "/tmp/rx-estop-mark-XXXXXX")) != NULL, "E6 setup: halt directory");
+ snprintf(mark, sizeof mark, "%s/%s", dir, RX_GEN_HALT_MARK);
+ Env e;
+ check(setup(&e, 1, 1u << 16) == 0, "E6 setup: world");
+ check(rx_world_set_halt_dir(&e.w, dir) == 0, "E6 no mark: set_halt_dir answers 0, world runs");
+ RxHaltStatus h;
+ check(rx_world_emergency_stop(&e.w, OP, &e.cr_op, e.c_op, 606, &h) == RX_OK && h.durable == 1,
+ "E6 the stop wrote its mark durably (durable = 1)");
+ int n = read_file(mark, raw, sizeof raw);
+ char want_head[200];
+ snprintf(want_head, sizeof want_head, "aien-operator-halt v1\nseq 1\nsubject %u\ncap %u %llu\nreason 606\n",
+ OP, e.c_op.cap_id, U(e.c_op.generation));
+ check(n > 0 && strncmp(raw, want_head, strlen(want_head)) == 0 && strstr(raw, "\nsha256 "),
+ "E6 the mark names the operator, the capability and the reason, and is sealed");
+ teardown(&e); /* the process "restarts": a new world over the same directory */
+
+ check(setup(&e, 1, 1u << 16) == 0, "E6 restart: new world");
+ int rr = rx_world_set_halt_dir(&e.w, dir);
+ rx_world_halt_status(&e.w, &h);
+ check(rr == 1 && h.halted && h.restored && h.seq == 1 && h.subject == OP && h.reason == 606,
+ "E6 the new world starts stopped, restored from the mark (seq, operator, reason)");
+ check(publish(&e, 0, 1) == RX_ERR_HALTED, "E6 the restored stop refuses publication");
+ teardown(&e);
+
+ /* A changed byte: still stopped, reported torn. */
+ char torn[600];
+ memcpy(torn, raw, (size_t)n + 1);
+ torn[30] = torn[30] == '1' ? '2' : '1';
+ char tpath[200];
+ snprintf(tpath, sizeof tpath, "%s/torn", dir);
+ check(mkdir(tpath, 0700) == 0, "E6 setup: directory with a damaged mark");
+ char tmark[240];
+ snprintf(tmark, sizeof tmark, "%s/%s", tpath, RX_GEN_HALT_MARK);
+ FILE *f = fopen(tmark, "w");
+ if (f) { fwrite(torn, 1, (size_t)n, f); fclose(f); }
+ check(setup(&e, 1, 1u << 16) == 0, "E6 torn: new world");
+ rr = rx_world_set_halt_dir(&e.w, tpath);
+ rx_world_halt_status(&e.w, &h);
+ check(rr == RX_ERR_TORN && h.halted && h.reason == RX_ERR_TORN,
+ "E6 a mark with one byte changed still stops the world (RX_ERR_TORN)");
+ check(resume(&e, OP, &e.cr_op, e.c_op) == RX_OK && access(tmark, F_OK) != 0,
+ "E6 an authorized resume lifts the torn stop and retires its mark");
+ char rname[260], rpath[520], rbuf[1400];
+ check(count_resumed(tpath, rname, sizeof rname) == 1, "E6 the torn record is kept, not deleted");
+ snprintf(rpath, sizeof rpath, "%s/%s", tpath, rname);
+ check(read_file(rpath, rbuf, sizeof rbuf) > n && memcmp(rbuf, torn, (size_t)n) == 0,
+ "E6 the kept record starts with the damaged bytes, unchanged");
+ teardown(&e);
+
+ /* An unbound store over the directory will not promote while the mark exists. */
+ RxGenStore *gs = NULL;
+ check(rx_gen_open(dir, &gs) == RX_GEN_OK, "E6 unbound store opened over the halt directory");
+ static const uint8_t ev[] = "estop";
+ RxGenObject obj = { 1, 1, { 0 } };
+ RxGenDraft gd;
+ memset(&gd, 0, sizeof gd);
+ gd.proofs_ok = 1;
+ gd.n_objects = 1;
+ gd.objects = &obj;
+ gd.evidence = ev;
+ gd.evidence_len = sizeof ev - 1;
+ uint64_t cand = 0, a0 = 0, l0 = 0, a1 = 0, l1 = 0;
+ int prc = rx_gen_propose(gs, PROP, &gd, &cand);
+ rx_gen_active(gs, &a0, &l0);
+ RxPromotionRequest req = { cand, PRO, 1, 1, RX_GEN_RES_PROMOTION, RX_GEN_RIGHT_PROMOTE, { 0, { 0 } } };
+ int rc = prc == RX_GEN_OK ? rx_gen_promote(gs, &req, auth_any, NULL, NULL, NULL, NULL, NULL) : prc;
+ rx_gen_active(gs, &a1, &l1);
+ check(rc == RX_GEN_ERR_HALTED && a1 == a0, "E6 unbound store: promotion refused by the mark");
+
+ /* Resume through a world: record kept, mark gone, the store promotes. */
+ check(setup(&e, 1, 1u << 16) == 0 && rx_world_set_halt_dir(&e.w, dir) == 1, "E6 world restored stopped");
+ if (geteuid() == 0) {
+ printf("[~] E6 read-only directory case skipped: running as root ignores the permission\n");
+ } else {
+ check(chmod(dir, 0500) == 0, "E6 setup: halt directory made read-only");
+ check(resume(&e, OP, &e.cr_op, e.c_op) == RX_ERR_IO && halted(&e) && access(mark, F_OK) == 0,
+ "E6 a resume that cannot retire the mark is refused: world stays stopped, mark stays");
+ check(chmod(dir, 0700) == 0, "E6 setup: halt directory writable again");
+ }
+ check(resume(&e, OP, &e.cr_op, e.c_op) == RX_OK && !halted(&e) && access(mark, F_OK) != 0,
+ "E6 resume: world runs, mark removed");
+ check(count_resumed(dir, rname, sizeof rname) == 1, "E6 exactly one kept stop record");
+ snprintf(rpath, sizeof rpath, "%s/%s", dir, rname);
+ int rn = read_file(rpath, rbuf, sizeof rbuf);
+ char who[120];
+ snprintf(who, sizeof who, "resumed_by %u\nresume_cap %u %llu\n", OP, e.c_op.cap_id,
+ U(e.c_op.generation));
+ check(rn > n && memcmp(rbuf, raw, (size_t)n) == 0 && strstr(rbuf + n, who) &&
+ strstr(rbuf + n, "\nsha256 "),
+ "E6 kept record = the stop's bytes + who resumed, sealed");
+ rc = rx_gen_promote(gs, &req, auth_any, NULL, NULL, NULL, NULL, NULL);
+ rx_gen_active(gs, &a1, &l1);
+ check(rc == RX_GEN_OK && a1 == cand, "E6 control: with the mark gone the store promotes");
+ rx_gen_close(gs);
+ teardown(&e);
+ char cmd[128];
+ snprintf(cmd, sizeof cmd, "rm -rf '%s'", dir);
+ if (system(cmd) != 0) fprintf(stderr, "cleanup of %s failed\n", dir);
+}
+
+/* ---- E7 budget, create/retire, a mark that is not a file -------------------- */
+static void e7_budget_objects(void) {
+ Env e;
+ g_with_r3 = 1;
+ int su = setup(&e, 1, 1u << 16);
+ g_with_r3 = 0;
+ check(su == 0, "E7 setup: world with R3 (woken by R's commit)");
+ if (su != 0) return;
+ RxStabilityBudget sb;
+ memset(&sb, 0, sizeof sb);
+ sb.activation_budget = 1; /* one activation per reaction per episode */
+ rx_world_set_stability(&e.w, &sb);
+ pthread_mutex_lock(&g.mu);
+ g.armed3 = 1;
+ pthread_mutex_unlock(&g.mu);
+ check(publish(&e, 0, 6) > 0, "E7 setup: publish E.f0 = 6 (R runs, its commit wakes R3)");
+ check(wait_inside() == 0, "E7 setup: R3 is computing, held in its function");
+ check(stop(&e, OP, &e.cr_op, e.c_op, 707) == RX_OK, "E7 operator stop while R3 computes");
+ gate_release();
+ usleep(50 * 1000);
+ pthread_mutex_lock(&e.w.mu);
+ bool quarantined = e.w.reactions[e.id_r3].quarantined;
+ pthread_mutex_unlock(&e.w.mu);
+ check(!quarantined, "E7 the refused activation did not spend R3's episode budget (not quarantined)");
+
+ /* Create and retire are commits too: refused under the stop, nothing changes. */
+ uint8_t d0[32], d1[32];
+ digest(&e, d0);
+ uint64_t n0 = crumbs(&e);
+ uint64_t init[RX_MAX_FIELDS] = { 0 };
+ RxObjRef nr = { UINT32_MAX, 0 };
+ check(rx_world_create(&e.w, 1, RX_PERSIST_RESIDENT, 0x7ff, init, &nr) == RX_ERR_HALTED &&
+ nr.id == UINT32_MAX,
+ "E7 object create under the stop: RX_ERR_HALTED, no object");
+ check(rx_world_retire(&e.w, e.q) == RX_ERR_HALTED, "E7 object retire under the stop: RX_ERR_HALTED");
+ digest(&e, d1);
+ check(memcmp(d0, d1, 32) == 0 && crumbs(&e) == n0 && field(&e, e.q) != UINT64_MAX,
+ "E7 refused create/retire changed nothing (digest, crumbs, Q still live)");
+
+ check(resume(&e, OP, &e.cr_op, e.c_op) == RX_OK, "E7 operator resume");
+ check(wait_commits(&e, e.id_r3, 1) == 0, "E7 R3 ran again after resume and committed");
+ RxObject q;
+ check(rx_world_read(&e.w, e.q, &q) == RX_OK && q.field[1] == 700, "E7 its result: Q.f1 = (6+1)*100");
+ teardown(&e);
+
+ /* A mark that is a symlink (here dangling) is not a mark the world can read:
+ * the world starts stopped (TORN, never "absent, go"), and resume keeps a
+ * record and removes the link, so the store is not blocked for good. */
+ char dir[64], mark[160], rname[260];
+ check(mkdtemp(strcpy(dir, "/tmp/rx-estop-link-XXXXXX")) != NULL, "E7 setup: halt directory");
+ snprintf(mark, sizeof mark, "%s/%s", dir, RX_GEN_HALT_MARK);
+ check(symlink("/nonexistent/rx-estop-target", mark) == 0, "E7 setup: OPERATOR_HALT is a dangling symlink");
+ check(setup(&e, 1, 1u << 16) == 0, "E7 link: new world");
+ int rr = rx_world_set_halt_dir(&e.w, dir);
+ check(rr == RX_ERR_TORN && halted(&e), "E7 a symlink mark stops the world (RX_ERR_TORN)");
+ check(resume(&e, OP, &e.cr_op, e.c_op) == RX_OK && !halted(&e), "E7 resume lifts it");
+ struct stat st;
+ check(lstat(mark, &st) != 0 && count_resumed(dir, rname, sizeof rname) == 1,
+ "E7 the link is removed and a resumed record kept");
+ teardown(&e);
+ char cmd[128];
+ snprintf(cmd, sizeof cmd, "rm -rf '%s'", dir);
+ if (system(cmd) != 0) fprintf(stderr, "cleanup of %s failed\n", dir);
+}
+
+int main(void) {
+ setvbuf(stdout, NULL, _IOLBF, 0);
+ Env e;
+ if (setup(&e, 1, 1u << 16) != 0) {
+ printf("[-] setup failed\nRX_EMERGENCY_STOP: FAIL\n");
+ return 1;
+ }
+ e1_refusals(&e);
+ e2_e3(&e);
+ teardown(&e);
+ if (setup(&e, 4, 1u << 21) != 0) {
+ printf("[-] setup (4 workers) failed\nRX_EMERGENCY_STOP: FAIL\n");
+ return 1;
+ }
+ e4_race(&e);
+ teardown(&e);
+ e5_promotion();
+ e6_durable();
+ e7_budget_objects();
+ printf("RX_EMERGENCY_STOP: %s (%d failures; host CPU, real caproot authority)\n",
+ g_fail ? "FAIL" : "PASS", g_fail);
+ return g_fail ? 1 : 0;
+}
diff --git a/tests/runtime/rx_emergency_mutants.sh b/tests/runtime/rx_emergency_mutants.sh
new file mode 100755
index 000000000..d4dc224ed
--- /dev/null
+++ b/tests/runtime/rx_emergency_mutants.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+# R16 G6 operator emergency stop: each guard is load-bearing. Every mutant below
+# removes one guard from a temporary copy of the runtime; tests/runtime/rx_emergency.c
+# must FAIL against each one (and PASS against the unmutated copy). A mutant whose
+# pattern no longer matches is a failure of this script, never a silent skip.
+set -u
+HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
+W=$(mktemp -d "${TMPDIR:-/tmp}/rx-estop-mut.XXXXXX")
+trap 'rm -rf "$W"' EXIT
+CC=${CC:-cc}
+SRCS="src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c src/runtime/rx_generation.c src/sha256.c tests/runtime/rx_emergency.c"
+
+# name|file|perl substitution (applied with -0, must match exactly once)
+MUTANTS='M1 run_one publishes under a stop|src/runtime/rx_world.c|s/(on resume, against the state then \(rearm keeps its admission path\)\. \*\/\n )if \(w->halted\) \{/${1}if (0) {/
+M2 workers take work under a stop|src/runtime/rx_world.c|s/\(w->halted \|\| !pop_ready\(w, &rid\)\)/(!pop_ready(w, \&rid))/
+M3 outside publication under a stop|src/runtime/rx_world.c|s/if \(w->halted\) \{( +)\/\* R16 G6: nothing outside publishes \*\//if (0) {$1\/* R16 G6: nothing outside publishes *\//
+M4 caller check ignores the stop|src/runtime/rx_world.c|s/if \(w->halted\) \{\n pthread_mutex_unlock\(&w->callers_mu\);\n return RX_CALLER_ERR_HALTED;/if (0) {\n pthread_mutex_unlock(\&w->callers_mu);\n return RX_CALLER_ERR_HALTED;/
+M5 a reaction subject may stop the world|src/runtime/rx_world.c|s/if \(w->reactions\[i\]\.desc\.subject == subject\) return RX_ERR_AUTHORITY;/(void)i;/
+M6 store ignores the durable mark|src/runtime/rx_generation.c|s/(static int halt_marked\(const RxGenStore \*store\) \{\n)/$1 if (store) return 0;\n/
+M7 a restarted world ignores the mark|src/runtime/rx_world.c|s/\} else if \(rc != 0 && !w->halted\) \{/} else if (0) {/
+M8 resume deletes the mark without keeping the record|src/runtime/rx_world.c|s/if \(rc == RX_OK && durable_write\(w->halt_dir, name, buf, \(size_t\)n, true\) != 0\)/if (0)/
+M9 the stop is not in force until the disk write returns|src/runtime/rx_world.c|s/( w->halted = true; \/\* in force before any disk work \*\/\n)( w->halt\.durable = halt_mark_write\(w\);\n)/$2 if (w->halt.durable != 1) w->halted = false; else w->halted = true;\n/
+M10 a refused activation spends the episode budget|src/runtime/rx_world.c|s/ if \(r->episode_activations\) r->episode_activations--;\n r->rearm = true;\n end_activation\(w, rid\);/ r->rearm = true;\n end_activation(w, rid);/
+M11 object create under a stop|src/runtime/rx_world.c|s/(RxObjRef \*out\) \{\n pthread_mutex_lock\(&w->mu\);\n )if \(w->halted\)/${1}if (0)/
+M12 object retire under a stop|src/runtime/rx_world.c|s/(int rx_world_retire\(RxWorld \*w, RxObjRef ref\) \{\n pthread_mutex_lock\(&w->mu\);\n )if \(w->halted\)/${1}if (0)/
+M13 a symlink mark reads as absent|src/runtime/rx_world.c|s/errno == ELOOP \? RX_ERR_TORN : RX_ERR_IO/errno == ELOOP ? 0 : RX_ERR_IO/'
+
+build_run() { # dir -> exit status of the test
+ (cd "$1" && $CC -std=gnu11 -Wall -Wextra -D_GNU_SOURCE -O2 -Isrc -pthread -o t $SRCS) >"$1/build.log" 2>&1 || { echo "build failed:"; tail -5 "$1/build.log"; return 99; }
+ (cd "$1" && timeout 300 ./t) >"$1/run.log" 2>&1
+}
+
+copy() { mkdir -p "$1"; (cd "$HERE" && tar -cf - src tests/runtime/rx_emergency.c) | tar -xf - -C "$1"; }
+
+fails=0
+copy "$W/base"
+build_run "$W/base"; rc=$?
+if [ $rc = 0 ]; then echo "ok unmutated: PASS"; else echo "FAIL unmutated: exit $rc"; tail -5 "$W/base/run.log"; fails=$((fails + 1)); fi
+while IFS='|' read -r name file sub; do
+ [ -n "$name" ] || continue
+ d="$W/m${name%% *}"
+ copy "$d"
+ # Count with the same pattern applied globally (s///g returns the number of
+ # matches); apply the mutant only when it matches exactly once.
+ n=$(perl -0 -e 'my $s = do { local $/; }; my $c = eval "\$s =~ $ARGV[0]g"; die $@ if $@; print $c ? $c + 0 : 0' "$sub" < "$d/$file")
+ if [ "$n" != 1 ]; then
+ echo "FAIL $name: pattern matched ${n:-?} times (must be 1)"; fails=$((fails + 1)); continue
+ fi
+ perl -0pi -e "$sub" "$d/$file"
+ if cmp -s "$d/$file" "$HERE/$file"; then
+ echo "FAIL $name: substitution changed nothing"; fails=$((fails + 1)); continue
+ fi
+ build_run "$d"; rc=$?
+ # Killed means the test ran and at least one check failed; a crash or a
+ # timeout without a failed check is not counted as a kill.
+ nf=$(grep -c '^\[-\]' "$d/run.log" 2>/dev/null); nf=${nf:-0}
+ if [ $rc = 99 ]; then echo "FAIL $name: mutant did not build"; fails=$((fails + 1))
+ elif [ $rc != 0 ] && [ "$nf" -gt 0 ]; then echo "ok $name: killed ($nf checks failed)"
+ elif [ $rc != 0 ]; then echo "FAIL $name: exit $rc with no failed check (crash or timeout)"; fails=$((fails + 1))
+ else echo "FAIL $name: SURVIVED"; fails=$((fails + 1)); fi
+done <<< "$MUTANTS"
+if [ $fails = 0 ]; then echo "RX_EMERGENCY_MUTANTS: PASS"; else echo "RX_EMERGENCY_MUTANTS: FAIL ($fails)"; exit 1; fi
diff --git a/tests/runtime/rx_r12_resident.c b/tests/runtime/rx_r12_resident.c
index bc65b4300..78ffb1bcf 100644
--- a/tests/runtime/rx_r12_resident.c
+++ b/tests/runtime/rx_r12_resident.c
@@ -27,7 +27,7 @@
#define X 40u
#define Y 2u
-enum { SUBJ_SEAT = 3, SUBJ_DEPEND = 4, SUBJ_EXTERNAL = 100, ISSUER = 3 };
+enum { SUBJ_SEAT = 3, SUBJ_DEPEND = 4, SUBJ_OPERATOR = 7, SUBJ_EXTERNAL = 100, ISSUER = 3 };
static int g_checks;
static int g_fail;
@@ -745,6 +745,52 @@ static void t_slot_renewal(void) {
env_stop(&e);
}
+/* R16 G6 operator emergency stop (spec/r16-operator-emergency-stop.md) on the
+ * resident seat, with the native AIENOS authority: the seat's result lands
+ * after the stop. It is not published (canonical B and B's window keep the
+ * world's value, the dependent does not run, the claim closes); after resume
+ * the seat runs again and the chain completes with the right values. */
+static void t_emergency_stop(void) {
+ printf("[*] operator emergency stop: a seat result under a stop is refused, resume reruns it\n");
+ Rig r;
+ CHECK(rig_start(&r, 1) == 0, "setup");
+ if (g_fail && r.e.w.n_workers == 0) return;
+ RxCallerCred op;
+ CHECK(rx_world_enroll_caller(&r.e.w, SUBJ_OPERATOR, &op) == RX_OK, "enroll the operator");
+ RxCapRef halt = mint(&r.e, SUBJ_OPERATOR, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT);
+ CHECK(halt.cap_id != UINT32_MAX, "the native authority refused the operator halt capability");
+ offer(&r.e.w, RX_ACCEL_BLACKWELL);
+ CHECK(poke(&r, X, Y) > 0, "stimulus");
+ CHECK(wait_seat(&r.e.w, r.seat) == 0, "admitted seat did not reach the claim");
+ CHECK(rx_resident_seat_step(&r.e.w) == 1, "stand-in step");
+ CHECK(window_field(&r.e.w, r.ch.b.id, 0) == X + Y, "B's window does not hold the sum");
+
+ RxHaltStatus h;
+ CHECK(rx_world_emergency_stop(&r.e.w, SUBJ_OPERATOR, &op, halt, 12, &h) == RX_OK && h.halted,
+ "operator stop");
+ CHECK(rx_resident_accept(&r.e.w) == RX_ERR_HALTED, "a seat result was published under the stop");
+ CHECK(field_of(&r.e.w, r.ch.b, 0) == 0, "canonical B changed under the stop");
+ CHECK(window_field(&r.e.w, r.ch.b.id, 0) == 0, "B's window was not re-projected from the world");
+ CHECK(r.e.w.reactions[r.seat].resident_seat == false, "the seat claim stayed open");
+ CHECK(poke(&r, X + 1, Y) == RX_ERR_HALTED, "outside publication under the stop");
+ sleep_ms(50);
+ CHECK(field_of(&r.e.w, r.ch.c, 0) == 0, "the dependent ran under the stop");
+ CHECK(rx_resident_seat_step(&r.e.w) == 0, "a claim was posted under the stop");
+ rx_world_halt_status(&r.e.w, &h);
+ CHECK(h.halted && h.refused >= 2, "stop status (halted %d, refused %llu)", (int)h.halted,
+ (unsigned long long)h.refused);
+
+ CHECK(rx_world_emergency_resume(&r.e.w, SUBJ_OPERATOR, &op, halt, &h) == RX_OK && !h.halted,
+ "operator resume");
+ CHECK(wait_seat(&r.e.w, r.seat) == 0, "the seat did not run again after resume");
+ CHECK(rx_resident_seat_step(&r.e.w) == 1, "stand-in step after resume");
+ CHECK(rx_resident_accept(&r.e.w) == RX_OK, "accept after resume");
+ CHECK(rx_world_wait_quiescent(&r.e.w, 3000) == RX_OK, "dependent did not finish");
+ CHECK(field_of(&r.e.w, r.ch.b, 0) == X + Y, "canonical B after resume");
+ CHECK(field_of(&r.e.w, r.ch.c, 0) == X + Y + 1, "dependent after resume");
+ env_stop(&r.e);
+}
+
int main(void) {
signal(SIGPIPE, SIG_IGN);
t_shape();
@@ -760,6 +806,7 @@ int main(void) {
t_seat_lost_retry();
t_seat_lost_final();
t_slot_renewal();
+ t_emergency_stop();
printf("checks %d failures %d\n", g_checks, g_fail);
write_receipt();
return g_fail ? 1 : 0;
diff --git a/tools/.crumb b/tools/.crumb
index ca20b6a02..f0d84cbb9 100644
--- a/tools/.crumb
+++ b/tools/.crumb
@@ -44,7 +44,7 @@
},
{
"digest": "11eb4960ad04fe5bd01ee9d2bbb6900712176c0991ecc0b02b3204ac60248eeb",
- "last_commit": "8fd3afe",
+ "last_commit": "38a6a56",
"name": "estimation",
"purpose": "Directory tools/estimation. Purpose not yet described by a human."
},
@@ -56,14 +56,14 @@
}
],
"children_root": "sha256:8a042dc49a250f0d1b7ae1358fc70bf7bdc9eff651a5ff7c9ee41fd49d329041",
- "compiled_at": "2026-10-05T16:48:41Z",
+ "compiled_at": "2026-10-05T17:01:01Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:39a4a935c81a9ba2a047be53e745857892c48a9c9e17f5f166e037d36f7a28b6",
+ "digest": "sha256:cc003d272b6b0ba376a8fa7eb4f05a51041c945677ebe6eedcdccaaa929b6545",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"files": 134,
- "generated_at_commit": "678ed89f7b0213130c92d20d481bf429414772e2",
- "source_tree": "sha256:d47b5eda2ca06c7cfafa2cdc13145fc3d587cffaa5c87b765626c7bd06d922ae"
+ "generated_at_commit": "714835409175f776b4a5630d892cf9383ba43b44",
+ "source_tree": "sha256:4a4582c7e05916245e2cc7ad03ce80fa85e56abd1cb13d5dc4703d7113cc317a"
},
"owner_lane": "",
"provenance": {
diff --git a/tools/r16_qualify.sh b/tools/r16_qualify.sh
index ab73dbff1..5e9457168 100755
--- a/tools/r16_qualify.sh
+++ b/tools/r16_qualify.sh
@@ -343,6 +343,14 @@ if [ "${LV[M19]}" = PASS ]; then
LV[M19]=FAIL
fi
fi
+# R16 G6 operator emergency stop runtime (spec/r16-operator-emergency-stop.md): host test
+# plus the guard mutants. PASS needs exit 0 and both pass lines.
+run_target "$RAW_DIR/rx_emergency.log" test-rx-emergency
+LV[RX_EMERGENCY]=$(verdict "$RC" "$RAW_DIR/rx_emergency.log" "RX_EMERGENCY_MUTANTS: PASS")
+if [ "${LV[RX_EMERGENCY]}" = PASS ] && ! grep -Fq -- "RX_EMERGENCY_STOP: PASS" "$RAW_DIR/rx_emergency.log"; then
+ LV[RX_EMERGENCY]=FAIL
+fi
+TG[RX_EMERGENCY]=test-rx-emergency; LOGF[RX_EMERGENCY]="$RAW_DIR/rx_emergency.log"
# g6_test : status of one exercising test; a skipped or unexercised log is NOT_RUN.
g6_test() {
local s=${LV[$1]:-NOT_RUN}
@@ -360,7 +368,7 @@ r9_crash_recovery_passing|src/runtime/rx_generation.c:rx_gen_recover:f|R9|PROXY:
r10_verifier_passing|src/omega_verify.c:omega_verify_v0_structural:f|R10|PROXY: omega_verify_v0_structural is the verifier R10 reaches through rx_omega.c; R10 pass in this run is the evidence.
r12_seat_loss_handling_passing|src/runtime/rx_world.c:rx_resident_seat_lost:f|R12_host,R12_silicon|rx_resident_seat_lost is the seat-loss handler (spec/r12-resident-seat.md, Seat loss). R12 host and silicon exercise it; rx_gpu_seat_kill is only the test hook and is not counted here.
r14_recovery_paths_passing|src/runtime/rx_living.c:fn_restore:f|R14_host,R14_silicon|PROXY: fn_restore (generation.restore reaction) is one R14 recovery path chosen here; R14 host and silicon exercise the recovery runs.
-operator_emergency_controls_passing||R12_silicon|MISSING_IMPLEMENTATION: the spec and brief only list operator emergency controls (docs/r16-operator-brief.md:245) and name no implementation. A search of omega, sovereign-core, aegis-runtime, aienos and physics found none with a test (aegis-runtime EmergencyStop is an unused enum variant). rx_gpu_seat_kill is a test hook, not an operator control, and is not a proxy PASS.
+operator_emergency_controls_passing|src/runtime/rx_world.c:rx_world_emergency_stop:f;src/runtime/rx_world.c:rx_world_emergency_resume:f;src/runtime/rx_generation.c:rx_gen_promote:f;tests/runtime/rx_r13_living.c:rx_world_set_halt_dir:t|RX_EMERGENCY,R12_host|MISSING_IMPLEMENTATION: the runtime control exists (spec/r16-operator-emergency-stop.md: rx_world_emergency_stop / _resume; authority = enrolled caller credential plus an RX_WORLD_RES_CONTROL capability with the privileged RX_RIGHT_EPOCH right, never a reaction subject; a durable sealed OPERATOR_HALT mark that the generation store obeys and a restarted world restores). RX_EMERGENCY (host, real caproot: refusals, in-flight and racing stops, store under a stop, restart, resume, nine guard mutants) and R12_host t_emergency_stop (resident seat stand-in, native AIENOS authority) exercise it. Missing: the production R13 program does not wire it (no rx_world_set_halt_dir, no operator entry point), so no operator can reach it on the candidate; no silicon run exercises a stop.
benchmark_reference_paths_seq_passing|src/runtime/rx_seq_reference.c:rx_seq_pulse:f|R15_parity_host,R15_parity_silicon|Spec line 183 names rx_seq_reference as class D reference oracle. R15 parity host and silicon compare the reaction path with it.'
declare -A G6S
G6LIST=""; G6ALL=""; G6MISSING=0
```