Copilot commented on code in PR #7174:
URL: https://github.com/apache/incubator-kie/pull/7174#discussion_r4207321722
##########
drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java:
##########
@@ -158,6 +171,28 @@ public void setSequencer(Sequencer sequencer) {
this.hashcode = calculateHashCode();
}
+ void replayExistingFacts(SequenceNodeMemory memory, ReteEvaluator
reteEvaluator) {
+ // Only replay when the sequencer was activated by the InitialFact (no
anchor pattern).
+ // When there is a real anchor, facts that arrived before it must not
be captured —
+ // that is the documented temporal contract of the sequence API.
+ if (!anchorless) {
+ return;
+ }
+ WorkingMemoryEntryPoint ep = reteEvaluator.getDefaultEntryPoint();
+ for (AlphaAdapter adapter : alphaAdapters) {
+ LinkedList<DynamicFilter> activeFilters =
memory.getActiveFilters()[adapter.adapterIndex];
+ if (activeFilters == null || activeFilters.isEmpty()) {
+ continue;
+ }
+ ObjectTypeNode otn = (ObjectTypeNode) adapter.source;
+ Class<?> classType = ((org.drools.base.base.ClassObjectType)
otn.getObjectType()).getClassType();
+ java.util.Iterator<InternalFactHandle> it =
ep.getObjectStore().iterateFactHandles(classType);
Review Comment:
An anchorless sequence starting with a prototype pattern throws
`ClassCastException` on its first `fireAllRules()`, even with no stored facts.
`PrototypePatternDef` is a supported `PatternDef`/`SequenceStep`, but the
compiler resolves it to `PrototypeObjectType`, not `ClassObjectType`. Handle
prototype types separately and filter their handles with
`PrototypeObjectType.matches` so facts belonging to other prototypes are not
replayed.
##########
drools-core/src/main/java/org/drools/core/reteoo/SequenceNode.java:
##########
@@ -158,6 +171,28 @@ public void setSequencer(Sequencer sequencer) {
this.hashcode = calculateHashCode();
}
+ void replayExistingFacts(SequenceNodeMemory memory, ReteEvaluator
reteEvaluator) {
+ // Only replay when the sequencer was activated by the InitialFact (no
anchor pattern).
+ // When there is a real anchor, facts that arrived before it must not
be captured —
+ // that is the documented temporal contract of the sequence API.
+ if (!anchorless) {
+ return;
+ }
+ WorkingMemoryEntryPoint ep = reteEvaluator.getDefaultEntryPoint();
+ for (AlphaAdapter adapter : alphaAdapters) {
Review Comment:
Each adapter represents a distinct fact type and is visited only once. For
an anchorless `Toy("ball") → Relationship("go") → Toy("doll")` sequence with
all three facts already present, the Toy scan finishes before Relationship
activates the final Toy filter. Replay therefore misses the doll and leaves the
sequence incomplete. Make unconsumed handles available to newly activated
filters even when their adapter was already visited, without consuming the same
handle twice. Add an anchorless batch regression alongside
`sameTypeInFirstAndThirdStep`.
--
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]