Heat the oven to 400°F. Toss onions and shallots with melted butter, oil, salt and pepper in a large roasting pan, spreading evenly.
Roast for 70 to 85 minutes, stirring every 20 minutes and more often near the end, until softened and deeply golden without blackened edges. Transfer the onions to a soup pot.
Pour sherry and 1/2 cup of the measured broth into the still-warm roasting pan and scrape up browned juices with a wooden spoon. Add this liquid to the soup pot with remaining broth, thyme and bay leaf.
Bring to a simmer and cook uncovered for 20 minutes. Meanwhile, toast baguette slices on a sheet in the 400°F oven for 6 to 8 minutes until crisp, then heat the broiler.
Discard bay leaf and divide soup among 6 broiler-safe bowls set on a rimmed sheet. Top each with one toast slice and an equal share of Gruyere, then broil 6 inches from the heat for 2 to 4 minutes until cheese bubbles and browns.
Let bowls stand for 5 minutes before serving and warn diners that the bowls remain hot.