Trim the beans and cut them into 1 1/2 inch pieces, slice the mushrooms 1/4 inch thick, and mince the shallot and garlic. Heat the oven to 350°F with the rack in the middle, grease the 9x13-inch baking dish lightly, and bring 3 quarts of water with 1 tablespoon of kosher salt to a rolling boil. Set up an ice bath with 4 cups of ice and 4 cups of cold water.
Boil the green beans for 4 minutes, until bright green and slightly bendy with some resistance.
Move the beans to the ice water for 2 minutes, then drain and roll them in a clean kitchen towel until cool and dry.
Melt the butter in the skillet over medium high heat. Cook the mushrooms in one layer for 8 to 10 minutes, stirring every 2 minutes, until the pan looks dry and the edges are deep brown.
Add the shallot and cook for 2 minutes until soft and translucent. Add the garlic and thyme and cook for 30 seconds until fragrant.
Sprinkle the flour over the mushrooms and stir constantly for 1 minute, until pasty with no dry flour and lightly toasty.
Pour in the broth slowly while whisking, add the half-and-half, and simmer gently for 3 to 4 minutes, until the sauce coats a spoon and leaves a clear line when a finger is dragged across it.
Take the skillet off the heat and stir in the salt, pepper, nutmeg, and lemon juice. Taste the sauce, which should seem slightly too salty on its own, and look for a glossy, smooth finish.
Fold in the beans and 1/2 cup of the fried onions, spread in the baking dish, and bake uncovered at 350°F for 25 minutes, until the edges bubble and the center steams.
Scatter the remaining 1 1/2 cups of fried onions on top and bake for 5 to 8 minutes, until deep golden and toasty, not dark brown.
Rest the casserole for 5 minutes, until the sauce stops sloshing when you tilt the dish.