It known the changes over the same part of the message can result in undesired content, you have to use msg_apply_changes() in between see also *SIP Message Processing* in the FAQ:
- https://www.kamailio.org/wikidocs/tutorials/faq/main/
Note that this tracker is used for reporting bugs in the c code, not the case here, this being by design. For discussing further use sr-users@lists.kamailio.org mailing list.