This: AIWaveTargetGatherD(..) could be your problem. Use this target only if you wish the AI to leave units behind from the wave you're controlling.
A retreat with this as target will cause the AI to leave a portion of its force behind.
A retreat with this as target will cause the AI to leave a portion of its force behind.