Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/node/view.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / node / view.om` 704 lines ยท 15955 bytes Raw Blame History 1 note seed/node/view.om -- the Omega Node operator view (DRA-291). OM-2. 2 note Compose after seed/net/http.om, transport.om, pool.om, super.om, 3 note sched.om, seed/authority/action.om, journal.om and auth.om, before the 4 note program that drives the creator (code.om). 5 note One shared page (32768 bytes) carries the creator's state to a view 6 note process it forks, and operator commands back. The view process only 7 note reads state and posts commands; the creator alone decides them, 8 note through the authority and the journal, and then acknowledges them. 9 note Page words: 0 magic, 1 layout 1, 2 snapshot seqlock (odd while the 10 note creator writes), 3 version (events so far, this incarnation), 4 11 note incarnation (the journal fence), 5 creator pid, 6 stop, 7 view port, 12 note 8 requests served, 9 view pid. 13 note Snapshot words, written by the creator under the seqlock: 14 note 16..21 authority: generation, paused, journal seq, journal failed, 15 note fence, version of the last pause change; 32..39 queue: waiting, 16 note ready, running, in review, UNKNOWN, admission limit, review limit, 17 note admissions refused while full; 44..46 commands committed, refused, 18 note last id; 48 workers, then 4 words each at 64+4w: pid (0 none), 19 note incarnation, control seq acknowledged, paused as seen; 96 uncertain 20 note jobs (outcome UNKNOWN), their ids at 97..112; 128 objectives, then 16 21 note words each at 136+16i (set by the driver); 200..205 limits. 22 note Events: a ring of 256 at word 1024, 4 words each: version, type | 23 note target << 8 | x << 16, a, b. Types: 1 job (x what, a job id, b 24 note value), 2 objective result (a result, b turns), 3 command (x op, a 25 note id, b status), 4 pause (a 1 paused 0 resumed), 5 worker (x slot, a 26 note pid, b 1 started 0 lost), 6 admission refused (a job id), 7 uncertain 27 note (a job id). 28 note Mailbox at word 2048: 0 state (0 free, 1 posted, 2 acknowledged), 1 29 note command id, 2 op, 3 target, 4 view version the command was based on, 30 note 5..8 arguments, 9 status, 10 version, 11 journal seq, 12 incarnation. 31 note Ops: 1 pause, 2 resume, 3 cancel objective, 4 budget objective a 32 note (model turns), 5 redirect objective to kind a, K b, N c, A d. 33 note Status: 0 committed, 1 stale, 2 invalid, 3 refused, 4 duplicate (the 34 note id was committed before; the version is the original one). 35 const VWBYTES ulong 32768 36 const VWMAG ulong `1330466390` 37 const VWRING ulong 1024 38 const VWBOX ulong 2048 39 text vwjson "application/json" 40 text vwctype "Content-Type" 41 text vwpview "/view" 42 text vwpcmd "/cmd" 43 text vwphlth "/health" 44 text vwget "GET" 45 text vwpost "POST" 46 text vwkhd "{\"layout\":1,\"incarnation\":" 47 text vwkver ",\"version\":" 48 text vwksnap ",\"kind\":\"snapshot\"" 49 text vwkdel ",\"kind\":\"delta\",\"since\":" 50 text vwkev ",\"events\":[" 51 text vwkauth ",\"authority\":" 52 text vwnauth "generation,paused,journal_seq,journal_failed,fence,version," 53 text vwkq ",\"queue\":" 54 text vwnq "waiting,ready,running,review,unknown,limit,review_limit,refused," 55 text vwkc ",\"commands\":" 56 text vwnc "committed,refused,last_id," 57 text vwkw ",\"workers\":[" 58 text vwnw "pid,incarnation,ack,paused," 59 text vwku "],\"uncertain\":[" 60 text vwko "],\"objectives\":[" 61 text vwno "kind,k,n,a,state,turns,budget,phase,job,result,version,redirect,cancel,seq," 62 text vwkl "],\"limits\":" 63 text vwnl "max_turns,deadline_s,max_tokens,max_objectives,action_slots,ring," 64 text vwkid "{\"id\":" 65 text vwkst ",\"status\":\"" 66 text vwkst2 "\",\"version\":" 67 text vwkjs ",\"journal_seq\":" 68 text vwkinc ",\"incarnation\":" 69 text vwsts "committed,stale,invalid,refused,duplicate,busy,pending," 70 text vwhlth "{\"ok\":true}" 71 text vwqsin "since" 72 text vwqinc "inc" 73 text vwqid "id" 74 text vwqop "op" 75 text vwqtg "target" 76 text vwqver "ver" 77 text vwqa "a" 78 text vwqb "b" 79 text vwqc "c" 80 text vwqd "d" 81 global vwmap long 1 82 global vwver ulong 1 83 global vwcnt ulong 4 84 85 note ======== the page (without vw_new every write is dropped and reads are 0, 86 note so the driver also runs without a view) 87 88 fn vw_g o ulong to ulong 89 if le get vwmap 0 0 90 ret 0 91 end 92 ret mapget get vwmap 0 mul o 8 8 93 end 94 95 fn vw_s o ulong v ulong to void 96 if le get vwmap 0 0 97 ret 98 end 99 r = mapset get vwmap 0 mul o 8 8 v 100 end 101 102 note Creator, before it forks anything: map the page for incarnation inc. 103 note 0 or a mapping errno. 104 fn vw_new inc ulong to long 105 h = mapnew neg int 1 0 VWBYTES 3 33 106 if le h 0 107 ret h 108 end 109 put vwmap 0 h 110 put vwver 0 0 111 for i ulong 4 112 put vwcnt i 0 113 end 114 vw_s 1 1 115 vw_s 4 inc 116 vw_s 5 ulong getpid 117 vw_s 0 VWMAG 118 ret 0 119 end 120 121 note Creator: append an event; its version. Words first, version last. 122 fn vw_ev ty ulong t ulong x ulong a ulong b ulong to ulong 123 v = add get vwver 0 1 124 o = add VWRING mul and v 255 4 125 vw_s add o 1 or or ty shl t 8 shl x 16 126 vw_s add o 2 a 127 vw_s add o 3 b 128 vw_s o v 129 put vwver 0 v 130 vw_s 3 v 131 ret v 132 end 133 134 fn vw_ver to ulong 135 ret get vwver 0 136 end 137 138 note Creator: count c (0 admissions refused, 1 commands committed, 2 139 note commands refused, 3 last command id). 140 fn vw_cnt c ulong v ulong to void 141 put vwcnt c v 142 end 143 144 fn vw_cget c ulong to ulong 145 ret get vwcnt c 146 end 147 148 fn vw_begin to void 149 vw_s 2 or vw_g 2 1 150 end 151 152 fn vw_end to void 153 vw_s 2 add vw_g 2 1 154 end 155 156 note Creator, between vw_begin and vw_end: the generic sections. 157 fn vw_gen c long to void 158 vw_s 16 get augen 0 159 vw_s 17 get scpause 0 160 vw_s 18 get jseq 0 161 vw_s 19 get jbad 0 162 vw_s 20 get jfence 0 163 for s ulong 4 164 vw_s add 32 s sched_count add s 1 add s 1 165 end 166 vw_s 36 sched_count 6 6 167 vw_s 37 get sclim 0 168 vw_s 38 get sclim 1 169 vw_s 39 get vwcnt 0 170 vw_s 44 get vwcnt 1 171 vw_s 45 get vwcnt 2 172 vw_s 46 get vwcnt 3 173 n = mapget c 48 8 174 vw_s 48 n 175 for w ulong n bound 8 176 o = add 64 mul w 4 177 vw_s o ulong get swpid w 178 vw_s add o 1 get auinc w 179 vw_s add o 2 auth_wctl w 180 vw_s add o 3 au_cell w 104 181 end 182 vw_unc 183 end 184 185 note Uncertain jobs: UNKNOWN in the scheduler, or released by the journal 186 note with outcome UNKNOWN (a class 1 effect whose fate nobody knows). 187 fn vw_unc to void 188 k = ulong 0 189 for j ulong 64 190 if and eq get sjst j 6 lt k 16 191 vw_s add 97 k get sjid j 192 k = add k 1 193 end 194 end 195 for e ulong 256 196 b = mul e 8 197 if and and ne get jjob b 0 ne get jjob add b 4 0 lt k 16 198 if eq and get jjob add b 5 255 0 199 vw_s add 97 k get jjob add b 1 200 k = add k 1 201 end 202 end 203 end 204 vw_s 96 k 205 end 206 207 note Creator: the posted command into d (id, op, target, version, a..d); 208 note false when none is posted. 209 fn vw_take d edit ulong 8 to bool 210 if ne vw_g VWBOX 1 211 ret false 212 end 213 for i ulong 8 214 put d i vw_g add VWBOX add 1 i 215 end 216 ret true 217 end 218 219 note Creator: acknowledge the posted command. 220 fn vw_ack st ulong v ulong js ulong to void 221 vw_s add VWBOX 9 st 222 vw_s add VWBOX 10 v 223 vw_s add VWBOX 11 js 224 vw_s add VWBOX 12 vw_g 4 225 vw_s VWBOX 2 226 end 227 228 note Creator: fork the view process on 127.0.0.1:port. Its pid (it writes 229 note the bound port to word 7 once listening), or a negative errno. The 230 note child is not a worker: it drops the creator's life-pipe write end (so 231 note workers still see the creator's death) and the journal descriptors. 232 fn vw_spawn port ulong to long 233 pid = fork 234 if eq pid 0 235 r = fclose get swpar 1 236 r = fclose get jfd 0 237 r = fclose get jlk 0 238 exit vw_serve port 239 end 240 if gt pid 0 241 vw_s 9 ulong pid 242 end 243 ret pid 244 end 245 246 note Creator: stop the view process and reap it. 247 fn vw_stop to void 248 pid = vw_g 9 249 if eq pid 0 250 ret 251 end 252 vw_s 6 1 253 st = new uchar 8 0 254 for t ulong 300 255 r = waitpid int pid st 0 4 1 256 if eq r long pid 257 vw_s 9 0 258 ret 259 end 260 x = sleepns `10000000` 261 end 262 r = killpid int pid 9 263 r = waitpid int pid st 0 4 0 264 vw_s 9 0 265 end 266 267 note ======== the view process 268 269 note Serve until the creator stops or is gone: 0, or 2 when the port 270 note cannot be bound. 271 fn vw_serve port ulong to int 272 cs = new ulong 320 0 273 io = new uchar 131072 0 274 ob = new uchar 32768 0 275 a = new uchar 16 0 276 r = haddr4 a `2130706433` port 277 lf = hlisten a 16 278 if lt lf 0 279 ret 2 280 end 281 vw_s 7 hport a 282 me = vw_g 5 283 for t ulong `1000000000` 284 if or ne vw_g 6 0 ne ulong getppid me 285 break 286 end 287 c = haccept int lf `200000000` 288 if ge c 0 289 vw_one int c cs io ob 290 end 291 end 292 x = fclose int lf 293 ret 0 294 end 295 296 note One request on connection fd, then close it. 297 fn vw_one fd int cs edit ulong 320 io edit uchar 131072 ob edit uchar 32768 to void 298 r = hinit cs io fd 1 299 if lt r 0 300 x = hclose cs 301 ret 302 end 303 hsettmo cs `2000000000` `2000000000` 304 hsetbdl cs `2000000000` 305 r = hreqrd cs io 306 if le r 0 307 if lt r 0 308 x = hreject cs io r 309 end 310 x = hclose cs 311 ret 312 end 313 vw_s 8 add vw_g 8 1 314 r = vw_route cs io ob 315 x = hclose cs 316 end 317 318 fn vw_route cs edit ulong 320 io edit uchar 131072 ob edit uchar 32768 to long 319 if hispath cs io vwpview 320 if hismeth cs io vwget 321 n = vw_view cs io ob 322 ret vw_send cs io ob n 200 323 end 324 ret hrsperr cs io 405 325 end 326 if hispath cs io vwpcmd 327 if hismeth cs io vwpost 328 ret vw_post cs io ob 329 end 330 ret hrsperr cs io 405 331 end 332 if hispath cs io vwphlth 333 n = vw_cat ob 0 vwhlth 334 ret vw_send cs io ob n 200 335 end 336 ret hrsperr cs io 404 337 end 338 339 fn vw_send cs edit ulong 320 io edit uchar 131072 ob view uchar 32768 n ulong code ulong to long 340 put cs HKEEP 0 341 r = hrspst cs io code 342 r = hfe r hhname cs io vwctype 343 r = hfe r hhval cs io vwjson 344 r = hfe r hhend cs io 0 n 345 r = hfe r hput cs io view part ob 0 n 346 ret hfe r hwfin cs io 347 end 348 349 note Query parameter key of the request target as a decimal; all ones 350 note when absent or not a number of 1..19 digits. 351 fn vw_qnum cs edit ulong 320 io view uchar 131072 key view uchar * to ulong 352 t = get cs HTOFF 353 n = get cs HTLEN 354 q = ulong 0 355 for i ulong n 356 if eq get io add t i 63 357 q = add i 1 358 break 359 end 360 end 361 if eq q 0 362 ret not ulong 0 363 end 364 p = q 365 for it ulong 64 366 if ge p n 367 break 368 end 369 e = vw_seg io t p n 370 if vw_keq io add t p key 371 ret vw_qdec io add add t p add len key 1 sub sub e p add len key 1 372 end 373 p = add e 1 374 end 375 ret not ulong 0 376 end 377 378 note End of the query segment starting at p (index of '&' or n). 379 fn vw_seg io view uchar 131072 t ulong p ulong n ulong to ulong 380 for i ulong sub n p 381 if eq get io add t add p i 38 382 ret add p i 383 end 384 end 385 ret n 386 end 387 388 note key= at io[o]. 389 fn vw_keq io view uchar 131072 o ulong key view uchar * to bool 390 for i ulong len key 391 if ne get io add o i get key i 392 ret false 393 end 394 end 395 ret eq get io add o len key 61 396 end 397 398 fn vw_qdec io view uchar 131072 o ulong m ulong to ulong 399 if or eq m 0 gt m 19 400 ret not ulong 0 401 end 402 v = ulong 0 403 for i ulong m 404 c = ulong get io add o i 405 if or lt c 48 gt c 57 406 ret not ulong 0 407 end 408 v = add mul v 10 sub c 48 409 end 410 ret v 411 end 412 413 note ======== JSON 414 415 fn vw_cat o edit uchar 32768 p ulong a view uchar * to ulong 416 for i ulong len a 417 if lt add p i 32768 418 put o add p i get a i 419 end 420 end 421 ret hmin add p len a 32768 422 end 423 424 fn vw_dec o edit uchar 32768 p ulong v ulong to ulong 425 d = new uchar 20 0 426 k = ulong 20 427 x = v 428 for it ulong 20 429 k = sub k 1 430 put d k uchar add rem x 10 48 431 x = div x 10 432 if eq x 0 433 break 434 end 435 end 436 q = p 437 for i ulong sub 20 k 438 if lt q 32768 439 put o q get d add k i 440 end 441 q = add q 1 442 end 443 ret hmin q 32768 444 end 445 446 fn vw_ch o edit uchar 32768 p ulong c ulong to ulong 447 if lt p 32768 448 put o p uchar c 449 end 450 ret hmin add p 1 32768 451 end 452 453 note "name": for the k-th comma-terminated name in names. 454 fn vw_key o edit uchar 32768 p ulong names view uchar * k ulong to ulong 455 s = ulong 0 456 m = ulong 0 457 for i ulong len names 458 if eq get names i 44 459 if eq m k 460 q = vw_ch o p 34 461 q = vw_cat o q view part names s sub i s 462 q = vw_ch o q 34 463 ret vw_ch o q 58 464 end 465 m = add m 1 466 s = add i 1 467 end 468 end 469 ret p 470 end 471 472 note {"name":s[b],...}, one member per comma-terminated name. 473 fn vw_obj o edit uchar 32768 p ulong names view uchar * s view ulong 1024 b ulong to ulong 474 n = ulong 0 475 for i ulong len names 476 if eq get names i 44 477 n = add n 1 478 end 479 end 480 q = vw_ch o p 123 481 for k ulong n 482 if gt k 0 483 q = vw_ch o q 44 484 end 485 q = vw_key o q names k 486 q = vw_dec o q get s add b k 487 end 488 ret vw_ch o q 125 489 end 490 491 note A stable copy of words 0..1023 (retries while the creator writes). 492 fn vw_load s edit ulong 1024 to bool 493 for t ulong 1000 494 a = vw_g 2 495 if eq and a 1 0 496 for i ulong 1024 497 put s i vw_g i 498 end 499 if eq vw_g 2 a 500 ret true 501 end 502 end 503 x = sleepns 100000 504 end 505 ret false 506 end 507 508 note The view: a delta since the client's version when the client holds 509 note this incarnation and every event since it is still in the ring, else 510 note a snapshot. The length. 511 fn vw_view cs edit ulong 320 io view uchar 131072 ob edit uchar 32768 to ulong 512 s = new ulong 1024 0 513 sv = vw_qnum cs io vwqsin 514 ic = vw_qnum cs io vwqinc 515 x = vw_load s 516 v = get s 3 517 p = vw_cat ob 0 vwkhd 518 p = vw_dec ob p get s 4 519 p = vw_cat ob p vwkver 520 p = vw_dec ob p v 521 if and and eq ic get s 4 le sv v le sub v sv 255 522 ret vw_delta ob p sv v 523 end 524 ret vw_snap ob p s 525 end 526 527 fn vw_delta ob edit uchar 32768 p0 ulong sv ulong v ulong to ulong 528 p = vw_cat ob p0 vwkdel 529 p = vw_dec ob p sv 530 p = vw_cat ob p vwkev 531 for k ulong sub v sv 532 e = add sv add k 1 533 o = add VWRING mul and e 255 4 534 if gt k 0 535 p = vw_ch ob p 44 536 end 537 p = vw_evj ob p o e 538 end 539 p = vw_ch ob p 93 540 ret vw_ch ob p 125 541 end 542 543 note [version,type,target,x,a,b] of the event at word o. 544 fn vw_evj ob edit uchar 32768 p0 ulong o ulong e ulong to ulong 545 w = vw_g add o 1 546 p = vw_ch ob p0 91 547 p = vw_dec ob p vw_g o 548 p = vw_ch ob p 44 549 p = vw_dec ob p and w 255 550 p = vw_ch ob p 44 551 p = vw_dec ob p and shr w 8 255 552 p = vw_ch ob p 44 553 p = vw_dec ob p shr w 16 554 p = vw_ch ob p 44 555 p = vw_dec ob p vw_g add o 2 556 p = vw_ch ob p 44 557 p = vw_dec ob p vw_g add o 3 558 ret vw_ch ob p 93 559 end 560 561 fn vw_snap ob edit uchar 32768 p0 ulong s view ulong 1024 to ulong 562 p = vw_cat ob p0 vwksnap 563 p = vw_cat ob p vwkauth 564 p = vw_obj ob p vwnauth s 16 565 p = vw_cat ob p vwkq 566 p = vw_obj ob p vwnq s 32 567 p = vw_cat ob p vwkc 568 p = vw_obj ob p vwnc s 44 569 p = vw_cat ob p vwkw 570 for w ulong get s 48 bound 8 571 if gt w 0 572 p = vw_ch ob p 44 573 end 574 p = vw_obj ob p vwnw s add 64 mul w 4 575 end 576 p = vw_cat ob p vwku 577 for k ulong get s 96 bound 16 578 if gt k 0 579 p = vw_ch ob p 44 580 end 581 p = vw_dec ob p get s add 97 k 582 end 583 p = vw_cat ob p vwko 584 for i ulong get s 128 bound 4 585 if gt i 0 586 p = vw_ch ob p 44 587 end 588 p = vw_obj ob p vwno s add 136 mul i 16 589 end 590 p = vw_cat ob p vwkl 591 p = vw_obj ob p vwnl s 200 592 ret vw_ch ob p 125 593 end 594 595 note ======== commands 596 597 note POST /cmd?id=&op=&target=&inc=&ver=&a=&b=&c=&d=: post it to the creator 598 note and wait up to 5 s for the acknowledgement. A command made for another 599 note incarnation (inc) is stale without reaching the creator, since its ver 600 note counts another incarnation's events. 503 while another command is 601 note posted and not yet taken, 504 when no acknowledgement came in time 602 note (the command may still commit: post it again with the same id). 603 fn vw_post cs edit ulong 320 io edit uchar 131072 ob edit uchar 32768 to long 604 d = new ulong 8 0 605 id = vw_qnum cs io vwqid 606 put d 0 vw_qnum cs io vwqop 607 put d 1 vw_qnum cs io vwqtg 608 put d 2 vw_qnum cs io vwqver 609 put d 3 vw_qnum cs io vwqa 610 put d 4 vw_qnum cs io vwqb 611 put d 5 vw_qnum cs io vwqc 612 put d 6 vw_qnum cs io vwqd 613 if or eq id 0 eq id not ulong 0 614 ret hrsperr cs io 400 615 end 616 st = ulong 1 617 bx = false 618 if eq vw_qnum cs io vwqinc vw_g 4 619 st = vw_box id d 620 bx = lt st 5 621 end 622 n = vw_ackj ob id st bx 623 ret vw_send cs io ob n vw_code st 624 end 625 626 note Post command id with d[0..6] = op, target, version, a..d; the status 627 note (0..4 from the creator, 5 busy, 6 pending). 628 fn vw_box id ulong d view ulong 8 to ulong 629 b = vw_g VWBOX 630 if eq b 1 631 ret 5 632 end 633 vw_s add VWBOX 1 id 634 for i ulong 7 635 vw_s add VWBOX add 2 i get d i 636 end 637 vw_s VWBOX 1 638 for t ulong 5000 639 if eq vw_g VWBOX 2 640 st = vw_g add VWBOX 9 641 vw_s VWBOX 0 642 ret st 643 end 644 x = sleepns `1000000` 645 end 646 ret 6 647 end 648 649 fn vw_code st ulong to ulong 650 if or eq st 0 eq st 4 651 ret 200 652 end 653 if eq st 1 654 ret 409 655 end 656 if eq st 2 657 ret 400 658 end 659 if eq st 3 660 ret 500 661 end 662 if eq st 5 663 ret 503 664 end 665 ret 504 666 end 667 668 note The acknowledgement: the creator's version and journal seq when bx, 669 note else the current version (the view's own verdict) and 0. 670 fn vw_ackj ob edit uchar 32768 id ulong st ulong bx bool to ulong 671 p = vw_cat ob 0 vwkid 672 p = vw_dec ob p id 673 p = vw_cat ob p vwkst 674 p = vw_name ob p vwsts st 675 p = vw_cat ob p vwkst2 676 v = vw_g 3 677 js = ulong 0 678 if bx 679 v = vw_g add VWBOX 10 680 js = vw_g add VWBOX 11 681 end 682 p = vw_dec ob p v 683 p = vw_cat ob p vwkjs 684 p = vw_dec ob p js 685 p = vw_cat ob p vwkinc 686 p = vw_dec ob p vw_g 4 687 ret vw_ch ob p 125 688 end 689 690 note The k-th comma-terminated name of names, unquoted. 691 fn vw_name o edit uchar 32768 p ulong names view uchar * k ulong to ulong 692 s = ulong 0 693 m = ulong 0 694 for i ulong len names 695 if eq get names i 44 696 if eq m k 697 ret vw_cat o p view part names s sub i s 698 end 699 m = add m 1 700 s = add i 1 701 end 702 end 703 ret p 704 end