Add the olive oil to a large cooking pot and place over medium heat. Stir in the sugar. Add the onions and sauté until caramelized.
Sprinkle in the flour, stir until blended and continue to cook until the flour emits a nutty aroma, about 1 minute. Incorporate the stock in increments while stirring and bring to a boil. Stir in the dry sherry or wine and add the bay leaf and thyme.
Reduce the heat to a gentle simmer, partially cover the pot and cook for 30 minutes, stirring occasionally. Season the soup with salt and pepper to taste.
Preheat the oven to 325°F.
While the soup is simmering, prepare the Gruyère Melt. After preparation, remove from the heat to allow the melt to thicken.
Cut 1-inch thick slices of bread. Place the slices on a baking sheet and toast until lightly browned and crisp, about 10 minutes. Remove from the oven.
Set the oven on 'Broil'.
Remove the bay leaf and ladle the soup into oven-safe soup bowls. Spread a generous amount of the Gruyère melt on each bread slice and top each soup bowl. Place the soup bowls on the baking sheet for easier handling.
Place under the broiler until the cheese is lightly browned and bubbly. Serve immediately.