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
omega-mv / docs / r16-operator-control.md
| 1 | # R16 G6: operator control of the production program (interface contract) |
| 2 | |
| 3 | Status: CONTRACT, written before the code (lane ESTOP, CAND-3), then implemented. Two |
| 4 | points were corrected from the code: when the socket opens (section 2) and a store |
| 5 | 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 |
| 6 | operator outside the running production program reaches that control, and what the |
| 7 | program does with a request. It adds no authority scheme: every decision is made by the |
| 8 | existing world authority (`rx_world_emergency_stop` / `_resume`, `halt_authorize` in |
| 9 | `src/runtime/rx_world.c`). |
| 10 | |
| 11 | Production program: `tests/runtime/rx_r13_living.c`, built without `AIEN_TEST_BUILD` as |
| 12 | `build/rx_r13_living_host` and `build/rx_r13_living_silicon`. It runs six modes, each in |
| 13 | its own world. Every statement below holds for each of those worlds. |
| 14 | |
| 15 | ## 1. Who the operator is and how its authority reaches the program |
| 16 | |
| 17 | * One operator subject, `RX_OPERATOR_SUBJ` (70), not used by any faculty, reaction or |
| 18 | composition subject (`rx_living.h` 61-64, `rx_omega.h` 21-22, `rx_aien.h` 31, |
| 19 | `rx_aegis.h` 41-42, `rx_compose.h` 200+). |
| 20 | * **Credential.** At each world start, with the other production subjects and before |
| 21 | enrollment closes (`rx_living_enroll_callers`, then `rx_world_bind_callers`), the |
| 22 | program enrolls the operator with `rx_world_enroll_caller`: a fresh 32-byte random |
| 23 | secret and a generation, issued by the runtime. The program keeps no copy after |
| 24 | handing it over (below) and wipes its buffer. |
| 25 | * **Capability.** The program mints, through the native Aienux authority it already |
| 26 | starts (`aienos_cap_start`, the same `mint()` path every production grant uses), one |
| 27 | capability for `RX_OPERATOR_SUBJ` on `RX_WORLD_RES_CONTROL` (0x906) with |
| 28 | `RX_WORLD_RIGHT_HALT` (`RX_RIGHT_EPOCH`: privileged, never delegable). No other |
| 29 | subject is minted anything on that resource; the program's authority sweep fails the |
| 30 | run if any live capability on it belongs to another subject or carries another right. |
| 31 | * **Hand-over.** Both are written to the operator credential file |
| 32 | `<state>/control/operator.cred` (format §3), created mode 0600 in a 0700 directory |
| 33 | owned by the program's user, written to a temporary file, fsynced and renamed. It is |
| 34 | the operator's copy; the world holds only the credential digest and the authority |
| 35 | holds the capability. Anyone who can read the file is, by construction, the operator |
| 36 | account (the program's own uid, or root). |
| 37 | * **No editable boolean grants authority.** The file carries a credential the world |
| 38 | checks in constant time and a capability reference the authority validates; editing |
| 39 | either makes it fail. Nothing in the file, the socket, the environment or the command |
| 40 | line switches a check off. |
| 41 | * **A reaction subject can never control the world.** The world refuses any subject |
| 42 | that a registered reaction runs under (`halt_authorize`, spec §2 point 2). The |
| 43 | operator subject runs no reaction. The program's own reaction credentials never leave |
| 44 | the program, so they cannot be presented from outside; that refusal is proven |
| 45 | in-process by `make test-rx-emergency` (E1) and is not re-proven from outside. |
| 46 | |
| 47 | ## 2. The outside entry point |
| 48 | |
| 49 | * An `AF_UNIX` stream socket `<state>/control/operator.sock`, created right after the |
| 50 | world's credential, capability and halt directory exist (before its objects are |
| 51 | built) and removed when the world is torn down. While the program sets the world |
| 52 | up, a request waits (the client allows 60 s) and is answered once setup is done, so |
| 53 | a stop never lands inside setup; a world restored stopped answers at once (it does |
| 54 | no setup until resumed). Between worlds there is no socket: a client gets |
| 55 | "connection refused" and the request does nothing. |
| 56 | * **One program per state directory.** At startup the program takes an exclusive |
| 57 | `flock` on `<dir>/operator.lock` (opened `O_CLOEXEC|O_NOFOLLOW`, a regular file of its |
| 58 | uid) and, when a world first uses it, on `<dir>/gen-<mode-key>/operator.lock`; it holds |
| 59 | both for its whole life. A second program on the same state directory, or one whose |
| 60 | state directory is the first one's generation directory, is refused (exit 2, |
| 61 | `... is in use by another program (pid N)`) before it touches a socket or a |
| 62 | credential. Each world also locks `control/` the same way while its entry point is |
| 63 | open. The control directory is held open as a descriptor: the stale socket is removed, |
| 64 | the socket bound (through `/proc/self/fd/<fd>/operator.sock`) and the credential |
| 65 | written and renamed relative to that descriptor, never by a path looked up again. |
| 66 | Close removes the socket and the credential only if they are still the files this |
| 67 | instance created (same device and inode), then releases the lock. |
| 68 | * Two walls before the credential: the directory is 0700 and owned by the program's |
| 69 | user (validated at startup, §5), and every accepted connection is checked with |
| 70 | `SO_PEERCRED`: the peer uid must equal the program's effective uid, else the reply |
| 71 | is `REFUSED reason=peer` and nothing is read further. Root can pass the directory but |
| 72 | not the peer check. |
| 73 | * One request per connection, read with a 2 s receive and send timeout (if either |
| 74 | cannot be set the connection is closed with no reply); at most 511 bytes up to |
| 75 | the first newline. One reply line, then the connection is closed. Requests are served |
| 76 | one at a time by one listener thread (`src/runtime/rx_operator.c`); it never holds the |
| 77 | world lock across a request. |
| 78 | * Client: `build/rx_operator` (`tools/rx_operator.c`). It reads the credential file and |
| 79 | sends one request: `rx_operator --control <state>/control <command> [reason]`, or |
| 80 | `--cred <file>` to present another file (used by the tests for stale and forged |
| 81 | credentials), or `--raw <line>` (malformed-request tests). |
| 82 | |
| 83 | ## 3. Formats |
| 84 | |
| 85 | Credential file (text): |
| 86 | |
| 87 | ``` |
| 88 | aien-operator-credential v1 |
| 89 | world <mode-key> <program pid> <world start CLOCK_REALTIME ns> |
| 90 | socket <absolute socket path> |
| 91 | subject 70 |
| 92 | cred <generation> <64 hex secret> |
| 93 | cap <cap_id> <cap generation> |
| 94 | ``` |
| 95 | |
| 96 | Request (one line): |
| 97 | |
| 98 | ``` |
| 99 | aien-operator v1 <command> subject=<u32> gen=<u64> secret=<64 hex> cap=<id>:<gen> deadline=<u64> [reason=<int>] |
| 100 | ``` |
| 101 | |
| 102 | `deadline` is required: the `CLOCK_MONOTONIC` time in nanoseconds after which the client |
| 103 | has given up (the client sends now + 55 s and waits 60 s). A deadline more than 120 s |
| 104 | ahead is `BAD_REQUEST`. A request that waited for the world's setup past its deadline is |
| 105 | answered `EXPIRED` and not run, unless it is a `stop`: a late stop is fail-safe and still |
| 106 | runs; a late resume would restart a world nobody is watching. |
| 107 | |
| 108 | `<command>` is `status`, `stop`, `resume`, `revoke-cap`, `revoke` or `shutdown`. Any other |
| 109 | token, a missing or repeated field, a secret that is not 64 hex digits, a number out of |
| 110 | range or extra bytes is `BAD_REQUEST`, decided before any world call. |
| 111 | |
| 112 | Reply (one line): `aien-operator v1 <RESULT> key=value ...`. RESULT is one of `OK`, |
| 113 | `STOPPED_NOT_DURABLE` (the stop is in force in memory but its mark could not be written: |
| 114 | a restart would NOT come up stopped; carries `durable=<-errno> errno=<n> (<text>)`), |
| 115 | `ALREADY` (stop of a stopped world), `NOT_STOPPED` (resume or shutdown of a running world), |
| 116 | `EXPIRED` (the client deadline passed while the request waited; nothing done), |
| 117 | `REFUSED reason=peer|identity|authority`, `BAD_REQUEST`, `ERROR rc=<n>`. |
| 118 | A refusal says nothing about the world: no state, no counters. |
| 119 | |
| 120 | Client exit status: 0 for `OK`, 3 for `STOPPED_NOT_DURABLE`, 1 for any other reply, 2 for |
| 121 | a usage error, no credential file, no world serving the socket, or a reply timeout that |
| 122 | could not be set. |
| 123 | |
| 124 | ## 4. Commands |
| 125 | |
| 126 | Every command except `BAD_REQUEST` cases goes to the world authority first. `status`, |
| 127 | `revoke-cap`, `revoke` and `shutdown` are checked by `rx_world_operator_authorize` (the |
| 128 | same `halt_authorize` the stop and resume use, under the same locks, added to |
| 129 | `rx_world.c` so no second authority check exists). `stop` and `resume` are checked inside |
| 130 | `rx_world_emergency_stop` / `_resume` themselves. |
| 131 | |
| 132 | | command | world call | reply on success | |
| 133 | |---|---|---| |
| 134 | | `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=` | |
| 135 | | `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 | |
| 136 | | `resume` | `rx_world_emergency_resume` | `OK state=running seq=`; a running world: `NOT_STOPPED` | |
| 137 | | `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` | |
| 138 | | `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` | |
| 139 | | `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. | |
| 140 | |
| 141 | A revoked operator cannot be re-enrolled in the same world (enrollment is closed); the |
| 142 | world keeps running without operator control until the program starts the next world, |
| 143 | which issues a new credential and capability. Revoking while stopped leaves the world |
| 144 | stopped for the rest of that world's life; the durable mark makes the next start of that |
| 145 | mode come up stopped, and the next credential can resume it. |
| 146 | |
| 147 | **Stale credentials.** A credential is valid for one world of one program start: every |
| 148 | world start enrolls a new random secret and mints a new capability. A credential from an |
| 149 | earlier world or an earlier program start fails the constant-time caller check |
| 150 | (`REFUSED reason=identity`). |
| 151 | |
| 152 | ## 5. State directory, durability and restart |
| 153 | |
| 154 | * `--state-dir <dir>` names the program's durable state (default: a fresh 0700 scratch |
| 155 | directory under `$TMPDIR`, as before, so `make test-r13-host` keeps running unchanged). |
| 156 | Layout: `<dir>/control/` (credential file and socket) and one generation store per mode, |
| 157 | `<dir>/gen-<mode-key>/` (`positive`, `no-aien`, `no-promotion`, `revoked-experiment`, |
| 158 | `stale-gpu`, `failed-verification`). |
| 159 | * **Validated at startup, refuse if wrong.** `<dir>` and each subdirectory must be a real |
| 160 | directory (opened `O_DIRECTORY|O_NOFOLLOW` and checked with `fstat` on that descriptor, |
| 161 | so a symlink is refused and nothing can be swapped in between), owned by the effective uid, with |
| 162 | no group or other permission bits (`mode & 077 == 0`). A missing subdirectory is |
| 163 | created 0700. A path too long for a socket address is refused. On any refusal the |
| 164 | program prints the reason and exits 2 before any world starts. |
| 165 | * **The durable halt directory is the generation store's directory**: |
| 166 | `rx_world_set_halt_dir(w, <dir>/gen-<mode-key>)`, called right after the store is opened |
| 167 | and bound and **before any object is created or any work is published**. A mark there |
| 168 | (`OPERATOR_HALT`, sealed) makes the world start stopped (spec §4: a torn or unreadable |
| 169 | mark also stops it). The program then serves operator requests on the socket and does |
| 170 | nothing else until a resume (or `shutdown`); only then does it build the world's |
| 171 | objects and run. So a restart while stopped restores the stop before it accepts any |
| 172 | work, including its own setup. |
| 173 | * Resume keeps the sealed resumed record `OPERATOR_HALT.resumed.<seq>.<t_ns>` and only |
| 174 | then removes the mark (spec §4, unchanged). |
| 175 | * Directory protection beyond these checks (another process of the same uid deleting the |
| 176 | mark while no program runs) is the operating system's job (spec §7.3). |
| 177 | |
| 178 | ## 6. What a stop covers, and what it does not |
| 179 | |
| 180 | * It stops the world's publications and promotions, exactly as spec §3 lists: no commit, |
| 181 | no outside publication (the production request stream included), no seat result, no |
| 182 | object create or retire, no generation proposal or promotion. In-flight activations |
| 183 | are refused at commit and run again on resume. |
| 184 | * The program keeps its own clocks honest: time spent stopped does not count toward the |
| 185 | episode's deadlines (`run_clock`), a production request refused by the stop is |
| 186 | published again after resume, and the end-of-mode checks wait while the world is |
| 187 | stopped. A durable generation proposal or promotion that the store refuses |
| 188 | because of the stop (`RX_GEN_ERR_HALTED`) is not an outcome: the activation waits |
| 189 | and posts it again after the resume (`halted_wait`, `src/runtime/rx_living.c`). A world |
| 190 | whose episode is done is not torn down while stopped: the program waits for the resume |
| 191 | (or `shutdown`) before it audits and ends the mode. A seat result caught by a stop is |
| 192 | claimed again after the resume; the world counts those claims (`stats.resident_halted`) |
| 193 | and the episode check subtracts them before it compares claims with trials. |
| 194 | A stop therefore delays the episode and leaves its outcome unchanged. |
| 195 | * Evidence: at the end of every mode the program reads its crumb log (the canonical |
| 196 | evidence, spec §4) and prints `R13 operator <mode-key>: stops S resumes R restored X |
| 197 | open O; under stop: commits 0 externals 0 cancelled C`. Any COMMIT or EXTERNAL crumb |
| 198 | between an OPERATOR_STOP and its OPERATOR_RESUME (or after an unresumed stop) fails the |
| 199 | mode. The R13 receipt carries the totals under `"operator"`. |
| 200 | * **Outside effects already underway (spec §7.4).** A stop does not reach a durable |
| 201 | executor already performing an effect outside the world, and it does not interrupt a |
| 202 | GPU kernel already running on the resident seat. The production program has one |
| 203 | outside effect path, the resident seat: a seat result that lands under a stop is |
| 204 | refused and the output window re-projected from the world (spec §3, R12 |
| 205 | `t_emergency_stop`); the kernel's work is discarded and runs again on resume. A stop |
| 206 | does not stop the process, its threads, ARGUS observation or the authority; it is not a |
| 207 | kill switch and not a rollback. |
| 208 | |
| 209 | ### 6.1 Closed limit: the halt right is the epoch right |
| 210 | |
| 211 | **Closed at aienos.lock `b84c0a67590a934f3f3e001b12ec85ebc086a9eb` (aienos#272, closing |
| 212 | aienos#266).** The native `auth_use` now honors a privileged right only on an entry whose |
| 213 | resource is `AIENOS_CAP_RES_AUTHORITY`, else `AIENOS_CAP_ERR_RESOURCE`. omega's Linux |
| 214 | oracle (`src/runtime/rx_caproot.c` `auth_use`) carries the same rule so R7 parity holds. |
| 215 | Proof: `make test-r16-operator-authority-misuse` mints the operator capability as R13 does and |
| 216 | requires every authority operation to refuse it (and one holding every privileged right on |
| 217 | the control resource), the halt check to accept it, and the office to still operate; against |
| 218 | bbad5e4 the halt capability bumps the epoch and the test fails. `make test-r7` compares the |
| 219 | two authorities on the same case. The text below is the record at bbad5e4. |
| 220 | |
| 221 | The spec gives the stop the privileged epoch right (`spec/r16-operator-emergency-stop.md` |
| 222 | §2 lines 44-45: "The right is `RX_RIGHT_EPOCH` ... The right that may void every |
| 223 | capability may also pause the world"). ADR 0016 (aien-architecture main 014159e) is |
| 224 | silent on a halt or pause right: neither word occurs in it. Its capability section |
| 225 | (lines 367-382) lists the resource among what a capability binds, and line 1475 asks |
| 226 | that a wrong-resource attack fail. |
| 227 | |
| 228 | The locked native authority does not check the resource when a capability is used: |
| 229 | `auth_use` (aienos `native/capability/aienos_capability.c` lines 205-218 at aienos.lock |
| 230 | bbad5e4) checks delivery, generation, state, epoch, expiry, the delegation chain and |
| 231 | the rights, not the entry's resource. So the operator's control capability |
| 232 | (`RX_WORLD_RES_CONTROL` with `RX_RIGHT_EPOCH`) would also pass `aienos_cap_bump_epoch` |
| 233 | (same file, line 555, through `auth_use(..., AIENOS_CAP_RIGHT_EPOCH, ...)` at line 369) |
| 234 | if anything handed it there. omega does not change the locked authority; the request |
| 235 | is aien-dev/aienux#266 (a resource check in `auth_use`, or a dedicated halt right). |
| 236 | |
| 237 | What keeps it closed today is omega's own code, shown here and tested: |
| 238 | |
| 239 | * The capability is minted once per world (`tests/runtime/rx_r13_living.c` 449, |
| 240 | `mint(r, RX_OPERATOR_SUBJ, RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT)`) and passed only |
| 241 | to `rx_operator_open` (line 327), which writes it to the operator's credential file |
| 242 | and keeps no other use of it. |
| 243 | * A presented capability (`q->cap`, parsed at `src/runtime/rx_operator.c` 262) reaches |
| 244 | exactly four calls: `rx_world_emergency_stop` (291), `rx_world_emergency_resume` |
| 245 | (312), `rx_world_operator_authorize` (328, for status, shutdown, revoke-cap and |
| 246 | revoke) and, as the *target* of a revocation authorized by the authority's office, |
| 247 | `aienos_cap_revoke` (360). The first three validate it with |
| 248 | `rx_world_validate_cap(..., RX_WORLD_RES_CONTROL, RX_WORLD_RIGHT_HALT, ...)` inside |
| 249 | `halt_authorize` (`src/runtime/rx_world.c` 914). |
| 250 | * Every other command, with a full valid credential, is `BAD_REQUEST` before any |
| 251 | authority call (`rx_operator.c` 327). The host test sends `explode`, `bump-epoch`, |
| 252 | `bump_epoch`, `mint`, `grant`, `epoch`, `STOP`, `Stop`, `stop2`, `resume2` and `halt` |
| 253 | and requires `BAD_REQUEST` for each; mutant O22 removes that refusal and the test fails. |
| 254 | * `aienos_cap_bump_epoch` has no caller in omega's production sources (`git grep`: the |
| 255 | declaration in `src/runtime/aienos_cap.h` 56 and the R7 oracle test |
| 256 | `tests/runtime/rx_r7_native.c` 217 only). |
| 257 | |
| 258 | A future omega change that hands the control capability to any other authority entry |
| 259 | point reopened this while it was a known limit (until aienos#266 closed; see the note above). |
| 260 | |
| 261 | ## 7. Proof (G6 by execution) |
| 262 | |
| 263 | `make test-r16-operator-host` (`tests/runtime/rx_operator_host.sh`) starts the production |
| 264 | host binary and drives it only through `build/rx_operator` and signals, checking replies, |
| 265 | the files in the state directory and the program's crumb-log audit lines: authorized stop |
| 266 | and resume; forged secret, wrong capability, wrong peer (root via `sudo -n`, reported |
| 267 | SKIPPED and therefore NOT_RUN if sudo is unavailable), malformed request; stale |
| 268 | credential (earlier world, earlier program start); `revoke-cap` and `revoke`; repeated |
| 269 | stop and resume; repeated stop and resume cycles under production load (in-flight work |
| 270 | refused and re-run); promotion blocked while stopped and completed after resume; restart |
| 271 | while stopped after `shutdown` and after `SIGKILL`; recovery to a passing R13 episode; |
| 272 | startup refusal of a group-readable, foreign-owned or symlinked state directory; a |
| 273 | second program on the same state directory or on the first one's generation directory |
| 274 | refused while the first keeps its socket and credential; a stop whose mark cannot be |
| 275 | written (generation directory made 0500) answering `STOPPED_NOT_DURABLE errno=13` with |
| 276 | client exit 3; eleven unknown commands with a full credential refused; an expired |
| 277 | resume answering `EXPIRED` and doing nothing, a missing or too-distant deadline refused. |
| 278 | On host three checks are made deterministic by holding one thread of the production |
| 279 | program under gdb in non-stop mode (the socket keeps serving): the seat acceptor held |
| 280 | with a computed seat result while a stop is accepted, then released, must end that claim |
| 281 | halted (`seat_halted` in status, so the episode's claim subtraction is exercised on |
| 282 | host); the positive world held after its episode's work, stopped, then released, must |
| 283 | stay up and stopped and print that it waits for a resume; the next world's open held |
| 284 | after the positive world closed must find a credential file planted by someone else |
| 285 | still in place. Without gdb those checks are SKIPPED (gate NOT_RUN). Silicon runs |
| 286 | without gdb; its in-flight count is reported, not checked. A host run whose only gap is a |
| 287 | missing `sudo -n` or gdb is NOT_RUN with the reason in the receipt, never FAIL. |
| 288 | `tests/runtime/rx_operator_mutants.sh` rebuilds the production program from mutated |
| 289 | copies and requires the test to fail against each (wiring missing, handler disconnected, |
| 290 | success reply without a state transition, unauthorized resume accepted, wiring present |
| 291 | only in a comment, wiring present only as an unused call, and the others it lists). |
| 292 | `make test-r16-operator-silicon` runs the same test on `build/rx_r13_living_silicon` |
| 293 | (resident GB10 seat) without the SIGKILL phase (a chip program is never killed). The |
| 294 | receipt labels host and silicon results separately. The silicon test requires the |
| 295 | program's own gate `R13_LIVING_SYSTEM=PASS` (bound to the candidate commit on a clean |
| 296 | tree): the spec allows no `SILICON_PASS_UNBOUND`. Each run writes |
| 297 | `operator_<seat>_receipt.json` to `RX_OP_OUT` (default `build/r16-operator`); the mutant |
| 298 | script gives every mutant its own directory, so a mutant never overwrites the real receipt. |
| 299 | `tools/r16_qualify.sh` copies both receipts into its raw directory (covered by the raw |
| 300 | digest) and refuses PASS unless each names its seat, the candidate commit on a clean tree, |
| 301 | no failure or skip, the seat's gate, and the SHA-256 of the production binary built in that |
| 302 | run; the silicon run counts toward `silicon_observed`. The G6 item |
| 303 | `operator_emergency_controls_passing` is PASS only when both ran and passed in the same |
| 304 | qualification run on the candidate. |