Heat the olive oil in a large skillet over medium heat, then add the sliced onions along with the sugar and salt. Let them cook low and slow, stirring every few minutes so nothing catches on the bottom of the pan. After about 15 to 20 minutes they should turn a deep golden brown and smell incredibly sweet. Pull them off the heat and let them cool slightly before handling.
While the onions cool, preheat your oven to 400°F and line a baking sheet with parchment paper. Unroll the puff pastry onto the sheet and, if it is not already a neat rectangle, gently smooth it out with a rolling pin. Use a fork to prick the center a few times, leaving a small border untouched around the edges. This border is what puffs up into that pretty golden frame.
Spread the cooled caramelized onions evenly over the pastry, staying inside the border you left. Lay the brie slices on top so they are spread out rather than piled in one spot, which helps the cheese melt evenly across the tart. Scatter the fresh thyme leaves over everything and finish with a small pinch of black pepper.
Using your pastry brush, coat the exposed border of puff pastry with the beaten egg. This is what gives the crust that shiny, bakery-style finish once it comes out of the oven. Try not to let the egg wash drip down the sides, since it can glue the pastry to the parchment paper.
Slide the tart into the preheated oven and bake for 20 to 25 minutes, until the pastry is puffed and deeply golden and the brie has melted into soft, gooey pools. Every oven runs a little differently, so start checking around the 18-minute mark if yours tends to bake hot.
Let the tart rest on the baking sheet for about 5 minutes before transferring it to a cutting board. This short rest lets the cheese set just enough that it will not run everywhere when you slice it. Cut it into squares or wedges and serve while it is still warm.