diff --git a/.crumb b/.crumb index 65be78dd9..f994a392e 100644 --- a/.crumb +++ b/.crumb @@ -51,8 +51,8 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "01a9aa128e136ecccdaca33b6babef24d4011a95c2ca1a5dd839d84e2841ce3d", - "last_commit": "38a6a56", + "digest": "01f9bcaf892355eff231425a96bf8f625fc9d9be4c1480991db92b6fefd6cd49", + "last_commit": "96748a2", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -81,39 +81,39 @@ "purpose": "Directory research. Purpose not yet described by a human." }, { - "digest": "4dde878eff597b3669b7dafeb572ba3a560c51ac52d99681524745684c45b258", - "last_commit": "c62f47b", + "digest": "a208771d61d51324273b06beab565036bbc61f3218dfb6cba76d853ec3515073", + "last_commit": "96748a2", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "216a1cd73e993694a7c2ff9580d2b9ec299ddb0876e29ddcaf23e35844ef73bd", - "last_commit": "c2c3073", + "digest": "bf667679bc7c3494f148e83e9d8f56193a3768c2f7145a614a21e701e3bddabd", + "last_commit": "96748a2", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "54875b73cdd1fad056918c0ea3dbadfb1f02ea072a1e2115a8933a202c1d7012", - "last_commit": "6c93c0e", + "digest": "c9825de4f77620c738f1cac290238b55040200959e0938ac03fa41a3c95c488d", + "last_commit": "96748a2", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "6a6bc2fc769c40efe05fcaaa1bc5169b89e3446d1e427060747b78b43dd729a9", - "last_commit": "6c93c0e", + "digest": "ef22f063312bab17b11019f16b48d0e30d907c7bd1af458b6dbc6923907b517f", + "last_commit": "96748a2", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:ec128923135d5c8ffefa1d9295d0046f313f600cd30f09e04b4096ba92e1d7b4", - "compiled_at": "2026-10-05T22:53:19Z", + "children_root": "sha256:51f1e1336815973b126e9f70072b8f3bb765d6088310ab5d70c5787b77e93997", + "compiled_at": "2026-10-06T00:26:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:64c48291581e4edd8e53b866b55e3d4b3217c6f98c5147eee2d1f685c0b3a2f8", + "digest": "sha256:a3e434d50da665e07aec3de6c4c65b3aa19099beb5f41981b7d8119fb6dddab5", "evidence_files": 3304, "evidence_root": "sha256:9594e3e2a05603747e60ab08376dcf98a6857a89e43720f33126d5b68e41f4d1", - "files": 5109, - "generated_at_commit": "120e281a85954a716fc6693a5592759df330f78f", - "source_tree": "sha256:50d7628ab849023c4a45f54a8e11a21480322b2ea458e57d1ee616cdbfc2e767" + "files": 5115, + "generated_at_commit": "96748a2078862997c4ee423797ed4d1a99dcf300", + "source_tree": "sha256:fc575a3688dbd5f8b40cc9933da2ff056ece6af0d601a81e5c4c93d25a99e1b3" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/host-suites-2.yml b/.github/workflows/host-suites-2.yml index 313adae71..8d983f86a 100644 --- a/.github/workflows/host-suites-2.yml +++ b/.github/workflows/host-suites-2.yml @@ -51,6 +51,12 @@ name: Host suites 2 # rx-host.yml only builds the R13/R14 hosts. Spark -j1: all three PASS. # rx-host.yml runs R16-G3 checks 1-3 (sources, link map, embedded names) on # the host and silicon builds and declares every Spark/chip-only run SKIP; +# test-r16-operator-host, test-r16-operator-mutants: environment, same reason. +# They start the production R13 host program and drive it through its +# operator socket; every world runs an R13 episode ("needs both core +# classes", tests/runtime/rx_r13_living.c run()), and the host test holds +# threads of that program under gdb (non-stop). Spark -j1: host 34 s, +# mutants (25) about 5 min, both PASS; test-r16-operator-silicon is a chip target; # test-polyglot: environment. mk/polyglot.mk builds its -O3 flavor with # -mcpu=native next to -march=armv8.6-a+...; on the runner (Neoverse N2) gcc # resolves native to a CPU that conflicts with that -march and -Werror stops diff --git a/Makefile b/Makefile index f216481d4..0de1d65b8 100644 --- a/Makefile +++ b/Makefile @@ -638,6 +638,7 @@ RX_R13_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c \ src/runtime/rx_coherent.c src/runtime/rx_native_bind.c \ src/runtime/rx_aegis.c src/runtime/rx_aien.c src/runtime/rx_omega.c \ src/runtime/rx_generation.c src/runtime/rx_living.c \ + src/runtime/rx_operator.c \ src/sha256.c src/omega_evidence.c src/omega_canonical.c \ src/omega_validate.c src/omega_core.c src/omega_codec.c \ src/aarch64_encoder.c src/aarch64_decoder.c src/omega_realize.c \ @@ -707,7 +708,7 @@ test-jspace-prod: $(RX_JSPACE_PROD_TEST) # R14: the R13 organism attacked while alive. Host uses the R12 processor # stand-in and cannot claim the gate; silicon runs D and E on the GB10 seat. -RX_R14_SRCS = $(filter-out tests/runtime/rx_r13_living.c,$(RX_R13_SRCS)) \ +RX_R14_SRCS = $(filter-out tests/runtime/rx_r13_living.c src/runtime/rx_operator.c,$(RX_R13_SRCS)) \ tests/runtime/rx_r14_recovery.c RX_R14_HOST = $(OUT_DIR)/rx_r14_recovery_host RX_R14_SILICON = $(OUT_DIR)/rx_r14_recovery_silicon @@ -748,7 +749,7 @@ test-r15-instr: $(RX_R15_INSTR) # R15: SEQ semantic parity gate (spec §16 C1 item 9). The R13 body is built # by tests/runtime/rx_r15_rig.c for RES-1 and for the sequential reference. -RX_R15_RIG_SRCS = $(filter-out tests/runtime/rx_r13_living.c,$(RX_R13_SRCS)) \ +RX_R15_RIG_SRCS = $(filter-out tests/runtime/rx_r13_living.c src/runtime/rx_operator.c,$(RX_R13_SRCS)) \ src/runtime/rx_seq_reference.c tests/runtime/rx_r15_rig.c RX_R15_RIG_HDRS = src/runtime/rx_living.h src/runtime/rx_seq_reference.h \ src/runtime/rx_world.h tests/runtime/rx_r15_rig.h @@ -1308,6 +1309,28 @@ test-prod-refuses-test-pieces: $(ARGUS_STAMP) $(AIENOS_CAP_LIB) $(RX_R13_HOST) CC="$(CC)" CFLAGS="$(CFLAGS)" ARGUS_SRC="$(ARGUS_SRC)" OUT="$(OUT_DIR)/prod-refuses" MAKE="$(MAKE)" PROD_BIN="$(RX_R13_HOST)" \ sh tools/r16_prod_refuses.sh +# R16 G6 operator control by execution (docs/r16-operator-control.md): the +# production program driven from outside through its operator entry point. +# Host: the production host binary (R12 processor stand-in). Silicon: the +# production GB10 binary on the resident seat, needs the quiet lock, never +# killed (no SIGKILL phase). The mutants rebuild the production host program +# from mutated copies; the test must fail against each. +RX_OPERATOR_CLI = $(OUT_DIR)/rx_operator +$(RX_OPERATOR_CLI): tools/rx_operator.c | $(OUT_DIR) + $(CC) $(CFLAGS) -o $@ tools/rx_operator.c + +.PHONY: test-r16-operator-host test-r16-operator-silicon test-r16-operator-mutants +test-r16-operator-host: $(RX_R13_HOST) $(RX_OPERATOR_CLI) + bash tests/runtime/rx_operator_host.sh host $(RX_R13_HOST) $(RX_OPERATOR_CLI) + +test-r16-operator-silicon: $(RX_R13_SILICON) $(RX_OPERATOR_CLI) + bash tests/runtime/rx_operator_host.sh silicon $(RX_R13_SILICON) $(RX_OPERATOR_CLI) + +test-r16-operator-mutants: $(RX_R13_HOST) $(RX_OPERATOR_CLI) + CC="$(CC)" CFLAGS="$(CFLAGS)" RX_PROD_ARGUS_FLAGS="$(RX_PROD_ARGUS_FLAGS)" \ + RX_R13_SRCS="$(RX_R13_SRCS)" RX_PROD_ARGUS_SRCS="$(RX_PROD_ARGUS_SRCS)" \ + AIENOS_CAP_LIB="$(AIENOS_CAP_LIB)" bash tests/runtime/rx_operator_mutants.sh $(RX_OPERATOR_CLI) + ARGUS_R7 = $(ARGUS_OUT)/rx_r7_native_test ARGUS_R8 = $(ARGUS_OUT)/rx_r8_aegis_test ARGUS_R9 = $(ARGUS_OUT)/rx_r9_barrier_test diff --git a/docs/.crumb b/docs/.crumb index b1461bf83..8c941367a 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -76,7 +76,7 @@ }, { "digest": "56a5a999ce726e90d89c1c88b9e20c81857c8e6ee82af8d651ac80ea70e2c46d", - "last_commit": "25311c0", + "last_commit": "38a6a56", "name": "estimation", "purpose": "Directory docs/estimation. Purpose not yet described by a human." }, @@ -118,14 +118,14 @@ } ], "children_root": "sha256:ce53c9c7f75a7d122d6a926bb304b2df1bd0730693b54887b842ad3559bafe83", - "compiled_at": "2026-10-05T15:40:51Z", + "compiled_at": "2026-10-06T00:23:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:01a9aa128e136ecccdaca33b6babef24d4011a95c2ca1a5dd839d84e2841ce3d", + "digest": "sha256:01f9bcaf892355eff231425a96bf8f625fc9d9be4c1480991db92b6fefd6cd49", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", - "files": 112, - "generated_at_commit": "25311c0c2aee4eb4991052115d9ad91f5b4d2a1e", - "source_tree": "sha256:cb189c97510cfdc47126abee0105eb8dba61520c3f654644838eba1f08a930ad" + "files": 113, + "generated_at_commit": "fa18e58a86a7402de785e07044f5f444a1dcca3c", + "source_tree": "sha256:0a688cde0c483735c8aee62f8ae2162bc7fbc30456961d7fc031b897c64e1587" }, "owner_lane": "", "provenance": { diff --git a/docs/r16-operator-control.md b/docs/r16-operator-control.md new file mode 100644 index 000000000..597a69a9f --- /dev/null +++ b/docs/r16-operator-control.md @@ -0,0 +1,294 @@ +# R16 G6: operator control of the production program (interface contract) + +Status: CONTRACT, written before the code (lane ESTOP, CAND-3), then implemented. Two +points were corrected from the code: when the socket opens (section 2) and a store +refusal under a stop (section 6). The runtime control it wires is `spec/r16-operator-emergency-stop.md` (merged #300); this document says how an +operator outside the running production program reaches that control, and what the +program does with a request. It adds no authority scheme: every decision is made by the +existing world authority (`rx_world_emergency_stop` / `_resume`, `halt_authorize` in +`src/runtime/rx_world.c`). + +Production program: `tests/runtime/rx_r13_living.c`, built without `AIEN_TEST_BUILD` as +`build/rx_r13_living_host` and `build/rx_r13_living_silicon`. It runs six modes, each in +its own world. Every statement below holds for each of those worlds. + +## 1. Who the operator is and how its authority reaches the program + +* One operator subject, `RX_OPERATOR_SUBJ` (70), not used by any faculty, reaction or + composition subject (`rx_living.h` 61-64, `rx_omega.h` 21-22, `rx_aien.h` 31, + `rx_aegis.h` 41-42, `rx_compose.h` 200+). +* **Credential.** At each world start, with the other production subjects and before + enrollment closes (`rx_living_enroll_callers`, then `rx_world_bind_callers`), the + program enrolls the operator with `rx_world_enroll_caller`: a fresh 32-byte random + secret and a generation, issued by the runtime. The program keeps no copy after + handing it over (below) and wipes its buffer. +* **Capability.** The program mints, through the native AIENOS authority it already + starts (`aienos_cap_start`, the same `mint()` path every production grant uses), one + capability for `RX_OPERATOR_SUBJ` on `RX_WORLD_RES_CONTROL` (0x906) with + `RX_WORLD_RIGHT_HALT` (`RX_RIGHT_EPOCH`: privileged, never delegable). No other + subject is minted anything on that resource; the program's authority sweep fails the + run if any live capability on it belongs to another subject or carries another right. +* **Hand-over.** Both are written to the operator credential file + `/control/operator.cred` (format §3), created mode 0600 in a 0700 directory + owned by the program's user, written to a temporary file, fsynced and renamed. It is + the operator's copy; the world holds only the credential digest and the authority + holds the capability. Anyone who can read the file is, by construction, the operator + account (the program's own uid, or root). +* **No editable boolean grants authority.** The file carries a credential the world + checks in constant time and a capability reference the authority validates; editing + either makes it fail. Nothing in the file, the socket, the environment or the command + line switches a check off. +* **A reaction subject can never control the world.** The world refuses any subject + that a registered reaction runs under (`halt_authorize`, spec §2 point 2). The + operator subject runs no reaction. The program's own reaction credentials never leave + the program, so they cannot be presented from outside; that refusal is proven + in-process by `make test-rx-emergency` (E1) and is not re-proven from outside. + +## 2. The outside entry point + +* An `AF_UNIX` stream socket `/control/operator.sock`, created right after the + world's credential, capability and halt directory exist (before its objects are + built) and removed when the world is torn down. While the program sets the world + up, a request waits (the client allows 60 s) and is answered once setup is done, so + a stop never lands inside setup; a world restored stopped answers at once (it does + no setup until resumed). Between worlds there is no socket: a client gets + "connection refused" and the request does nothing. +* **One program per state directory.** At startup the program takes an exclusive + `flock` on `/operator.lock` (opened `O_CLOEXEC|O_NOFOLLOW`, a regular file of its + uid) and, when a world first uses it, on `/gen-/operator.lock`; it holds + both for its whole life. A second program on the same state directory, or one whose + state directory is the first one's generation directory, is refused (exit 2, + `... is in use by another program (pid N)`) before it touches a socket or a + credential. Each world also locks `control/` the same way while its entry point is + open. The control directory is held open as a descriptor: the stale socket is removed, + the socket bound (through `/proc/self/fd//operator.sock`) and the credential + written and renamed relative to that descriptor, never by a path looked up again. + Close removes the socket and the credential only if they are still the files this + instance created (same device and inode), then releases the lock. +* Two walls before the credential: the directory is 0700 and owned by the program's + user (validated at startup, §5), and every accepted connection is checked with + `SO_PEERCRED`: the peer uid must equal the program's effective uid, else the reply + is `REFUSED reason=peer` and nothing is read further. Root can pass the directory but + not the peer check. +* One request per connection, read with a 2 s receive and send timeout (if either + cannot be set the connection is closed with no reply); at most 511 bytes up to + the first newline. One reply line, then the connection is closed. Requests are served + one at a time by one listener thread (`src/runtime/rx_operator.c`); it never holds the + world lock across a request. +* Client: `build/rx_operator` (`tools/rx_operator.c`). It reads the credential file and + sends one request: `rx_operator --control /control [reason]`, or + `--cred ` to present another file (used by the tests for stale and forged + credentials), or `--raw ` (malformed-request tests). + +## 3. Formats + +Credential file (text): + +``` +aien-operator-credential v1 +world +socket +subject 70 +cred <64 hex secret> +cap +``` + +Request (one line): + +``` +aien-operator v1 subject= gen= secret=<64 hex> cap=: deadline= [reason=] +``` + +`deadline` is required: the `CLOCK_MONOTONIC` time in nanoseconds after which the client +has given up (the client sends now + 55 s and waits 60 s). A deadline more than 120 s +ahead is `BAD_REQUEST`. A request that waited for the world's setup past its deadline is +answered `EXPIRED` and not run, unless it is a `stop`: a late stop is fail-safe and still +runs; a late resume would restart a world nobody is watching. + +`` is `status`, `stop`, `resume`, `revoke-cap`, `revoke` or `shutdown`. Any other +token, a missing or repeated field, a secret that is not 64 hex digits, a number out of +range or extra bytes is `BAD_REQUEST`, decided before any world call. + +Reply (one line): `aien-operator v1 key=value ...`. RESULT is one of `OK`, +`STOPPED_NOT_DURABLE` (the stop is in force in memory but its mark could not be written: +a restart would NOT come up stopped; carries `durable=<-errno> errno= ()`), +`ALREADY` (stop of a stopped world), `NOT_STOPPED` (resume or shutdown of a running world), +`EXPIRED` (the client deadline passed while the request waited; nothing done), +`REFUSED reason=peer|identity|authority`, `BAD_REQUEST`, `ERROR rc=`. +A refusal says nothing about the world: no state, no counters. + +Client exit status: 0 for `OK`, 3 for `STOPPED_NOT_DURABLE`, 1 for any other reply, 2 for +a usage error, no credential file, no world serving the socket, or a reply timeout that +could not be set. + +## 4. Commands + +Every command except `BAD_REQUEST` cases goes to the world authority first. `status`, +`revoke-cap`, `revoke` and `shutdown` are checked by `rx_world_operator_authorize` (the +same `halt_authorize` the stop and resume use, under the same locks, added to +`rx_world.c` so no second authority check exists). `stop` and `resume` are checked inside +`rx_world_emergency_stop` / `_resume` themselves. + +| command | world call | reply on success | +|---|---|---| +| `status` | `rx_world_operator_authorize`, `rx_world_halt_status` | `OK state=running\|stopped restored= seq= durable= refused= cancelled= crumbs= reactions=` plus program counters `served= production_commits= promotion= inforce= active_generation= seat_claims= seat_halted=` | +| `stop [reason]` | `rx_world_emergency_stop` | `OK state=stopped seq= crumb= durable=1`; mark not written: `STOPPED_NOT_DURABLE ... errno=` (client exit 3); a second stop: `ALREADY` with no new crumb | +| `resume` | `rx_world_emergency_resume` | `OK state=running seq=`; a running world: `NOT_STOPPED` | +| `revoke-cap` | authorize, then `aienos_cap_revoke` of the presented control capability by the authority's office | `OK revoked=capability`; afterwards every request with that capability is `REFUSED reason=authority` | +| `revoke` | authorize, then `aienos_cap_revoke` (capability) and `rx_world_revoke_caller` (credential); the credential file is removed | `OK revoked=capability,credential`; afterwards `REFUSED reason=identity` | +| `shutdown` | authorize; only while stopped | `OK state=stopped shutdown=1`; the program ends the current mode, tears the world down with the stop still in force, writes no R13 receipt and exits 3. The durable mark stays. | + +A revoked operator cannot be re-enrolled in the same world (enrollment is closed); the +world keeps running without operator control until the program starts the next world, +which issues a new credential and capability. Revoking while stopped leaves the world +stopped for the rest of that world's life; the durable mark makes the next start of that +mode come up stopped, and the next credential can resume it. + +**Stale credentials.** A credential is valid for one world of one program start: every +world start enrolls a new random secret and mints a new capability. A credential from an +earlier world or an earlier program start fails the constant-time caller check +(`REFUSED reason=identity`). + +## 5. State directory, durability and restart + +* `--state-dir ` names the program's durable state (default: a fresh 0700 scratch + directory under `$TMPDIR`, as before, so `make test-r13-host` keeps running unchanged). + Layout: `/control/` (credential file and socket) and one generation store per mode, + `/gen-/` (`positive`, `no-aien`, `no-promotion`, `revoked-experiment`, + `stale-gpu`, `failed-verification`). +* **Validated at startup, refuse if wrong.** `` and each subdirectory must be a real + directory (opened `O_DIRECTORY|O_NOFOLLOW` and checked with `fstat` on that descriptor, + so a symlink is refused and nothing can be swapped in between), owned by the effective uid, with + no group or other permission bits (`mode & 077 == 0`). A missing subdirectory is + created 0700. A path too long for a socket address is refused. On any refusal the + program prints the reason and exits 2 before any world starts. +* **The durable halt directory is the generation store's directory**: + `rx_world_set_halt_dir(w, /gen-)`, called right after the store is opened + and bound and **before any object is created or any work is published**. A mark there + (`OPERATOR_HALT`, sealed) makes the world start stopped (spec §4: a torn or unreadable + mark also stops it). The program then serves operator requests on the socket and does + nothing else until a resume (or `shutdown`); only then does it build the world's + objects and run. So a restart while stopped restores the stop before it accepts any + work, including its own setup. +* Resume keeps the sealed resumed record `OPERATOR_HALT.resumed..` and only + then removes the mark (spec §4, unchanged). +* Directory protection beyond these checks (another process of the same uid deleting the + mark while no program runs) is the operating system's job (spec §7.3). + +## 6. What a stop covers, and what it does not + +* It stops the world's publications and promotions, exactly as spec §3 lists: no commit, + no outside publication (the production request stream included), no seat result, no + object create or retire, no generation proposal or promotion. In-flight activations + are refused at commit and run again on resume. +* The program keeps its own clocks honest: time spent stopped does not count toward the + episode's deadlines (`run_clock`), a production request refused by the stop is + published again after resume, and the end-of-mode checks wait while the world is + stopped. A durable generation proposal or promotion that the store refuses + because of the stop (`RX_GEN_ERR_HALTED`) is not an outcome: the activation waits + and posts it again after the resume (`halted_wait`, `src/runtime/rx_living.c`). A world + whose episode is done is not torn down while stopped: the program waits for the resume + (or `shutdown`) before it audits and ends the mode. A seat result caught by a stop is + claimed again after the resume; the world counts those claims (`stats.resident_halted`) + and the episode check subtracts them before it compares claims with trials. + A stop therefore delays the episode and leaves its outcome unchanged. +* Evidence: at the end of every mode the program reads its crumb log (the canonical + evidence, spec §4) and prints `R13 operator : stops S resumes R restored X + open O; under stop: commits 0 externals 0 cancelled C`. Any COMMIT or EXTERNAL crumb + between an OPERATOR_STOP and its OPERATOR_RESUME (or after an unresumed stop) fails the + mode. The R13 receipt carries the totals under `"operator"`. +* **Outside effects already underway (spec §7.4).** A stop does not reach a durable + executor already performing an effect outside the world, and it does not interrupt a + GPU kernel already running on the resident seat. The production program has one + outside effect path, the resident seat: a seat result that lands under a stop is + refused and the output window re-projected from the world (spec §3, R12 + `t_emergency_stop`); the kernel's work is discarded and runs again on resume. A stop + does not stop the process, its threads, ARGUS observation or the authority; it is not a + kill switch and not a rollback. + +### 6.1 Known limit: the halt right is the epoch right + +The spec gives the stop the privileged epoch right (`spec/r16-operator-emergency-stop.md` +§2 lines 44-45: "The right is `RX_RIGHT_EPOCH` ... The right that may void every +capability may also pause the world"). ADR 0016 (aien-architecture main 014159e) is +silent on a halt or pause right: neither word occurs in it. Its capability section +(lines 367-382) lists the resource among what a capability binds, and line 1475 asks +that a wrong-resource attack fail. + +The locked native authority does not check the resource when a capability is used: +`auth_use` (aienos `native/capability/aienos_capability.c` lines 205-218 at aienos.lock +bbad5e4) checks delivery, generation, state, epoch, expiry, the delegation chain and +the rights, not the entry's resource. So the operator's control capability +(`RX_WORLD_RES_CONTROL` with `RX_RIGHT_EPOCH`) would also pass `aienos_cap_bump_epoch` +(same file, line 555, through `auth_use(..., AIENOS_CAP_RIGHT_EPOCH, ...)` at line 369) +if anything handed it there. omega does not change the locked authority; the request +is aien-dev/aienos#266 (a resource check in `auth_use`, or a dedicated halt right). + +What keeps it closed today is omega's own code, shown here and tested: + +* The capability is minted once per world (`tests/runtime/rx_r13_living.c` 449, + `mint(r, RX_OPERATOR_SUBJ, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT)`) and passed only + to `rx_operator_open` (line 327), which writes it to the operator's credential file + and keeps no other use of it. +* A presented capability (`q->cap`, parsed at `src/runtime/rx_operator.c` 262) reaches + exactly four calls: `rx_world_emergency_stop` (291), `rx_world_emergency_resume` + (312), `rx_world_operator_authorize` (328, for status, shutdown, revoke-cap and + revoke) and, as the *target* of a revocation authorized by the authority's office, + `aienos_cap_revoke` (360). The first three validate it with + `rx_world_validate_cap(..., RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT, ...)` inside + `halt_authorize` (`src/runtime/rx_world.c` 914). +* Every other command, with a full valid credential, is `BAD_REQUEST` before any + authority call (`rx_operator.c` 327). The host test sends `explode`, `bump-epoch`, + `bump_epoch`, `mint`, `grant`, `epoch`, `STOP`, `Stop`, `stop2`, `resume2` and `halt` + and requires `BAD_REQUEST` for each; mutant O22 removes that refusal and the test fails. +* `aienos_cap_bump_epoch` has no caller in omega's production sources (`git grep`: the + declaration in `src/runtime/aienos_cap.h` 56 and the R7 oracle test + `tests/runtime/rx_r7_native.c` 217 only). + +A future omega change that hands the control capability to any other authority entry +point reopens this; it stays a known limit until aienos#266 is closed. + +## 7. Proof (G6 by execution) + +`make test-r16-operator-host` (`tests/runtime/rx_operator_host.sh`) starts the production +host binary and drives it only through `build/rx_operator` and signals, checking replies, +the files in the state directory and the program's crumb-log audit lines: authorized stop +and resume; forged secret, wrong capability, wrong peer (root via `sudo -n`, reported +SKIPPED and therefore NOT_RUN if sudo is unavailable), malformed request; stale +credential (earlier world, earlier program start); `revoke-cap` and `revoke`; repeated +stop and resume; repeated stop and resume cycles under production load (in-flight work +refused and re-run); promotion blocked while stopped and completed after resume; restart +while stopped after `shutdown` and after `SIGKILL`; recovery to a passing R13 episode; +startup refusal of a group-readable, foreign-owned or symlinked state directory; a +second program on the same state directory or on the first one's generation directory +refused while the first keeps its socket and credential; a stop whose mark cannot be +written (generation directory made 0500) answering `STOPPED_NOT_DURABLE errno=13` with +client exit 3; eleven unknown commands with a full credential refused; an expired +resume answering `EXPIRED` and doing nothing, a missing or too-distant deadline refused. +On host three checks are made deterministic by holding one thread of the production +program under gdb in non-stop mode (the socket keeps serving): the seat acceptor held +with a computed seat result while a stop is accepted, then released, must end that claim +halted (`seat_halted` in status, so the episode's claim subtraction is exercised on +host); the positive world held after its episode's work, stopped, then released, must +stay up and stopped and print that it waits for a resume; the next world's open held +after the positive world closed must find a credential file planted by someone else +still in place. Without gdb those checks are SKIPPED (gate NOT_RUN). Silicon runs +without gdb; its in-flight count is reported, not checked. A host run whose only gap is a +missing `sudo -n` or gdb is NOT_RUN with the reason in the receipt, never FAIL. +`tests/runtime/rx_operator_mutants.sh` rebuilds the production program from mutated +copies and requires the test to fail against each (wiring missing, handler disconnected, +success reply without a state transition, unauthorized resume accepted, wiring present +only in a comment, wiring present only as an unused call, and the others it lists). +`make test-r16-operator-silicon` runs the same test on `build/rx_r13_living_silicon` +(resident GB10 seat) without the SIGKILL phase (a chip program is never killed). The +receipt labels host and silicon results separately. The silicon test requires the +program's own gate `R13_LIVING_SYSTEM=PASS` (bound to the candidate commit on a clean +tree): the spec allows no `SILICON_PASS_UNBOUND`. Each run writes +`operator__receipt.json` to `RX_OP_OUT` (default `build/r16-operator`); the mutant +script gives every mutant its own directory, so a mutant never overwrites the real receipt. +`tools/r16_qualify.sh` copies both receipts into its raw directory (covered by the raw +digest) and refuses PASS unless each names its seat, the candidate commit on a clean tree, +no failure or skip, the seat's gate, and the SHA-256 of the production binary built in that +run; the silicon run counts toward `silicon_observed`. The G6 item +`operator_emergency_controls_passing` is PASS only when both ran and passed in the same +qualification run on the candidate. diff --git a/docs/r16-production-entry-point.md b/docs/r16-production-entry-point.md index 8e1935bc6..337d5aed4 100644 --- a/docs/r16-production-entry-point.md +++ b/docs/r16-production-entry-point.md @@ -31,6 +31,20 @@ credential, and work can no longer be added already done. | recovery | `tests/runtime/rx_r14_recovery.c` on the same sources | `test-r14-host`, `test-r14-silicon` | | proof that no legacy orchestrator is in the path (G3) | link map, strings and exec trace of the production binaries above | `test-r16-authpath`, `test-r16-authpath-silicon` | +### Operator control (R16 G6, CAND-3) + +The production program takes one optional argument, `--state-dir `: its +durable state, validated at startup (a real directory owned by the program's +user, no group or other permission bits; anything else is refused with exit 2 +before any world starts). Without it the program uses a fresh 0700 scratch +directory, as before. `/gen-/` is each mode's generation store and +also its durable halt directory; `/control/` holds the operator credential +file and the owner-only socket `operator.sock`. The only outside entry point is +that socket, driven by `build/rx_operator` (`tools/rx_operator.c`): status, stop, +resume, revoke-cap, revoke, and shutdown while stopped. The contract is +`docs/r16-operator-control.md`; the proof is `make test-r16-operator-host`, +`make test-r16-operator-mutants` and `make test-r16-operator-silicon`. + ### Production program and test build (Lane 32) Test-only pieces build only with one flag, `AIEN_TEST_BUILD` (`-DAIEN_TEST_BUILD=1`, diff --git a/spec/.crumb b/spec/.crumb index eb6e3f7ae..497aafead 100644 --- a/spec/.crumb +++ b/spec/.crumb @@ -20,14 +20,14 @@ } ], "children_root": "sha256:6834a3241647d3a098283d4eafedbdb1428dfa4d834f9ed5f22025b6d2303093", - "compiled_at": "2026-10-05T17:35:25Z", + "compiled_at": "2026-10-06T00:23:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:4dde878eff597b3669b7dafeb572ba3a560c51ac52d99681524745684c45b258", + "digest": "sha256:a208771d61d51324273b06beab565036bbc61f3218dfb6cba76d853ec3515073", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 56, - "generated_at_commit": "b3f7c97a22a105748d4dc4cf5bd34ca2e912f853", - "source_tree": "sha256:cf38443997fd6250145703f37288a5141786e8d878db262612464e33a5663d17" + "generated_at_commit": "fa18e58a86a7402de785e07044f5f444a1dcca3c", + "source_tree": "sha256:7dd1a87e6835f7a9c18cd979acbcfa96f53a8fa6ac309fccbb015470b024823f" }, "owner_lane": "", "provenance": { diff --git a/spec/r16-operator-emergency-stop.md b/spec/r16-operator-emergency-stop.md index 58d37b0d6..4ab5ed29d 100644 --- a/spec/r16-operator-emergency-stop.md +++ b/spec/r16-operator-emergency-stop.md @@ -1,10 +1,12 @@ # 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. +Status: runtime control IMPLEMENTED and host-tested; WIRED into the production R13 +program with an outside operator entry point (`docs/r16-operator-control.md`, +CAND-3 lane ESTOP). G6 item `operator_emergency_controls_passing` is operated +only by execution: the host integration test `make test-r16-operator-host` and its +mutants `make test-r16-operator-mutants`, plus the silicon run +`make test-r16-operator-silicon`. It is not PASS until a silicon receipt from the +candidate exists. 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`), @@ -155,16 +157,23 @@ 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. +## 7. Not done + +1. **Production wiring: DONE (CAND-3).** The production R13 program sets the + generation store's directory as the halt directory before any object exists, + restores a durable stop before it accepts work, and serves an owner-only + operator socket (`src/runtime/rx_operator.c`, client `build/rx_operator`). The + interface contract is `docs/r16-operator-control.md`. The old string-presence + check (`rx_world_set_halt_dir` text in the R13 source) is gone: the G6 item now + needs the operator integration test, its mutants and the silicon run to pass. + Found by the integration test and fixed with it: a durable promotion or + proposal that the store refused because of a stop (`RX_GEN_ERR_HALTED`) was + recorded as the final outcome, so the positive episode never promoted after + the resume. `src/runtime/rx_living.c` now treats that refusal as "run again + after the resume" (`halted_wait`). +2. **Silicon.** The silicon run of the operator test (`make + test-r16-operator-silicon`, resident GB10 seat, no SIGKILL phase) is the only + chip evidence; until it has passed on the candidate the item is not PASS. 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; diff --git a/spec/r16-orchestrator-retirement-map.md b/spec/r16-orchestrator-retirement-map.md index a3f9845ed..15fc89faf 100644 --- a/spec/r16-orchestrator-retirement-map.md +++ b/spec/r16-orchestrator-retirement-map.md @@ -383,6 +383,8 @@ any production binary); in-file Rust `#[cfg(test)]` modules likewise. | OM-282 | omega | `tools/estimation/est6dev.c` | 251 | `run_g1` | EST v6 development G1 scoring walk | - | N | false | N: walk: scores recorded ticks in order (data ticks, not a scheduler tick), without wait or hand-off; offline development tool, not on the production path | `for (size_t t = 0; t < tk->n; t++) {` | | OM-283 | omega | `tools/estimation/test_est_json.c` | 62,74 | `jvalue` | JSON object/array parse in the strict-JSON test validator | test / reference path | D | false | test of the EST strict-JSON receipt rules: recursive JSON parse without wait or hand-off; not built into any production binary | `else for (;;) {` | | OM-284 | omega | `tools/estimation/test_est_json.c` | 101 | `slurp` | whole-file read in the strict-JSON test validator | test / reference path | D | false | test of the EST strict-JSON receipt rules: file read into a growing buffer until end of file, without wait or hand-off; not built into any production binary | `for (;;) {` | +| OM-285 | omega | `src/runtime/rx_operator.c` | 319 | `listener_main` | operator control socket listener | R16 G6 operator entry point of the production program | B | true | explicit deterministic operator mechanism: waits (poll) for one operator connection on the owner-only socket, answers that one request through the world authority, waits for the next; the operator decides every stop and resume, the loop decides no faculty order (docs/r16-operator-control.md) | `for (;;) {` | +| OM-286 | omega | `tests/runtime/rx_r13_living.c` | 311 | `publish` | production request publication waits out an operator stop | R16 G6 operator stop honoured by the production request stream | B | true | operator emergency stop mechanism: a publication refused with RX_ERR_HALTED waits until the operator resumes (or shuts the program down) and publishes the same request again; any other result returns at once; decides no faculty order | `for (;;) {` | | SC-001 | aien-sovereign-core | `benchmarks/crates/bench_apples_to_apples/src/engine_max.rs` | 55 | `start` | test/benchmark loop (while:body:sleep) | test / reference path | D | false | test, benchmark or example code; not built into any production binary | `while start.elapsed() < timeout {` | | SC-002 | aien-sovereign-core | `benchmarks/crates/bench_apples_to_apples/src/telemetry.rs` | 96 | `start` | test/benchmark loop (while:body:tick) | test / reference path | D | false | test, benchmark or example code; not built into any production binary | `while !stop_clone.load(Ordering::Relaxed) {` | | SC-003 | aien-sovereign-core | `benchmarks/crates/bench_apples_to_apples/src/telemetry.rs` | 168 | `enforce_thermal_cooldown` | test/benchmark loop (while:body:sleep) | test / reference path | D | false | test, benchmark or example code; not built into any production binary | `while start.elapsed() < max_wait {` | @@ -652,6 +654,9 @@ exists in the file (symbol not verified) and applies the same class rules. | OM-M01 | omega | `tools/omegatool.c` | manual (2642) | `legacy_oracle_run_demonstration_living_matvec` | body of the hand-sequenced living-matvec demonstration | retire with `--demonstrate-living-matvec` (W5) | A | false | the function the class-A dispatcher row calls; moved behind a `legacy_oracle` name (W5) | `static void legacy_oracle_run_demonstration_living_matvec(void) {` | | OM-103 | omega | `tools/omegatool.c` | manual (3749) | `legacy_oracle_demonstrate_living_matvec` | hand-sequenced living matvec demonstration (spec -> machine -> kernel -> benchmark -> select) | retire: legacy oracle only, under the explicit mode `--legacy-oracle-living-matvec` (R16-G5); the old `--demonstrate-living-matvec` mode is gone | A | false | spec 3.1 / 4: the omega hand-sequenced tool path replaced by the R13 living system; retired behind legacy_oracle symbol names (W5) and, for G5, an explicit legacy mode name; moved to the manual rows because the renamed mode no longer matches the cli-mode pattern | `if (strcmp(arg, "--legacy-oracle-living-matvec") == 0) {` | | OM-M02 | omega | `tools/omegatool.c` | manual (3821) | `main` | hand-sequenced milestone demonstrations (16 modes: arithmetic, physics, realization, self-host, verify, program, synthesis, library, discovery, machine, realization-synthesis, accelerator, accelerator-world, blackwell-matmul, blackwell-codegen, blackwell-vector) | reference oracle (legacy orchestrated runtime) | D | false | historical milestone demonstrations; migration map: omegatool = Oracle; not a production entry point; G5: kept only under `--reference-demonstrate-`, dispatched from the one `reference_modes` table that also prints usage; replaces the 16 per-mode cli-mode rows, which the table-driven dispatch no longer shows to the pattern | `int ref_rc = reference_demonstrate(argv[1], 0);` | +| OM-M03 | omega | `tests/runtime/rx_r13_living.c` | manual (306) | `wait_running` | wait while the world is under an operator stop | R16 G6 operator stop honoured by the production program | B | true | operator emergency stop mechanism: polls the world's halt state (1 ms) until the operator resumes, shuts the program down or the world is torn down; sequences no faculty; listed by hand (the loop pattern does not see a `while` on a call) | `while (world_halted(r)) {` | +| OM-M04 | omega | `tests/runtime/rx_r13_living.c` | manual (1064) | `run` | stale-GPU retire waits out an operator stop | R16 G6 operator stop honoured by the stale-GPU injection | B | true | operator emergency stop mechanism: a retire refused with RX_ERR_HALTED waits for the resume (`wait_running`) and is tried again; sequences no faculty; listed by hand | `while ((rr = rx_world_retire(&r->w, r->living.o.output)) == RX_ERR_HALTED)` | +| OM-M05 | omega | `tests/runtime/rx_r13_living.c` | manual (1104) | `run` | end-of-episode quiescence wait under an operator stop | R16 G6 operator stop honoured before the episode checks | B | true | operator emergency stop mechanism: the settled-world wait is repeated only while the world is stopped, each time after waiting for the resume; sequences no faculty; listed by hand | `while ((quiet = rx_world_wait_quiescent(&r->w, 10000)) != RX_OK && world_halted(r))` | ## 5. Structural findings (non-greppable §4 terms) @@ -914,3 +919,36 @@ After: `sites=521 unclassified=0 question=0 bad_class=0 a_reachable=0 stale=0 map_errors=0 skipped=0 -> PASS`. (omega code `79a805d`; this map change touches no code, so the CAND-2 omega commit is `79a805d`.) This is the G1/G2 inventory for the CAND-2 code, not an R16 qualification receipt. + +### 8.7 Update 2026-10-05 (cand3 lane ESTOP): operator control of the production program + +The CAND-3 operator-control change (branch `cand3/operator-control`, docs/r16-operator-control.md) +adds two loop sites. Scan set: this omega tree, and clean checkouts of the §8.6 commits for the +other repos (aien-sovereign-core at `286fa9b`, which differs from `2eec75b` only in `.crumb` and +`omega.lock`; aegis-runtime `f4e8709`; aienos `bbad5e4`; physics `6d7cf0d`). + +Before: `sites=523 unclassified=2 question=0 bad_class=0 a_reachable=0 stale=0 map_errors=0 skipped=0 -> FAIL`. + +Reconciliation, each row from reading the loop (no tool, pattern, threshold or class rule changed): +- OM-285, class B: the operator socket listener (`listener_main`, `src/runtime/rx_operator.c`). +- OM-286, class B: the production request publication waiting out an operator stop (`publish`, + `tests/runtime/rx_r13_living.c`). +Neither sequences faculties: each waits for the operator or for the world to run again. + +After: `sites=523 unclassified=0 question=0 bad_class=0 a_reachable=0 stale=0 map_errors=0 skipped=0 -> PASS`. +This is the G1/G2 inventory for the CAND-3 operator-control code, not an R16 qualification receipt. + +### 8.8 Update 2026-10-05 (cand3 lane ESTOP, review fixes): operator wait loops listed by hand + +Review of omega#309 (gate integrity, G8) asked that the operator-stop wait loops the +pattern scan does not count be listed by hand with a class. Three manual rows (§4.1), +each from reading the loop: +- OM-M03, class B: `wait_running` (`tests/runtime/rx_r13_living.c`), the 1 ms poll while the + world is under an operator stop. +- OM-M04, class B: the stale-GPU retire in `run` that waits out a stop and tries again. +- OM-M05, class B: the settled-world wait in `run`, repeated only while the world is stopped. +None sequences faculties: each waits for the operator. The tool checks that each evidence +line still exists (a changed evidence line was shown to give `stale=1 -> FAIL`). + +After: `sites=523 unclassified=0 question=0 bad_class=0 a_reachable=0 stale=0 map_errors=0 skipped=0 -> PASS` +(same scan set as §8.7). Not an R16 qualification receipt. diff --git a/src/.crumb b/src/.crumb index 0eb185b4e..d0e514468 100644 --- a/src/.crumb +++ b/src/.crumb @@ -133,8 +133,8 @@ "purpose": "Directory src/polyglot. Purpose not yet described by a human." }, { - "digest": "7927099dac3838db8f33a305a185873d9610c7c496fc3763ec9e5dc9e901bb9d", - "last_commit": "bf89cda", + "digest": "63f3df62adf0a29ee2fdfdc4e170409de18f8a2a33c5644ab8d4009cf1c5246f", + "last_commit": "def0a0d", "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:100d089dae58ac28d48f3c8e0426a60913380b117fd49f9e54ee33620370ff25", - "compiled_at": "2026-10-05T20:10:00Z", + "children_root": "sha256:920218d42490379078986bd65f6d50e8ef9064df20da67bfc0ca50ea0de4b4c0", + "compiled_at": "2026-10-06T00:23:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:216a1cd73e993694a7c2ff9580d2b9ec299ddb0876e29ddcaf23e35844ef73bd", + "digest": "sha256:bf667679bc7c3494f148e83e9d8f56193a3768c2f7145a614a21e701e3bddabd", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 406, - "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", - "source_tree": "sha256:d2d655d8913f1943c3e771446f0d82a900b32e690527cde887157aef0e74de8d" + "files": 408, + "generated_at_commit": "fa18e58a86a7402de785e07044f5f444a1dcca3c", + "source_tree": "sha256:d171d30065cacc0d402c1013b920ad3cf4392e78ed56d71fd0fa4669a2ac865b" }, "owner_lane": "", "provenance": { diff --git a/src/runtime/.crumb b/src/runtime/.crumb index afd44ab97..b30b38677 100644 --- a/src/runtime/.crumb +++ b/src/runtime/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-05T20:10:00Z", + "compiled_at": "2026-10-06T00:23:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:7927099dac3838db8f33a305a185873d9610c7c496fc3763ec9e5dc9e901bb9d", + "digest": "sha256:63f3df62adf0a29ee2fdfdc4e170409de18f8a2a33c5644ab8d4009cf1c5246f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 59, - "generated_at_commit": "f8ce768210e58d33e675a7bbae2208ccbfc58db7", - "source_tree": "sha256:6eede518faaae5783b6f84140535af1105d811b5975bffdda56934065ac91687" + "files": 61, + "generated_at_commit": "fa18e58a86a7402de785e07044f5f444a1dcca3c", + "source_tree": "sha256:d6c5fe7ac0396ceedc2c666adae44e38d9c03553974f120898eea988cbc033a4" }, "owner_lane": "", "provenance": { diff --git a/src/runtime/rx_living.c b/src/runtime/rx_living.c index a10d917a5..2efb1c46b 100644 --- a/src/runtime/rx_living.c +++ b/src/runtime/rx_living.c @@ -179,6 +179,17 @@ static void resume_promoter(void *ctx) { rx_world_resume(p->world, p->reaction); } +/* R16 G6: a durable store step refused because an operator stop is in force + * (RX_GEN_ERR_HALTED, from the world or the durable mark) is not an outcome. + * The activation waits in place: it defers and asks to run again, and no + * worker takes work while the world is stopped, so the re-run comes after the + * resume and posts the step again (spec section 3: in-flight work runs again + * on resume). Recording the refusal instead would make it final. */ +static int halted_wait(RxWorld *w, uint32_t reaction) { + rx_world_resume(w, reaction); + return RX_FN_DEFER; +} + static int fn_candidate(RxCtx *c) { RxLiving *l = c->user; RxWorld *w = l->world; @@ -302,6 +313,7 @@ static int fn_candidate(RxCtx *c) { RxGenJobResult jr; if (rx_gen_job_state(l->store, RX_GEN_JOB_PROPOSE, &jr) == RX_GEN_JOB_DONE) { rx_gen_job_take(l->store, RX_GEN_JOB_PROPOSE); + if (jr.rc == RX_GEN_ERR_HALTED) return halted_wait(w, l->r_candidate); if (jr.rc == RX_GEN_OK) { l->proposed_epoch = jr.key; l->candidate_id = jr.id; @@ -335,10 +347,13 @@ static int fn_candidate(RxCtx *c) { /* The store's fsyncs run on the durable executor, not on this * worker. A proposal still in flight (this epoch's or an older * one's) resumes this activation when it lands. */ - if (rx_gen_job_state(l->store, RX_GEN_JOB_PROPOSE, NULL) == RX_GEN_JOB_IDLE && - rx_gen_post_propose_as(l->store, epoch, RX_LIVING_PREPARE_SUBJ, - rx_caller_find(l->keys, RX_LIVING_PREPARE_SUBJ), &draft, - resume_candidate, l) != RX_GEN_OK) { + int prc = RX_GEN_OK; + if (rx_gen_job_state(l->store, RX_GEN_JOB_PROPOSE, NULL) == RX_GEN_JOB_IDLE) + prc = rx_gen_post_propose_as(l->store, epoch, RX_LIVING_PREPARE_SUBJ, + rx_caller_find(l->keys, RX_LIVING_PREPARE_SUBJ), &draft, + resume_candidate, l); + if (prc == RX_GEN_ERR_HALTED) return halted_wait(w, l->r_candidate); + if (prc != RX_GEN_OK) { decline(l, RX_LIVING_WHY_PROPOSE); return -1; } @@ -462,6 +477,7 @@ static int fn_promote(RxCtx *c) { int rc = RX_GEN_OK; if (rx_gen_exec_running(p->store)) { if (promote_durable(p, id, &rc, &active, &ns)) return RX_FN_DEFER; + if (rc == RX_GEN_ERR_HALTED) return halted_wait(p->world, p->reaction); } else { promote_inline(p, id, &rc, &active, &ns); } diff --git a/src/runtime/rx_operator.c b/src/runtime/rx_operator.c new file mode 100644 index 000000000..8cbd3aef8 --- /dev/null +++ b/src/runtime/rx_operator.c @@ -0,0 +1,549 @@ +/* R16 G6 operator entry point (docs/r16-operator-control.md). */ +#include "rx_operator.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct RxOperator { + RxOperatorConfig cfg; + char sock_path[sizeof(((struct sockaddr_un *)0)->sun_path)]; + int dir_fd; /* the validated control directory, held open */ + int lock_fd; /* flock on RX_OPERATOR_LOCK in it, held until close */ + struct stat sock_st, cred_st;/* what this instance created (device, inode) */ + int sock_made, cred_made; + int listen_fd; + int wake[2]; /* a byte on wake[1] ends the listener */ + pthread_t thread; + int thread_live; + pthread_mutex_t gate; /* held by the program while it sets the world up */ +}; + +/* Validate an open directory descriptor: a directory owned by this uid with no + * group or other bits. Checks the descriptor itself, not a path. */ +static int dir_fd_ok(int fd, const char *dir, char *why, size_t n) { + struct stat st; + if (fstat(fd, &st) != 0) { snprintf(why, n, "%s: %s", dir, strerror(errno)); return -1; } + if (!S_ISDIR(st.st_mode)) { snprintf(why, n, "%s is not a directory", dir); return -1; } + if (st.st_uid != geteuid()) { + snprintf(why, n, "%s is owned by uid %u, not by this program's uid %u", dir, + (unsigned)st.st_uid, (unsigned)geteuid()); + return -1; + } + if (st.st_mode & 077) { + snprintf(why, n, "%s has mode %03o: group or other may reach it (need no bits in 077)", + dir, (unsigned)(st.st_mode & 0777)); + return -1; + } + return 0; +} + +int rx_operator_dir_open(const char *dir, int create, int *fd_out, char *why, size_t n) { + *fd_out = -1; + if (!dir || !dir[0]) { snprintf(why, n, "no directory"); return -1; } + int fd = open(dir, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); + if (fd < 0 && errno == ENOENT && create) { + if (mkdir(dir, 0700) != 0 && errno != EEXIST) { + snprintf(why, n, "%s: cannot create: %s", dir, strerror(errno)); + return -1; + } + fd = open(dir, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); + } + if (fd < 0) { + int e = errno; + struct stat st; /* only to name the refusal; the decision is the failed open */ + int l = lstat(dir, &st) == 0; + if (l && S_ISLNK(st.st_mode)) snprintf(why, n, "%s is a symlink", dir); + else if (l && st.st_uid != geteuid()) + snprintf(why, n, "%s is owned by uid %u, not by this program's uid %u (%s)", dir, + (unsigned)st.st_uid, (unsigned)geteuid(), strerror(e)); + else if (e == ENOTDIR) snprintf(why, n, "%s is not a directory", dir); + else snprintf(why, n, "%s: %s", dir, strerror(e)); + return -1; + } + if (dir_fd_ok(fd, dir, why, n) != 0) { close(fd); return -1; } + *fd_out = fd; + return 0; +} + +int rx_operator_dir_check(const char *dir, int create, char *why, size_t n) { + int fd; + if (rx_operator_dir_open(dir, create, &fd, why, n) != 0) return -1; + close(fd); + return 0; +} + +/* flock on RX_OPERATOR_LOCK inside the held directory `dfd`. */ +static int lock_at(int dfd, const char *dir, int *lock_fd, char *why, size_t n) { + *lock_fd = -1; + int fd = openat(dfd, RX_OPERATOR_LOCK, O_RDWR | O_CREAT | O_CLOEXEC | O_NOFOLLOW, 0600); + if (fd < 0) { snprintf(why, n, "%s/%s: %s", dir, RX_OPERATOR_LOCK, strerror(errno)); return -1; } + struct stat st; + if (fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) || st.st_uid != geteuid()) { + snprintf(why, n, "%s/%s is not a regular file of this uid", dir, RX_OPERATOR_LOCK); + close(fd); + return -1; + } + if (flock(fd, LOCK_EX | LOCK_NB) != 0) { + int e = errno; + char held[32] = ""; + ssize_t r = pread(fd, held, sizeof held - 1, 0); + held[r > 0 ? r : 0] = 0; + held[strcspn(held, "\n")] = 0; + if (e == EWOULDBLOCK) + snprintf(why, n, "%s is in use by another program (pid %s)", dir, held[0] ? held : "?"); + else + snprintf(why, n, "%s/%s: lock: %s", dir, RX_OPERATOR_LOCK, strerror(e)); + close(fd); + return -1; + } + char pid[32]; + int len = snprintf(pid, sizeof pid, "%ld\n", (long)getpid()); + if (ftruncate(fd, 0) != 0 || pwrite(fd, pid, (size_t)len, 0) != len) { + snprintf(why, n, "%s/%s: %s", dir, RX_OPERATOR_LOCK, strerror(errno)); + close(fd); + return -1; + } + *lock_fd = fd; + return 0; +} + +int rx_operator_lock_dir(const char *dir, int create, int *lock_fd, char *why, size_t n) { + int dfd; + *lock_fd = -1; + if (rx_operator_dir_open(dir, create, &dfd, why, n) != 0) return -1; + int rc = lock_at(dfd, dir, lock_fd, why, n); + close(dfd); + return rc; +} + +static void hex32(const uint8_t *b, char out[65]) { + for (int i = 0; i < 32; i++) snprintf(out + 2 * i, 3, "%02x", b[i]); +} + +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; +} + +static uint64_t monotonic_ns(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec; +} + +/* The operator's copy of its credential: 0600, written whole or not at all, + * every name relative to the held control directory. */ +static int write_cred(RxOperator *op, uint32_t subject, const RxCallerCred *cred, RxCapRef cap) { + static const char tmp[] = RX_OPERATOR_CRED ".partial"; + char secret[65], buf[1024]; + hex32(cred->secret, secret); + int len = snprintf(buf, sizeof buf, + "aien-operator-credential v1\nworld %s %ld %llu\nsocket %s\nsubject %u\n" + "cred %llu %s\ncap %u %llu\n", + op->cfg.world_key ? op->cfg.world_key : "-", (long)getpid(), + (unsigned long long)realtime_ns(), op->sock_path, subject, + (unsigned long long)cred->generation, secret, cap.cap_id, + (unsigned long long)cap.generation); + for (size_t i = 0; i < sizeof secret; i++) ((volatile char *)secret)[i] = 0; + if (len <= 0 || (size_t)len >= sizeof buf) return -1; + int fd = openat(op->dir_fd, tmp, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, 0600); + int rc = fd < 0 ? -1 : 0; + if (rc == 0 && fchmod(fd, 0600) != 0) rc = -1; + for (int off = 0; rc == 0 && off < len;) { + ssize_t w = write(fd, buf + off, (size_t)(len - off)); + if (w < 0 && errno == EINTR) continue; + if (w <= 0) rc = -1; else off += (int)w; + } + if (rc == 0 && fsync(fd) != 0) rc = -1; + if (rc == 0 && fstat(fd, &op->cred_st) != 0) rc = -1; + if (fd >= 0) close(fd); + for (size_t i = 0; i < sizeof buf; i++) ((volatile char *)buf)[i] = 0; + if (rc == 0 && renameat(op->dir_fd, tmp, op->dir_fd, RX_OPERATOR_CRED) != 0) rc = -1; + if (rc == 0 && fsync(op->dir_fd) != 0) rc = -1; + if (rc != 0) unlinkat(op->dir_fd, tmp, 0); + else op->cred_made = 1; + return rc; +} + +/* Remove `name` from the held directory only if it is still the file this + * instance made (same device and inode). */ +static void unlink_own(RxOperator *op, const char *name, const struct stat *made, int *flag) { + struct stat st; + if (!*flag || op->dir_fd < 0) return; + if (fstatat(op->dir_fd, name, &st, AT_SYMLINK_NOFOLLOW) == 0 && + st.st_dev == made->st_dev && st.st_ino == made->st_ino) + unlinkat(op->dir_fd, name, 0); + *flag = 0; +} + +/* ---- one request ---------------------------------------------------------- */ + +typedef struct { + char cmd[16]; + uint32_t subject; + RxCallerCred cred; + RxCapRef cap; + int32_t reason; + uint64_t deadline_ns; /* CLOCK_MONOTONIC: the client has given up after this */ + int have_subject, have_gen, have_secret, have_cap, have_reason, have_deadline; +} Req; + +/* A request deadline further ahead than this is refused (the client waits 60 s). */ +#define RX_OPERATOR_DEADLINE_MAX_NS 120000000000ull + +static int hexval(char c) { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + return -1; +} + +/* Strict unsigned decimal into *out, at most `max`. */ +static int udec(const char *s, uint64_t max, uint64_t *out) { + if (!*s) return -1; + uint64_t v = 0; + for (; *s; s++) { + if (*s < '0' || *s > '9') return -1; + uint64_t d = (uint64_t)(*s - '0'); + if (v > (max - d) / 10) return -1; + v = v * 10 + d; + } + *out = v; + return 0; +} + +static int parse(char *line, Req *q) { + memset(q, 0, sizeof *q); + char *save = NULL; + char *t = strtok_r(line, " ", &save); + if (!t || strcmp(t, "aien-operator") != 0) return -1; + if (!(t = strtok_r(NULL, " ", &save)) || strcmp(t, "v1") != 0) return -1; + if (!(t = strtok_r(NULL, " ", &save)) || strlen(t) >= sizeof q->cmd) return -1; + snprintf(q->cmd, sizeof q->cmd, "%s", t); + while ((t = strtok_r(NULL, " ", &save))) { + char *eq = strchr(t, '='); + if (!eq) return -1; + *eq = 0; + const char *k = t, *v = eq + 1; + uint64_t x, y; + if (strcmp(k, "subject") == 0 && !q->have_subject) { + if (udec(v, UINT32_MAX, &x) != 0) return -1; + q->subject = (uint32_t)x; q->have_subject = 1; + } else if (strcmp(k, "gen") == 0 && !q->have_gen) { + if (udec(v, UINT64_MAX, &x) != 0) return -1; + q->cred.generation = x; q->have_gen = 1; + } else if (strcmp(k, "secret") == 0 && !q->have_secret) { + if (strlen(v) != 2 * RX_CALLER_SECRET_LEN) return -1; + for (unsigned i = 0; i < RX_CALLER_SECRET_LEN; i++) { + int hi = hexval(v[2 * i]), lo = hexval(v[2 * i + 1]); + if (hi < 0 || lo < 0) return -1; + q->cred.secret[i] = (uint8_t)(hi << 4 | lo); + } + q->have_secret = 1; + } else if (strcmp(k, "cap") == 0 && !q->have_cap) { + char a[24]; + const char *c = strchr(v, ':'); + if (!c || (size_t)(c - v) >= sizeof a) return -1; + memcpy(a, v, (size_t)(c - v)); + a[c - v] = 0; + if (udec(a, UINT32_MAX, &x) != 0 || udec(c + 1, UINT64_MAX, &y) != 0) return -1; + q->cap = (RxCapRef){(uint32_t)x, y}; q->have_cap = 1; + } else if (strcmp(k, "reason") == 0 && !q->have_reason) { + if (udec(v, INT32_MAX, &x) != 0) return -1; + q->reason = (int32_t)x; q->have_reason = 1; + } else if (strcmp(k, "deadline") == 0 && !q->have_deadline) { + if (udec(v, UINT64_MAX, &x) != 0) return -1; + q->deadline_ns = x; q->have_deadline = 1; + } else { + return -1; + } + } + if (!q->have_subject || !q->have_gen || !q->have_secret || !q->have_cap || !q->have_deadline) + return -1; + if (q->deadline_ns > monotonic_ns() + RX_OPERATOR_DEADLINE_MAX_NS) return -1; + if (q->have_reason && strcmp(q->cmd, "stop") != 0) return -1; + return 0; +} + +static const char *refusal(int rc) { + return rc == RX_ERR_IDENTITY ? "identity" : rc == RX_ERR_AUTHORITY ? "authority" : NULL; +} + +static void handle(RxOperator *op, Req *q, char *out, size_t n) { + RxWorld *w = op->cfg.world; + RxHaltStatus h; + memset(&h, 0, sizeof h); + int stop = strcmp(q->cmd, "stop") == 0, resume = strcmp(q->cmd, "resume") == 0; + int rc; + if (stop) { + rc = rx_world_emergency_stop(w, q->subject, &q->cred, q->cap, q->reason, &h); + if (rc == RX_OK) { + if (op->cfg.on_halt) op->cfg.on_halt(op->cfg.ctx, 1); + if (h.durable == 1) + snprintf(out, n, "OK state=stopped seq=%llu crumb=%llu durable=1", + (unsigned long long)h.seq, (unsigned long long)h.crumb); + else /* in force in memory; a restart would NOT come up stopped */ + snprintf(out, n, "STOPPED_NOT_DURABLE state=stopped seq=%llu crumb=%llu durable=%d " + "errno=%d (%s)", (unsigned long long)h.seq, (unsigned long long)h.crumb, + h.durable, h.durable < 0 ? -h.durable : 0, + h.durable < 0 ? strerror(-h.durable) : "no durable halt directory"); + } else if (rc == RX_HALT_ALREADY) { + snprintf(out, n, "ALREADY state=stopped seq=%llu", (unsigned long long)h.seq); + } else if (refusal(rc)) { + snprintf(out, n, "REFUSED reason=%s", refusal(rc)); + } else { + snprintf(out, n, "ERROR rc=%d", rc); + } + return; + } + if (resume) { + rc = rx_world_emergency_resume(w, q->subject, &q->cred, q->cap, &h); + if (rc == RX_OK) { + if (op->cfg.on_halt) op->cfg.on_halt(op->cfg.ctx, 0); + snprintf(out, n, "OK state=running seq=%llu", (unsigned long long)h.seq); + } else if (rc == RX_HALT_NOT_STOPPED) { + snprintf(out, n, "NOT_STOPPED state=running"); + } else if (refusal(rc)) { + snprintf(out, n, "REFUSED reason=%s", refusal(rc)); + } else { + snprintf(out, n, "ERROR rc=%d", rc); + } + return; + } + int status = strcmp(q->cmd, "status") == 0, shutdown = strcmp(q->cmd, "shutdown") == 0; + int revoke = strcmp(q->cmd, "revoke") == 0, revoke_cap = strcmp(q->cmd, "revoke-cap") == 0; + if (!status && !shutdown && !revoke && !revoke_cap) { snprintf(out, n, "BAD_REQUEST"); return; } + rc = rx_world_operator_authorize(w, q->subject, &q->cred, q->cap); + if (rc != RX_OK) { + if (refusal(rc)) snprintf(out, n, "REFUSED reason=%s", refusal(rc)); + else snprintf(out, n, "ERROR rc=%d", rc); + return; + } + rx_world_halt_status(w, &h); + if (status) { + int used = snprintf(out, n, "OK state=%s restored=%d seq=%llu durable=%d refused=%llu " + "cancelled=%llu crumbs=%llu reactions=%u", + h.halted ? "stopped" : "running", h.restored ? 1 : 0, + (unsigned long long)h.seq, h.durable, (unsigned long long)h.refused, + (unsigned long long)h.cancelled, + (unsigned long long)__atomic_load_n(&w->n_crumbs, __ATOMIC_RELAXED), + (unsigned)__atomic_load_n(&w->n_reactions, __ATOMIC_RELAXED)); + if (op->cfg.describe && used > 0 && (size_t)used + 2 < n) { + out[used++] = ' '; + op->cfg.describe(op->cfg.ctx, out + used, n - (size_t)used); + } + return; + } + if (shutdown) { + if (!h.halted) { snprintf(out, n, "NOT_STOPPED state=running"); return; } + if (op->cfg.on_shutdown) op->cfg.on_shutdown(op->cfg.ctx); + snprintf(out, n, "OK state=stopped shutdown=1"); + return; + } + /* revoke-cap / revoke: the authority's office voids the control + * capability; revoke also retires the caller enrollment (it needs the + * current credential, so only its holder can). */ + AienosCapRef office; + if (aienos_cap_office(op->cfg.admin, &office) != 0 || + aienos_cap_revoke(op->cfg.admin, office, + (AienosCapRef){q->cap.cap_id, q->cap.generation}) != 0) { + snprintf(out, n, "ERROR rc=revoke-capability"); + return; + } + if (revoke) { + rc = rx_world_revoke_caller(w, q->subject, &q->cred); + if (rc != RX_CALLER_OK) { snprintf(out, n, "ERROR rc=revoke-credential %d", rc); return; } + unlink_own(op, RX_OPERATOR_CRED, &op->cred_st, &op->cred_made); + snprintf(out, n, "OK revoked=capability,credential"); + return; + } + snprintf(out, n, "OK revoked=capability"); +} + +static void serve_one(RxOperator *op, int fd) { + char line[RX_OPERATOR_LINE], body[RX_OPERATOR_LINE + 512]; + struct ucred pc; + socklen_t pl = sizeof pc; + struct timeval tv = {2, 0}; + /* Without both timeouts one client could hold the listener: refused, no reply. */ + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv) != 0 || + setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv) != 0) + return; + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &pc, &pl) != 0 || pl != sizeof pc || + pc.uid != geteuid()) { + snprintf(body, sizeof body, "REFUSED reason=peer"); + goto reply; + } + size_t got = 0; + int complete = 0; + while (got < sizeof line - 1) { + ssize_t r = read(fd, line + got, sizeof line - 1 - got); + if (r < 0 && errno == EINTR) continue; + if (r <= 0) break; + got += (size_t)r; + char *nl = memchr(line, '\n', got); + if (nl) { + size_t len = (size_t)(nl - line); + *nl = 0; + /* nothing after the newline, no NUL byte inside the line */ + complete = len == got - 1 && strlen(line) == len; + break; + } + } + Req q; + memset(&q, 0, sizeof q); + if (!complete || parse(line, &q) != 0) { + snprintf(body, sizeof body, "BAD_REQUEST"); + } else { + pthread_mutex_lock(&op->gate); + /* A request waits here while the program sets a world up. Once its + * client has given up (deadline passed) it is dropped, never run late: + * a late resume would restart a world nobody is watching. A late stop + * is fail-safe and still runs. */ + if (strcmp(q.cmd, "stop") != 0 && monotonic_ns() > q.deadline_ns) + snprintf(body, sizeof body, "EXPIRED (the client deadline passed; nothing done)"); + else + handle(op, &q, body, sizeof body); + pthread_mutex_unlock(&op->gate); + } + for (size_t i = 0; i < sizeof q; i++) ((volatile uint8_t *)&q)[i] = 0; + for (size_t i = 0; i < sizeof line; i++) ((volatile char *)line)[i] = 0; +reply:; + char out[sizeof body + 32]; + int len = snprintf(out, sizeof out, "aien-operator v1 %s\n", body); + if (len > 0) { + size_t sent = 0; + while (sent < (size_t)len) { + ssize_t s = send(fd, out + sent, (size_t)len - sent, MSG_NOSIGNAL); + if (s < 0 && errno == EINTR) continue; + if (s <= 0) break; + sent += (size_t)s; + } + } + /* Read what the client still sends (a refusal is answered before its request is + * read) until it closes its side, so closing here never resets a client that is + * still writing. Bounded: a few reads, each under the 2 s receive timeout. */ + shutdown(fd, SHUT_WR); + char sink[RX_OPERATOR_LINE]; + for (int i = 0; i < 4;) { + ssize_t r = read(fd, sink, sizeof sink); + if (r < 0 && errno == EINTR) continue; + if (r <= 0) break; + i++; + } +} + +/* The listener: one connection at a time until the wake pipe fires. It + * sequences no faculty; it carries operator requests to the world. */ +static void *listener_main(void *arg) { + RxOperator *op = arg; + for (;;) { + struct pollfd p[2] = {{op->listen_fd, POLLIN, 0}, {op->wake[0], POLLIN, 0}}; + int r = poll(p, 2, -1); + if (r < 0 && errno == EINTR) continue; + if (r < 0 || (p[1].revents & (POLLIN | POLLHUP | POLLERR))) break; + if (!(p[0].revents & POLLIN)) continue; + int fd = accept4(op->listen_fd, NULL, NULL, SOCK_CLOEXEC); + if (fd < 0) continue; + serve_one(op, fd); + close(fd); + } + return NULL; +} + +int rx_operator_open(RxOperator **out, const RxOperatorConfig *cfg, uint32_t subject, + RxCallerCred *cred, RxCapRef cap) { + if (!out || !cfg || !cfg->world || !cfg->admin || !cfg->control_dir || !cred) return -1; + *out = NULL; + char why[320]; + RxOperator *op = calloc(1, sizeof *op); + if (!op) return -1; + op->cfg = *cfg; + op->dir_fd = op->lock_fd = op->listen_fd = -1; + op->wake[0] = op->wake[1] = -1; + pthread_mutex_init(&op->gate, NULL); + pthread_mutex_lock(&op->gate); /* held until rx_operator_release */ + /* The control directory is held open and locked: from here every name in + * it is resolved against this descriptor, and no other program can be + * serving or replacing the socket and the credential. */ + if (rx_operator_dir_open(cfg->control_dir, 0, &op->dir_fd, why, sizeof why) != 0 || + lock_at(op->dir_fd, cfg->control_dir, &op->lock_fd, why, sizeof why) != 0) { + fprintf(stderr, "R13 operator: control directory refused: %s\n", why); + goto fail; + } + char bind_path[sizeof(((struct sockaddr_un *)0)->sun_path)]; + if ((size_t)snprintf(op->sock_path, sizeof op->sock_path, "%s/%s", cfg->control_dir, + RX_OPERATOR_SOCK) >= sizeof op->sock_path || + (size_t)snprintf(bind_path, sizeof bind_path, "/proc/self/fd/%d/%s", op->dir_fd, + RX_OPERATOR_SOCK) >= sizeof bind_path) { + fprintf(stderr, "R13 operator: control path too long for a socket address\n"); + goto fail; + } + /* A socket left by an earlier start of this program (the lock is ours). */ + if (unlinkat(op->dir_fd, RX_OPERATOR_SOCK, 0) != 0 && errno != ENOENT) { + fprintf(stderr, "R13 operator: stale socket: %s\n", strerror(errno)); + goto fail; + } + struct sockaddr_un a; + memset(&a, 0, sizeof a); + a.sun_family = AF_UNIX; + memcpy(a.sun_path, bind_path, strlen(bind_path) + 1); /* lands in the held directory */ + op->listen_fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + mode_t old = umask(077); + int ok = op->listen_fd >= 0 && bind(op->listen_fd, (struct sockaddr *)&a, sizeof a) == 0; + umask(old); + if (ok && fstatat(op->dir_fd, RX_OPERATOR_SOCK, &op->sock_st, AT_SYMLINK_NOFOLLOW) == 0 && + S_ISSOCK(op->sock_st.st_mode)) + op->sock_made = 1; + else + ok = 0; + ok = ok && fchmodat(op->dir_fd, RX_OPERATOR_SOCK, 0600, 0) == 0 && + listen(op->listen_fd, 8) == 0 && pipe2(op->wake, O_CLOEXEC) == 0 && + write_cred(op, subject, cred, cap) == 0; + for (size_t i = 0; i < sizeof *cred; i++) ((volatile uint8_t *)cred)[i] = 0; + if (ok && pthread_create(&op->thread, NULL, listener_main, op) == 0) { + op->thread_live = 1; + *out = op; + return 0; + } + fprintf(stderr, "R13 operator: entry point could not start: %s\n", strerror(errno)); +fail: + for (size_t i = 0; i < sizeof *cred; i++) ((volatile uint8_t *)cred)[i] = 0; + pthread_mutex_unlock(&op->gate); + rx_operator_close(op); + return -1; +} + +void rx_operator_hold(RxOperator *op) { if (op) pthread_mutex_lock(&op->gate); } +void rx_operator_release(RxOperator *op) { if (op) pthread_mutex_unlock(&op->gate); } + +void rx_operator_close(RxOperator *op) { + if (!op) return; + if (op->thread_live) { + char b = 1; + while (write(op->wake[1], &b, 1) < 0 && errno == EINTR) {} + pthread_join(op->thread, NULL); + } + if (op->listen_fd >= 0) close(op->listen_fd); + if (op->wake[0] >= 0) close(op->wake[0]); + if (op->wake[1] >= 0) close(op->wake[1]); + /* Only what this instance created, while its lock is still held. */ + unlink_own(op, RX_OPERATOR_SOCK, &op->sock_st, &op->sock_made); + unlink_own(op, RX_OPERATOR_CRED, &op->cred_st, &op->cred_made); + if (op->lock_fd >= 0) close(op->lock_fd); /* releases the flock */ + if (op->dir_fd >= 0) close(op->dir_fd); + pthread_mutex_destroy(&op->gate); + free(op); +} diff --git a/src/runtime/rx_operator.h b/src/runtime/rx_operator.h new file mode 100644 index 000000000..5140f3bd8 --- /dev/null +++ b/src/runtime/rx_operator.h @@ -0,0 +1,68 @@ +#ifndef RX_OPERATOR_H +#define RX_OPERATOR_H +/* R16 G6: the operator's outside entry point to a running production world + * (docs/r16-operator-control.md). An owner-only Unix-domain socket in a + * validated 0700 directory, a SO_PEERCRED check, and one line per request + * carrying the operator's runtime-issued caller credential and its + * RX_WORLD_RES_CONTROL capability. Every decision is the world's + * (rx_world_emergency_stop / _resume / rx_world_operator_authorize); this + * module only carries requests and replies. */ +#include "rx_world.h" +#include "aienos_cap.h" + +#include +#include + +#define RX_OPERATOR_SUBJ 70u /* runs no reaction; holds only the control capability */ +#define RX_OPERATOR_CRED "operator.cred" +#define RX_OPERATOR_SOCK "operator.sock" +#define RX_OPERATOR_LINE 512u + +typedef struct RxOperator RxOperator; + +typedef struct { + RxWorld *world; + AienosCapAdmin *admin; /* the authority: its office revokes the capability */ + const char *control_dir; /* validated with rx_operator_dir_check */ + const char *world_key; /* the mode this world runs, for the credential file */ + /* Program counters appended to a status reply (key=value ...). */ + void (*describe)(void *ctx, char *buf, size_t n); + /* Called after the world accepted a stop (1) or a resume (0). */ + void (*on_halt)(void *ctx, int halted); + /* Called after an authorized shutdown of a stopped world. */ + void (*on_shutdown)(void *ctx); + void *ctx; +} RxOperatorConfig; + +/* `dir` must be a real directory (opened O_DIRECTORY|O_NOFOLLOW, then + * fstat on that descriptor: no symlink, no path re-resolution), owned by the + * effective uid, with no group or other permission bits. With `create`, a + * missing directory is made 0700 first. 0 ok; -1 refused, with the reason in + * `why`. rx_operator_dir_open also hands back the held descriptor. */ +int rx_operator_dir_check(const char *dir, int create, char *why, size_t n); +int rx_operator_dir_open(const char *dir, int create, int *fd_out, char *why, size_t n); + +/* Exclusive lock on `dir` (validated as above): flock(LOCK_EX|LOCK_NB) on + * RX_OPERATOR_LOCK, opened with openat(O_CLOEXEC|O_NOFOLLOW) in the held + * directory. Held until the returned descriptor is closed (or the process + * ends). -1 refused (held by another program: its pid is in `why`). */ +#define RX_OPERATOR_LOCK "operator.lock" +int rx_operator_lock_dir(const char *dir, int create, int *lock_fd, char *why, size_t n); + +/* Lock the control directory (refused if another program holds it), write + * the credential file (0600, temporary file, fsync, rename, all relative to + * the held directory descriptor), wipe `cred`, bind the socket inside the + * held directory and start the listener. The request gate starts + * HELD by the caller: no request is served until rx_operator_release. */ +int rx_operator_open(RxOperator **out, const RxOperatorConfig *cfg, uint32_t subject, + RxCallerCred *cred, RxCapRef cap); +/* The request gate: while the program holds it (world setup), requests wait. */ +void rx_operator_hold(RxOperator *op); +void rx_operator_release(RxOperator *op); +/* Stop the listener and remove the socket and the credential file, each only + * if it is still the file this instance created (same device and inode), + * then release the control directory lock. The gate must not be held by the + * caller. */ +void rx_operator_close(RxOperator *op); + +#endif diff --git a/src/runtime/rx_world.c b/src/runtime/rx_world.c index d5a711ca1..7f95f2520 100644 --- a/src/runtime/rx_world.c +++ b/src/runtime/rx_world.c @@ -1067,6 +1067,7 @@ int rx_world_set_halt_dir(RxWorld *w, const char *dir) { h.restored = true; h.durable = 1; h.refused = w->halt.refused; + h.cancelled = w->halt.cancelled; h.crumb = halt_crumb(w, RX_CRUMB_OPERATOR_STOP, h.cap, h.reason, 0); w->halt = h; w->halted = true; @@ -1096,6 +1097,7 @@ int rx_world_emergency_stop(RxWorld *w, uint32_t subject, const RxCallerCred *cr h.reason = reason; h.t_ns = realtime_ns(); h.refused = w->halt.refused; + h.cancelled = w->halt.cancelled; h.crumb = halt_crumb(w, RX_CRUMB_OPERATOR_STOP, cap, reason, 0); w->halt = h; w->halted = true; /* in force before any disk work */ @@ -1153,6 +1155,16 @@ int rx_world_emergency_resume(RxWorld *w, uint32_t subject, const RxCallerCred * return rc; } +int rx_world_operator_authorize(RxWorld *w, uint32_t subject, const RxCallerCred *cred, RxCapRef cap) { + 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); + 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); @@ -1837,6 +1849,7 @@ static void run_one(RxWorld *w, uint32_t rid, uint32_t worker) { k.t_end_ns = now_ns(); crumb_append(w, &k); w->halt.refused++; + w->halt.cancelled++; /* 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--; @@ -2558,7 +2571,9 @@ int rx_resident_accept(RxWorld *w) { crumb_append(w, &k); r->resident_seat = false; w->stats.resident_closed++; + w->stats.resident_halted++; w->halt.refused++; + w->halt.cancelled++; if (r->episode_activations) r->episode_activations--; /* not spent */ r->rearm = true; end_activation(w, (uint32_t)rid); diff --git a/src/runtime/rx_world.h b/src/runtime/rx_world.h index 5743a3e22..66a195354 100644 --- a/src/runtime/rx_world.h +++ b/src/runtime/rx_world.h @@ -444,6 +444,7 @@ typedef struct { uint64_t desc_rejected; uint64_t resident_claims; /* claims posted to a resident seat */ uint64_t resident_closed; /* claims ended: committed, refused, or lost */ + uint64_t resident_halted; /* of those closed, results caught by an operator stop (re-run on resume) */ uint64_t deferrals; /* activations that handed an effect to a durable executor */ uint64_t seat_losses; /* times a seat was declared lost */ /* R15 instrumentation. Counted, never inferred. */ @@ -529,6 +530,7 @@ typedef struct { 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 */ + uint64_t cancelled; /* of those, activations and seat results caught by a stop, re-run on resume */ } RxHaltStatus; /* Durable recorder (M20 Cortex). Called with the world mutex held, once per @@ -824,6 +826,11 @@ int rx_world_emergency_stop(RxWorld *w, uint32_t subject, const RxCallerCred *c 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); +/* The same authority check as stop and resume (credential, not a reaction + * subject, live control capability), without acting: RX_OK, RX_ERR_IDENTITY + * or RX_ERR_AUTHORITY. For operator requests that read or retire the + * operator's own authority (docs/r16-operator-control.md). Never call with mu held. */ +int rx_world_operator_authorize(RxWorld *w, uint32_t subject, const RxCallerCred *cred, RxCapRef cap); /* A stimulus from outside the organism (sensor, human input). Requires a * capability for (external_subject, object resource, WRITE). Returns the diff --git a/tests/.crumb b/tests/.crumb index 12349e8ac..0484543a0 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -253,8 +253,8 @@ "purpose": "Directory tests/relations. Purpose not yet described by a human." }, { - "digest": "71ee11a9ea01b73efaf1c3f4fa3495aa98cc7d610b5570ce591f0718bb25a4d4", - "last_commit": "c2c3073", + "digest": "810c8881a76b9617e39a887e006c69f51301e96ebcdda35478a7060fc8788b75", + "last_commit": "96748a2", "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:5e49c39abb592f9a527e51b78cbb625925b7c4421476815cdcebe6b394a7ecda", - "compiled_at": "2026-10-05T22:53:19Z", + "children_root": "sha256:cc7551dc7594896ade97e5a5f78205cd93aad4878acd6e114b6b188e02ff10e6", + "compiled_at": "2026-10-06T00:26:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:54875b73cdd1fad056918c0ea3dbadfb1f02ea072a1e2115a8933a202c1d7012", + "digest": "sha256:c9825de4f77620c738f1cac290238b55040200959e0938ac03fa41a3c95c488d", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", - "files": 808, - "generated_at_commit": "120e281a85954a716fc6693a5592759df330f78f", - "source_tree": "sha256:c903806bc7979b01d455ddbe31854fd4385adaf591a3ec46adf07edd35865d82" + "files": 810, + "generated_at_commit": "96748a2078862997c4ee423797ed4d1a99dcf300", + "source_tree": "sha256:7cb4aeb7d1d40a33eb72f6873af832428d8c6c91bcf40b01eb8d231560ad6977" }, "owner_lane": "", "provenance": { diff --git a/tests/r16_qualify/run.sh b/tests/r16_qualify/run.sh index e2b3b0b2b..dc475488f 100755 --- a/tests/r16_qualify/run.sh +++ b/tests/r16_qualify/run.sh @@ -17,7 +17,7 @@ check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; FAILS=$((FAILS W=$SCR/w mkdir -p "$W/tools" cp "$HERE/tools/r16_qualify.sh" "$HERE/tools/aienos_lock_source.sh" "$W/tools/" -G6FILES="src/omega_accelerator_world.c src/runtime/rx_generation.c src/omega_world_gates.c tools/omegatool.c src/runtime/rx_native_bind.c src/omega_evidence.c src/omega_verify.c src/runtime/rx_resident_gpu.c src/runtime/rx_seq_reference.c src/runtime/rx_world.c src/runtime/rx_living.c" +G6FILES="src/omega_accelerator_world.c src/runtime/rx_generation.c src/omega_world_gates.c tools/omegatool.c src/runtime/rx_native_bind.c src/omega_evidence.c src/omega_verify.c src/runtime/rx_resident_gpu.c src/runtime/rx_seq_reference.c src/runtime/rx_world.c src/runtime/rx_living.c src/runtime/rx_operator.c tests/runtime/rx_r13_living.c" for p in $G6FILES; do mkdir -p "$W/$(dirname "$p")"; cp "$HERE/$p" "$W/$p"; done printf 'build/\n' > "$W/.gitignore" g() { git -C "$W" -c user.name=r16 -c user.email=r16@invalid -c commit.gpgsign=false "$@"; } @@ -49,8 +49,8 @@ check "output under evidence/: exit 2" '[ $rc = 2 ]' out=$(Q R16_RUN_ID=none 2>&1); rc=$? R=$W/build/r16-raw/none/DRY-RUN-receipt.json check "no fixtures: exit 3 (nothing ran)" '[ $rc = 3 ]' -check "no fixtures: G6 MISSING_IMPLEMENTATION (one item has no implementation; no test ran)" 'echo "$out" | grep -q "G6=MISSING_IMPLEMENTATION (items missing: 1)"' -check "no fixtures: summary all NOT_RUN" 'echo "$out" | grep -q "^Gates: G1=NOT_RUN G2=NOT_RUN G3=NOT_RUN G4=NOT_RUN G5=NOT_RUN G6=MISSING_IMPLEMENTATION G7=NOT_RUN G8=NOT_RUN$"' +check "no fixtures: G6 NOT_RUN (every item implemented, no test ran)" 'echo "$out" | grep -q " G6=NOT_RUN" && ! echo "$out" | grep -q "G6=MISSING_IMPLEMENTATION"' +check "no fixtures: summary all NOT_RUN" 'echo "$out" | grep -q "^Gates: G1=NOT_RUN G2=NOT_RUN G3=NOT_RUN G4=NOT_RUN G5=NOT_RUN G6=NOT_RUN G7=NOT_RUN G8=NOT_RUN$"' check "no fixtures: receipt gate NOT_RUN" 'grep -q "\"gate\": \"NOT_RUN\"" "$R"' check "no fixtures: receipt has no PASS value" '! grep -q "\"PASS\"" "$R"' check "no fixtures: silicon_observed false (computed)" 'grep -q "\"silicon_observed\": false" "$R"' @@ -79,7 +79,7 @@ check "bad exit status with pass line: G5 FAIL, exit 1" '[ $rc = 1 ] && echo "$o echo 0 > "$F/r16_surface.log.rc" out=$(Q R16_RUN_ID=fx 2>&1); rc=$? check "good G4/G5 fixtures: those gates PASS" 'echo "$out" | grep -q "G4=PASS" && echo "$out" | grep -q "G5=PASS"' -check "all-good G4/G5 still exit 3 (G6 tests did not run)" '[ $rc = 3 ] && echo "$out" | grep -q "G6=MISSING_IMPLEMENTATION"' +check "all-good G4/G5 still exit 3 (G6 tests did not run)" '[ $rc = 3 ] && echo "$out" | grep -q "G6=NOT_RUN"' # 6b. R11 that skipped its living run (load > 2) exits 0 with "failures 0": NOT_RUN, never PASS printf 'checks 400 failures 0\n' > "$F/r11_aien.log"; echo 0 > "$F/r11_aien.log.rc" @@ -215,6 +215,29 @@ git -C "$LK" init -q && git -C "$LK" add -A && git -C "$LK" -c user.name=r16 -c git -C "$LK" rev-parse HEAD > "$W/aienos.lock" g add -A; g commit -qm "lock file" export AIENOS_LOCK_REPO=$LK +# Operator receipts (G2): each seat's test writes one; the script copies it into the raw +# directory and checks it against the production binary of the run. Fixture binaries in +# build/ (git-ignored); templates filled with the current HEAD and binary digest by G6Q. +mkdir -p "$W/build" +printf 'host production binary fixture\n' > "$W/build/rx_r13_living_host" +printf 'silicon production binary fixture\n' > "$W/build/rx_r13_living_silicon" +# op_tmpl [sed expression...]: the receipt template of one seat, then edits. +op_tmpl() { + local seat=$1 gate=HOST_PASS_NON_SILICON e; shift + [ "$seat" = silicon ] && gate=PASS + printf '{\n "schema": "AIEN_R16_G6_OPERATOR_CONTROL_V1",\n "seat": "%s",\n "candidate_commit": "@HEAD@",\n "tree_dirty": false,\n "binary": "rx_r13_living_%s",\n "binary_sha256": "@SHA@",\n "checks": 90,\n "failures": 0,\n "skipped": 0,\n "skip_reasons": [],\n "gate": {"R16_G6_OPERATOR": "%s"}\n}\n' \ + "$seat" "$seat" "$gate" > "$G/op_$seat.tmpl" + for e in "$@"; do sed -i "$e" "$G/op_$seat.tmpl"; done +} +op_render() { + local s + for s in host silicon; do + rm -f "$G/operator_${s}_receipt.json" + [ -f "$G/op_$s.tmpl" ] || continue + sed -e "s/@HEAD@/$(g rev-parse HEAD)/" -e "s/@SHA@/$(sha256sum < "$W/build/rx_r13_living_$s" | cut -d' ' -f1)/" \ + "$G/op_$s.tmpl" > "$G/operator_${s}_receipt.json" + done +} # g6log [rc]: fixture log + exit status for one exercising test g6log() { printf '%s\n' "$2" > "$G/$1"; echo "${3:-0}" > "$G/$1.rc"; } g6_good_logs() { @@ -232,18 +255,25 @@ RX_EMERGENCY_MUTANTS: PASS" g6log r15_parity_host.log "SEQ_SEMANTIC_PARITY=PASS" g6log r15_parity_silicon.log "SEQ_SEMANTIC_PARITY=PASS" g6log r15_receipt.log "r15 receipt test: 0 failure(s)" + g6log r16_operator_host.log "R16 operator: 120 checks, 0 failures, 0 skipped (host, phases: startup control restart kill) +R16 operator gate: R16_G6_OPERATOR=HOST_PASS_NON_SILICON" + g6log r16_operator_mutants.log "RX_OPERATOR_MUTANTS: 14 mutants, 0 failures, 0 skipped +RX_OPERATOR_MUTANTS: PASS" + g6log r16_operator_silicon.log "R16 operator: 100 checks, 0 failures, 0 skipped (silicon, phases: startup control restart kill) +R16 operator gate: R16_G6_OPERATOR=PASS" + op_tmpl host; op_tmpl silicon } -G6Q() { Q R16_RUN_ID=g6 2>&1; } +G6Q() { op_render; Q R16_RUN_ID=g6 2>&1; } R=$G/DRY-RUN-receipt.json g6_item() { sed -n 's/^.*"item": "'"$1"'", "status": "\([A-Z_]*\)".*$/\1/p' "$R"; } g6_good_logs out=$(G6Q); rc=$? -check "G6 all good: G6 is MISSING_IMPLEMENTATION (operator emergency controls named nowhere), never PASS" 'echo "$out" | grep -q "G6=MISSING_IMPLEMENTATION" && ! echo "$out" | grep -q "G6=PASS"' -check "G6 all good: eleven items PASS, operator emergency controls MISSING_IMPLEMENTATION" '[ "$(grep -c "\"item\": \"[a-z0-9_]*\", \"status\": \"PASS\"" "$R")" = 11 ] && [ "$(g6_item operator_emergency_controls_passing)" = MISSING_IMPLEMENTATION ]' +check "G6 all good: every item implemented and operated, G6 PASS" 'echo "$out" | grep -q " G6=PASS"' +check "G6 all good: twelve items PASS, operator emergency controls among them" '[ "$(grep -c "\"item\": \"[a-z0-9_]*\", \"status\": \"PASS\"" "$R")" = 12 ] && [ "$(g6_item operator_emergency_controls_passing)" = PASS ]' check "G6 all good: protected_surfaces_kept six presence flags true" '[ "$(grep -c "_present\": true" "$R")" = 6 ]' check "G6 all good: no FAIL anywhere and G6 alone does not make the run pass (exit 3)" '[ $rc = 3 ] && ! echo "$out" | grep -q "G6=FAIL"' check "G6 all good: receipt names file and symbol per item" 'grep -q "\"file\": \"src/runtime/rx_generation.c\", \"symbol\": \"rx_gen_recover\", \"source\": \"omega_tree\", \"defined\": true" "$R"' -check "G6 operated checks cite the test and its status" 'grep -q "{\"name\": \"R9\", \"target\": \"test-r9\", \"status\": \"PASS\"}" "$R"' +check "G6 operated checks cite the test and its status" 'grep -q "{\"name\": \"R9\", \"target\": \"test-r9\", \"seat\": \"host\", \"status\": \"PASS\"}" "$R"' # presence without operation: symbols all defined, tests never ran -> NOT_RUN, never PASS rm -f "$G"/*.log "$G"/*.rc @@ -283,7 +313,7 @@ check "G6 fake log reporting failures (no pass line): FAIL, exit 1" '[ $rc = 1 ] g6log r9_barrier.log "generation barrier kept a single coherent generation through every injected stop" g6log r12_silicon.log "checks 40 failures 3 silicon 1" 1 out=$(G6Q) -check "G6 operator emergency controls stay MISSING_IMPLEMENTATION even when its mapped test fails or passes" '[ "$(g6_item operator_emergency_controls_passing)" = MISSING_IMPLEMENTATION ] && echo "$out" | grep -q "G6=FAIL"' +check "G6 a failing silicon seat-loss run: G6 FAIL" 'echo "$out" | grep -q "G6=FAIL" && [ "$(g6_item r12_seat_loss_handling_passing)" = FAIL ]' g6log r12_silicon.log "checks 40 failures 0 silicon 1" g6log m19_world.log "STAGE 1 / PERSISTENT WORLD QUALIFICATION: 17 / 18 M19 GATES PASSED [FAIL] OMEGA_ACCEL_RESIDENT_FAULT_RECOVERY_PASS : x" 0 @@ -291,6 +321,105 @@ out=$(G6Q) check "G6 M19 log with a [FAIL] gate line (exit 0): known_good_fallback FAIL" '[ "$(g6_item known_good_fallback_present)" = FAIL ]' g6log m19_world.log "STAGE 1 / PERSISTENT WORLD QUALIFICATION: 18 / 18 M19 GATES PASSED" +# operator emergency controls: operated only by execution of the production program, +# host and silicon apart; the old string-presence check can no longer pass it. +g6log r16_operator_silicon.log "R16 operator gate: R16_G6_OPERATOR=HOST_PASS_NON_SILICON" +out=$(G6Q) +check "G6 operator: a host result in the silicon slot is not a silicon pass: item FAIL" '[ "$(g6_item operator_emergency_controls_passing)" = FAIL ]' +rm -f "$G/r16_operator_silicon.log" "$G/r16_operator_silicon.log.rc" +out=$(G6Q) +check "G6 operator: host test and mutants passed, no silicon receipt: item NOT_RUN, G6 not PASS" '[ "$(g6_item operator_emergency_controls_passing)" = NOT_RUN ] && ! echo "$out" | grep -q "G6=PASS"' +g6log r16_operator_silicon.log "[SKIPPED] unauthorized: peer of another uid (sudo -n unavailable) +R16 operator gate: R16_G6_OPERATOR=PASS" +out=$(G6Q) +check "G6 operator: silicon log with a SKIPPED case and the pass line: NOT_RUN, never PASS" '[ "$(g6_item operator_emergency_controls_passing)" = NOT_RUN ]' +g6log r16_operator_silicon.log "[-] stop: authorized stop accepted, durable +R16 operator gate: R16_G6_OPERATOR=FAIL" 1 +out=$(G6Q) +check "G6 operator: failed silicon run: item FAIL, G6 FAIL" '[ "$(g6_item operator_emergency_controls_passing)" = FAIL ] && echo "$out" | grep -q "G6=FAIL"' +g6log r16_operator_silicon.log "R16 operator gate: R16_G6_OPERATOR=PASS" +g6log r16_operator_host.log "R16 operator gate: R16_G6_OPERATOR=FAIL" 1 +out=$(G6Q) +check "G6 operator: failed host run with a passing silicon log: item FAIL" '[ "$(g6_item operator_emergency_controls_passing)" = FAIL ]' +g6log r16_operator_host.log "R16 operator gate: R16_G6_OPERATOR=PASS" +out=$(G6Q) +check "G6 operator: a host log carrying the silicon pass line is not the host verdict: FAIL" '[ "$(g6_item operator_emergency_controls_passing)" = FAIL ]' +g6log r16_operator_host.log "R16 operator gate: R16_G6_OPERATOR=HOST_PASS_NON_SILICON" +g6log r16_operator_mutants.log "ok O1 wiring missing: killed +FAIL O5 success reply without a state transition: SURVIVED (exit 0) +RX_OPERATOR_MUTANTS: FAIL" 1 +out=$(G6Q) +check "G6 operator: a surviving mutant: item FAIL" '[ "$(g6_item operator_emergency_controls_passing)" = FAIL ]' +g6log r16_operator_mutants.log "RX_OPERATOR_MUTANTS: PASS" +RL=$W/tests/runtime/rx_r13_living.c +sed -i 's|^static int operator_open(Rig \*r) {|/* static int operator_open(Rig *r) { */ static int operator_0pen(Rig *r) {|' "$RL"; g add -A; g commit -qm "mutation: entry point only in a comment" +out=$(G6Q) +check "G6 operator: production wiring present only in a comment (string still in the file), every log passing: MISSING_IMPLEMENTATION" '[ "$(g6_item operator_emergency_controls_passing)" = MISSING_IMPLEMENTATION ] && grep -q "operator_open(Rig" "$RL" && ! echo "$out" | grep -q "G6=PASS"' +g6_unmut +out=$(G6Q) +check "G6 operator: reverted, all logs passing: PASS" '[ "$(g6_item operator_emergency_controls_passing)" = PASS ]' +# G2: the operator receipt. Good receipts first, then one broken field at a time. +op_item() { g6_item operator_emergency_controls_passing; } +op_test() { jq -r ".g6_items[] | select(.item==\"operator_emergency_controls_passing\") | .tests[] | select(.name==\"$1\") | .$2" "$R"; } +check "G6 operator receipts: both copied into the raw directory and covered by its digest" \ + 'grep -q " operator_host_receipt.json$" "$G/SHA256SUMS" && grep -q " operator_silicon_receipt.json$" "$G/SHA256SUMS" && [ "$(op_item)" = PASS ]' +check "G6 operator: tests labelled by seat (host test host, silicon test silicon)" \ + '[ "$(op_test R16_OP_HOST seat)" = host ] && [ "$(op_test R16_OP_MUTANTS seat)" = host ] && [ "$(op_test R16_OP_SILICON seat)" = silicon ] && [ "$(jq -r .operator_control.silicon.seat "$R")" = silicon ]' +op_bad() { # op_bad