code wiki / (root) / nx_wflow_engine.nx

nx_wflow_engine.nx

buildroot/runtime/nx_wflow_engine.nx

68064 B1618 linesdepth 3pulls 3 transitivereach 13 importersview sourcekind librarytopic wflow
docsdependenciesstructsconstsfunctions

about

nx_wflow_engine.nx -- R1 KEYSTONE of the Workflow Automation ladder (/compare/automation census row "Unified multi-step durable workflow engine"). A WORKFLOW = DATA (law: data as data): flow header = `flowid|event-kind|cond(k=v or -)` step row = `flowid|idx|action|channel-or-dash|arg|max-attempts` (idx 1-based, author ascending) An EVENT = `kind~k=v~...~id=EN` (the nx_crm_flow contract). The engine upgrades nx_crm_flow from single-shot in-memory rules to DURABLE EXECUTION (the Temporal model, sovereign): - every transition is ONE appended line in an append-only RUN LEDGER (flock + O_APPEND, torn-free): `WFRUN rid=<evid>.<flowid> flow=<f> step=<n> status=START|ATT|OK|FAILSTEP|FAILED|DONE att=<k>` - state is DERIVED BY REPLAY of the ledger (event-sourced; nothing mutates, history is sacred) - IDEMPOTENT by construction: a (event id, flow) pair with a START line never starts twice -- the dedup survives crashes/restarts (stronger than the in-memory seen[] of nx_crm_flow) - per-step RETRY up to max-attempts; exhausted -> run FAILED at that step, later steps never run - wf_resume: any run with START but neither DONE nor FAILED (a crash mid-flight) is completed from its first non-OK step; already-OK steps are NOT re-executed (proven in the selftest) ACTIONS v1 (in-process, composing the send plane like nx_crm_flow): create-task | send (any nx_send channel, sr_valid-checked at load) | notify | update-field | probe-fail (DIAGNOSTIC: fails while attempt < arg -- the deterministic retry witness; keep it out of production flows). wf_load validates the WHOLE step set up front (unknown action / bad channel / attempts<1 = LOUD -1, nothing half-loaded). Production ledger path suggestion: knowledge/status/wflow_runs.log. R3 CONNECTOR LAYER (exec-organ): a step can run ANY blessed organ as a workflow step, resolved through a GREEN fail-closed catalog (rows `name<TAB>elf<TAB>GREEN`, the tool_allowlist.conf shape; cx[3]=catalog path, 0=exec-organ refused). Child exit 0 = step OK, nonzero = step fail (so per-step retry applies to REAL organ execution). Production catalog: knowledge/wflow/connectors.conf. PURE CORE (no main -- the house pure-core+gate idiom): gates = _hdl_build/nx_wflow_engine_gate (wf_selftest) + _hdl_build/nx_wflow_connect_gate (connector battery). license_tier: ORIGINAL

dependencies 1 imports · 13 importers

nx_send.nx nx_wflow_engine.nx nx_wflow.nx nx_wflow_approve_gate.nx nx_wflow_branch_gate.nx nx_wflow_capture_gate.nx nx_wflow_cli_gate.nx nx_wflow_connect_gate.nx nx_wflow_data_gate.nx nx_wflow_engine_gate.nx nx_wflow_loop_gate.nx nx_wflow_obs_gate.nx

diagram shows first 10 each side; +0 more imports, +3 more importers in the complete lists below.

imports: nx_send.nx

imported by: nx_wflow.nxnx_wflow_approve_gate.nxnx_wflow_branch_gate.nxnx_wflow_capture_gate.nxnx_wflow_cli_gate.nxnx_wflow_connect_gate.nxnx_wflow_data_gate.nxnx_wflow_engine_gate.nxnx_wflow_loop_gate.nxnx_wflow_obs_gate.nxnx_wflow_onerr_gate.nxnx_wflow_tpl_gate.nxnx_wflow_version_gate.nx

structs

none

consts

27const WF_MAGIC_1089: i64 = 1089
28const WF_MAGIC_65536: i64 = 65536
29const WF_MAGIC_16777216: i64 = 16777216
30const WF_MAGIC_1024: i64 = 1024
31const WF_MAGIC_60000: i64 = 60000
110const WF_LEDCAP: i64 = 1048576

functions

