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/code.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 / code.om` 1719 lines ยท 36782 bytes Raw Blame History 1 note seed/node/code.om -- the Omega Node coding workflow (DRA-290): the 2 note round40 repair protocol (read, check, edit, check again, answer) driven 3 note by the own Omega model through the Node's scheduler, authority and 4 note journal, under live operator control (DRA-291). OM-2. Compose after 5 note seed/net/http.om, seed/net/notls.om, transport.om, pool.om, super.om, 6 note sched.om, seed/authority/action.om, journal.om, auth.om, view.om, 7 note seed/node/gram.om, and before one program with fn main (code-main.om 8 note or code-test.om). 9 note Processes. The creator holds every objective's state; it alone reads 10 note model output and decides. Two workers run granted jobs, each one child 11 note process in its own process group (auth_wtool): omnode-infer for a model 12 note turn, omnode-tool for read_file, omega_check and replace_text, and a 13 note review (a fresh omnode-tool check of the edited file). A job's input is 14 note the packed argv the creator published on the objective's topic bit; 15 note the worker proposes it, the creator grants it (generation, staleness, 16 note cancellation, journal START), the worker runs it and returns the 17 note child's record (OMNI1 or OMNT1, at most 3968 bytes) with the outcome. 18 note One inference at a time: the provider is a single local ollm serve. 19 note A turn has 160 new tokens (as round40 sampled) and 900 s, since the CPU 20 note server needs minutes for a long prompt on a shared host. 21 note Policy, as round40 repair.py jobs_run: at most 7 model turns; the action 22 note must name the objective's path; read_file only when unread, omega_check 23 note only when read or edited, replace_text only when failed, whose old text 24 note must occur exactly once in the source the model was shown and whose 25 note result must stay in the repair grammar (checked here before the grant); 26 note Tests passed. only when the last check passed (then a review job runs), 27 note File not found. only when the read found no file. Anything else ends 28 note the objective as failed; nothing is repaired or retried. 29 note Results: 1 PASS; failures 10 action not valid in its state, 11 wrong 30 note path, 12 out of turns, 13 edit refused, 14 Tests passed. unverified, 31 note 15 the file differs from the workflow's source, or the review's fresh check of the saved 32 note file did not pass (a test run killed at the 2 s wall clock included), 16 inference failed 33 note (exit status in the event line; no fallback), 17 tool failed, 18 34 note malformed record, 19 cancelled, 20 prompt too long, 21 outcome UNKNOWN, 35 note 22 job input lost, 23 refused by the authority. 36 note Restart: the journal releases what the last creator left (auth_recover); 37 note jobs still waiting for input are cancelled; an objective whose result 38 note the journal holds (RESULT) is reported with it again and never resumed; 39 note every other objective resumes from the durable workspace in state 40 note unread, with the model turns already performed counted against its 41 note budget and its job ids continuing; the committed operator commands are 42 note then applied again in order to the objectives still open. 43 note Operator (DRA-291): the creator writes a snapshot of its state and an 44 note event per change to view.om's page every loop, and takes one posted 45 note command per loop. A command is checked against the version the 46 note operator saw (stale when its target changed since), committed in the 47 note journal (OPER; pause and resume first through auth_pause), then acted 48 note on and acknowledged: pause and resume, cancel an objective (its job in 49 note flight is cancelled through the authority and the objective ends 19), 50 note set its turn budget (0..7; out of turns ends 12), or redirect it to 51 note another goal (its job in flight is cancelled and it starts over from 52 note unread). A tool job the authority refuses ends its objective with 23. 53 note Events on stdout, one line each: CWP (prompt) and CWR (model text) are 54 note followed by their bytes and a newline; CWE job events; CWO results; 55 note CWV the operator view's port once it listens. 56 const CWOBJ ulong 4 57 text cwtask "Task: " 58 text cwfile "\nFile: " 59 text cwgoal "\nGoal: " 60 text cwstat "\nState: " 61 text cwsrcl "Source:\n" 62 text cwtres "Tool result: " 63 text cwansw "Answer:\n" 64 text cwnl "\n" 65 text cwsp " " 66 text cwgl1 "calc starts with x and adds " 67 text cwgl2 " exactly " 68 text cwgl3 " times in a for loop. main calls calc with " 69 text cwgl4 "calc returns x " 70 text cwplus "plus " 71 text cwtims "times " 72 text cwgl5 ". main calls calc with " 73 text cwdot "." 74 text cwsun "unread" 75 text cwsrd "read" 76 text cwsfl "failed" 77 text cwsed "edited" 78 text cwsck "checked" 79 text cwsms "missing" 80 text cwvrd "read" 81 text cwvck "check" 82 text cwvrp "replace" 83 text cwmax "160" 84 text cwdl "900" 85 text cwo "/o" 86 text cwadd "add" 87 text cwmul "mul" 88 text cwloop "loop" 89 text cwhi "OMNI1 " 90 text cwht "OMNT1 " 91 text cwep "CWP " 92 text cwer "CWR " 93 text cwee "CWE " 94 text cwfpre "code-main: " 95 text cwfex ", exit " 96 text cwfpool "pool_new failed" 97 text cwfsup "sup_init failed" 98 text cwfsch "sched_new failed" 99 text cwfaut "auth_new failed" 100 text cwfjrn "journal refused (exit 30 + 20 fenced, 21 incompatible, 22 other objective, 23 corrupt, 24/25 refused record, 26 directory over 100 bytes, 27 I/O error)" 101 text cwfrec "restart recovery refused (exit 30 + 24/25 refused record, 27 I/O error, 28 write, 29 sync, 30 journal failed earlier, 31 the scheduler refused a restore: incarnation, capacities or policy, a job admitted again, or the last FAIR, 32 action record not restored)" 102 text cwfvwn "vw_new failed" 103 text cwfspn "worker spawn failed" 104 text cwfvw "view process not started" 105 text cwfcan "restart cleanup could not cancel a job the last creator left waiting or ready (the journal refused its CANCEL, or the RELEASE after a cancel that freed it)" 106 text cweo "CWO " 107 text cwpass "PASS" 108 text cwfail "FAIL" 109 text cwsum "CWSUM pass=" 110 text cwsumf " fail=" 111 text cwfresult "objective RESULT could not be committed" 112 global cwresultbad ulong 1 113 global cwcf uchar 8192 114 global cwcl ulong 8 115 global cwno ulong 1 116 global cwos uchar 2048 117 global cwob ulong 128 118 global cwsrc uchar 16384 119 global cwobs uchar 4096 120 global cwcan uchar 16384 121 global cwinf ulong 1 122 global cwgot ulong 64 123 global cwt0 ulong 4 124 global cwtk ulong 2 125 global cwpv ulong 1 126 global cwql ulong 1 127 global cwtu ulong 1 128 text cwcwv "CWV " 129 note Objective words shown in the view's rows, as characters '0' + word. 130 text cwvw "012367@9:, the objective's private compile directory. 376 fn cw_wdir t edit uchar 4096 i ulong to ulong 377 p = cw_catl t 0 14 0 378 p = cw_cat t p cwo 379 ret cw_dec t p i 380 end 381 382 note ======== events 383 384 fn cw_ev i ulong id ulong what ulong v ulong to void 385 o = new uchar 4096 0 386 p = cw_cat o 0 cwee 387 p = cw_dec o p i 388 p = cw_cat o p cwsp 389 p = cw_dec o p id 390 p = cw_cat o p cwsp 391 p = cw_dec o p what 392 p = cw_cat o p cwsp 393 p = cw_dec o p v 394 p = cw_cat o p cwnl 395 cw_out o p 396 cw_s i 17 vw_ev 1 i what id v 397 end 398 399 note A framed transcript record: tag i turn n, newline, the bytes, newline. 400 fn cw_rec tag ulong i ulong b view uchar * to void 401 o = new uchar 4096 0 402 p = ulong 0 403 if eq tag 0 404 p = cw_cat o 0 cwep 405 else 406 p = cw_cat o 0 cwer 407 end 408 p = cw_dec o p i 409 p = cw_cat o p cwsp 410 p = cw_dec o p cw_g i 7 411 p = cw_cat o p cwsp 412 p = cw_dec o p len b 413 p = cw_cat o p cwnl 414 cw_out o p 415 cw_out b len b 416 cw_out cwnl 1 417 end 418 419 note Objective i finished with result r (1 PASS, else the failure): RESULT 420 note is made durable first. A refusal latches a creator failure and emits no result. 421 fn cw_end i ulong r ulong to void 422 if ne get cwresultbad 0 0 423 ret 424 end 425 x = jn_result i r cw_g i 7 426 if ne x 0 427 put cwresultbad 0 x 428 ret 429 end 430 cw_pub i r 431 end 432 433 note Publish objective i's result r: its CWO line and view event. 434 fn cw_pub i ulong r ulong to void 435 o = new uchar 4096 0 436 cw_s i 12 r 437 cw_s i 9 4 438 p = cw_cat o 0 cweo 439 p = cw_dec o p i 440 p = cw_cat o p cwsp 441 if eq r 1 442 p = cw_cat o p cwpass 443 else 444 p = cw_cat o p cwfail 445 end 446 p = cw_cat o p cwsp 447 p = cw_dec o p r 448 p = cw_cat o p cwsp 449 p = cw_dec o p cw_g i 7 450 p = cw_cat o p cwnl 451 cw_out o p 452 cw_s i 17 vw_ev 2 i 0 r cw_g i 7 453 end 454 455 note ======== creator: issuing jobs 456 457 note Admit job kind (1 inference, 2 read, 3 check, 4 replace, 5 review) of 458 note objective i with input pk[0, pn), then publish the input on the 459 note objective's topic, which makes the job ready. The job id, or 0 when it 460 note was not admitted. A refused inference is asked for again at the next 461 note step (admission refusals are counted for the view). A refused tool job 462 note ends the objective with 23: it cannot be a full queue (a tool job is 463 note issued only after its objective's previous job left the queue, so it 464 note takes that job's place), and nothing is left waiting unseen. 465 fn cw_issue c long i ulong kind ulong pk view uchar 4096 pn ulong to ulong 466 if ne get cwresultbad 0 0 467 ret 0 468 end 469 s = cw_g i 11 470 if ge s 99 471 cw_end i 20 472 ret 0 473 end 474 id = add add mul add i 1 1000 mul s 10 kind 475 fl = ulong 1 476 if eq kind 4 477 fl = 0 478 end 479 t = shl ulong 1 i 480 j = jn_admit id t fl 481 if lt j 0 482 if eq j neg long 2 483 vw_cnt 0 add vw_cget 0 1 484 end 485 if ne kind 1 486 cw_end i 23 487 end 488 ret 0 489 end 490 cw_s i 11 add s 1 491 v = sched_publish c t pk pn 492 if le v 0 493 x = auth_cancel c ulong j 494 cw_end i 22 495 ret 0 496 end 497 cw_s i 10 id 498 put cwt0 i ulong monons 499 cw_ev i id 1 kind 500 ret id 501 end 502 503 note Start objective i's next model turn: the prompt as the only input. 504 fn cw_turn c long i ulong to void 505 pr = new uchar 4096 0 506 pk = new uchar 4096 0 507 n = cw_prmt pr i 508 if gt n 3800 509 cw_end i 20 510 ret 511 end 512 p = cw_cfg pk 2 0 513 p = cw_cfg pk p 6 514 p = cw_arg pk p cwmax 515 p = cw_arg pk p cwdl 516 p = cw_arg pk p view part pr 0 n 517 if gt p 4096 518 cw_end i 20 519 ret 520 end 521 id = cw_issue c i 1 pk p 522 if gt id 0 523 cw_s i 7 add cw_g i 7 1 524 cw_s i 9 1 525 put cwinf 0 add i 1 526 cw_rec 0 i view part pr 0 n 527 end 528 end 529 530 note TOOL verb ROOT PATH into pk; the length. 531 fn cw_targ pk edit uchar 4096 i ulong vb ulong to ulong 532 p = cw_cfg pk 2 1 533 if eq vb 2 534 p = cw_arg pk p cwvrd 535 end 536 if or eq vb 3 eq vb 5 537 p = cw_arg pk p cwvck 538 end 539 if eq vb 4 540 p = cw_arg pk p cwvrp 541 end 542 p = cw_cfg pk p 3 543 ret cw_argl pk p 0 i 544 end 545 546 note A read (2), check (3) or review (5) job for objective i. 547 fn cw_tool c long i ulong kind ulong to void 548 pk = new uchar 4096 0 549 t = new uchar 4096 0 550 p = cw_targ pk i kind 551 if ne kind 2 552 n = cw_wdir t i 553 p = cw_arg pk p view part t 0 n 554 p = cw_cfg pk p 2 555 p = cw_narg pk p cw_g i 0 556 p = cw_narg pk p cw_g i 1 557 p = cw_narg pk p cw_g i 2 558 p = cw_narg pk p cw_g i 3 559 end 560 id = cw_issue c i kind pk p 561 if gt id 0 562 cw_s i 9 2 563 if eq kind 5 564 cw_s i 9 3 565 end 566 end 567 end 568 569 note A replace job for objective i: old (h5 bytes at b[o]) and new (h6 570 note bytes after it) as the model gave them. 571 fn cw_repl c long i ulong b view uchar 4096 o ulong h view ulong 16 to void 572 pk = new uchar 4096 0 573 p = cw_targ pk i 4 574 p = cw_arg pk p view part b o get h 5 575 p = cw_arg pk p view part b add o get h 5 get h 6 576 id = cw_issue c i 4 pk p 577 if gt id 0 578 cw_s i 9 2 579 end 580 end 581 582 note ======== creator: records 583 584 note Parse k decimal fields of record b after the 6-byte tag into h[0..k); 585 note the offset after the header line, or 0 when malformed. 586 fn cw_hdr b view uchar 4096 k ulong h edit ulong 16 to ulong 587 p = ulong 6 588 for f ulong k 589 v = ulong 0 590 nd = ulong 0 591 for it ulong 12 592 c = ulong get b p 593 if or lt c 48 gt c 57 594 break 595 end 596 v = add mul v 10 sub c 48 597 nd = add nd 1 598 p = add p 1 599 end 600 if eq nd 0 601 ret 0 602 end 603 put h f v 604 c2 = get b p 605 if lt add f 1 k 606 if ne c2 32 607 ret 0 608 end 609 else 610 if ne c2 10 611 ret 0 612 end 613 end 614 p = add p 1 615 end 616 ret p 617 end 618 619 fn cw_tag b view uchar 4096 t view uchar * to bool 620 for i ulong 6 621 if ne get b i get t i 622 ret false 623 end 624 end 625 ret true 626 end 627 628 note Objective i's model record b: the turn's action, checked against the 629 note state before anything is granted. 630 fn cw_ires c long i ulong b view uchar 4096 to void 631 h = new ulong 16 0 632 if not cw_tag b cwhi 633 cw_end i 18 634 ret 635 end 636 d = cw_hdr b 8 h 637 if or eq d 0 gt add add add add d get h 4 get h 5 get h 6 get h 7 3968 638 cw_end i 18 639 ret 640 end 641 x = add add add d get h 4 get h 5 get h 6 642 cw_rec 1 i view part b x get h 7 643 cw_ev i 0 2 get h 0 644 cw_act c i b d h 645 end 646 647 note The policy of repair.py jobs_run for action kind h[0], with path at 648 note b[d, d + h4), old after it (h5 bytes), new after that (h6 bytes). 649 fn cw_act c long i ulong b view uchar 4096 d ulong h view ulong 16 to void 650 u = new uchar 4096 0 651 un = cw_ld u 0 i 652 k = get h 0 653 st = cw_g i 6 654 if eq k 4 655 if and eq st 4 eq cw_g i 8 1 656 cw_tool c i 5 657 else 658 cw_end i 14 659 end 660 ret 661 end 662 if eq k 5 663 if eq st 5 664 cw_end i 1 665 else 666 cw_end i 10 667 end 668 ret 669 end 670 if or eq k 9 gt k 5 671 cw_end i 10 672 ret 673 end 674 if not cw_eq view part b d get h 4 view part u 0 un 675 cw_end i 11 676 ret 677 end 678 if and eq k 1 eq st 0 679 cw_tool c i 2 680 ret 681 end 682 if and eq k 2 or eq st 1 eq st 3 683 cw_tool c i 3 684 ret 685 end 686 if and eq k 3 eq st 2 687 cw_edit c i b add d get h 4 h 688 ret 689 end 690 cw_end i 10 691 end 692 693 note replace_text: the model's old must occur exactly once in the source it 694 note was shown and the result must stay in the grammar; the candidate is 695 note kept to compare with what the tool saved. 696 fn cw_edit c long i ulong b view uchar 4096 o ulong h view ulong 16 to void 697 u = new uchar 4096 0 698 un = cw_ld u 2 i 699 if ne cw_count view part u 0 un view part b o get h 5 1 700 cw_end i 13 701 ret 702 end 703 n = cw_cand i b o h 704 if gt n 3800 705 cw_end i 13 706 ret 707 end 708 cw_repl c i b o h 709 end 710 711 note The candidate source of objective i into cwcan: its length, or 5000 712 note when it is over 3800 bytes or outside the grammar. 713 fn cw_cand i ulong b view uchar 4096 o ulong h view ulong 16 to ulong 714 t = new uchar 4096 0 715 u = new uchar 4096 0 716 sn = cw_ld u 2 i 717 k = cw_at view part u 0 sn view part b o get h 5 718 p = cw_cat t 0 view part u 0 k 719 p = cw_cat t p view part b add o get h 5 get h 6 720 r = add k get h 5 721 p = cw_cat t p view part u r sub sn r 722 if gt p 3800 723 ret 5000 724 end 725 if not gr_src t p 726 ret 5000 727 end 728 cw_keep i t p 729 ret p 730 end 731 732 note The first occurrence of a in s (len s when none). 733 fn cw_at s view uchar * a view uchar * to ulong 734 for k ulong len s 735 if le add k len a len s 736 if cw_eq view part s k len a a 737 ret k 738 end 739 end 740 end 741 ret len s 742 end 743 744 fn cw_keep i ulong t view uchar 4096 n ulong to void 745 for j ulong n 746 put cwcan add mul i 4096 j get t j 747 end 748 cw_s i 15 n 749 end 750 751 note Objective i's tool record b for job kind. 752 fn cw_tres c long i ulong kind ulong b view uchar 4096 to void 753 h = new ulong 16 0 754 if not cw_tag b cwht 755 cw_end i 18 756 ret 757 end 758 d = cw_hdr b 3 h 759 if or eq d 0 or gt get h 1 1024 gt add add d get h 1 get h 2 3968 760 cw_end i 18 761 ret 762 end 763 st = get h 0 764 cw_ev i 0 3 st 765 if eq kind 2 766 cw_read i st b d h 767 ret 768 end 769 if eq kind 4 770 cw_saved i st b d h 771 ret 772 end 773 cw_chk i add mul kind 256 st b d h 774 end 775 776 note A tool record's observation is h1 bytes at b[d], its content the h2 777 note bytes after it. cw_same: the content equals loaded item sel. 778 fn cw_same i ulong sel ulong b view uchar 4096 d ulong h view ulong 16 to bool 779 u = new uchar 4096 0 780 un = cw_ld u sel i 781 ret cw_eq view part b add d get h 1 get h 2 view part u 0 un 782 end 783 784 note A check (kind 3) or review (5) record, ks = 256 kind + status: the file 785 note checked must be the source the workflow holds. 786 fn cw_chk i ulong ks ulong b view uchar 4096 d ulong h view ulong 16 to void 787 kind = shr ks 8 788 st = and ks 255 789 if not cw_same i 2 b d h 790 cw_end i 15 791 ret 792 end 793 if eq kind 5 794 if eq st 0 795 cw_end i 1 796 else 797 cw_end i 15 798 end 799 ret 800 end 801 if eq st 0 802 cw_s i 6 4 803 cw_s i 8 1 804 else 805 if ne st 6 806 cw_end i 17 807 ret 808 end 809 cw_s i 6 2 810 cw_s i 8 0 811 end 812 cw_seto i view part b d get h 1 813 cw_s i 9 0 814 end 815 816 fn cw_read i ulong st ulong b view uchar 4096 d ulong h view ulong 16 to void 817 if eq st 0 818 cw_s i 6 1 819 cw_setsrc i view part b add d get h 1 get h 2 820 cw_seto i view part b d get h 1 821 cw_s i 9 0 822 ret 823 end 824 if eq st 1 825 cw_s i 6 5 826 cw_s i 13 0 827 cw_seto i view part b d get h 1 828 cw_s i 9 0 829 ret 830 end 831 cw_end i 17 832 end 833 834 fn cw_saved i ulong st ulong b view uchar 4096 d ulong h view ulong 16 to void 835 if eq st 5 836 cw_end i 13 837 ret 838 end 839 if ne st 0 840 cw_end i 17 841 ret 842 end 843 if not cw_same i 4 b d h 844 cw_end i 15 845 ret 846 end 847 cw_s i 6 3 848 cw_s i 8 0 849 cw_setsrc i view part b add d get h 1 get h 2 850 cw_seto i view part b d get h 1 851 cw_s i 9 0 852 end 853 854 fn cw_setsrc i ulong f view uchar * to void 855 for j ulong len f 856 put cwsrc add mul i 4096 j get f j 857 end 858 cw_s i 13 len f 859 end 860 861 fn cw_seto i ulong o view uchar * to void 862 for j ulong len o 863 put cwobs add mul i 1024 j get o j 864 end 865 cw_s i 14 len o 866 end 867 868 note ======== creator: results 869 870 note A job of objective i in review: its result bytes are read before it is 871 note released and before the next auth_step, so no later job of the same 872 note worker (which needs a grant first) can have overwritten them. 873 fn cw_done c long j ulong id ulong to void 874 b = new uchar 4096 0 875 i = sub div id 1000 1 876 kind = rem id 10 877 if or ge i get cwno 0 ne id cw_g i 10 878 ret 879 end 880 r = sched_result get sjw j b 881 o = get sjout j 882 cw_s i 10 0 883 if eq kind 1 884 put cwinf 0 0 885 end 886 cw_ev i id 4 o 887 f = cw_fate o kind 888 if eq f 21 889 x = vw_ev 7 i 0 id 0 890 end 891 if cw_oper i 892 ret 893 end 894 if ne f 0 895 cw_end i f 896 ret 897 end 898 if eq kind 1 899 cw_ires c i b 900 ret 901 end 902 cw_tres c i kind b 903 end 904 905 note The failure for job outcome word o of a job of kind, 0 when its child 906 note ran and exited 0: refused 16 + verdict (cancelled, verdict 6: 19), 907 note input lost 90, not performed 1 (cancelled: 19), UNKNOWN 0 or a child 908 note killed by a signal (21), a nonzero exit (16 inference, 17 tool). 909 fn cw_fate o ulong kind ulong to ulong 910 lo = and o 255 911 if eq lo 2 912 ws = shr o 8 913 if ne and ws 127 0 914 ret 21 915 end 916 if eq and shr ws 8 255 0 917 ret 0 918 end 919 if eq kind 1 920 ret 16 921 end 922 ret 17 923 end 924 if or eq lo 1 eq lo 22 925 ret 19 926 end 927 if eq lo 0 928 ret 21 929 end 930 if eq lo 90 931 ret 22 932 end 933 ret 23 934 end 935 936 note Collect: every job in review is handled once, then released (again at 937 note the next step while its DONE is not yet durable). A job whose worker 938 note died mid-job (UNKNOWN) ends its objective; its slot stays UNKNOWN, 939 note since only the journal's recovery may settle what may have happened. 940 fn cw_coll c long to void 941 for j ulong 64 942 s = get sjst j 943 id = get sjid j 944 if and eq s 4 ne get cwgot j id 945 put cwgot j id 946 cw_done c j id 947 end 948 if eq s 4 949 x = jn_release j 950 end 951 if and eq s 6 ne get cwgot j id 952 put cwgot j id 953 cw_lost id 954 end 955 end 956 end 957 958 fn cw_lost id ulong to void 959 i = sub div id 1000 1 960 if and lt i get cwno 0 eq id cw_g i 10 961 cw_s i 10 0 962 if eq rem id 10 1 963 put cwinf 0 0 964 end 965 x = vw_ev 7 i 0 id 0 966 if not cw_oper i 967 cw_end i 21 968 end 969 end 970 end 971 972 note After objective i's job in flight finished or was lost: an operator 973 note cancel ends it (19); a redirect waiting for the job takes effect. True 974 note when one of them applied. 975 fn cw_oper i ulong to bool 976 if ne cw_g i 19 0 977 cw_end i 19 978 ret true 979 end 980 if ne cw_g i 18 0 981 cw_redo i 982 ret true 983 end 984 ret false 985 end 986 987 note Objective i starts over from unread with its new goal (a redirect): 988 note turns, budget and job ids continue. 989 fn cw_redo i ulong to void 990 cw_s i 18 0 991 cw_s i 6 0 992 cw_s i 8 0 993 cw_s i 9 0 994 cw_s i 13 0 995 cw_s i 14 0 996 cw_s i 15 0 997 end 998 999 note ======== creator: planning 1000 1001 note Start a turn for one objective that needs one (one inference in flight 1002 note at a time); the test hook cwtk cancels an inference after ms. An 1003 note objective out of its turn budget ends with 12. 1004 fn cw_plan c long to void 1005 cw_hook c 1006 if gt get cwinf 0 0 1007 ret 1008 end 1009 for i ulong get cwno 0 bound 4 1010 if and eq cw_g i 9 0 eq cw_g i 12 0 1011 if ge cw_g i 7 cw_g i 16 1012 cw_end i 12 1013 else 1014 cw_turn c i 1015 ret 1016 end 1017 end 1018 end 1019 end 1020 1021 fn cw_hook c long to void 1022 if ne get cwtu 0 0 1023 cw_hooku 1024 end 1025 k = get cwtk 0 1026 if eq k 0 1027 ret 1028 end 1029 i = sub k 1 1030 if or ne cw_g i 9 1 eq cw_g i 10 0 1031 ret 1032 end 1033 if lt sub ulong monons get cwt0 i mul get cwtk 1 `1000000` 1034 ret 1035 end 1036 for j ulong 64 1037 if and eq get sjid j cw_g i 10 eq get sjst j 3 1038 x = auth_cancel c j 1039 if ge x 0 1040 cw_ev i cw_g i 10 5 ulong x 1041 put cwtk 0 0 1042 end 1043 end 1044 end 1045 end 1046 1047 note Test hook cwtu: SIGKILL the worker of the first replace, once, after its 1048 note START is durable; whether the edit happened is then unknown to the 1049 note creator and to the journal. A job is assigned (state 3) before its 1050 note worker's proposal is decided and START journaled, so state 3 alone 1051 note could kill a worker whose job holds ADMIT only (DRA-292, job 1054). 1052 fn cw_hooku to void 1053 for j ulong 64 1054 if and and eq get sjst j 3 eq rem get sjid j 10 4 jn_started get sjid j 1055 x = killpid int get swpid get sjw j 9 1056 put cwtu 0 0 1057 ret 1058 end 1059 end 1060 end 1061 1062 fn cw_left to ulong 1063 n = ulong 0 1064 for i ulong get cwno 0 bound 4 1065 if eq cw_g i 12 0 1066 n = add n 1 1067 end 1068 end 1069 ret n 1070 end 1071 1072 note Creator loop until every objective finished or dl ns pass: 0 or 62. 1073 fn cw_drive c long dl ulong to int 1074 for t ulong `1000000000` 1075 r = sched_step c `5000000` 1076 cw_coll c 1077 if ne get cwresultbad 0 0 1078 ret 58 1079 end 1080 k = auth_step c 1081 cw_cmd c 1082 if ne get cwresultbad 0 0 1083 ret 58 1084 end 1085 cw_plan c 1086 if ne get cwresultbad 0 0 1087 ret 58 1088 end 1089 cw_vsnap c 1090 if eq cw_left 0 1091 ret 0 1092 end 1093 if ge ulong monons dl 1094 ret 62 1095 end 1096 end 1097 ret 62 1098 end 1099 1100 note ======== creator: operator view and commands (DRA-291, seed/node/view.om) 1101 1102 note The snapshot: generic sections, then the objectives and the limits. 1103 fn cw_vsnap c long to void 1104 vw_begin 1105 vw_gen c 1106 vw_s 21 get cwpv 0 1107 vw_s 128 get cwno 0 1108 for i ulong get cwno 0 bound 4 1109 o = add 136 mul i 16 1110 for w ulong 14 1111 vw_s add o w cw_g i sub ulong get cwvw w 48 1112 end 1113 end 1114 vw_s 200 7 1115 vw_s 201 900 1116 vw_s 202 160 1117 vw_s 203 CWOBJ 1118 vw_s 204 64 1119 vw_s 205 256 1120 vw_end 1121 end 1122 1123 note One posted command: a committed id is acknowledged again as a 1124 note duplicate; otherwise it is checked against the state the operator saw 1125 note (stale, invalid), committed (OPER durable, then acted on), and 1126 note acknowledged. 1127 fn cw_cmd c long to void 1128 d = new ulong 8 0 1129 if not vw_take d 1130 ret 1131 end 1132 k = jn_ofind get d 0 1133 if ge k 0 1134 vw_ack 4 jn_opw ulong k 7 get jseq 0 1135 ret 1136 end 1137 st = cw_cchk d 1138 if eq st 0 1139 st = cw_exec c d 1140 end 1141 if eq st 0 1142 vw_cnt 1 add vw_cget 1 1 1143 vw_cnt 3 get d 0 1144 vw_ack 0 jn_opw ulong jn_ofind get d 0 7 get jseq 0 1145 ret 1146 end 1147 vw_cnt 2 add vw_cget 2 1 1148 vw_ack st vw_ver get jseq 0 1149 end 1150 1151 note 0 when command d (id, op, target, version, a..d) may run now; 1 stale 1152 note (what it targets changed after the version the operator saw, or the 1153 note version is not of this incarnation), 2 invalid. 1154 fn cw_cchk d view ulong 8 to ulong 1155 op = get d 1 1156 t = get d 2 1157 if eq get d 3 not ulong 0 1158 ret 2 1159 end 1160 if gt get d 3 vw_ver 1161 ret 1 1162 end 1163 if or eq op 1 eq op 2 1164 if gt get cwpv 0 get d 3 1165 ret 1 1166 end 1167 if eq get scpause 0 sub 2 op 1168 ret 2 1169 end 1170 ret 0 1171 end 1172 if or or lt op 3 gt op 5 ge t get cwno 0 1173 ret 2 1174 end 1175 if gt cw_g t 17 get d 3 1176 ret 1 1177 end 1178 if eq cw_g t 9 4 1179 ret 2 1180 end 1181 if and eq op 4 gt get d 4 7 1182 ret 2 1183 end 1184 if eq op 5 1185 ret cw_rchk d 1186 end 1187 ret 0 1188 end 1189 1190 fn cw_rchk d view ulong 8 to ulong 1191 if or lt get d 4 1 gt get d 4 3 1192 ret 2 1193 end 1194 for m ulong 3 1195 if gt get d add 5 m 99 1196 ret 2 1197 end 1198 end 1199 ret 0 1200 end 1201 1202 note Commit command d: pause and resume go through auth_pause (which 1203 note journals PAUSE) and are then recorded; objective commands are recorded 1204 note (OPER durable) and then applied. 0, or 3 refused. 1205 fn cw_exec c long d view ulong 8 to ulong 1206 a = new ulong 4 0 1207 for m ulong 4 1208 put a m get d add 4 m 1209 end 1210 op = get d 1 1211 v = add vw_ver 1 1212 if le op 2 1213 x = auth_pause c eq op 1 1214 if ne get jbad 0 0 1215 ret 3 1216 end 1217 end 1218 if ne jn_oper get d 0 op get d 2 a v 0 1219 ret 3 1220 end 1221 x = vw_ev 3 get d 2 op get d 0 0 1222 if le op 2 1223 put cwpv 0 vw_ev 4 0 0 sub 2 op 0 1224 ret 0 1225 end 1226 cw_apply c get d 2 op a 1227 ret 0 1228 end 1229 1230 note Apply objective command op to objective i (also when the journal is 1231 note replayed at a restart, when nothing is in flight). 1232 fn cw_apply c long i ulong op ulong a view ulong 4 to void 1233 if eq op 4 1234 cw_s i 16 get a 0 1235 cw_s i 17 vw_ver 1236 ret 1237 end 1238 if eq op 5 1239 for m ulong 4 1240 cw_s i m get a m 1241 end 1242 end 1243 if eq cw_g i 10 0 1244 if eq op 3 1245 cw_end i 19 1246 else 1247 cw_redo i 1248 end 1249 cw_s i 17 vw_ver 1250 ret 1251 end 1252 if eq op 3 1253 cw_s i 19 1 1254 else 1255 cw_s i 18 1 1256 end 1257 cw_s i 17 vw_ver 1258 cw_stop c cw_g i 10 1259 end 1260 1261 note Cancel job id through the authority wherever it is (waiting, ready or 1262 note running); its result then reaches cw_oper. 1263 fn cw_stop c long id ulong to void 1264 for j ulong 64 1265 s = get sjst j 1266 if and eq get sjid j id and ge s 1 le s 3 1267 x = auth_cancel c j 1268 end 1269 end 1270 end 1271 1272 note At a restart: the committed operator commands again, in order. 1273 fn cw_replay c long to void 1274 a = new ulong 4 0 1275 for k ulong jn_nops bound 128 1276 for m ulong 4 1277 put a m jn_opw k add 3 m 1278 end 1279 op = jn_opw k 1 1280 i = jn_opw k 2 1281 if and ge op 3 lt i get cwno 0 1282 if ne cw_g i 9 4 1283 cw_apply c i op a 1284 end 1285 end 1286 vw_cnt 1 add vw_cget 1 1 1287 vw_cnt 3 jn_opw k 0 1288 end 1289 end 1290 1291 note ======== worker 1292 1293 note Worker w: the input of its job (objective i): the newest version on the 1294 note objective's topic that is not newer than the assignment's version. 1295 fn cw_input c long w ulong i ulong dst edit uchar 4096 to long 1296 v = sc_cell w 24 1297 t = shl ulong 1 i 1298 h = pool_hold c w sc_cell w 16 1299 if le h 0 1300 ret neg long 1 1301 end 1302 cur = ulong 0 1303 last = ulong 0 1304 for k ulong 65 1305 x = node_next h cur t 1306 if le x 0 1307 break 1308 end 1309 if gt ulong x v 1310 break 1311 end 1312 last = ulong x 1313 cur = last 1314 end 1315 n = neg long 1 1316 if gt last 0 1317 n = node_read h last dst 1318 end 1319 r = pool_release c w 1320 ret n 1321 end 1322 1323 note Worker w, assignment q: propose, wait for the decision, run the child 1324 note when granted, report. Outcome word: the authority's outcome (0 UNKNOWN, 1325 note 1 not performed, 2 performed) plus the wait status shifted by 8; 16 + 1326 note verdict when refused; 90 when the input was not found. 1327 fn cw_job c long w ulong q ulong to void 1328 pk = new uchar 4096 0 1329 op = new ulong 4 0 1330 id = sc_cell w 8 1331 n = cw_input c w sub div id 1000 1 pk 1332 if le n 0 1333 r = sched_wdone w q 90 pk 0 1334 ret 1335 end 1336 put op 0 id 1337 put op 1 rem id 10 1338 put op 2 div id 1000 1339 put op 3 1 1340 r = auth_propose w q op cw_class id 1341 v = auth_wdecide c w q `30000000000` 1342 if ne v 0 1343 r = sched_wdone w q add 16 ulong v pk 0 1344 ret 1345 end 1346 cw_wrun c w q pk ulong n 1347 end 1348 1349 note Replace changes the workspace (class 1); the others are rerunnable. 1350 fn cw_class id ulong to ulong 1351 if eq rem id 10 4 1352 ret 1 1353 end 1354 ret 2 1355 end 1356 1357 fn cw_wrun c long w ulong q ulong pk view uchar 4096 n ulong to void 1358 ob = new uchar 4096 0 1359 o = auth_wtool c w q pk n cw_class sc_cell w 8 1360 r = auth_wreport w q ulong o 1361 m = auth_wout w ob 1362 x = or ulong o shl auth_cell w 96 8 1363 r = sched_wdone w q x ob m 1364 end 1365 1366 fn cw_worker c long w ulong to int 1367 for it ulong `1000000000` 1368 q = sched_wjob w 1369 if gt q 0 1370 cw_job c w q 1371 end 1372 r = auth_wwait c w neg int 1 `1000000000` 1373 if or eq r 2 eq r 3 1374 ret 0 1375 end 1376 if eq r 4 1377 t = auth_wctl w 1378 end 1379 if lt r 0 1380 ret 45 1381 end 1382 end 1383 ret 46 1384 end 1385 1386 note ======== setup 1387 1388 note Objective argument "KIND,K,N,A,PATH,TASK" (KIND add, mul or loop) into 1389 note slot i. false when malformed. 1390 fn cw_parse i ulong a view uchar * to bool 1391 f = new ulong 8 0 1392 cw_s i 16 7 1393 k = ulong 0 1394 for j ulong len a 1395 if and lt k 5 eq get a j 44 1396 put f k j 1397 k = add k 1 1398 end 1399 end 1400 if ne k 5 1401 ret false 1402 end 1403 if cw_eq view part a 0 get f 0 cwadd 1404 cw_s i 0 1 1405 end 1406 if cw_eq view part a 0 get f 0 cwmul 1407 cw_s i 0 2 1408 end 1409 if cw_eq view part a 0 get f 0 cwloop 1410 cw_s i 0 3 1411 end 1412 if eq cw_g i 0 0 1413 ret false 1414 end 1415 for m ulong 3 1416 v = cw_pnum a add get f m 1 get f add m 1 1417 if gt v 99 1418 ret false 1419 end 1420 cw_s i add m 1 v 1421 end 1422 ret cw_ptxt i a f 1423 end 1424 1425 fn cw_pnum a view uchar * s ulong e ulong to ulong 1426 if or ge s e gt sub e s 2 1427 ret 999 1428 end 1429 v = ulong 0 1430 for j ulong sub e s 1431 c = ulong get a add s j 1432 if or lt c 48 gt c 57 1433 ret 999 1434 end 1435 v = add mul v 10 sub c 48 1436 end 1437 ret v 1438 end 1439 1440 note PATH and TASK of the objective argument a (field ends in f). 1441 fn cw_ptxt i ulong a view uchar * f view ulong 8 to bool 1442 ps = add get f 3 1 1443 pn = sub get f 4 ps 1444 ts = add get f 4 1 1445 tn = sub len a ts 1446 if or or eq pn 0 gt pn 128 or eq tn 0 gt tn 383 1447 ret false 1448 end 1449 cw_put add mul i 512 0 view part a ps pn 1450 cw_put add mul i 512 128 view part a ts tn 1451 cw_s i 4 pn 1452 cw_s i 5 tn 1453 ret true 1454 end 1455 1456 fn cw_put o ulong a view uchar * to void 1457 for j ulong len a 1458 put cwos add o j get a j 1459 end 1460 end 1461 1462 note Argument ai into config slot k; false when empty or over 1000 bytes. 1463 fn cw_carg ai ulong k ulong to bool 1464 n = argread ai cwcf mul k 1024 1000 1465 if lt n 1 1466 ret false 1467 end 1468 put cwcl k ulong n 1469 ret true 1470 end 1471 1472 note Next job seq and performed model turns of objective i from the journal. 1473 fn cw_resume i ulong to void 1474 s = ulong 0 1475 t = ulong 0 1476 for q ulong 99 1477 for kd ulong 5 1478 id = add add mul add i 1 1000 mul q 10 add kd 1 1479 if jn_known id 1480 s = add q 1 1481 if and eq kd 0 eq and jn_jout id 255 2 1482 t = add t 1 1483 end 1484 end 1485 end 1486 end 1487 cw_s i 11 s 1488 cw_s i 7 t 1489 end 1490 1491 note FNV-1a 64 of the objective arguments, for the journal's identity. 1492 fn cw_ident a0 ulong n ulong to ulong 1493 b = new uchar 1024 0 1494 x = ulong `14695981039346656037` 1495 for i ulong n 1496 m = argread add a0 i b 0 1024 1497 for j ulong ulong m 1498 x = mul xor x ulong get b j `1099511628211` 1499 end 1500 x = mul xor x 255 `1099511628211` 1501 end 1502 ret x 1503 end 1504 1505 note The journal's objective: tag 0x4f4d4e43 ("OMNC"), the objective count, 1506 note the hash of the objective arguments, the issue number. A JDIR over 100 1507 note bytes is jn_open's refusal 26 here, before the 128-byte copy (a JDIR of 1508 note 129..1000 bytes used to trap 4 in that loop, exit 104 with no cause line). 1509 fn cw_jopen ai ulong n ulong to ulong 1510 if gt get cwcl 5 100 1511 ret 26 1512 end 1513 d = new uchar 128 0 1514 o = new ulong 4 0 1515 for j ulong get cwcl 5 bound 128 1516 put d j get cwcf add 5120 j 1517 end 1518 put o 0 `1330466371` 1519 put o 1 n 1520 put o 2 cw_ident ai n 1521 put o 3 290 1522 ret jn_open d get cwcl 5 o 3000 1523 end 1524 1525 note Make WORK/o for every objective (an existing one is reused). 1526 fn cw_dirs to void 1527 t = new uchar 4096 0 1528 for i ulong get cwno 0 bound 4 1529 n = cw_wdir t i 1530 x = makedir t 0 n 448 1531 end 1532 end 1533 1534 note omnode-code INFER TOOL OMC ROOT WORK JDIR PORT VIEW OBJ... from 1535 note argument k on (1..4 objectives; all paths absolute; VIEW the operator 1536 note view's port on 127.0.0.1, 0 for none). Exit 0 all passed, 1 some 1537 note failed, 2 usage, 62 out of time, 30 + journal or recovery refusal, 1538 note 50.. setup, 57 also a job left waiting or ready by the last creator 1539 note that could not be cancelled; the refusals, setup failures and 57 first 1540 note write a cause line (cw_fail). 1541 fn cw_main k ulong dls ulong to int 1542 b = new uchar 1024 0 1543 c = ulong argcnt 1544 if or lt c add k 9 gt c add k 12 1545 ret 2 1546 end 1547 for a ulong 8 1548 if not cw_carg add k a a 1549 ret 2 1550 end 1551 end 1552 if gt cw_cnum 7 65535 1553 ret 2 1554 end 1555 put cwno 0 sub c add k 8 1556 for i ulong get cwno 0 bound 4 1557 m = argread add add k 8 i b 0 1024 1558 if lt m 1 1559 ret 2 1560 end 1561 if not cw_parse i view part b 0 ulong m 1562 ret 2 1563 end 1564 end 1565 ret cw_run k dls 1566 end 1567 1568 note Config slot k as a decimal of 1..5 digits; `99999999` otherwise. 1569 fn cw_cnum k ulong to ulong 1570 n = get cwcl k 1571 if or eq n 0 gt n 5 1572 ret `99999999` 1573 end 1574 v = ulong 0 1575 for j ulong n 1576 d = ulong get cwcf add mul k 1024 j 1577 if or lt d 48 gt d 57 1578 ret `99999999` 1579 end 1580 v = add mul v 10 sub d 48 1581 end 1582 ret v 1583 end 1584 1585 note cw_fail r what: "code-main: WHAT, exit R" on stderr, then R. Journal refusals (30 + 20..27) 1586 note share numbers with the setup failures 50..56, so the line names which one it was. 1587 fn cw_fail r ulong what view uchar * to int 1588 o = new uchar 4096 0 1589 p = cw_cat o 0 cwfpre 1590 p = cw_cat o p what 1591 p = cw_cat o p cwfex 1592 p = cw_dec o p r 1593 p = cw_cat o p cwnl 1594 x = write 2 o 0 p 1595 ret int r 1596 end 1597 1598 fn cw_run k ulong dls ulong to int 1599 c = pool_new 4 2 1600 if le c 0 1601 ret cw_fail 50 cwfpool 1602 end 1603 if ne sup_init c 0 1604 ret cw_fail 51 cwfsup 1605 end 1606 ql = get cwql 0 1607 if eq ql 0 1608 ql = 8 1609 end 1610 if ne sched_new c ql 8 0 1611 ret cw_fail 52 cwfsch 1612 end 1613 if ne auth_new c 0 1614 ret cw_fail 53 cwfaut 1615 end 1616 e = cw_jopen add k 8 get cwno 0 1617 if ne e 0 1618 ret cw_fail add 30 e cwfjrn 1619 end 1620 e = auth_recover c 1621 if ne e 0 1622 ret cw_fail add 30 e cwfrec 1623 end 1624 for j ulong 64 1625 s = get sjst j 1626 if or eq s 1 eq s 2 1627 if lt auth_cancel c j 0 1628 ret cw_fail 57 cwfcan 1629 end 1630 end 1631 end 1632 if ne vw_new jn_fence 0 1633 ret cw_fail 55 cwfvwn 1634 end 1635 for i ulong get cwno 0 bound 4 1636 cw_resume i 1637 if ne jn_res i 0 1638 cw_s i 7 jn_rturn i 1639 cw_pub i jn_res i 1640 end 1641 end 1642 cw_replay c 1643 if ne get cwresultbad 0 0 1644 sup_closeall 1645 jn_close 1646 ret cw_fail 58 cwfresult 1647 end 1648 cw_dirs 1649 for w ulong 2 1650 p = auth_spawn c w 1651 if eq p 0 1652 exit cw_worker c w 1653 end 1654 if le p 0 1655 ret cw_fail 54 cwfspn 1656 end 1657 end 1658 if not cw_view c 1659 ret cw_fail 56 cwfvw 1660 end 1661 r = cw_drive c add ulong monons mul dls `1000000000` 1662 vw_stop 1663 x = sched_stop c `2000000000` 1664 sup_closeall 1665 jn_close 1666 if eq r 58 1667 ret cw_fail 58 cwfresult 1668 end 1669 ret cw_sum r 1670 end 1671 1672 note Start the view process when VIEW is not 0 and print CWV port once it 1673 note listens; false when it could not. 1674 fn cw_view c long to bool 1675 o = new uchar 4096 0 1676 pt = cw_cnum 7 1677 if eq pt 0 1678 ret true 1679 end 1680 cw_vsnap c 1681 if le vw_spawn pt 0 1682 ret false 1683 end 1684 for t ulong 3000 1685 if ne vw_g 7 0 1686 p = cw_cat o 0 cwcwv 1687 p = cw_dec o p vw_g 7 1688 p = cw_cat o p cwnl 1689 cw_out o p 1690 ret true 1691 end 1692 x = sleepns `1000000` 1693 end 1694 vw_stop 1695 ret false 1696 end 1697 1698 fn cw_sum r int to int 1699 o = new uchar 4096 0 1700 np = ulong 0 1701 for i ulong get cwno 0 bound 4 1702 if eq cw_g i 12 1 1703 np = add np 1 1704 end 1705 end 1706 p = cw_cat o 0 cwsum 1707 p = cw_dec o p np 1708 p = cw_cat o p cwsumf 1709 p = cw_dec o p sub get cwno 0 np 1710 p = cw_cat o p cwnl 1711 cw_out o p 1712 if ne r 0 1713 ret r 1714 end 1715 if eq np get cwno 0 1716 ret 0 1717 end 1718 ret 1 1719 end