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.