The logic issue in the original rule posted is that while the “sleep” is running, additional triggers can take place.
Additional copies of your rule will start up, each coming to a sleep/wait. (This is a bad, resource-consuming idea as already pointed out).
As those sleeps run out, each rule will try to turn OFF the light based on what presence is now, and ignoring anything that happened in the meantime.
To fix the logic error, you need a way to reset, cancel, or restart the timing when something happens during the waiting time.
The expire method takes care of that for you.
There are other ways too, if you prefer not to create an additional Item.