DocumentSourceQuerySettings still uses boost::dynamic_pointer_cast<exec::agg::Stage>. This cast might start to fail when we split the relevant stages into QO and QE classes.
Since DocumentSourceQuerySettings is creating a QO stage from scratch, the most fitting way would be to use the existing exec::agg::buildStage() function to construct the QE counterpart instead of trying to cast.
In addition, we need to clarify with QuerySettings team why the stage is created dynamically, and not during query optimization.