Skip to content

Add sequential inter-record Rhai helpers: prev/lag/delta/ewma#162

Open
dloss wants to merge 2 commits intomainfrom
codex/implement-dev/spec-inter-record-delta-lag
Open

Add sequential inter-record Rhai helpers: prev/lag/delta/ewma#162
dloss wants to merge 2 commits intomainfrom
codex/implement-dev/spec-inter-record-delta-lag

Conversation

@dloss
Copy link
Copy Markdown
Owner

@dloss dloss commented Apr 11, 2026

Motivation

  • Provide ergonomic adjacent-record helpers for common sequential workflows such as latency jumps, multi-record deltas and smoothing with EWMA.
  • Keep behavior deterministic and memory-bounded for streaming processing by defining clear lifecycle semantics and sequential-only mode.
  • Surface resilient and strict variants to allow both permissive and fail-fast scripting styles.

Description

  • Implemented a new Rhai module src/rhai_functions/inter_record.rs that provides prev, lag, delta, ewma and strict variants with validation (n >= 1, n <= 10_000, alpha in (0,1]), native-numeric delta semantics, and explicit --parallel mode errors using thread-local state.
  • Integrated lifecycle hooks into the pipeline so the current event is set before per-event script stages and committed after scripts finish (including filtered events), with clear_current_event on script errors (src/pipeline/mod.rs).
  • Added run-time reset calls for inter-record state at pipeline startup in both sequential and parallel contexts and worker initialization (src/runner.rs, src/parallel/worker.rs).
  • Registered the new functions in the Rhai registry (src/rhai_functions/mod.rs) and added help/docs entries and reference text describing semantics and lifecycle (src/rhai_functions/docs.rs, docs/reference/functions.md, docs/reference/script-variables.md).
  • Added integration tests under tests/inter_record_integration_test.rs and unit tests inside the module to cover history progression, filtered-event advancement, EWMA, contract validation, and explicit --parallel error behavior.

Testing

  • Ran cargo fmt --all successfully to format code.
  • Ran cargo clippy --all-targets --all-features -- -D warnings successfully with no warnings.
  • Ran full test suite with cargo test, which completed successfully (all tests passed).
  • Ran targeted tests cargo test rhai_functions::inter_record::tests::prev_and_lag_follow_history -- --nocapture and cargo test --test inter_record_integration_test, both of which passed.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant