I remember in df2014 troglodytes despite being labelled as hostile were -never- attacking any dwarves while those same trogs were a threat in past versions (34.11 and earlier).
In 42.x i have seen a few trogs in my caverns and not a single one of them ever attacked any of my civilian (i don't use taverns, so they're no drunken civilians), but new to 42.x the trogs have been -always- running away from my civilians at any opportunity (in df2014 they just weren't moving).
So i guess the df2014 bug is still present in some way.
From what i've witnessed firsthand, despite it not being technically a scientific observation, is that troglodytes since they carry a sentient [CAN_LEARN] & [SLOWLEARNER] tags retract in fear upon witnessing death or aggressive actions much like peasants in adventure mode or at-least carry greater intelligence than typical animals despite acting much like them.
In one of my forts upon breaching the caverns i killed some troggs to clear out a safe zone, (as of 42.x, specific build avoids my memory) a few stray troggs that had become separated from the cluster were quickly put down but after the initial battle some more troglodytes came closer then retracted in fear to run after coming within "visual range" of my warrior and freshly killed trogg. I never suffered another attack from that group since, because they were fearful despite being fully hostile and aggressive before.
Whether trogg aggression against fortress inhabitants is world-wide across the cavern population or locally for that embark is a malleable value remains to be seen by applied science and testing. Theoretically if it is world wide, you can train troglodytes to avoid your embarks therefore allowing your farmers to do work in peace.