I am running into a wall mentally when trying to think of a way to solve this problem. At my work we process customer data through some complex reasoning logic. Sometimes this logic will cause infinite looping. We actually know how to just remove some of the logic that will cause this but for political reasons we aren't allowed to touch the logic.... sigh
Anyway, I decided to open my big mouth and suggest there must be some way to detect cycles in the logic calls, so here I am tasked with figuring out a way to detect cycles in the logic and then move past the loop if one happens.
I have come up with a rough plan but I wanted to see if any of the smart people here had some input.
To begin, I already have access to every function call and its inputs via our logging so my plan was as follows:
- find a way to hash the function call/inputs combinations
- map the above combos to a call ID
- keep a list of all calls made so far
- use the map from 2 and the list from 3 to create a potentially cyclical representation of the calls
- Run Brent's cycle detection algorithm on this list to see if a cycle has happened.
I feel like this is fairly convoluted. I was wondering if others had some input.
The programming language for this is Java, and the logic is in Drools. With Event listeners I can see exactly what rules activate and the facts that activate them. Sometimes no rules actually fire just ruleflow groups get activated. My thinking was that by keeping a list of all pervious activations I can rebuild the call order into something akin to a linked list and apply some cycle detection algorithm. Then after every activation I need to check if this activation has started a loop.