Appearance
ADR-2506: The engine_core Rule AST Is Superseded by the One Rule Language
- Status: Accepted
- Date: 2026-09-30
- Authors: @fderuiter
- Deciders: @fderuiter
- Requirements: PRD-DDF-001 (static circular dependency checks on skip logic)
- Relates to: ADR-2461 (the one rule language), ADR-2502 (DDF item rules)
- Issue: #4789
1. Context & Problem Statement
packages/engine_core still holds two Python reference files for its old rule engine:
rules/ast.py: an expression tree withfield_ref,variableand operator nodes, aRuleDefinitionwith skip logic, edit check and derived-variable types, andvalidate_nodeshape checks.rules/sentinels.py: static checks before a rule is published. It collects field references, measures depth and node count, reports references to unknown fields or visits, and finds cycles in skip logic and derived variables.
The inventory lists both as "Port missing". Their evaluator was ported earlier as Cadence.Core.Domain.Rules.RuleEvaluator, a JsonLogic-style engine with its own AST (RuleAst.cs). Only its own tests call it.
ADR-2461 made one rule language for edit checks, skip logic, conformance and indicators (K-RULE-3), and rejected JsonLogic. ADR-2502 moved DDF item rules onto it.
2. Decision Drivers & Constraints
- K-RULE-3: one rule language. A second AST with its own evaluator is a second language.
- Each check the sentinels made must still happen somewhere, or be recorded as not needed.
- A Python reference file leaves the inventory when a tested port exists or an ADR records that the behaviour is not carried forward (ADR-2492).
3. Options Considered
Option 1: Port validate_node and the sentinels onto the engine_core AST
- Cons:
- ❌ It builds out a second rule language that nothing in production uses.
Option 2: Map each check onto the one rule language, and retire the engine_core rule engine (Selected)
- Pros:
- ✅ One language, one parser and one set of static checks.
- Cons:
- ❌ The engine_core
RuleEvaluatortests go with the engine they test.
- ❌ The engine_core
4. Decision Outcome
- Chosen Option: Option 2.
rules/ast.pyandrules/sentinels.pyare not ported. Each check maps as follows:
| engine_core check | Where it lives now |
|---|---|
validate_node (operand counts, required fields) | RuleExpressionJson parsing is strict: an unknown operator or property, or a wrong number of arguments, is an error when a pack or item rule is read |
calculate_expression_complexity | RuleExpressionJson.MaxDepth (64) and MaxNodes (4096) refuse an expression that is too deep or too large |
extract_field_references, detect_unresolved_references for form items | DDF compile: a rule that names an item the study does not have fails the compile (ADR-2502) |
detect_unresolved_references for rule packs | Binding collection-stage packs to the CollectionSpec versions they check (#4728) |
detect_circular_dependencies, skip logic | DdfDependencyGraph.FindCycles in the DDF compile (ADR-2502) |
detect_circular_dependencies, derived variables | Derived variables (#5043) |
RuleDefinition versioning, checksum and audit fields | Rule packs are versioned library content with the kernel audit log (ADR-2461) |
Cadence.Core.Domain.Rules(RuleAst.cs,RuleEvaluator.cs) is a second rule language with no production caller. It is removed, withRuleEvaluatorTests,RuleChecksumTestsand the rule case inDomainEngineUnitTests, in the same maintainer-approved deletion as the Python files.
5. Consequences & Trade-offs
- Positive Impact:
- One rule language in the codebase once the deletion lands.
rules/ast.py,rules/sentinels.pyandrules/__init__.pycan be deleted once a maintainer approves.
- Negative Impact / Technical Debt:
- Until then, the engine_core rule engine stays in the build, unused.
- Mitigation Strategy: nothing new may call
Cadence.Core.Domain.Rules; rules go throughIRuleEvaluator.
6. Implementation & Verification
- Affected Repositories / Services: documentation only: this ADR,
docs/PYTHON_REFERENCE_INVENTORY.mdand the engine_core README. - Verification Plan:
pnpm cadence check adrsand the documentation gates. Each check's new home is covered by its own tests:RuleExpressionTestsfor parsing and the limits, andDdfRulesTestsfor unknown items and cycles.