daniel-clark-mint opened a new issue, #2117:
URL: https://github.com/apache/incubator-kie-issues/issues/2117

   I don't know if this is a defect or just a change in behavior we need to 
adapt for. This is the last (or second to last...) of the changes we have 
detected while preparing to upgrade from drools 7 to 10. We have approximately 
3500 hand-written rules and 14000 unit test rules to test these in continuous 
integration, so I am confident we will turn up all "breaking changes" for our 
use cases.
   When firing rules we fill the session with non-dynamic objects from our c++ 
application using the `org.kie.api.runtime.rule.EntryPoint.insert(Object 
object)` function before calling FireAllRules on the same stateful kiesession.
   During the rule execution there are a lot of rules which insert objects via 
insertLogical. We have a lot of rules using the CountAccumulateFunction to 
inform logic based on the number of objects present, and based upon failing 
tests it seems some of these tests aren't re-evaluating as suspected (based on 
drools 7 behavior). I am including a reproducer below (I think it is too 
complicated but it took 3 days for me to get there from the original rules).
   
   Most importantly for the reproducer:
   * When the input objects are inserted by the rules themselves the rule 
evaluates twice, once before and once after the final object is inserted.
   * When the objects are inserted from the java caller before the FireAllRules 
call, the rule only evaluates once, before insertion of the final object.
   
   Additionally:
   * If the "or not" node is removed the rule also fires twice...
   * using `exists` instead of `accumulate` the rule doesn't seem to evaluate 
the second time even if the objects are inserted in the rule file.
   
   I assume something has changed around the linking of nodes in the memory 
path when non-dynamic objects are present and they aren't re-added to the stack 
- but despite debugging I haven't been able to identify the change in the stack.
   I would be happy for advice on if we need to change a runtime compiler 
setting or just use a different insert method up front (these objects do not 
change during runtime), or if this is a bug.
   
   Thank you for your assistance!
   
   Reproducer:
   ```
   package com.example.reproducer;
   
   declare ObjectReference
     id: Integer
     description: String
     type1: String
     type2: String
   end
   
   declare AlphaInputObject
     ref: ObjectReference
     value: Integer
   end
   
   declare BetaInputObject
     ref: ObjectReference
     type3: String
     answered: Boolean
   end
   
   declare BetaInferenceObject2
     ref: ObjectReference
   end
   
   // rule "test" evaluates twice with this reproducer, once before rule "3" 
($count == 0) and once after ($count == 1).
   // however when these facts are inserted from java via EntryPoint.Insert() 
only the first activation occurs, there is no update after the insert from rule 
"3".
   rule "1" salience 100
     when
     then
       insert( new AlphaInputObject( new ObjectReference( 1, "Input Object 1", 
"", "" ), 2 ) );
       insert( new BetaInputObject( new ObjectReference( 1, "Input Object 1", 
"type1", "type2" ), "type3", true ) );
   end
   
   rule "test"
     when
       AlphaInputObject(
         $ref: ref,
         value in ( 1, 2 )
       )
       BetaInputObject(
         ref.id == $ref.id,
         ref.description == $ref.description,
         ref.type1 == "type1",
         ref.type2 == "type2",
         type3 == "type3",
         answered == true
       )
       or not BetaInputObject(
         ref.id == $ref.id,
         ref.description == $ref.description,
         ref.type1 == "type1",
         type3 == "type3",
         answered == true
       )
       accumulate(
         BetaInferenceObject2(
           ref.id == $ref.id,
           ref.description == $ref.description
         );
         $count: count()
       )
     then
       System.err.println( Long.toString( $count ) );
   end
   
   rule "3"
     when
       AlphaInputObject( $ref: ref, ref.id == 1, ref.description == "Input 
Object 1" );
     then
       insertLogical( new BetaInferenceObject2( $ref ) );
   end
   ```
   
   _Originally posted by @daniel-clark-mint in 
https://github.com/apache/incubator-kie-issues/discussions/2109_


-- 
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