How SparkRules works¶
High-level flow¶
- Author rules in DRL or decision-table form.
- Parse and validate rule syntax and references.
- Compile rules into execution-ready structures.
- Evaluate facts and produce rule results.
- Persist and/or emit run metadata and result data.
- Replay by reusing pinned run context and rule versions.
Main components¶
- Parser: converts DRL text into AST structures.
- Compiler: prepares rule packages and strategy metadata.
- Executor: evaluates compiled logic against facts.
- Metadata store: versions rules and resolves active sets.
- Runtime helpers: replay, cache, streaming support primitives.
- API layer: exposes operational endpoints; Workbench (static), LSP analyze, simulations (including counterfactual and chain), time-travel debug rows, and governance (pins + deprecations).
Execution controls¶
- Salience: prioritizes competing activations.
- Agenda groups: scope which rules run in a stage.
- Activation groups: XOR behavior for competing rules.
Observability, rollout, and limits (V2)¶
- Classification transparency:
RulePack.debug_classification()returns each rule’s strategy plus a stableclassification_rationalecode (e.g.SQL_PUSH_TRANSLATABLE,PYTHON_ONLY_REGEX). - Counters (opt-in): set
SPARKRULES_ENGINE_METRICS=1then pollsnapshot_engine_metrics()fromsparkrules.runtime.engine_metrics(evaluations, row counts, firings-by-strategy, translation-failure tally, coarse latency buckets).LocalRuleExecutorandapply_pandasrecord automatically when metrics are enabled. - Structured logs: at INFO,
LocalRuleExecutoremits one line per firing with rule name, strategy, salience, and reason codes. - Rollout knobs:
rollout_config_from_environ()readsSPARKRULES_SHADOW_DUAL_EVAL,SPARKRULES_ENGINE_METRICS,SPARKRULES_MAX_RULEPACK_BYTES. For single-rule parity smoke tests usecompare_v1_v2_single_rule_fired(fact, drl). - Serialized RulePack caps: optional hard limit via
SPARKRULES_MAX_RULEPACK_BYTES; soft warning still applies when blobs exceedRULEPACK_LARGE_SERIALIZE_WARN_BYTES.
See docs/REQUIREMENTS_V2_ENGINE.md (Req 30–34) for normative wording.
Data and output model¶
- Rule evaluation returns fired state, bound field values, and action outputs.
- Runtime records include run identifiers and reproducibility metadata.
- Store and runtime APIs are designed for deterministic behavior under replay.