We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
output/hydra.yaml is wrong
hydra.yaml in output directory is malformed (not rooted at hydra.)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `hydra/plugins/common/utils.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
2 
3 import copy
4 import logging
5 import os
6 import re
7 import sys
8 from time import strftime, localtime
9 
10 import six
11 from omegaconf import OmegaConf, DictConfig
12 
13 # pylint: disable=C0103
14 log = logging.getLogger(__name__)
15 
16 
17 def configure_log(log_config, verbose=None):
18     if log_config is not None:
19         conf = log_config.to_container(resolve=True)
20         logging.config.dictConfig(conf)
21     else:
22         # default logging to stdout
23         root = logging.getLogger()
24         root.setLevel(logging.INFO)
25         handler = logging.StreamHandler(sys.stdout)
26         formatter = logging.Formatter(
27             "[%(asctime)s][%(name)s][%(levelname)s] - %(message)s"
28         )
29         handler.setFormatter(formatter)
30         root.addHandler(handler)
31 
32     if verbose is not None:
33         if verbose == "root":
34             logging.getLogger().setLevel(logging.DEBUG)
35         for logger in verbose.split(","):
36             logging.getLogger(logger).setLevel(logging.DEBUG)
37 
38 
39 def save_config(cfg, filename):
40     with open(os.path.join(filename), "w") as file:
41         file.write(cfg.pretty())
42 
43 
44 def get_overrides_dirname(lst, exclude_keys=[]):
45     lst = [x for x in lst if x not in exclude_keys]
46     lst.sort()
47     return re.sub(pattern="[=]", repl="=", string=",".join(lst))
48 
49 
50 def filter_overrides(overrides):
51     """
52     :param overrides: overrides list
53     :return: returning a new overrides list with all the keys starting with hydra. fitlered.
54     """
55     return [x for x in overrides if not x.startswith("hydra.")]
56 
57 
58 def run_job(config, task_function, verbose, job_dir_key, job_subdir_key):
59     old_cwd = os.getcwd()
60     working_dir = str(config.select(job_dir_key))
61     if job_subdir_key is not None:
62         # evaluate job_subdir_key lazily.
63         # this is running on the client side in sweep and contains things such as job:id which
64         # are only available there.
65         subdir = str(config.select(job_subdir_key))
66         working_dir = os.path.join(working_dir, subdir)
67     try:
68         ret = JobReturn()
69         ret.working_dir = working_dir
70         task_cfg = copy.deepcopy(config)
71         hydra_cfg = task_cfg["hydra"]
72         del task_cfg["hydra"]
73         ret.cfg = task_cfg
74         ret.hydra_cfg = copy.deepcopy(HydraConfig())
75         ret.overrides = config.hydra.overrides.task.to_container()
76         if not os.path.exists(working_dir):
77             os.makedirs(working_dir)
78         os.chdir(working_dir)
79         configure_log(config.hydra.job_logging, verbose)
80 
81         save_config(task_cfg, "config.yaml")
82         save_config(hydra_cfg, "hydra.yaml")
83         save_config(config.hydra.overrides.task, "overrides.yaml")
84         ret.return_value = task_function(task_cfg)
85         ret.task_name = JobRuntime().get("name")
86         return ret
87     finally:
88         os.chdir(old_cwd)
89 
90 
91 def get_valid_filename(s):
92     s = str(s).strip().replace(" ", "_")
93     return re.sub(r"(?u)[^-\w.]", "", s)
94 
95 
96 def setup_globals():
97     try:
98         OmegaConf.register_resolver(
99             "now", lambda pattern: strftime(pattern, localtime())
100         )
101 
102         def job_error(x):
103             raise Exception(
104                 "job:{} is no longer available. use hydra.job.{}".format(x, x)
105             )
106 
107         OmegaConf.register_resolver("job", job_error)
108 
109     except AssertionError:
110         # calling it again in no_workers mode will throw. safe to ignore.
111         pass
112 
113 
114 class JobReturn:
115     def __init__(self):
116         self.overrides = None
117         self.return_value = None
118         self.cfg = None
119         self.hydra_cfg = None
120         self.working_dir = None
121         self.task_name = None
122 
123 
124 class Singleton(type):
125     _instances = {}
126 
127     def __call__(cls, *args, **kwargs):
128         if cls not in cls._instances:
129             cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
130         return cls._instances[cls]
131 
132     @staticmethod
133     def get_state():
134         return Singleton._instances
135 
136     @staticmethod
137     def set_state(instances):
138         Singleton._instances = instances
139 
140 
141 @six.add_metaclass(Singleton)
142 class JobRuntime:
143     def __init__(self):
144         self.conf = OmegaConf.create()
145         self.set("name", "UNKNOWN_NAME")
146 
147     def get(self, key):
148         ret = self.conf.select(key)
149         if ret is None:
150             raise KeyError("Key not found in {}: {}".format(type(self).__name__, key))
151         return ret
152 
153     def set(self, key, value):
154         log.debug("Setting {}:{}={}".format(type(self).__name__, key, value))
155         self.conf[key] = value
156 
157 
158 @six.add_metaclass(Singleton)
159 class HydraConfig(DictConfig):
160     def __init__(self):
161         super(HydraConfig, self).__init__(content={})
162         self.hydra = None
163 
164     def set_config(self, cfg):
165         try:
166             OmegaConf.set_readonly(self, False)
167             self.hydra = copy.deepcopy(cfg.hydra)
168         finally:
169             OmegaConf.set_readonly(self, True)
170
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/hydra/plugins/common/utils.py b/hydra/plugins/common/utils.py
--- a/hydra/plugins/common/utils.py
+++ b/hydra/plugins/common/utils.py
@@ -68,7 +68,8 @@
         ret = JobReturn()
         ret.working_dir = working_dir
         task_cfg = copy.deepcopy(config)
-        hydra_cfg = task_cfg["hydra"]
+        # TODO: update this after https://github.com/omry/omegaconf/issues/42 is resolved
+        hydra_cfg = OmegaConf.create({"hydra": task_cfg["hydra"]});
         del task_cfg["hydra"]
         ret.cfg = task_cfg
         ret.hydra_cfg = copy.deepcopy(HydraConfig())

{"golden_diff": "diff --git a/hydra/plugins/common/utils.py b/hydra/plugins/common/utils.py\n--- a/hydra/plugins/common/utils.py\n+++ b/hydra/plugins/common/utils.py\n@@ -68,7 +68,8 @@\n         ret = JobReturn()\n         ret.working_dir = working_dir\n         task_cfg = copy.deepcopy(config)\n-        hydra_cfg = task_cfg[\"hydra\"]\n+        # TODO: update this after https://github.com/omry/omegaconf/issues/42 is resolved\n+        hydra_cfg = OmegaConf.create({\"hydra\": task_cfg[\"hydra\"]});\n         del task_cfg[\"hydra\"]\n         ret.cfg = task_cfg\n         ret.hydra_cfg = copy.deepcopy(HydraConfig())\n", "issue": "output/hydra.yaml is wrong\nhydra.yaml in output directory is malformed (not rooted at hydra.)\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\nimport copy\nimport logging\nimport os\nimport re\nimport sys\nfrom time import strftime, localtime\n\nimport six\nfrom omegaconf import OmegaConf, DictConfig\n\n# pylint: disable=C0103\nlog = logging.getLogger(__name__)\n\n\ndef configure_log(log_config, verbose=None):\n    if log_config is not None:\n        conf = log_config.to_container(resolve=True)\n        logging.config.dictConfig(conf)\n    else:\n        # default logging to stdout\n        root = logging.getLogger()\n        root.setLevel(logging.INFO)\n        handler = logging.StreamHandler(sys.stdout)\n        formatter = logging.Formatter(\n            \"[%(asctime)s][%(name)s][%(levelname)s] - %(message)s\"\n        )\n        handler.setFormatter(formatter)\n        root.addHandler(handler)\n\n    if verbose is not None:\n        if verbose == \"root\":\n            logging.getLogger().setLevel(logging.DEBUG)\n        for logger in verbose.split(\",\"):\n            logging.getLogger(logger).setLevel(logging.DEBUG)\n\n\ndef save_config(cfg, filename):\n    with open(os.path.join(filename), \"w\") as file:\n        file.write(cfg.pretty())\n\n\ndef get_overrides_dirname(lst, exclude_keys=[]):\n    lst = [x for x in lst if x not in exclude_keys]\n    lst.sort()\n    return re.sub(pattern=\"[=]\", repl=\"=\", string=\",\".join(lst))\n\n\ndef filter_overrides(overrides):\n    \"\"\"\n    :param overrides: overrides list\n    :return: returning a new overrides list with all the keys starting with hydra. fitlered.\n    \"\"\"\n    return [x for x in overrides if not x.startswith(\"hydra.\")]\n\n\ndef run_job(config, task_function, verbose, job_dir_key, job_subdir_key):\n    old_cwd = os.getcwd()\n    working_dir = str(config.select(job_dir_key))\n    if job_subdir_key is not None:\n        # evaluate job_subdir_key lazily.\n        # this is running on the client side in sweep and contains things such as job:id which\n        # are only available there.\n        subdir = str(config.select(job_subdir_key))\n        working_dir = os.path.join(working_dir, subdir)\n    try:\n        ret = JobReturn()\n        ret.working_dir = working_dir\n        task_cfg = copy.deepcopy(config)\n        hydra_cfg = task_cfg[\"hydra\"]\n        del task_cfg[\"hydra\"]\n        ret.cfg = task_cfg\n        ret.hydra_cfg = copy.deepcopy(HydraConfig())\n        ret.overrides = config.hydra.overrides.task.to_container()\n        if not os.path.exists(working_dir):\n            os.makedirs(working_dir)\n        os.chdir(working_dir)\n        configure_log(config.hydra.job_logging, verbose)\n\n        save_config(task_cfg, \"config.yaml\")\n        save_config(hydra_cfg, \"hydra.yaml\")\n        save_config(config.hydra.overrides.task, \"overrides.yaml\")\n        ret.return_value = task_function(task_cfg)\n        ret.task_name = JobRuntime().get(\"name\")\n        return ret\n    finally:\n        os.chdir(old_cwd)\n\n\ndef get_valid_filename(s):\n    s = str(s).strip().replace(\" \", \"_\")\n    return re.sub(r\"(?u)[^-\\w.]\", \"\", s)\n\n\ndef setup_globals():\n    try:\n        OmegaConf.register_resolver(\n            \"now\", lambda pattern: strftime(pattern, localtime())\n        )\n\n        def job_error(x):\n            raise Exception(\n                \"job:{} is no longer available. use hydra.job.{}\".format(x, x)\n            )\n\n        OmegaConf.register_resolver(\"job\", job_error)\n\n    except AssertionError:\n        # calling it again in no_workers mode will throw. safe to ignore.\n        pass\n\n\nclass JobReturn:\n    def __init__(self):\n        self.overrides = None\n        self.return_value = None\n        self.cfg = None\n        self.hydra_cfg = None\n        self.working_dir = None\n        self.task_name = None\n\n\nclass Singleton(type):\n    _instances = {}\n\n    def __call__(cls, *args, **kwargs):\n        if cls not in cls._instances:\n            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)\n        return cls._instances[cls]\n\n    @staticmethod\n    def get_state():\n        return Singleton._instances\n\n    @staticmethod\n    def set_state(instances):\n        Singleton._instances = instances\n\n\n@six.add_metaclass(Singleton)\nclass JobRuntime:\n    def __init__(self):\n        self.conf = OmegaConf.create()\n        self.set(\"name\", \"UNKNOWN_NAME\")\n\n    def get(self, key):\n        ret = self.conf.select(key)\n        if ret is None:\n            raise KeyError(\"Key not found in {}: {}\".format(type(self).__name__, key))\n        return ret\n\n    def set(self, key, value):\n        log.debug(\"Setting {}:{}={}\".format(type(self).__name__, key, value))\n        self.conf[key] = value\n\n\n@six.add_metaclass(Singleton)\nclass HydraConfig(DictConfig):\n    def __init__(self):\n        super(HydraConfig, self).__init__(content={})\n        self.hydra = None\n\n    def set_config(self, cfg):\n        try:\n            OmegaConf.set_readonly(self, False)\n            self.hydra = copy.deepcopy(cfg.hydra)\n        finally:\n            OmegaConf.set_readonly(self, True)\n", "path": "hydra/plugins/common/utils.py"}], "after_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved\n\nimport copy\nimport logging\nimport os\nimport re\nimport sys\nfrom time import strftime, localtime\n\nimport six\nfrom omegaconf import OmegaConf, DictConfig\n\n# pylint: disable=C0103\nlog = logging.getLogger(__name__)\n\n\ndef configure_log(log_config, verbose=None):\n    if log_config is not None:\n        conf = log_config.to_container(resolve=True)\n        logging.config.dictConfig(conf)\n    else:\n        # default logging to stdout\n        root = logging.getLogger()\n        root.setLevel(logging.INFO)\n        handler = logging.StreamHandler(sys.stdout)\n        formatter = logging.Formatter(\n            \"[%(asctime)s][%(name)s][%(levelname)s] - %(message)s\"\n        )\n        handler.setFormatter(formatter)\n        root.addHandler(handler)\n\n    if verbose is not None:\n        if verbose == \"root\":\n            logging.getLogger().setLevel(logging.DEBUG)\n        for logger in verbose.split(\",\"):\n            logging.getLogger(logger).setLevel(logging.DEBUG)\n\n\ndef save_config(cfg, filename):\n    with open(os.path.join(filename), \"w\") as file:\n        file.write(cfg.pretty())\n\n\ndef get_overrides_dirname(lst, exclude_keys=[]):\n    lst = [x for x in lst if x not in exclude_keys]\n    lst.sort()\n    return re.sub(pattern=\"[=]\", repl=\"=\", string=\",\".join(lst))\n\n\ndef filter_overrides(overrides):\n    \"\"\"\n    :param overrides: overrides list\n    :return: returning a new overrides list with all the keys starting with hydra. fitlered.\n    \"\"\"\n    return [x for x in overrides if not x.startswith(\"hydra.\")]\n\n\ndef run_job(config, task_function, verbose, job_dir_key, job_subdir_key):\n    old_cwd = os.getcwd()\n    working_dir = str(config.select(job_dir_key))\n    if job_subdir_key is not None:\n        # evaluate job_subdir_key lazily.\n        # this is running on the client side in sweep and contains things such as job:id which\n        # are only available there.\n        subdir = str(config.select(job_subdir_key))\n        working_dir = os.path.join(working_dir, subdir)\n    try:\n        ret = JobReturn()\n        ret.working_dir = working_dir\n        task_cfg = copy.deepcopy(config)\n        # TODO: update this after https://github.com/omry/omegaconf/issues/42 is resolved\n        hydra_cfg = OmegaConf.create({\"hydra\": task_cfg[\"hydra\"]});\n        del task_cfg[\"hydra\"]\n        ret.cfg = task_cfg\n        ret.hydra_cfg = copy.deepcopy(HydraConfig())\n        ret.overrides = config.hydra.overrides.task.to_container()\n        if not os.path.exists(working_dir):\n            os.makedirs(working_dir)\n        os.chdir(working_dir)\n        configure_log(config.hydra.job_logging, verbose)\n\n        save_config(task_cfg, \"config.yaml\")\n        save_config(hydra_cfg, \"hydra.yaml\")\n        save_config(config.hydra.overrides.task, \"overrides.yaml\")\n        ret.return_value = task_function(task_cfg)\n        ret.task_name = JobRuntime().get(\"name\")\n        return ret\n    finally:\n        os.chdir(old_cwd)\n\n\ndef get_valid_filename(s):\n    s = str(s).strip().replace(\" \", \"_\")\n    return re.sub(r\"(?u)[^-\\w.]\", \"\", s)\n\n\ndef setup_globals():\n    try:\n        OmegaConf.register_resolver(\n            \"now\", lambda pattern: strftime(pattern, localtime())\n        )\n\n        def job_error(x):\n            raise Exception(\n                \"job:{} is no longer available. use hydra.job.{}\".format(x, x)\n            )\n\n        OmegaConf.register_resolver(\"job\", job_error)\n\n    except AssertionError:\n        # calling it again in no_workers mode will throw. safe to ignore.\n        pass\n\n\nclass JobReturn:\n    def __init__(self):\n        self.overrides = None\n        self.return_value = None\n        self.cfg = None\n        self.hydra_cfg = None\n        self.working_dir = None\n        self.task_name = None\n\n\nclass Singleton(type):\n    _instances = {}\n\n    def __call__(cls, *args, **kwargs):\n        if cls not in cls._instances:\n            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)\n        return cls._instances[cls]\n\n    @staticmethod\n    def get_state():\n        return Singleton._instances\n\n    @staticmethod\n    def set_state(instances):\n        Singleton._instances = instances\n\n\n@six.add_metaclass(Singleton)\nclass JobRuntime:\n    def __init__(self):\n        self.conf = OmegaConf.create()\n        self.set(\"name\", \"UNKNOWN_NAME\")\n\n    def get(self, key):\n        ret = self.conf.select(key)\n        if ret is None:\n            raise KeyError(\"Key not found in {}: {}\".format(type(self).__name__, key))\n        return ret\n\n    def set(self, key, value):\n        log.debug(\"Setting {}:{}={}\".format(type(self).__name__, key, value))\n        self.conf[key] = value\n\n\n@six.add_metaclass(Singleton)\nclass HydraConfig(DictConfig):\n    def __init__(self):\n        super(HydraConfig, self).__init__(content={})\n        self.hydra = None\n\n    def set_config(self, cfg):\n        try:\n            OmegaConf.set_readonly(self, False)\n            self.hydra = copy.deepcopy(cfg.hydra)\n        finally:\n            OmegaConf.set_readonly(self, True)\n", "path": "hydra/plugins/common/utils.py"}]}