Thanks for the detailed reply. Numeric 402 existed long before nickserv, so it is a generic event that is not nickserv-specific. As far as I can tell, it is not possible for a client to know that the error is related to nickserv. mIRC does handle numeric 402 but only in relation to a /whois reply in a specific context sent by an ircd from 1995. Is the numeric 402 you are seeing specifying nickserv as the issue?

mIRC could assume that if it sees a generic numeric 402 event while waiting for a /nickserv reply, that it is related to nickserv, and to trigger perform immediately. As long as ircds don't send this numeric, and scripts don't send commands that trigger it, during the connection/logon process for other reasons, that could work.