Heat the oven to 375°F / 190°C. Lightly grease a 9x13-inch (23x33 cm) baking dish or a 3-quart oven dish. (If making ahead, skip preheating — see step 6.)
Blanch the beans: bring a large pot of salted water to the boil, add the beans and cook 3–4 minutes until bright green and just tender-crisp. Drain and plunge into cold water to stop the cooking; drain very well and pat dry.
Make the sauce: melt the butter in a large skillet over medium-high heat. Add the mushrooms and cook 5–6 minutes, stirring occasionally, until they release their liquid and start to brown. Stir in the garlic for 30 seconds.
Sprinkle the flour over the mushrooms and stir for 1 minute. Slowly whisk in the broth, then the milk and cream. Simmer 3–4 minutes, stirring, until the sauce thickens enough to coat the back of a spoon. Stir in the soy sauce if using, pepper, nutmeg and salt to taste.
Combine: fold the drained beans and 1/2 cup of the crispy onions into the sauce until evenly coated. Tip into the prepared dish and level the top.
Bake now: scatter the remaining 2 cups crispy onions evenly over the top and bake 20–25 minutes until bubbling at the edges and the onions are deep golden. Make ahead instead: cover the dish (without the top onions) and refrigerate up to 2 days; on the day, bake covered at 375°F / 190°C for 20 minutes, uncover, add the onions and bake 12–15 minutes more until bubbling and crisp.
Rest 5 minutes before serving — the sauce settles and scoops cleanly. Serve warm.