* feat(engine): compiled engine for columnar graphs and policies New engine for decisions and policies built on the lane VM: a compiled graph plan that evaluates batches column-wise (typed kernels where expressions allow, lane programs otherwise), a row runner for batch and single-row evaluation, and a compiled policy runtime with a columnar pass. - Decision::evaluate_columns / Workspace::evaluate_columns return one ColumnarOutput type; diagnostics live in zen_engine::diagnostics - rows the plan cannot finish are deferred to the row runner and never re-run nodes; sub-decisions run inside the parent plan; date input schemas stay on the plan - DecisionEngine keeps compiled graphs, sub-decisions and policies per key while the loader returns the same content - failed $dictionary imports are retried, not cached - the old engine stays available behind the driver feature for comparisons; there is no fallback to it - benchmark harness (tests/bench_matrix.rs) comparing old and new across the spec corpus, fixtures and policies * refactor(engine): isolate compiled engine from release node and graph code Release code outside core/engine/src/compiled is restored to release/2.2. The compiled engine keeps its own copy of the node, graph and JS function implementation under compiled/host and reaches release only through types and pure helpers. Release files gain only additive hooks: the ZEN_CONFIG.compiled runtime flag (off by default), per-instance interpreted()/compiled_engine() on Decision, DecisionEngine and PolicyWorkspace, and the batch and columnar entry points. - the driver feature and the modified old engine are removed; tests compare the compiled engine against the unmodified release engine - compiled-only behaviour (#7 empty collect columns, #16 collect order, BC1 thrown-object message) is allowlisted in the comparisons - #14 (policy whitespace cells) is dropped: release analysis rejects it - goldens re-recorded from the release engine - spec 42 nested-chain case lowered to depth 200: the release engine's JS conversion overflows a 2 MB debug thread at depth 500 * fix(engine): keep interpreted engines interpreted and tighten engine comparisons - DecisionEngine::interpreted() now holds while ZEN_CONFIG.compiled is on: decisions it creates (get_decision, create_decision, evaluation) carry its engine, and its release path runs in an interpreting scope so the Workspace built by the lazy policy path stays interpreted too - policy batches (DecisionEngine and PolicyWorkspace) deep-copy their inputs like graph batches, so callers' contexts are no longer written into - release test files run on the release engine again: the compiled-by-default ctor moved out of tests/support into tests/compiled_default, included only by the compiled test suites - spec `engines` notes are structured ({modes, intended, why}); unlisted modes are still compared with the reference, intended modes are checked against the spec, and open differences fail once they match the reference again. Stale notes found this way were removed; golden skips are per mode, and generated rows no longer inherit the first case's note * fix(engine): platform-independent spec suite ids and rustfmt - spec suite file paths are joined with '/', so suite ids and golden keys match on Windows (backslash paths missed every recorded golden) - engine spec json5 files are checked out with LF line endings - cargo fmt
ZEN engine conformance suite
Executable specification of decision graphs and policies, the engine-level sibling of
core/expression/tests/spec. Each case states what a decision is meant to produce, not
only what the current engine does. Known deviations are recorded in place.
Layout
graph/NN-chapter.json5: decision graphs (JDM), evaluated by the graph walker.policy/NN-chapter.json5: policies, evaluated by the policy driver.
A chapter is a sequence of suites. A suite is one decision plus the cases run against it.
Files use a JSON5-like syntax: // and /* */ comments, unquoted keys, single or double
quoted strings, trailing commas, and """raw""" strings for multi-line source (function
nodes). Numbers are read as exact decimals. date('...') is a date input that keeps its
source text, as the engine produces for schema date fields. Graph requests are normalized at
the input node, so in graph suites a date() input arrives as text; build date values with an
upstream d(...) expression or an input schema field with format: date.
Cases
cases: [
[input, output],
[input, output, "bug: why the engine differs"],
{input: {...}, output: {...}, goals: ["customer.tier"], note: "question: ..."},
]
- output: the expected result, compared by value. Numbers compare by exact decimal
value (
1.10 == 1.1); objects compare unordered."!error"expects any error;"!error: text"expects an error whose serialized form containstext(use it only for stable, user-facing error kinds). - note (optional):
bug: <why>: the output holds the intended result and the engine differs. A bug case that starts passing fails the run, so the note gets removed.question: <why>: the output holds current behaviour whose intent is unclear.
- goals (policy only): the request goals.
- engines (object form only): a documented difference between the reference (walker or
driver) and some compiled modes:
engines: {modes: ["batch", "columnar"], intended: true, why: "..."}. Modes aresingle,batch,columnar,engine(DecisionEngine) andtraced. Modes not listed are still compared with the reference. Withintended: truethe listed modes give the intended result and are checked against the spec output. Withintended: falsethe listed modes are a known open difference; once one of them matches the reference again the run fails, so the mode gets removed from the note. List only the modes that differ.
Evaluation time is fixed at 2025-03-20T10:15:30Z, time zone UTC (SPEC_TZ overrides).
Graph suites
{
name: "first hit returns the first matching rule",
graph: {
nodes: [
{table: "rules", hit: "first", inputs: ["age"], outputs: ["tier"], rules: [
["> 18", "'adult'"],
["", "'minor'"],
]},
],
},
cases: [
[{age: 20}, {tier: "adult"}],
],
}
graph is either {raw: <full JDM content>} or the shorthand below. Shorthand nodes name
their kind with one key whose value is the node name (also its id unless id is given):
| node | fields |
|---|---|
{input: "request", schema?} |
schema is a JSON schema object or string |
{output: "response", schema?} |
|
{expression: "calc", fields} |
fields is {key: "expr"} in order, or [["key", "expr"], ...] for duplicate keys |
{table: "t", hit?, inputs, outputs, rules} |
hit is first (default) or collect; inputs are field strings (null/"" = no field) or {field, name}; outputs are field paths (a [] suffix collects per column) or {field, type}; rules are rows of cell strings, inputs then outputs ("" = any) |
{switch: "s", hit?, when: ["cond", ...]} |
"" is the default branch; edges leave branch i as "s:i" |
{function: "f", source} |
v2 function node (export const handler = async (input) => ...) |
{functionV1: "f", source} |
v1 function node |
{decision: "d", key} |
sub-decision loaded from the suite's decisions |
{custom: "c", kind, config} |
spec adapter kinds: echo (returns input), config (returns config), render (each config key rendered as a template field), fail (errors with config.message) |
Expression, table and decision nodes also take passThrough, inputField, outputPath and
executionMode ("single" or "loop").
When the graph has no input or output node, nodes named input and output are added.
edges is a list of chains: "input -> a -> b -> output", "route:0 -> adult". Without
edges, the nodes are chained in order from input to output.
decisions: {key: <graph shorthand> | {raw: ...} | {policy: <policy shorthand>}} registers
sub-decisions for decision nodes.
Policy suites
{
name: "an expression block writes a computed property",
policy: {
models: {customer: {age: "number", companies: "company[]"}, company: {revenue: "number"}},
blocks: [
{expression: "customer.adult", value: "customer.age >= 18"},
],
},
cases: [
[{customer: {age: 20, companies: []}}, {customer: {age: 20, companies: [], adult: true}}],
],
}
policy is either {raw: <PolicyDocument>} or:
models: {entity: {property: "type"}}andglobals: {name: {...}}(global scope). Types:string,number,boolean,date,string(a|b|c)(enum),entity(relationship),&entity(reference); suffix[]for arrays and?for optional ("company[]?").dictionaries: {name: ["value", ["value", "label"], ...]}imports: ["path", ...]naming documents in the suite'spolicies.blocks, in document order:{expression: "path", value: "expr"}{match: "path", arms: [["condition", "value"], ["", "default"]]}{assertion: "path", conditions: ["expr", ["or", "expr", depth], ...]}{table: "id", hit?, inputs: ["field", ...], outputs: ["path", ...], rules: [[...]]}- any block takes an explicit
id.
policies: {path: <policy shorthand> | {graph: <graph shorthand>}} registers other
workspace documents. The suite's own policy is evaluated at path main.
Policies with error diagnostics are refused by DecisionEngine, so the runners gate them the
same way: every case of such a suite yields CompilationErrors [codes]. A suite that sets
diagnostics: ["TYPE_MISMATCH", ...] pins the exact set of error codes and evaluates its cases
through the workspace API, which runs policies despite errors; use it to specify runtime
behaviour of policies that only the workspace (editor) path can execute.
Runners
All runners live in core/engine/tests/spec.rs. Run with --all-features (exact decimals
need arbitrary_precision):
graph_spec_matches_walker: the graph walker against the spec.graph_engines_match_walker: the compiled engine (single, batch, columnar with plain, list and cycled column layouts, andDecisionEnginewith a loader) against the walker's actual result, bugs included.policy_spec_matches_driver: the policy driver against the spec.policy_engines_match_driver: the compiled policy engine (single, batch, andDecisionEnginefor cases without goals) against the driver's actual result.
A panic in any engine is reported as a failure of its suite and does not stop the run.
cargo test -p zen-engine --all-features --release --test spec
Environment knobs: SPEC_FILE=<substring> (files), SPEC_SUITE=<substring> (suite
names), SPEC_SHOW=<n> (failures printed), SPEC_BUGS=1 (list known bugs).