If I switch behaviour of AI unit's group to COMBAT (and either manually or automatically unitPos is changed to MIDDLE) and then I setBehaviour to SAFE, and unitPos to UP at the same time, unit gets to an endless swithcing loop rendering it unusable.
Seemingly BOTH behaviour AND unitPos changes are needed. Issuing DoStop doesn't prevent the bug though.
My steps below reproduce the bug always although I don't know which step really triggers it.
EDIT: After some tests, I could narrow the issue down:
setBehaviour "SAFE" or setBehaviour "CARELESS" together with setUnitPos "UP" on a MIDDLE unit
causes this issue. Not Aware, not Combat, nor DOWN in Safe/careless causes the bug.