In a food processor, pulse the flour with the cubed butter until it resembles fine breadcrumbs. Season and tip into a bowl.
Mix the 2 egg yolks with 3 tbsp cold water until combined and add this to the bowl with the chopped thyme. Stir this very quickly with the tip of a cutlery knife until it just comes together.
Lightly knead this until it forms a ball with no cracks and shape into a disc 2-3cm thick. Wrap this with clingfilm and place in the fridge to chill while you make the filling.
Preheat the oven to 200°C/gas mark 6. Toss the butternut squash in 1 tbsp of vegetable oil and season, then place on a large roasting tray. Roast for 20 minutes then turn over and roast for another 20 minutes, until deep golden on the edges.
Meanwhile, heat the remaining vegetable oil in a small saucepan over a medium heat and add the onions. Season to taste. Cook them over a low heat with a lid on, stirring regularly for 20 minutes or until completely softened. Add a splash of water if they begin to burn.
Add the balsamic vinegar and turn the heat up to medium/high. Cook, stirring regularly, for 10 minutes, until they have turned golden and caramelised. Allow to cool.
Take the pastry out of the fridge and place on a surface dusted with flour. Roll out to a large circle roughly 3mm thick then transfer to a wide, flat baking sheet lined with greaseproof paper.
Pile the butternut squash on the middle of the pastry and spread out evenly, leaving a 4cm edge. Lay the caramelised onion over this then sprinkle the goat's cheese on top. Trim any raggedy edges of the pastry off then bring the pastry up over the sides of the filling to create overlapping edges. Place this in the fridge for 20 minutes to allow the pastry to firm up.
Meanwhile, make the pesto. Pour 500ml boiling water over the frozen peas and leave to sit for 2 minutes, then drain and run them under cold water. Add these, the rest of the ingredients, a squeeze of lemon juice and a splash of water to a food processor and pulse until broken up, but still with a coarse texture. Season to taste.
Once the pastry has firmed up in the fridge, brush it with the beaten egg and transfer to the oven. Cook for 30-35 minutes at 200°C/gas mark 5, until the pastry is golden and the goat's cheese has browned. Serve warm with the pea pesto.