The head have a laser measurement tool and measures the exact position of the motor hood with sub milimeter precision. Then calculates corrections for its program to apply at the exact spot everytime.
Disclaimer: I work robots in paintshops like these.
Example:
The inside of your car door have plastizol sprayed over whole edge. That is actually sprayed while the doors are (almost) closed (think open as if latched by the lock, but not flush). The nozzle is a 0.5mm wide tube, that makes 3 90° degrees turns (left, right, right), and have opening in the direction pointing back at where it started. When the carbody gets into position, fixed cameras measure preset points to make sure its in right position (wiggle room ~20-100mm). Correction gets computed from that, and robot measure pass program is moved accordingly. Now the measure process is repeated with robot head holding a laser tool, measuring tenths of milimeter deviations, wiggle room ~2mm.
If the shape is just moved within tolerances, the robot modifies apply run with corrections from measurement and goes to work. Starting at corner, weaves the nozzle into position and runs along the whole doors (sometimes pulling out and back in at some corners, but some corners are turned without pulling out). Theres usually at least half a millimeter spacing between nozzle and an edge, the precision is maintained even during fast movements.
The nozzle is thin and long (5 cm) and easily breaks or bends.
Before every spray run the tool itself is measured (and the correction is computed and used), and used only if its not bent out of tolerance. If the tool is found faulty, robot can hotplug another nozzle (have like 5 ready), measure it and go fully autonomously.