ADR 0032 — Logic blocks in the flow engine
Status: accepted · 2026-11-01 (owner: a server-side list of blocks like the editor prototype’s; decided under ADR 0029).
Context
The owner keeps a Dart prototype of a block editor with its own engine (not in this repository). Its blocks are variables, arithmetic, if, hub, stopwatch, trace and text blocks. The flow engine (wyrm-flow, spec 06) had expression, scale, window and other node types, but not these. The owner asked for the same list on the server.
The prototype binds an input to an output by a path stored on the input. The flow engine sends samples on edges between ports. The blocks follow the engine’s model.
Decision
- One module,
wyrm_flow::blocks. Types:number,string,bool,add,subtract,multiply,divide,max,min,abs,round,modulo,not,if,hub,stopwatch,trace,concat,length.nodes::portsandnodes::buildask it first. The catalog lists them for the editor. - A parameter is config and, where it makes sense, a port. The value comes from the config or its default; a sample on
in.<parameter>replaces it. Variable inputs are the config listinputs(default0,1, at most 64), portsin.<name>; a name may not be a parameter’s. - Names are snake_case, as every other node type’s (
input_min,reset_value,ignore_null,on_change,on_loop). The prototype’s camelCase names are not taken. - Change-only outputs, by value and quality. A good-to-bad change of the same value goes out (honest quality). Events always go out, as
{event, id}. - Operators do not calculate at start. Only the variables send at start. A deploy, a hot swap or a restart never fires a command by itself. The prototype calculates every block when it is attached; the engine does not.
- Numbers as in the prototype where it matters: integers stay integers while they fit,
dividegives a float, non-finite results arenull,modulo’s quotient goes toward 0 and its remainder is never negative,roundto 0 places gives an integer. scalekeeps its meaning.k × in + bstays; the range form (input_min…output_max, outputinput_out_of_range) applies only once a range parameter is set or arrives. An existingscalewith no config stays the identity.stopwatchruns on a 50 ms clock (the runtime readstick_everyonce), counts at most every 0.05 s, and keeps its count across a hot swap.tracelogs attraceonly: its lines hold values.- The editor draws fixed ports and named ports together (
if:in.then,in.else, thenin.0, …);dyn_inputsadds toinputsinstead of replacing it. - Texts a block makes are at most 4 KiB (
concat,string), as the expression engine’s strings; a longer one isnull(concat: qualitybad). Aconcatin a loop through adelaywould otherwise grow without end (automated review ofe89b1d4).
Amended 2026-11-11 (spec 06 0.2.30, owner’s screenshots of the flow editor). A block whose
inputs are all typed constants showed nothing: add of 2 and 3, a CSV typed into
table_from_csv, a now with no wire. Since ADR 0040 the runtime marks a sample born at the
start, so the rule is narrowed, not dropped: a pure block (no state, no events, no clock of
its own; 83 types, listed in docs/flow-blocks.md “What calculates at start”) with no edge
into any of its ports calculates once at start from its constants and parameters. What it
sends is made of constants (Msg::constant): born at the start, carried on by the runtime
like that mark, and it runs no command anywhere, not even through in of set or invoke. A
block with a wired input waits for its first sample, as before; the blocks after a pure one
calculate from its start sample. A deploy, a hot swap or a restart still never fires a command
through a constant. A variable wired to in of a command still writes at deploy (ADR 0038 §6):
changing that would change deployed flows.
If wrong: a flow that expects an operator’s value right after deploy must start from a variable or a const; a block that should send every sample (not only changes) needs a filter or an expression in front of its sink.
Found on the way
publish, set and invoke started one task per sample, so two samples close together could be written in the other order: a published value could end on the older one, and a set could leave a device at the older value (true then false arriving as false then true). Each of these nodes now has one writer task: publish and invoke keep the order (a queue of 256; more are dropped and logged at debug), set writes the newest value (older ones not yet written are skipped). The test logic_blocks_in_a_deployed_flow failed 5 times in 6 before this.
Not done
The prototype’s own editor protocol (binding paths, its save format) is not taken: flows stay spec 06 definitions. Further block types come as the owner names them.