You are referencing the database view vAgentConfiguration and looking at the CurrentUser value.
You find that this does not always return the expected value - even though a user is logged in, the value returned is <null>
This is not the best source for this information. The value in this table is not updated frequently. A restart of the agent process with the user logged in WILL trigger this value to be updated, but this is not ideal.
WORKAROUND / SOLUTION
Instead of vAgentConfiguration/CurrentUser, use the more correct vAgentLabel/CurrentLogin
This gives you "live" information about the logged in user.