
Mark Pousee (Customer) asked a question.
Unexpected Rule Engine Behavior with Shared Data Object (SDO) Updates in Corticon 7
Hi Corticon community!
I’m Mrak Pousee, and I’m diving into a bit of a puzzling issue with the Corticon 7 rule enginespecifically around how Shared Data Objects (SDOs) are updated and reused across rule execution cycles.
Here’s what’s going on:
- I defined an SDO (say, CustomerOrder) with a nested collection of LineItems.
- In the first execution pass, the rules evaluate correctly, and the SDO gets updated as expected.
- However, in subsequent runs—even when invoking the same ruleset with new input—the SDO seems to retain stale data in LineItems, resulting in unexpected aggregations and logic misfires.
- I’ve tried isolating the issue by resetting the session context and forcing the SDO to reinitialize, but it seems like the engine isn't flushing the prior state as intended.
Here’s what I’ve already checked:
- Ensured I'm using a fresh Process Session for each execution.
- Used explicit Session.invalidate() to clear context—still no luck.
- Checked that the rule task definition doesn’t include any caching flags that could preserve state across runs.
So I’m wondering:
- Is this a known quirk in Corticon’s handling of SDOs when data structure definitions remain constant across runs?
- Does anyone use a custom pattern to truly clear or clone SDOs between executions?
- Are there recommended practices—like forcing deep copies or leveraging specific session constructs—to avoid this kind of state carryover?
I’m hoping to make each rule run purely stateless, and any insight, workarounds, or best-practice examples would be immensely helpful.
Thanks so much for any tips or code snippets you can share!
Mark Pousee
Hi Mark,
1. Is this a known quirk in Corticon’s handling of SDOs when data structure definitions remain constant across runs?
Rules will update the SDOs directly, and this is by design. If this is not desirable, you will need to clone the the SDOs or possibly convert the SDO data structure into a different form like JSON, and then pass in that JSON payload. Rules will then update the JSON directly and not the SDOs.
2. Does anyone use a custom pattern to truly clear or clone SDOs between executions?
You can add a clone() method inside each SDO, which will copy itself and its associated objects (Associations). You just need to be careful that you don't get into an infinite circular loop. The issue with cloning of the objects, Rules will be updating the cloned objects and not the originals. You may need to do post execution processing to figure out what the Rules changed.
3. Are there recommended practices—like forcing deep copies or leveraging specific session constructs—to avoid this kind of state carryover?
Not familiar with your SDOs and how your system is using them. Unfortunately, I have no recommendations for you.
I hope this helps.
Regards,
John Miller