34func wf_has(hay: *u8, needle: *u8) -> i64
called by 1: wf_match calls 1: slen
48func wf_evid(ev: *u8, out: *u8, cap: i64) -> i64
called by 1: wf_fire calls 1: slen
66func wf_cat(dst: *u8, off: i64, s: *u8) -> i64 { var x: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { dst[x] = s[i]; x = x + 1; i = i + 1 } return x }
67func wf_catn(dst: *u8, off: i64, v: i64) -> i64
called by 20: mainmainmainmainmainmain+14
79func wf_atoi(s: *u8) -> i64
95func wf_now() -> i64 { return sys_now_realtime_sec() }
98func wf_append(path: *u8, line: *u8) -> i64
111func wf_readall(path: *u8, szp: *i64) -> *u8
called by 26: ag_nbg_npg_ncgl_ncg_ncg_file_has+20 calls 1: p
127func wf_writeall(path: *u8, buf: *u8, n: i64) -> i64
called by 2: wf_tpl_instantiatewf_obs_html calls 1: p
137func wf_has_rng(buf: *u8, ls: i64, le: i64, needle: *u8) -> i64
151func wf_lines_with2(buf: *u8, n: i64, a: *u8, b: *u8) -> i64
163func wf_num_after(buf: *u8, ls: i64, le: i64, key: *u8) -> i64
183func wf_val_after(buf: *u8, ls: i64, le: i64, key: *u8, out: *u8, cap: i64) -> i64
called by 2: wf_resumewf_obs_runs calls 1: slen
203func wf_max_ok_step(buf: *u8, n: i64, ridtok: *u8) -> i64
called by 1: wf_resume calls 2: wf_has_rngwf_num_after
219func wf_action_ok(a: *u8) -> i64
called by 1: wf_load calls 1: seq
231func wf_load(steps: *i64, n: i64) -> i64
320func wf_load_flows(flows: *i64, n: i64) -> i64
332func wf_match(fhdr: *u8, ev: *u8) -> i64
called by 1: wf_fire calls 3: pipe_fieldseqwf_has
360func wf_emit(led: *u8, rid: *u8, fid: *u8, step: i64, st: *u8, att: i64) -> i64
380func wf_conn_resolve(cx: *i64, name: *u8, out: *u8) -> i64
called by 1: wf_exec_organ calls 3: pwf_readallslen
425func wf_rd32(b: *u8, off: i64) -> i64
called by 1: wf_exec_organ
431func wf_exec_organ(cx: *i64, name0: *u8, arg: *u8, rid: *u8) -> i64
532func wf_emit_iter(led: *u8, rid: *u8, n: i64, val: *u8) -> i64
called by 1: wf_for_each calls 3: wf_catwf_catnwf_append
549func wf_for_each(cx: *i64, chspec: *u8, argraw: *u8, rid: *u8) -> i64
611func wf_exec(cx: *i64, action: *u8, ch: *u8, arg: *u8, att: i64, rid: *u8) -> i64
631func wf_decision(cx: *i64, rid: *u8, idx: i64) -> i64
658func wf_decide(cx: *i64, rid: *u8, idx: i64, decision: *u8, who: *u8) -> i64
called by 2: mainmain calls 5: seqpwf_catwf_catnwf_append
683func wf_emit_var(led: *u8, rid: *u8, k: *u8, v: *u8) -> i64
697func wf_val_line_end(buf: *u8, ls: i64, le: i64, key: *u8, out: *u8, cap: i64) -> i64
called by 1: wf_var_get calls 1: slen
716func wf_obs_tok_fwd(tok: *u8, rid: *u8) -> i64
called by 1: wf_var_get calls 1: wf_cat
725func wf_var_get(cx: *i64, rid: *u8, key: *u8, out: *u8, cap: i64) -> i64
753func wf_subst(cx: *i64, rid: *u8, src: *u8, out: *u8, cap: i64) -> i64
called by 2: wf_for_eachwf_run_from calls 2: pwf_var_get
786func wf_bind_event(cx: *i64, rid: *u8, ev: *u8) -> i64
called by 1: wf_fire calls 1: wf_emit_var
819func wf_defs_version(path: *u8) -> i64
836func wf_emit_ver(led: *u8, rid: *u8, ver: i64) -> i64
called by 2: wf_firemain calls 3: wf_catwf_catnwf_append
847func wf_emit_drift(led: *u8, rid: *u8, ranv: i64, nowv: i64) -> i64
called by 1: wf_resume calls 3: wf_catwf_catnwf_append
861func wf_run_ver(buf: *u8, n: i64, ridtok: *u8) -> i64
called by 1: wf_resume calls 2: wf_has_rngwf_num_after
877func wf_tpl_exists(path: *u8) -> i64
called by 1: wf_tpl_list
883func wf_tpl_path(dir: *u8, name: *u8, ext: *u8, out: *u8) -> i64
893func wf_tpl_index_path(dir: *u8, out: *u8) -> i64
903func wf_tpl_list(dir: *u8) -> i64
948func wf_tpl_indexed(dir: *u8, name: *u8) -> i64
975func wf_tpl_instantiate(dir: *u8, name: *u8, df: *u8, ds: *u8) -> i64
1006func wf_cond_ok(cx: *i64, rid: *u8, cond: *u8) -> i64
called by 1: wf_run_from calls 2: wf_var_getseq
1026func wf_run_from(cx: *i64, rid: *u8, fid: *u8, s0: i64) -> i64
1185func wf_fire(cx: *i64, flows: *i64, nf: i64, ev: *u8) -> i64
1231func wf_flow_known(cx: *i64, fid: *u8) -> i64
called by 1: wf_resume calls 2: pipe_fieldseq
1245func wf_resume(cx: *i64) -> i64
1294func wf_lines_load(path: *u8, arr: *i64, cap: i64) -> i64
1322func wf_cx_files(flowsp: *u8, stepsp: *u8, led: *u8, cat: *u8, cx: *i64, flows: *i64) -> i64
1340func wf_fire_files(flowsp: *u8, stepsp: *u8, led: *u8, cat: *u8, ev: *u8) -> i64
called by 3: mainmainmain calls 2: wf_cx_fileswf_fire
1347func wf_resume_files(flowsp: *u8, stepsp: *u8, led: *u8, cat: *u8) -> i64
called by 2: mainmain calls 2: wf_cx_fileswf_resume
1356func wf_state_name(st: i64) -> *u8
1363func wf_run_state(buf: *u8, n: i64, tok: *u8) -> i64
1370func wf_obs_runs(buf: *u8, n: i64, rids: *i64, cap: i64) -> i64
1392func wf_obs_tok(tok: *u8, rid: *u8) -> i64
called by 3: wf_obs_boardwf_obs_htmlmain calls 1: wf_cat
1400func wf_obs_board(led: *u8) -> i64
1435func wf_obs_html(led: *u8, out: *u8) -> i64
1494func wf_selftest() -> i64