Arowx opened a new issue, #2428:
URL: https://github.com/apache/incubator-kie-issues/issues/2428

   # DMN alpha-network mode returns the first evaluation's result for every 
later evaluation on the same runtime
   
   **Component:** Drools DMN (`kie-dmn-core`), alpha-network compilation 
(`org.kie.dmn.compiler.alphanetwork=true`)
   **Version:** 10.2.0 (the same code is on `main`)
   **Java:** 25.0.5.1, Windows 11
   
   ## Summary
   
   With alpha-network compilation enabled, a decision table gives the correct 
answer for the first evaluation on a
   `DMNRuntime`. Every later evaluation on that runtime returns a result 
computed from the **first** evaluation's input
   values. Building a fresh runtime for each evaluation gives correct answers. 
Interpreted mode is correct throughout.
   
   ## Reproducer
   
   A standalone Maven project with a single class: 
https://github.com/Arowx/BinaryRuleEngine/tree/main/drools-alpha-repro
   
   ```
   cd drools-alpha-repro
   mvn compile exec:java
   ```
   
   It uses a 4-rule FIRST-hit table (`Age`, `RiskCategory`, `isAffordable` → 
`Approval Status`) and five inputs. Alpha mode is
   enabled in two ways: the way Drools' own 
`AlphaNetworkSupportInLargeDecisionTableTest` does it (system property plus
   `KieFileSystem`/`KieContainer`), and through `DMNRuntimeBuilder` with the 
compiler property. Both give the same result:
   
   ```
   input (Age, Risk, Affordable)  expected                 interpreted          
    alpha (reused)   alpha (fresh runtime)
   18, Medium, true               Approved                 Approved             
    Approved         Approved
   11, Low, true                  Declined (under 18)      Declined (under 18)  
    Approved  <--    Declined (under 18)
   30, High, true                 Declined (high risk)     Declined (high risk) 
    Approved  <--    Declined (high risk)
   30, Low, false                 Declined (unaffordable)  Declined 
(unaffordable)  Approved  <--    Declined (unaffordable)
   45, Low, true                  Approved                 Approved             
    Approved         Approved
   ```
   
   No error or warning messages are reported for the wrong answers.
   
   ## Likely cause
   
   In the generated evaluator template
   
`kie-dmn-core/src/main/resources/org/kie/dmn/core/alphasupport/DMNAlphaNetworkTemplate.java`:
   
   ```java
   public PropertyEvaluator getOrCreatePropertyEvaluator(EvaluationContext 
evaluationContext) {
       if(propertyEvaluator == null) {
           propertyEvaluator = new PropertyEvaluator(evaluationContext, 
"PROPERTY_NAMES");
       }
       return propertyEvaluator;
   }
   ```
   
   `PropertyEvaluator`'s constructor 
(`org.kie.dmn.core.compiler.alphanetbased.PropertyEvaluator`) copies the input 
values
   from the `EvaluationContext` into a `values` array. Because the instance is 
cached in a field of the compiled network, both
   `validate(...)` and `evaluate(...)` read the first evaluation's values for 
the lifetime of the runtime.
   
   A likely fix is to create the `PropertyEvaluator` per evaluation, or to 
refresh its values from the current
   `EvaluationContext`. Thread safety may also need a look: the cached instance 
is shared between concurrent evaluations.
   
   The existing alpha-network tests evaluate each runtime only once, which 
would explain why this isn't caught. A regression
   test that evaluates two different inputs on the same runtime would cover it.
   
   ## Related observation (possibly a separate issue)
   
   For a 1,000-rule decision table, alpha-network compilation fails with
   `KieMemoryCompilerException: ... PropertyEvaluatorNetwork....java (33878:23) 
: code too large`: the generated method
   exceeds the JVM's 64 KB method-size limit. The model then fails to load 
(`Unable to compile DMN model`) rather than
   falling back to interpreted mode.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to