No problem … hopefully we can get to the bottom of your issue for you.
The problem when you call that script you write (even just the once), it will reset their spells that were on them at the time. Now, that should not be a problem if the player has only just added them, as they had no idea what spells they had originally.
However, I am curious as to what script is being fired after they have been added and are in the party, and the player then levels the PC. i.e. At that stage, the above script you say you use to “add” the companions should NOT be being called if doing so compromises what you already allocated.
And, if you (as the builder at build time) are setting the spells, and are then trying to re-level the companion after the player asks them to join for the first time (which is what it sounds like to me), then I do not think you can use this function like that as it appears to have its own agenda as to what spells to rebuild the companion with and will overwrite any you have pre-selected. That is why I was recommending using SetXP (after comparing with the player) to reset the companion XP and just let the player level the companion manually after that.
That said, it may well be that you can edit the packages.2da (and cross referenced related package - PackSPWiz8) for that companion, to ensure a particular set of spells are learned. Although, I do not know how the engine chooses which spells from that 2da just looking at it.
So, first questions I wanted to ask/clarify with you: Did you give the companion the fireball spell prior to calling the function? And is it this selection that has “gone” after running the reset function during companion add?
EDIT: Another quick thought: Have you tried adding a very brief delay between them? ~ 0.1 sec
EDIT 2: I also read this in the function description, “The creature to which you want to set the Level-Up package. Player OWNED creatures are not valid for this function” So, bear that in mind.