Commit Graph
2 Commits
Author SHA1 Message Date
Stefan 9a9a8a56c8 fix(trace): return errors instead of panicking in trace code, drop rayon and zstd dev-dependencies
- trace library code (compiled/trace, outside tests) has no unwrap,
  expect, unreachable or panic left; shapes that an earlier check
  guaranteed are re-checked and fail with the new
  TraceError::Malformed ("malformed trace: ..."), and the clippy
  unwrap_used allows on the trace modules are gone
- shared paths, sub-decisions and loops are depth-limited (256), so a
  document whose path references itself is an error instead of a stack
  overflow
- sim.rs reads expressions with small hand-written scanners instead of
  five lazily compiled regexes; a unit test checks them against regex
- writers during evaluation: the native graph, batch and columnar
  writers already return a miss to the engine, and the steps that could
  panic (nesting, finishing the document) now return that miss too. On
  a miss the engine falls back to convert; if convert fails as well the
  trace is stored verbatim with the reason (TraceDocument::failed). The
  evaluation result is never affected. The policy writer and the rows
  writer have no fallible step.
- trace_damaged fuzzes convert and restore with mutated legacy traces,
  v1 documents, requests and release documents (wrong types at every
  path of small fixtures, removed keys, truncations, out-of-range
  indices, cut JSON); ZEN_TRACE_FUZZ_CASES sets the count (6000 by
  default), plus tests for self-referencing paths and deep nesting
- the rayon and zstd dev-dependencies are removed: the trace_corpus
  test and example run sequentially and report raw byte sizes only
2026-11-05 14:58:19 +01:00
Stefan 7fade4435c feat(trace): trace format v1 with TraceCollector on the compiled engine
Compiled engine only; the interpreted engine keeps legacy traces. The
interpreted graph, policy and function code is unchanged from
release/2.2: asked for a trace (true, v1 or legacy) it returns its
legacy trace, never converts to v1, and ignores now, timezone and seed.

- trace format v1 inside the engine (compiled/trace), public as
  zen_engine::trace: convert (legacy to v1), restore (v1 to legacy),
  inspect and redact, with the native encoder and policy writer, and
  TraceFormat, TraceDocument, PolicyTrace and TraceBatch; no separate
  crate
- TraceFormat option (off, v1, legacy) replacing EvaluationTraceKind on
  every evaluation path; on the compiled engine legacy traces are
  restored from v1
- native TraceCollector for single-row, batch and columnar evaluation:
  a static template per compiled graph and typed facts pushed by the
  engine (rule hits, switch branches, expression results, sub-decision
  and loop levels), written as v1 without a legacy map
- native policy writer for executions, members, reads, writes and
  absence markers
- engine glue under compiled/ (compiled/trace/mod.rs,
  compiled/pinning.rs); workspace request, result and error types take
  the trace format and the policy trace as type parameters defaulting
  to the legacy types, with public aliases for TraceFormat and
  PolicyTrace; the response trace enum gains V1 and its policy variant
  holds a PolicyTrace
- pinned evaluation context on the compiled engine: now, timezone and
  seed options, one clock read per evaluation and per batch, per-row
  random streams (row i draws from row_seed(seed, i)) in every batch and
  columnar path, Date and Math.random pinned in compiled function nodes;
  evaluatedAt, timezone and seed in the envelope
- format additions: result rows for repeated keys, $redacted and
  $omitted with truncated, reserved context, requires flags
- now, timezone, seed and trace format options in the Node, Python, C
  and uniffi bindings
- golden tests: compiled v1 and legacy restore to the base traces for
  every spec case, interpreted variants return legacy traces equal to
  the base for any trace option, native and convert agree, batch and
  columnar rows equal single rows, timing stress, pinned and
  random-stream tests, and the interpreted engine ignores pinning;
  trace API, damaged-input, POC fixture (tests/fixtures/trace) and
  corpus tests, and the trace_corpus example for the POC cross-check
2026-11-04 17:46:43 +01:00