Only mark environment loaded after load_config

Copy of #1033 to fix the same issue on master.