Preheat the oven to 160°C/325°F/Gas mark 3. Heat a heavy-based casserole dish with a lid on the hob. Add one tablespoon of the oil and as soon as it starts smoking, tip in the beef. Quickly brown on all sides, then transfer to a plate with a slotted spoon and set aside.
Add another tablespoon of oil to the pan, tip in the onions and cook for about 5 minutes until lightly golden, stirring occasionally. Stir in the thyme and cook for another minute, stirring. Sprinkle in the flour and continue to cook over a low heat for another minute or so, stirring constantly.
Gradually pour in the Guinness or stout, stirring until smooth after each addition. Pour in the stock, stirring to combine and season lightly, then add the sugar and vinegar. Bring to the boil, then remove from the heat and tip the reserved beef, mixing well to combine. Cover with a lid and transfer to the oven and cook for 1 hour until the beef is almost tender and the liquid has reduced and slightly thickened.
Meanwhile, cook the potatoes in a large pan of . salted water. Bring to the boil, then reduce the heat and simmer for 10 minutes until the potatoes are just starting to soften but are not cooked through. Drain, then quickly cool under cold running water then peel before coarsely grating the flesh. Set aside until needed.
Sprinkle the reserved grated potato over the beef stew and drizzle with the remaining tablespoon of oil, then dot with the butter. Return the pie to the oven for 30 minutes until the potato crust is nice and crispy. Serve straight to the table.