Foldl over the rules means last match wins... this is different from our other rules (say on resource documents, system_configs, ect) where first match wins.  You could make this a foldr.  I think a better approach would be to have a function to find the first matching rule.  That way you would know if match was found and if not you could address the comment bellow (line 555).