The current situation of trying to set up fortifications while getting hit with a full assault is far from ideal, HOWEVER, if I tell an AI soldier to build what I placed, they should stay there until it is finished. Currently, the priority seems to be following the player over building what they are supposed to, leaving it unfinished.
Suggestion 1: Make AI engineers prioritize construction orders over following the player.
Secondly, even when the AI are working on building something, they often stand or crouch directly dead center behind it, making themselves an extremely easy target.
Suggestion 2: Make AI engineers identify nearby cover and make use of it, or at the very least go prone when attempting to finish construction of a fortification.