1.Melt butter in a large pot and add the sliced onions with sugar and a pinch of salt to draw out their moisture and speed caramelization.
2.Cook over low heat, stirring occasionally, until deeply caramelized, about 45-50 minutes.
3.Stir in the garlic and flour and cook for 2 minutes, then pour in the sherry, scraping up the browned bits from the bottom of the pot as it deglazes.
4.Whisk in the beef broth with the thyme and bay leaf, and simmer for 15 minutes, seasoning to taste.
5.Ladle into oven-safe bowls, top with toasted baguette and cheese, and broil until bubbly.