Once a habit loop is fully established, it can continue running even when the organism is directly experiencing the resulting harm, as long as the behavior is triggered through its normal habitual cue rather than through a conscious assessment of danger. This is a specific and important distinction: the same animal that will readily avoid a visibly dangerous stimulus when evaluating it consciously will still walk directly into that danger when the habitual cue, rather than a deliberate choice, is what's driving the behavior.
This has direct relevance to understanding compulsive or addictive behavior in general: the pattern isn't necessarily evidence of a failure to understand the risk, since conscious awareness of danger and habitual response run through different pathways — a habit loop, once fully automatic, can keep running on cue even while a person or animal fully knows, in the moment they're not directly acting on the habit, that it's harmful.
Researchers trained mice to press a lever for a food reward, then made the food poisonous or electrified the floor leading to it. When mice were shown the danger directly — poisoned pellets visibly placed in a bowl, or an electrified panel they could see — they avoided it, showing they were fully capable of recognizing and responding to visible danger. But when exposed to their normal habitual cues that triggered the learned lever-pressing routine, the same mice pressed the lever and crossed the dangerous floor anyway, even while visibly getting sick or shocked in the process.