Add retry limits to prevent infinite loops.