Warm the olive oil in a large Dutch oven over medium heat. Add the sliced white onions, yellow onions, minced garlic, thyme sprig, kosher salt, black pepper, and granulated sugar.
Lower the heat to medium-low. Cook the mixture for 50 to 60 minutes, stirring frequently and scraping any browned residue from the bottom of the pot. Continue until the onions become deeply golden, soft, and thoroughly caramelized. Reduce the heat further if the onions begin sticking.
Raise the heat to medium and pour in the sherry. Stir thoroughly while loosening the flavorful browned bits from the base of the Dutch oven.
Cook for approximately 4 minutes, or until nearly all the sherry has evaporated. Remove and discard the thyme sprig.
Reduce the heat to low. Add the unsalted butter and stir until it has completely melted into the onion mixture.
Scatter the flour evenly over the onions, then stir until fully incorporated. Cook for 1 minute to eliminate the flour’s raw flavor and create a lightly thickened base.
Slowly pour in the beef broth, stirring continuously to prevent the flour from forming lumps.
Increase the heat to medium and bring the soup to a gentle simmer. Cook for about 20 minutes, allowing the flavors to blend and the broth to thicken slightly. Taste and adjust the seasoning as necessary.
Divide the hot soup among four bowls. Place two toasted baguette slices over each serving and cover them generously with shredded Gruyère.
For a softer, richer topping, spoon a small amount of additional hot soup over the bread and cheese. Garnish each bowl with finely chopped fresh parsley before serving.