Put the chicken in a large pan with the carrots, potatoes, celery, half the thyme and seasoning. Add stock and bring to the boil. Reduce heat, cover and cook gently for 15 minutes. Set a colander over a large bowl, pour in the pan contents and remove thyme. Reserve 600ml/1 pint stock (rest can be frozen).
Rinse the pan, return to heat and melt the butter. Cook the onions until soft, about 5 minutes. Stir in the flour, then the reserved stock a little at a time, to make a smooth thick sauce. Add the milk and simmer for 2 minutes. Off the heat, stir in the remaining thyme, lemon juice and parsley. Season.
Mix together the chicken, vegetables and ham in a deep 2.2litre/4 pint ovenproof dish, preferably with a rim or lip. Pour over the sauce and leave to cool slightly. Preheat the oven to 200C/gas 6/fan 180C.
Roll out the pastry to about 5cm/2in larger than the top of the dish. Cut a 2.5cm/1in strip from all round the pastry. Brush the rim of the dish with egg and press the strip all round. Brush with egg and lift the pastry on to it, pressing the edges to seal thoroughly. Trim off excess, then mark the pastry edge all round with a fork. Make 4 small slits in the centre. Brush with egg and bake for 25–30 minutes until crisp and golden.