Do you set the r-uri value inside kamailio.cfg via some assignment operations? Or it is updated only by the ims modules you are using?
If later, maybe @jaybeepee, @ngvoice or @richardgood can comment more on what happens in the c code for the modules.