code wiki / (root) / nx_model_get.nx

nx_model_get.nx

buildroot/runtime/nx_model_get.nx

19427 B395 linesdepth 21pulls 149 transitivereach 0 importersview sourcekind tooltopic model
docsdependenciesstructsconstsfunctions

about

nx_model_get.nx -- G9 mg_fetch: hash-verified model acquisition into the gen model store (/compare/gen watch G9). usage: nx_model_get <url> <expected-sha256> <dest-name> <dest-name> is relative to the model-store root (e.g. diffusion/z_image_turbo-Q8_0.gguf, loras/x.safetensors). COMPOSES INCUMBENTS, DUPLICATES NONE: transport = nx_https_fetch_range (own TLS-1.3, Range windows -- one bounded window in memory at a time, so a multi-GB body STREAMS and can never be silently truncated by a buffer cap) hashing = the streaming sha256_init/update/final already inside this compilation unit (nx_sha256 via the TLS stack / nx_weights_pull) -- the digest covers the FULL body across all windows verify law = nx_weights_pull (wp_hexenc + fail-closed compare): a mismatched body is DELETED, never stored decisions = nx_model_get_lib (dest admission, hex normalize, Content-Range/Length parse, conf parse), offline-proven by nx_model_get_gate Redirects (HF resolve -> CDN) are followed by a bytes=0-0 probe that reads the Location header, because the range fetcher itself deliberately does not follow. Resumable: an interrupted pull leaves <dest>.part; a re-run re-hashes the part from disk and continues from its byte count. Idempotent: an existing verified dest returns OK-ALREADY-VERIFIED with no network touched. An existing dest that does NOT match is REFUSED and kept (additive-only: this organ never deletes a model already in the store; only its own .part on hash mismatch). exit: 0 VERIFIED / OK-ALREADY-VERIFIED | 1 REFUSED (hash mismatch / existing mismatch) | 2 usage/bad-args | 3 UNPROVEN (transport, trust store, no-length -- partial kept for resume where one exists) license_tier: ORIGINAL

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_https_fetch_follow.nx nx_trust_store_load_from_certdata. nx_weights_pull.nx nx_model_get_lib.nx nx_model_get.nx

imports: nx_syscalls.nxnx_https_fetch_follow.nxnx_trust_store_load_from_certdata.nxnx_weights_pull.nxnx_model_get_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main mgo_put sys_write sys_mmap nxa_die sys_write ↻ sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ mg_hex_norm mg_lc mg_dest_ok sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close mg_conf_val mg_slen mg_parse_uint mg_cat mg_slen ↻ mgo_num mgo_put ↻ sys_mmap ↻ sys_write ↻ mg_join mg_cat ↻ sys_openat_rd ↻

structs

none

consts

27const MG_URLCAP: i64 = 4096 // same bound the fetch stack uses for a url buffer
28const MG_PROBE_CAP: i64 = 262144 // bytes=0-0 probe response buffer (headers + stub body)
29const MG_HOPS_MAX: i64 = 6 // redirect budget, mirrors the fetch stack's default
30const MG_HASH_WIN: i64 = 1048576 // on-disk re-hash window for idempotency/resume
31const MG_WINDOW_DEFAULT: i64 = 8388608 // range window when the conf carries none (8 MiB)
32const MG_WIN_RETRIES: i64 = 3 // window failures tolerated before declaring TRANSPORT-STALL
33const MG_PROGRESS_EVERY: i64 = 32 // announce progress every N windows
34const MG_CERT_ROOTS: i64 = 512
35const MG_CERT_CAP: i64 = 4194304
36const MG_CONF_PATH: *u8 = "knowledge/gen_model_store.conf"
37const MG_ROOT_DEFAULT: *u8 = "/volume1/ai/models"
38const MG_RECEIPT_PATH: *u8 = "knowledge/status/modelget.log"

functions

40func mgo_put(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
41func mgo_num(v: i64) -> i64
56func mg_hash_file_into(ctx: *Sha256, path: *u8) -> i64
73func mg_hash_file_hex(path: *u8, out_hex: *u8) -> i64
called by 1: main calls 2: sys_mmapmg_hash_file_into
89func mg_probe(urlbuf: *u8, store: *TrustStore, use_chrome: i64, st: *i64, locout: *u8, totbox: *i64) -> i64
146func mg_resolve(urlbuf: *u8, store: *TrustStore, chromebox: *i64, totbox: *i64) -> i64
174func mg_receipt(verdict: *u8, dest: *u8, bytes: i64, hex: *u8, url: *u8) -> i64
212func main(argc: i64, argv: *i64) -> i64
281func mg_fetch(url: *u8, exphex: *u8, dest: *u8, part: *u8, store: *TrustStore, window: i64) -> i64