The looping function itself is actually quite ‘dumb’ in terms of the logic behind it.
If you have the entire sample selected, then it will simply divide the sample in half and cross-fade the 2 halves together so they overlap.
If you have a smaller portion of the whole sample selected, then it divides that selection into 3 parts and cross-fades the 1st and 2nd parts together so they overlap, leaving the 3rd part untouched. The reasoning behind this 3-part split is that it allows you to play a sustained note during the looped portion of the sample, then have a note-off stage that transitions smoothly into the remaining tail end of the sample.
Overall, the end result is very much dependent on the audio material itself, and where you make the selections within the sample before applying the loop function. You will often be prone to some phase cancellation issues (which can of course lead to volume ducking), as the cross-faded sections may not always align perfectly with the phase of the waveform cycles in the sound itself.
This could be improved by performing more detailed analysis of the sound itself and trying to determine more ideal loop points, but obviously every sound is different, and extracting any meaningful data can often be incredibly difficult except in cases where the waveform itself is very simple.
The loop in your 02 sound is definitely a big improvement in this particular case anyway. Would you mind sharing the script, or your techniques for how you achieved this? Was there any special care taken with regard to choosing potential loop points/size, ie. some prep work you needed to do first, or is your script fully automated? How does it handle other waveform types?