ADR 0038 — Flow fields and live values
Status: proposed · 2026-11-08 (owner: the flow editor must show live values and treat every input as “a value or a binding”; screen spec studio/docs/design/specs/flow-editor.md; decided under ADR 0029).
Context
The flow editor spec (flow-editor.md §3) draws a block as fields: every parameter and every input is one row with a value, a left port (input) and a right port (output); outputs have only a right port. Values are live. One field holds a typed value and an optional binding, and feeds other blocks.
The engine today (research 2026-11-08):
- publishes only the flow’s
~valand thepublishnodes’ values; nothing per port (runtime.rsrun_nodeonly routes outputs); - lets a logic block’s parameter be config and port
in.<p>(ADR 0032 §2), last sample wins, butnode_typesdoes not say which parameter has a port, givesdefaultonly for choices and as a string, and gives no port types; - has no output for a parameter or an input, so a field cannot feed another block;
- has no way to watch a running flow or to run a draft.
ADR 0019 chose Deploy-only: no live ~set of a field.
Decision
1. Every field is also an output
- For each parameter
pof a node: an output portpcarrying the parameter’s effective value (config or default, replaced by the last sample onin.<p>where that port exists). It sends once when the node starts and then on every change. - For each input port
xthat is not a parameter’s port (in,in.0,in.1, …): an output portxthat repeats every sample the node receives onx, before the node handles it. - Names: the output is named exactly like the parameter or the input (
scale1.input_min,if1.in.0). Edges already split at the first dot (def.rsendpoint), soa.in.0is nodea, portin.0. - A clash with an existing output of the node (a parameter named like an output) keeps the existing output; that field has no echo output and the catalog says so (
echo: false). An input’s echo comes before a parameter’s:latchhas the inputresetand the parameterreset, so the parameter has no echo (echo: false). This is the only static clash today. - Cost: an echo output that no edge reads is never built. The compiler knows the edges; the runtime does not copy a sample for an unwired echo.
2. The catalog says what a field is (additive)
node_types keeps inputs, outputs, dyn_inputs, dyn_outputs and params as they are, and adds:
- per parameter:
port("in.<p>"when the parameter has an input port, absent otherwise),defaultas a typed value for every parameter that has one (a number stays a number; choices keep their string),echo(trueunless §1’s clash rule removes it); - per node type:
port_types: {<port>: <type name>}for inputs and outputs (number,bool,string,any, … asPortType::name), andecho_inputs: truewhen inputs repeat as outputs.
3. dataflows/<id>/~act/watch — live values of a deployed flow
- Level
readondataflows/<id>,stream: true,timeout_ms: 30000. - Args:
nodes(optional list of node ids; absent = all),max_hz(optional, default 4, at most 20, per node). - Rights: the caller’s
ptokauth(spec 04, as DQL queries) must cover reading every source (subscribe,liveliness) and every command target (the node of eachinvoke/set) of the flow; otherwisepermission_deniednaming the first key the caller cannot read. The values of a flow are derived from its sources, aninvokenode’s output carries its target’s answer and asetnode’s input is what it writes there (security review 2026-11-08). - Rows:
- first:
{t, snapshot: true, nodes: {<node>: {in: {<port>: [v, q]}, out: {<port>: [v, q]}, params: {<p>: v}}}}— the last value of every port and the effective value of every parameter; - then: the same shape with
snapshot: falseand only what changed since the last row, at mostmax_hzrows per node per second (the latest value wins inside a period); - a heartbeat
{t, nodes: {}}when nothing changed for 10 s (the gateway’s idle wait per reply istimeout_ms+ 5 s); - the stream ends after 30 min (
ttl), on a redeploy ({t, redeployed: <version>}as its last row), on remove, or when the caller goes; the editor opens it again.
- first:
- Cost:
the runtime records the last sample of a port only while at least one watch of that flow is open(changed 2026-11-08, spec 06 0.2.18, see §6 “From the start”): the runtime keeps the last sample of every port from the start. Watches per flow ≤ 8, per site ≤ 64 (busybeyond). - Values are never logged above
trace.
4. dataflows/<id>/~act/ports — one snapshot
Level read, same rights check, returns row 1 of §3. For tools (wyrm-agent, MCP) that do not keep a stream.
5. dataflows/~act/preview — live values of an undeployed draft (2026-11-08, spec 06 0.2.16)
The owner added a concat block to a draft in the Studio editor and saw no values: the engine runs only deployed flows. The editor must show live values on every field of the draft while it is edited, with no risk to devices.
- On the
dataflowsroot: levelread,stream: true,timeout_ms: 30000. Args:def(a spec 06 definition, the shapedeploytakes),nodes(optional list of node ids),max_hz(optional, default 4, at most 20). - Compile: the definition compiles as for deploy and validate (every step of spec 06, the sources’ sections and the
wasmartifacts included); an error isinvalid_parameterwith the compiler’s message.version,enabledandpermissions.maxpermare not checked against anything: nothing is deployed, and noproofsare needed, because nothing is written. - Rights: as
watch(§3): the caller’sauthcovers read on every source (subscribe,liveliness) and every command target (the node of eachinvoke/set); otherwisepermission_denied. Areaduser may preview a draft with asetit may not write: it sees what the set would write, which it may read anyway. - Sandbox: a real runtime instance of the draft that nothing persists: no store, no
~def, no node states (it starts with none and drops them at the end), no node in the tree. Its place is the preview registry, never the engine’s flows, so a draft with the id of a deployed flow touches neither that flow nor its watches. It reads through a session client without tokens. - Sinks cannot write by construction: the node builder has a preview mode (
nodes::Mode::Preview) in whichset,invokeandpublishare capture nodes. A capture node holds no client, no writer task and noctx, and never reads itsIo. It applies the deployed node’s own rule (allow_bad,on,deadband,$ininargs; one function for both modes) and reports the result. Aninvokecapture sends nothing onout(there is no answer). - Rows: exactly
watch’s (§3: snapshot row, change rows at mostmax_hzper node, heartbeat{t, nodes: {}}after 10 s), and any row may carrysinks: [{node, op, key, value}]:opisset,invokeorpublish;keyis the full key it would write:wy/<site>/<path>/~set,wy/<site>/<path>/~act/<action>,wy/<site>/dataflows/<def.id>/nodes/<node>;valueis the value it would write, or forinvokethe arguments map after$in. The snapshot holds each sink’s latest; a change row holds the sinks that acted since the previous row, the latest per node (a row of sinks alone is a change row withnodes: {}andsnapshot: false).nodesfilters sinks too.
- Recorded from the start: the probe is held before the first node runs, so every port’s last sample is kept from the start. The first row waits (at most 500 ms) until every node task runs and a round of asks passes in which no node records anything (each task answers an ask only once its inbox is empty). So the snapshot shows the variables’ start values and what they fed.
- Ends: after 10 min (
ttl; the editor opens it again with its latest draft), when a newer preview of the same subject takes its place, on a node panic (the stream ends withinternal_error; a preview never restarts) and when the engine stops (the engine waits up to 2 s for each preview to stop its runtime). Timers,stopwatch,delayandwindowrun as in a deployed flow. - Caps: at most 2 previews per subject (
origin, elsesub; a third ends that subject’s oldest) and 16 per site (busybeyond). The caps use the watch registry with the subject in the flow’s place. - Cost (measured 2026-11-08, Apple M4 Max, release,
tests/preview_cost.rs): live heap about 8 KB per node (10 nodes: 105 KB, 100: 0.85 MB, 1000: 8.2 MB), with the inbox growing on demand rather than reserved; a node task is one tokio task. The first row came after 25 ms (10 nodes) to 94 ms (1000 nodes in one chain, the start value passing every hop). Idle, a preview of blocks wakes only for its heartbeat; a source costs what it costs in a deployed flow, plus one lock and one value copy per port sample for the recorder. Bounds: at most 1000 nodes per flow (new compiler limit, spec 06 step 8; it applies to deploy and validate too), so one preview is at most about 8 MB, and 16 previews at most about 130 MB.
5a. Not now
- Live
~setof a field stays out (ADR 0019): a field changes by Deploy. - Done 2026-11-08 (spec 06 0.2.17): the older node types take the parameters the editor binds on
in.<p>, as ADR 0032 §2 (the config or default first, the last good sample wins):scalek,b;alarmhigh,low,hysteresis,delay_s,return_delay_s;delayms;windowsize_s;deadbandabs,pct;timerperiod_ms. Each is anumberport, listed in the catalog’sinputsand as the parameter’sport. A sample that is not a finite number, or is outside the parameter’s bounds (period_ms≥ 10,size_s> 0,ms≥ 0,delay_s/return_delay_s≥ 0), is ignored. The config rules stay (highorlow,absorpct,period_ms,size_s,msrequired): the config gives the start value. A parameter that changes a node’s clock (period_ms,ms,size_s, the alarm’s delays) takes effect at once: the runtime starts the new clock one period after the change. Adelaysample already waiting keeps its time. Not ported:expression,filter(their parameters are scripts), and choices (kind,fn,on_bad,max_samples).
6. Implementation notes (2026-11-08, §1–§4 built; spec 06 0.2.15)
- Echo types: an input’s echo has the input’s port type; a parameter’s echo is
number,boolormapas the parameter’s catalog type, every other type (string,dynamic,array)any. Every parameter has an echo,inputs/outputs/argsincluded, and every node type,wasmincluded (there a declared output keeps its name over an echo at compile time). port_typeslists the fixed inputs and outputs, the dynamic ports of theirdefaultnames (in.0,in.1) and every echo output; dynamic ports of other names areany.- A parameter’s echo sends at start, so an edge from it to
invoke/setfires a command at deploy (the one exception to ADR 0032’s rule;docs/flow-blocks.mdwarns). - The caller’s going is not seen. The SDK keeps a stream’s reply channel open until the action ends, and a reply to a gone requester does not fail, so a dropped watch lives until its ttl. At a cap, a new watch of the same subject (
origin, elsesub) ends that subject’s oldest watch (on the flow; at the site cap, anywhere on the site); another subject’s watch isbusy. An editor that reopens on every start stays within the caps. permission_deniedtravels without its text (the SDK never sends one with that status); the engine’s error names the first key, but the requester gets the status only.- Snapshots hold what was recorded: a port with no sample since the flow started is absent from
in/out(all three maps are always in row 1). - From the start (2026-11-08, spec 06 0.2.18; owner review of the Studio editor): on the demo,
ahu2_ctlhas variables feedingconcat1; a variable sends once at deploy, so a watch opened later showedin/outempty forever. The runtime now keeps the last sample of every input and output of a deployed flow from the start, watched or not;watch’s snapshot andportsshow them. Design: one record per node, each behind its own lock, made when the flow starts (a node task locks only its own record and never waits for another node; a watch locks each record in turn); one slot per port, made on the port’s first sample and overwritten in place afterwards; one change counter per flow (an atomic). A watch is woken only while one is open. Measured (Apple M4 Max, release,watch::tests::record_cost): one record of an input and an output costs about 20 ns for numbers and 54 ns for texts (a text is copied; a number or a bool allocates nothing after the port’s first sample); a node call records twice (its input before it runs, its outputs after), so about 25–65 ns per node call, against one atomic load before. Memory: about 100 bytes per port that had a sample, plus a text’s or a map’s own bytes, once per port and not per sample. The 5 sKEEPtime is gone. - Ends: ttl, remove and an engine stop end the stream without a row; a redeploy ends it with
{t, redeployed: <version>}.nodesabsent or empty = every node; an unknown id isinvalid_parameter;max_hzoutside (0, 20] isinvalid_parameter. - Stop/start, reload and a panic restart keep the watches (one recorder per deployed version).
- Preview (§5, built 2026-11-08): a preview’s caller going is not seen either, as for
watch: a dropped preview runs until its ttl, and the per-subject cap (a third preview ends the subject’s oldest) bounds what one editor leaves behind. - Ask barrier: a node task answers a request for its parameters only once its inbox is empty, after the iteration that emptied it. A watch’s snapshot and a preview’s first row so hold what start queued (a variable’s value); a busy node answers within the 200 ms wait or not at all.
- Source tasks end with their node:
subscribeandlivelinesskeep their I/O tasks and abort them when the node drops (a stop, a hot swap, the end of a preview). Before, every redeploy left one Zenoh subscriber per source running. - A stop leaves nothing running (2026-11-09; CI flake
InUseon a restart ofpeak_shaving_hot_swap_and_restart): the store (FlowHost, its WAL andLOCK) is free when the link’sstopreturns, so a restarted engine opens it at once (ADR 0036 restarts). Rules: (1) an aborted task is awaited afterabort(): tokio drops an aborted task’s future only later on a worker, and a flow’s supervisor holds the engine’s state; this holds for the supervisor (halt), node tasks cut at the 1 s drain (one deadline for the whole run, not 1 s per task) and streams cut at the 2 s stop deadline; (2) a supervisor stays the flow’s supervisor through its back-off after a node panic (it was detached before, so it outlived a stop, kept the store and started the flow again on a stopped engine; a start or deploy during the back-off made a second run); (3) the engine tracks itswatchandportstasks with the previews and ends them at stop (flows’ probes end first, then all streams are awaited); (4) the SDK drops the driver before it answersCmd::Stop(before,LinkHandle::stopcould return while the actor thread was still dropping the engine). Watches and previews never held the store; PR #32 only changed the timing. Tests:stop_releases_the_store_at_once(15 stop + immediate reopen rounds, a watch and a preview open at every other stop,Weak<FlowHost>count 0 after each stop), SDKstop_returns_after_the_driver_is_dropped.
5b. Ports for the remaining block parameters (2026-11-08, spec 06 0.2.20)
So every field can be bound: concat in.strict, if in.op, hub in.ignore_null, trace in.tracing, in.msg, with the blocks’ rule (config first, the last sample wins). if.op takes only an operator it knows; another text is ignored and the last good one stays. Every logic-block parameter now has a port, apart from a variable’s value (its input in does that) and inputs (it names the ports).
7. Operands hold a typed value (2026-11-08, spec 06 0.2.19; owner review of the Studio editor)
A block field is one entity: a typed value that a binding can replace. A parameter already is (config, then its port). An operand input (in, in.0, in.1, … of add, concat, if, …) had no constant.
- Config shape: one node key
values: {<port>: <value>}, e.g.{type: "concat", values: {"in.0": "AHU-", "in.1": 2}}. Chosen over flat"in.0": 5keys: a node’s config keys stay its parameters (spec 06 schema,only()checks), port names with a dot never become config keys, and one key is easy to check and to drop. A key must be an operand input of the block:in(where the block has it) orin.<name>of itsinputs; never a parameter’s port (that parameter’s config is its constant), neverstopwatch.reset(an event), and not the variables (number,string,bool: theirvalueis the constant). Anything else is a compile errornodes.<id>: values.<port>: not an operand input …; the value can be any value. - Meaning: the constant is the input’s value until a sample on that input replaces it (a binding wins). Removing the edge and deploying again falls back to the constant. Quality and time come only from inputs that had a sample.
watch/ports/previewshow each constant as the input’s value from the start (Node::seeds). - Safety (ADR 0032’s rule kept): a constant seeds its input and calculates nothing. A block calculates on its first real sample (on any input or parameter port), as before. So a deploy, a hot swap or a restart never fires a
setorinvokebecause of a constant. A block of constants only stays without output: a constant expression is a variable’s job. Refused alternative: evaluate at start and make command sinks drop start-time samples; it needs a start mark carried through every block and changes what a variable feeding asetdoes today. - Amended 2026-11-11 (spec 06 0.2.30): a block of constants only no longer stays without output when it is pure and has no wired input: it calculates once at start, and its sample is made of constants (
Msg::constant), a second mark the runtime carries on as it carries “born at the start” (ADR 0040 §2). Command sinks drop such a sample on every port,inincluded, so a variable feeding asetkeeps today’s behaviour. This is the refused alternative above in a narrow form: the mark is one bool set at two places (the pure block’s start,now’s start) and carried by the runtime, not by the blocks. See ADR 0032’s amendment anddocs/flow-blocks.md“What calculates at start”. - Scope: the logic blocks (
crate::blocks). Notexpressionand the older types (their singleinis the sample they act on). - Catalog: per type
values: truewhen its operand inputs (fixedinputsand thedyn_inputsports that are not a parameter’sport) take a constant.
8. Text operators, round.text and case (2026-11-08, spec 06 0.2.21)
if.opgains!=(the first input equals none of the others, compared as=),contains,starts_with,ends_with(the first input as text with any of the others; anullother never matches; anullfirst is empty text). Names are snake_case (ADR 0032 §3): camelCase spellings are refused at compile.round.min_precision(portin.min_precision, no default =precision) and a new outputtext: a rounded number is often shown as text with its places; WYRM keepsouta number (its port type, its edges) and addstextwithprecisionplaces, trailing zeros trimmed down tomin_precisionplaces.- A
caseblock: inputin;op(=,!=,>,<,>=,<=,contains,starts_with,ends_with, default=) andelse(defaultnull), both with ports; the variable inputsinputsare pairs (case value, then value), usually given as constants invalues(§7). It sends the then of the first pair whose case matchesin, elseelse; it calculates on any sample, as every block. An empty case text matches nothing in the text operators.regexpis left out: a pattern from a port can take any time to match, and the flow crate has no bounded regex engine.
If wrong: a field that should not feed other blocks gets an output anyway (harmless while unwired); a watch that misses a sample between two periods shows the latest value only, which is what an editor needs.
Studio
The flow editor builds fields from the catalog (§2; until the broker has it, from a matching in.<p>), draws a right port on every field (§1), and fills values from watch (§3) for a deployed flow and from preview (§5) for a draft, re-opening either when it ends (a preview also on every change of the draft). The old lookup of dataflows/<flow>/nodes/<block id> for live values is removed: that key exists only for publish nodes.