Caterpillar Duality for Constraint Satisfaction Problems