For replies, the function `is_first_hop()` is a best effort attempt to figure out if the proxy is the node next to the callee and cannot detect spirals. See the readme explaining what it does for a reply.
The parsing of the IP in the record route header is needed to match the source IP and detect loops, this is by design and needed for the expected behaviour.
A new function (or parameter) can be added to control if one needs to detect loops or not, based on how its SIP routing is designed through the proxy.