In your case that means $replacex(%reply_message, [username], %[color:red] $+ username)[/color]
(0) Before anything
$eval(You are $iif([username] == $null, are not logged in, logged in as [username]) $+ ., 2)
(1) After the replace
You are $iif(%username == $null, are not logged in, logged in as %username) $+ .
(2) After $eval finishes evaluating this again (in the case where %username is set to "test_username")
You are logged in as %username.
And this is the message sent to the user. So to put it in words, this fails to work whenever [username] is not delimited by spaces.