Hey,
This is not a solution but a workaround. What I did was to simply mask the shape layer to get cropped on the left side (or whichever side you wish). I also repositioned the shape so its center was on top of the beginning of the editable text.
I changed the code a bit as well to match my design:
margin = 0;
text_width = thisComp.layer("my_text").sourceRectAtTime().width*2;
text_height = thisComp.layer("my_text").sourceRectAtTime().height/6;
box_width = text_width + margin*2;
box_height = text_height + margin*2;
[box_width, box_height]
Hope this helps.