Thinly slice onions into even half-moons; separate any large layers.
Grate cheeses and slice baguette; preheat oven broiler to high.
Measure out stock, wine, and herbs; have a wooden spoon and heavy pot ready.
Cook Soup
Heat butter and olive oil in a large heavy-bottomed pot over medium heat until butter melts.
Add sliced onions and 1 tsp salt, stir to coat; cook, stirring frequently, 20–30 minutes until soft and beginning to brown.
Add 1 tsp sugar to encourage caramelization, reduce heat to medium-low and continue stirring every few minutes until deep golden brown, about 15–20 more minutes.
If using, sprinkle flour over onions, stir and cook 1–2 minutes to remove raw taste.
Pour in wine to deglaze, scraping browned bits from bottom; simmer 1–2 minutes to reduce slightly.
Add beef stock, thyme sprigs, and bay leaves; bring to a simmer, then reduce heat and simmer gently 15–20 minutes to meld flavors.
Remove thyme sprigs and bay leaves; taste and adjust salt and pepper.
Assemble & Broil
Ladle hot soup into oven-safe bowls, leaving room at top for bread and cheese.
Top each bowl with a toasted baguette slice (or two) and a generous handful of grated Gruyère; sprinkle a little Parmesan if desired.
Place bowls on a baking sheet and broil 2–4 minutes until cheese is bubbly and golden; watch closely to avoid burning.
Carefully remove from oven, let cool 2 minutes, and serve immediately.
Tips
Slice onions uniformly so they caramelize evenly and finish at the same time.
Be patient while caramelizing; low heat and frequent stirring yield deep flavor without burning.
Serve with lemon wedges or a crisp green salad to cut the richness.