I'm not sure if this is on purpose or not, but friendly attacks seem to turn off a spy's cloak.
I mean, if I'm trying to sneak through a battlefield, a friendly Demoman can uncloak me by shooting at me.
It's kind of annoying, and well, I just thought I should mention it if you decide to fix it in the next patch or something.