ADR 0044 — Flow blocks, third set: computation on the server
Status: accepted (2026-11-11, owner request “implement everything that can work in Rust and on the platform”; decisions delegated under ADR 0029).
Context
WYRM had 55 node types (ADR 0032, 0038, 0040). Flows on a broker also need
math, text and codecs, time, events, tables and reads of history and of a
node. Everything that is computation, data shaping, time, text, events, state
or a read of the tree belongs on the broker. What needs a screen, a browser,
the editor, a style, a device sensor or a file API does not. This set adds 70
types: node_types lists 125.
Decision
1. One block machinery
The new types are logic blocks of crates/wyrm-flow/src/blocks.rs (ADR 0032:
a value per parameter, a port in.<p> for every parameter that a wire may set,
change-only outputs, the worst quality of the inputs, nothing at start but the
variables; amended 2026-11-11: a pure block with no wired input calculates once
at start, spec 06 0.2.30). Their calculations are pure functions in blocks/*.rs with unit
tests. The readers (load_history, get_node) are kinds of
the reader of ADR 0040 §4 (readers.rs): load_history and get_node.
2. Tables
A table is a value:
{"columns": ["name", "kw"], "rows": [{"name": "pump", "kw": 3}, {"name": "fan", "kw": 7}]}
columnsgives the order; a row is a map. A cell that a row lacks isnull.- Every table input also takes a list of maps (the rows of
list_children, of asplit, ofmake_array): its columns are the keys in the order they first appear, sorted within one row (a WYRM map has sorted keys). Rows given as lists ({"columns": […], "rows": [[…]]}) are taken by position. - There is no
rowcolumn: a row’s index is its position from 0. No table gets an index column of its own. - Bounds: 10 000 rows, 128 columns, a column name of 256 bytes, 512 KiB of
encoded cells, nesting 32 (spec README rule 6). A table block whose result is
larger sends
nullwith qualitybad. - Mutators (
table_add_row,table_edit_rows,table_remove_rows) are pure transforms of their input: they write into no stored table; in a stream engine the output is the next table. A flow that keeps a table across samples wires it throughtable_recorderor keeps it in broker storage. - Per-row scripts (
table_filter,table_map_columns,table_edit_rows,table_remove_rows) are rhai over the variablesrow(the row as a map) andindex. A column name is not a variable: names come from the data and the compiler checks a script against fixed names. The scripts of one table have 100 ms in all (past that:nulland the reason onerror), each row the engine’s 10 000 operations.
3. Time
- A date value is a number of microseconds since the Unix epoch, as
tof every sample,HistRow.tandlast_run. A date input also takes RFC 3339 text,yyyy-M-d[ HH:mm[:ss]],yyyy/M/d,M/d/yyyy. Not milliseconds: WYRM keeps one unit for all its times. - Wall time is computed in the zone of the parameter
time_zone: an IANA name (Europe/Kyiv),UTC, or±HH:MM. The default isUTC, not the host’s zone: a broker in a container often has no zone file, and a flow must give the same result on every host. The tz data isjiff’s bundled tzdb, as inwyrm-schedule. A wall time in a DST gap moves forward, a repeated one takes the earlier instant (as the scheduler). - A block that depends on the clock (
now, a relativedate_range) reads it once per calculation through the runtime’s clock; the pure functions takenowas an argument, so tests are exact. A relative range is calculated again on a clock of 1 s while its input is relative, sotodayrolls over. date_rangetakesweek_start(defaultmonday) andtime_zone;previousN<unit>is the period beforecurrentN<unit>.
4. Readers
load_historyreads the historian (~val?history=, ADR 0014) throughWyrmClient::history: its rows{t, v, q}as a table, at mostlimit(1 … 10 000) rows. An answer that reachedlimitmay have more: theokevent saystruncated: trueandrows, so the cut is never silent. A table past 512 KiB is anerrorevent withresource_exhausted. A query field that changes while a read runs reads again after it, never cancels it.- Several keys merge by time with one
load_historyeach (the samewindow) andtable_joinont: one key per reader keeps the scope rules as they are. get_nodereads one node’s summary and its actions with their parameters.- Each is a read field in
nodes::read_fields, so the deployer, every watcher and every previewer must read its key or scope, asload_value(ADR 0040 §1). - A reader runs on
dataflows/<id>/~act/trigger {node}too (Studio §10 item 8): the caller must read the reader’s key and its scope (levelread), instead of a command target’smax(maxperm, write). - A trigger starts a run that flows on along the edges (security review
2026-11-11): the caller also needs
max(maxperm, write)on the target of everysetandinvokedownstream of the triggered node, found by a walk over every edge, transitively, with the custom blocks inlined. A reader with no command downstream needs read alone. The same rule holds for a command block: a command whose answer runs another command needs the rights of both.
5. Stream rules the blocks keep
WYRM is a stream engine: a block calculates on each sample, not on a timer.
- Numbers are integers while they fit, then floats; a result that is not
finite is
null(no NaN or Infinity in a WYRM value). There is no NaN constant:constwithnullstands for it. - A block calculates on each sample and sends its outputs in its declared
order; the compiler refuses a cycle that has no
delay. - An output goes out when its value or quality changed; events always.
- The catalog’s
defaultis the effective value. - A trigger is an event or a value that differs from the last one; a sample
born at the start never acts (ADR 0040 §2). The same
bornrule covers the start of a flow. - No block panics; a bad input gives
null(qualitybadwhere the input was valid but too large). medianof an even count is the mean of the two middle numbers;date_mathcounts years, months and days on the calendar oftime_zone, so a day over a DST change keeps the wall time.modulo’s remainder is never negative,max/minof no number arenull,scaledoes not clamp,splitgives a list,substringclamps an overrun: existing WYRM behaviour that deployed flows rely on.
6. Patterns
case, router and replace take regexp. A pattern is compiled by the regex crate
(linear time, no backreferences) with a compiled-size limit of 64 KiB and at
most 256 bytes of pattern; the input is at most 4 KiB. A pattern that does not
compile matches nothing.
7. Left out
repeat(one block instance per table row): the instance count is known only at run time, but the 1000-node budget and the deploy proofs are computed when the definition is compiled. A later set may bound it by amax_rowsin the config.- Archive parsing (zip): needs an archive codec with bounds on expansion; files reach a flow through the file store links.
- A PID block: it needs a decision on its form and its bounds.
- Error groups without wires: an implicit route between blocks would bypass
the cycle check,
watchandpreview;catch_errortakes wires. - Blocks that need a screen, a browser, the editor, a style, a device sensor or a file API.
Amendment 2026-11-11: now has a clock (spec 06 0.2.30)
now gave the time only on a sample of in, and its in took a typed
constant. A clock block that shows nothing until something is wired into it is
of no use (owner’s screenshot: today typed into in, no output), and the
value on in meant nothing. Now:
interval_ms(portin.interval_ms, default 1000; 0: only on samples ofin; else 100 … 86 400 000, as a command’s period; a value outside is refused in the config and ignored on the port).- With a period,
nowsends the time once at start, made of constants (it runs no command), and then every period; those ticks are ordinary samples, as atimer’s. A sample ofingives the time at once too. inis only a trigger: it takes no constant (values: trueis dropped from its catalog entry). Avaluessaved before is read and ignored, so a stored flow still compiles.- ОБЕРЕЖНО: a
nowstored before 0.2.30 has nointerval_ms, so after the upgrade it also sends every second (the default). Its ticks are ordinary samples: anowwired toinof asetor aninvoke, or to atrigger, then runs that command every second. Setinterval_ms: 0to keep the old behaviour (only on samples ofin). No deployed flow of the demo has anow(checked 2026-11-11).
Consequences
node_typeslists the new types; the catalog gainsdisplayper parameter (spec 06 0.2.29). Studio draws them from the catalog; its follow-up is in the pull request.- The guide (
docs/flow-blocks.md) has a section per group with fields, behaviour and bounds.