Bring a large pot of salted water to a rolling boil. Add the green beans and cook for 4 minutes until bright green and just barely tender. Transfer immediately to a bowl of ice water for 2 minutes. Drain and pat completely dry.
Preheat oven to 190°C (375°F).
Melt butter in a large oven-safe skillet over medium heat. Add mushrooms in a single layer and cook undisturbed for 4 minutes until golden on the underside. Stir and cook another 2–3 minutes until dry and browned.
Add garlic and cook 1 minute. Add flour and stir to coat, cooking 1 minute. Pour in stock gradually while stirring, then the milk. Add soy sauce, salt, and pepper. Cook 3–4 minutes, stirring, until the sauce coats the back of a spoon.
Remove from heat. Add the dried green beans and two-thirds of the onions (about 100g). Fold to combine. Transfer to a 9x13-inch baking dish if not using an oven-safe skillet.
Bake uncovered for 25 minutes until bubbling at the edges and hot in the centre (internal temperature 74°C / 165°F).
Scatter remaining onions over the top and bake for 5 more minutes until golden and crisp.
Rest 5 minutes before serving.