In a medium saucepan, heat the oil and butter over medium-low heat. Add the onions, stir them about to coat with oil and butter, cover the pot and cook for about 15 minutes, stirring occasionally. Uncover, turn the heat up to medium and add the sugar and salt. Cook for another half hour, stirring occasionally, until the onions are deep golden.
Sprinkle with the flour and stir for a couple minutes, then stir in the stock and wine. Simmer for another 30 minutes. Taste and adjust the seasonings.
Just before serving, stir in the cognac if you're using it. Julia suggests you place rounds of bread in soup bowls or a tureen and pour the soup on top; I ladle it into individual ovenproof dishes, top each with the toasted bread and sprinkle with grated cheese. Put them all on a baking sheet and brown under a hot broiler until golden and bubbly. Serve immediately.