The planar ally spell beseeches an otherworldly power to send you aid in the form of a celestial, elemental, or fiend. In my case, the players are trying to summon a somewhat homebrewed fiend; an existing demon that I upgraded with a few extra abilities stolen from other monsters. Most importantly, this fiend has the limited magic immunity feature that I "borrowed" from the Rakshasa.
The Rakshasa's Limited Magic Immunity trait states:
The rakshasa can't be affected or detected by spells of 6th level or lower unless it wishes to be. It has advantage on saving throws against all other spells and magical effects.
My creature shares that same ability. It is unaffected by the spells of 6th level or lower unless it wishes to be, and has advantage on all other spells and magical effects.
The planar ally spell states:
After the creature completes the task, or when the agreed-upon duration of service expires, the creature returns to its home plane after reporting back to you, if appropriate to the task and if possible.
The creature the players are trying to summon has no other way to enter the material plane other than being summoned. So, it would very much prefer to remain on that plane as long as possible.
Since planar ally is a 6th level spell, this creature could be immune to the spell if it so chooses. If it did appear and makes an appropriate deal with the spellcaster (as per the planar ally requirements) but then didn't want to return back to its home plane after completing the assigned task, could the creature enact its limited magic immunity power in order to refuse to return home?