Melt butter in a heavy-bottomed Dutch oven over medium heat. Add onions, halved lengthwise and cut into 1/4-inch slices. Cook, stirring occasionally, until caramelized and very soft, about 45 minutes.
Deglaze pan with Cognac and wine, scraping up bits from bottom of pan with a wooden spoon.
Sprinkle flour over onions; stir. Add beef stock and thyme leaves and
bring to a simmer. Cook, partially covered, until heated through, about 20 minutes. Season with salt and pepper to taste.
Preheat broiler. Arrange Gruyere on bread and broil until cheese is melted, about 1 to 2 minutes. Serve with soup.