This is an automated email from the ASF dual-hosted git repository.

tkobayas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie.git


The following commit(s) were added to refs/heads/main by this push:
     new 1db2381585f [incubator-kie#7134] fix(drools): not-subnetwork silently 
stops firing after cross-package segment split (#7135)
1db2381585f is described below

commit 1db2381585f639e8b640f158f495e2b79e453dd8
Author: Toni Rikkola <[email protected]>
AuthorDate: Tue Nov 10 03:06:43 2026 +0200

    [incubator-kie#7134] fix(drools): not-subnetwork silently stops firing 
after cross-package segment split (#7135)
    
    Closes #7134
    
    Assisted-by: IBM Bob
    
    Co-authored-by: Claude <[email protected]>
    Co-authored-by: Toshiya Kobayashi <[email protected]>
---
 .../org/drools/core/phreak/EagerPhreakBuilder.java |  4 ++
 .../SubnetworkSegmentSplitIntegrationTest.java     | 56 +++++++++++++++++++++-
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git 
a/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java 
b/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java
index 552c73fb9e5..d05aefa55c5 100644
--- a/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java
+++ b/drools-core/src/main/java/org/drools/core/phreak/EagerPhreakBuilder.java
@@ -637,6 +637,10 @@ public class EagerPhreakBuilder implements PhreakBuilder {
                 }
 
                 for (PathEndNode endNode : tn.getPathEndNodes()) {
+                    if (endNode.getAssociatedTerminalsSize() > 1) {
+                        // do nothing, this whole subnetwork is still shared
+                        continue;
+                    }
                     PathMemory pmem = (PathMemory) 
wm.getNodeMemories().peekNodeMemory(endNode);
 
                     // Iterate from root to tip.
diff --git 
a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SubnetworkSegmentSplitIntegrationTest.java
 
b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SubnetworkSegmentSplitIntegrationTest.java
index 817cbcfc42f..79fd2f4f04c 100644
--- 
a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SubnetworkSegmentSplitIntegrationTest.java
+++ 
b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/compiler/integrationtests/SubnetworkSegmentSplitIntegrationTest.java
@@ -23,12 +23,12 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Stream;
 
+import org.drools.kiesession.rulebase.InternalKnowledgeBase;
 import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
 import org.drools.testcoverage.common.util.KieBaseUtil;
 import org.drools.testcoverage.common.util.TestParametersUtil2;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.MethodSource;
-import org.drools.kiesession.rulebase.InternalKnowledgeBase;
 import org.kie.api.KieBase;
 import org.kie.api.runtime.KieSession;
 import org.kie.api.runtime.rule.FactHandle;
@@ -102,6 +102,60 @@ public class SubnetworkSegmentSplitIntegrationTest {
         }
     }
 
+    private static final String TP03_EXISTS_RULE_PACKAGE = """
+            package repro.tp03.b;
+            import %s;
+            global java.util.List results;
+            rule "exists-rule"
+            when
+                exists ( $c : Container() and String( this == "match" ) from 
$c.items )
+            then
+                results.add("exists-rule");
+            end
+            """.formatted(Container.class.getCanonicalName());
+
+    private static final String TP03_NOT_RULE_PACKAGE = """
+            package repro.tp03.a;
+            import %s;
+            global java.util.List results;
+            rule "not-rule"
+            when
+                not ( $c : Container() and String( this == "match" ) from 
$c.items )
+            then
+                results.add("not-rule");
+            end
+            """.formatted(Container.class.getCanonicalName());
+
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testTP03RuleRemovalOnSplitSubnetwork(KieBaseTestConfiguration 
cfg) {
+        KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl(
+                "tp03", cfg, TP03_NOT_RULE_PACKAGE, TP03_EXISTS_RULE_PACKAGE);
+        KieSession ks = kbase.newKieSession();
+        try {
+            List<String> fired = new ArrayList<>();
+            ks.setGlobal("results", fired);
+
+            // STEP 1: insert a container with 'match'. exists-rule fires, 
not-rule is blocked.
+            FactHandle container = ks.insert(new Container("match"));
+            ks.fireAllRules();
+            assertThat(fired).as("Step 1: Container('match') 
inserted").containsExactly("exists-rule");
+            fired.clear();
+
+            // STEP 2: remove exists-rule. The two rules shared a condition, 
so this
+            //         touches the chain that not-rule depends on.
+            kbase.removeRule("repro.tp03.b", "exists-rule");
+
+            // STEP 3: delete the container. not-rule must still wake up.
+            ks.delete(container);
+            ks.fireAllRules();
+            assertThat(fired).as("Step 3: not-rule must survive the removal of 
its sibling")
+                    .containsExactly("not-rule");
+        } finally {
+            ks.dispose();
+        }
+    }
+
     // =======================================================================
     // TP-04: removeRule cleans up stale eager prototype after segment merge
     // (Toshiya's comment on PR #7116)


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

Reply via email to