Creatures are assumed to automatically notice other creatures that are within the range of their sight or hearing, unless they make Stealth checks
The DMG offers a limited amount of guidance about how to determine whether or not creatures detect each other. In the exploration section of chapter 8 (“Running the game”), it states:
Noticing Other Creatures
While exploring, characters might encounter other creatures. An important question in such a situation is who notices whom.
If neither side is being stealthy, creatures automatically notice each other once they are within sight or hearing range of one another. Otherwise, compare the Dexterity (Stealth) check results of the creatures in the group that is hiding with the passive Wisdom (Perception) scores of the other group, as explained in the Player’s Handbook.
Unless a creature actually attempts to be stealthy and makes a stealth check, it is assumed to be automatically noticed by any other creature once it gets within the range of their sight or hearing. Of course, this just raises the question of what the range of vision or hearing is.
Unfortunately this is entirely up to the DM’s discretion for range of hearing, but for vision, this is quite clearly defined. The DMG in the same section also states:
When traveling outdoors, characters can see about 2 miles in any direction on a clear day, or until the point where trees, hills, or other obstructions block their view. Rain normally cuts maximum visibility down to 1 mile, and fog can cut it down to between 100 and 300 feet.
And we also have the PHB’s rules about vision and light:
In a lightly obscured area, such as dim light, patchy fog, or
moderate foliage, creatures have disadvantage on Wisdom (Perception)
checks that rely on sight.
A heavily obscured area—such as darkness, opaque fog, or dense
foliage—blocks vision entirely. A creature effectively suffers from
the blinded condition when trying to see something in that area.
The presence or absence of light in an environment creates three
categories of illumination: bright light, dim light, and darkness.
Bright light lets most creatures see normally. (…)
Dim light, also called shadows, creates a lightly obscured area. (…)
Darkness creates a heavily obscured area.
Here we see that a creature cannot see anything that is heavily obscured with respect to it, so will not automatically notice creatures that are in darkness until they are either close enough to hear or get within range of a light source or darkvision. It’s also obvious that creatures who have full cover from one another cannot see each other, but can see each other if there is less than full cover involved.
Altogether, if two creatures are close enough to meaningfully interact, they are certainly close enough to see each other and will notice each other automatically, unless there are obstructions between them sufficient to grant full cover or some other impediment to visibility which makes one or the other heavily obscured. Without such circumstances, the creature must make a stealth check if it doesn’t want to be noticed.
In the circumstances of your post – assuming that there were no special conditions of lighting or fog or other obstructions that would have made someone 20 feet further away actually impossible to see – the enemies should, by RAW, have noticed the unstealthy characters approaching as soon as they had line of sight, even if they are distracted.
Of course, it is important to note that these rules assume that stealth checks are opposed by a creature’s passive perception, and if circumstances would grant them disadvantage on a perception check – for instance, if you judge they are distracted by something – that disadvantage translates to a -5 penalty to their passive perception score. So, even characters who aren’t particularly skilled at stealth still have a good shot at sneaking up on distracted, unaware enemies.