Hi,
thank you very much for the detailed analyzes and finding the root cause. I could verify the difference in the group sizes based on your example.
Could you please try the attached patch? It appends the new variable to the end of the group now to keep the order intact, and it also adds an extra sanity check.
Thanks, Miklos [cfg_script.diff.gz](https://github.com/kamailio/kamailio/files/2506182/cfg_script.diff.gz)