GKRuleSystem facts are not reliably in order of saliency

Apple: see bug report 24316134.


GKRuleSystem's class reference claims that it is supposed to add rules to its "agenda" in order of each of its rules' "salience" property. In turn the agenda is said to control the order in which the rules are evaluated. At the end we get an array called "facts" that contains any facts that are the result of successful assertions (or the remainder after successful retractions).


"Facts" should get added to their facts array in the order their parent rules are evaluated. Therefore the order of the resulting "facts" in the array should be in the same order as the order of the rules in the agenda, which in turn is the order of salience.


However this is not how it works. RuleSys's agenda is broken. Facts appear in random order in the array.

Please fix this. There is basically no point to having a "salience" property if facts are in random order...

Thanks

Replies

So yeah does anyone have any insight into this? I filed a radar but no response yet...

Hi Jon,


I don't see anything in the documentation that promises the facts array will be ordered according to the salience of the rules in the agenda.


Once the GKRuleSystem has been evaluated, you should use gradeForFact:, minimumGradeForFacts:, or maximumGradeForFacts: to retrieve fact information. Different rules can operate on the same fact and may remove the fact from the facts array if a fact's grade falls below 0. Also, as facts are evaluated, the rule system may revisit certain rules. From the docs:


"Because other rules might depend on the set of facts, asserting or retracting facts causes the system to reevaluate itself—a single call to the

evaluate
method can cause the system to consider its set of rules several times."


Remember, salience is a property of GKRule, not of a fact. I think what you are looking for is a feature that Apple did not intend to provide.

Then what indeed is the point of salience, if it does not affect the order in which anything happens?