Determinism Guarantees
Property: Given the same initial state and the same sequence of events, Rezi will produce:- Identical VNode trees
- Identical layout results (cell coordinates)
- Identical drawlists (byte-for-byte)
- Identical terminal output
- Multiple runs on the same machine
- Different machines (same platform + runtime version)
- Different times (no clock dependencies in render path)
- Different terminal sizes (when viewport is fixed)
Sources of Determinism
Pinned Unicode Version
Rezi pins Unicode 15.1.0 for text measurement:packages/core/src/layout/unicode/tables_15_1_0.ts
Versioned Binary Protocols
All binary formats are versioned:- ZRDL: Drawlist format version in header (v1-v5)
- ZREV: Event batch version in header (v1)
Commit-Point Semantics
State updates are batched and committed at well-defined points:- After all event handlers complete
- Before next frame render
- On explicit
app.flush()
Deterministic Layout Algorithms
Layout engine uses deterministic algorithms: Integer distribution:packages/core/src/layout/engine/distributeInteger.ts
Flex/grid sizing:
- No floating-point rounding errors
- Deterministic resolution of ambiguous constraints
- Stable sort orders (instance IDs break ties)
Reconciliation Stability
Reconciliation matches children deterministically: Keyed children: Match by explicitkey prop
No Random State
Rezi’s render path contains:- No
Math.random()calls - No
Date.now()orperformance.now()reads - No non-deterministic hash functions
Record/Replay System
Rezi includes a record/replay system for debugging:Recording a Session
- Initial state
- All ZREV event batches
- State snapshots at each commit point
- Viewport size changes
.zrui file (compressed)
Replaying a Session
- Same initial state
- Same event sequence (timing doesn’t matter)
- Same state transitions at each commit point
- Reproduce user-reported bugs
- Verify fixes without manual reproduction
- Snapshot testing
packages/node/src/repro/
Snapshot Testing
Deterministic rendering enables snapshot tests:- ASCII: Text rendering of frame
- ZRDL: Binary drawlist
- Layout tree: Cell coordinates JSON
Non-Deterministic Inputs
Some inputs are inherently non-deterministic:Time
User code may readDate.now() or performance.now() in view functions:
Random State
User code may callMath.random():
External I/O
Reading files, network requests, or system APIs:Testing Determinism
Verify determinism with this test pattern:Caveats
Platform dependencies:- Terminal capabilities may differ (truecolor, mouse)
- Font rendering is terminal-specific
- Terminal emulator bugs may cause divergence
- Different Node.js versions may have different behavior
- Different V8 versions may optimize differently
- Rezi avoids floating-point in layout (uses integers)
- User code with floating-point may have platform differences
- Pin Node.js version in CI
- Use integer arithmetic for critical logic
- Test on multiple platforms
Related Documentation
- Render Pipeline — Rendering phases
- Layout Engine — Layout algorithms
- Protocol Versioning — Binary format versions
- Benchmarks — Performance measurements