prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Messenger - qa_data_collection task 
  Running the messenger qa_data_collection task, it gives me te following error:
  Exception in user code:
  Traceback (most recent call last):
    File "/home/micol/PycharmProjects/parlai_project/ParlAI/parlai/messenger/core/messenger_manager.py", line 552, in _task_function
      task_functions[world_type](self, opt, agents, conversation_id)
    File "run.py", line 45, in run_conversation
      task = task_class(task_opt)
    File "/home/micol/PycharmProjects/parlai_project/ParlAI/parlai/tasks/squad/agents.py", line 114, in __init__
      build(opt)
    File "/home/micol/PycharmProjects/parlai_project/ParlAI/parlai/tasks/squad/build.py", line 35, in build
      if 'fulldoc' in opt['task']:
  KeyError: 'task'
  "Facebook response from message send: {'recipient_id': '2172740222785536', 'message_id': 'm_rDniDdXXKp9KY2DDR7nYxf46FEm_jG446gMYoyCBkXQ1qs8d7VUug8eG31SNJbRdWO5T8BAyL5R4_1-p3tHWVQ'}"
  Message data received: {'object': 'page', 'entry': [{'id': '336760520259323', 'time': 1546939725227, 'messaging': [{'sender': {'id': '336760520259323'}, 'recipient': {'id': '2172740222785536'}, 'timestamp': 1546939724784, 'message': {'is_echo': True, 'app_id': 322301978494112, 'mid': 'rDniDdXXKp9KY2DDR7nYxf46FEm_jG446gMYoyCBkXQ1qs8d7VUug8eG31SNJbRdWO5T8BAyL5R4_1-p3tHWVQ', 'seq': 32111, 'text': 'Sorry, this world closed. Returning to overworld.'}}]}]}
  Message data received: {'object': 'page', 'entry': [{'id': '336760520259323', 'time': 1546939725478, 'messaging': [{'sender': {'id': '2172740222785536'}, 'recipient': {'id': '336760520259323'}, 'timestamp': 1546939725466, 'delivery': {'mids': ['rDniDdXXKp9KY2DDR7nYxf46FEm_jG446gMYoyCBkXQ1qs8d7VUug8eG31SNJbRdWO5T8BAyL5R4_1-p3tHWVQ'], 'watermark': 1546939724784, 'seq': 0}}]}]}
   
  What is the possible solution?
  
  Thank you
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `parlai/messenger/tasks/qa_data_collection/run.py`
  Content:
  ```
  1 #!/usr/bin/env python3
  2 
  3 # Copyright (c) 2017-present, Facebook, Inc.
  4 # All rights reserved.
  5 # This source code is licensed under the BSD-style license found in the
  6 # LICENSE file in the root directory of this source tree. An additional grant
  7 # of patent rights can be found in the PATENTS file in the same directory.
  8 from parlai.core.params import ParlaiParser
  9 from parlai.messenger.tasks.qa_data_collection.worlds import \
  10     QADataCollectionWorld
  11 from parlai.messenger.core.messenger_manager import MessengerManager
  12 from parlai.messenger.core.worlds import SimpleMessengerOverworld as \
  13     MessengerOverworld
  14 import os
  15 import importlib
  16 
  17 
  18 def main():
  19     argparser = ParlaiParser(False, False)
  20     argparser.add_parlai_data_path()
  21     argparser.add_messenger_args()
  22     opt = argparser.parse_args()
  23     opt['task'] = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
  24 
  25     # Initialize a SQuAD teacher agent, which we will get context from
  26     module_name = 'parlai.tasks.squad.agents'
  27     class_name = 'DefaultTeacher'
  28     my_module = importlib.import_module(module_name)
  29     task_class = getattr(my_module, class_name)
  30     task_opt = {}
  31     task_opt['datatype'] = 'train'
  32     task_opt['datapath'] = opt['datapath']
  33 
  34     messenger_manager = MessengerManager(opt=opt)
  35     messenger_manager.setup_server()
  36     messenger_manager.init_new_state()
  37 
  38     def get_overworld(opt, agent):
  39         return MessengerOverworld(opt, agent)
  40 
  41     def assign_agent_role(agent):
  42         agent[0].disp_id = 'Agent'
  43 
  44     def run_conversation(manager, opt, agents, task_id):
  45         task = task_class(task_opt)
  46         agent = agents[0]
  47         world = QADataCollectionWorld(
  48             opt=opt,
  49             task=task,
  50             agent=agent
  51         )
  52         while not world.episode_done():
  53             world.parley()
  54         world.shutdown()
  55 
  56     # World with no onboarding
  57     messenger_manager.set_onboard_functions({'default': None})
  58     task_functions = {'default': run_conversation}
  59     assign_agent_roles = {'default': assign_agent_role}
  60     messenger_manager.set_agents_required({'default': 1})
  61 
  62     messenger_manager.set_overworld_func(get_overworld)
  63     messenger_manager.setup_socket()
  64     try:
  65         messenger_manager.start_new_run()
  66         messenger_manager.start_task(
  67             assign_role_functions=assign_agent_roles,
  68             task_functions=task_functions,
  69         )
  70     except BaseException:
  71         raise
  72     finally:
  73         messenger_manager.shutdown()
  74 
  75 
  76 if __name__ == '__main__':
  77     main()
  78
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/parlai/messenger/tasks/qa_data_collection/run.py b/parlai/messenger/tasks/qa_data_collection/run.py
  --- a/parlai/messenger/tasks/qa_data_collection/run.py
  +++ b/parlai/messenger/tasks/qa_data_collection/run.py
  @@ -27,7 +27,7 @@
       class_name = 'DefaultTeacher'
       my_module = importlib.import_module(module_name)
       task_class = getattr(my_module, class_name)
  -    task_opt = {}
  +    task_opt = opt.copy()
       task_opt['datatype'] = 'train'
       task_opt['datapath'] = opt['datapath']
  
verification_info: {"golden_diff": "diff --git a/parlai/messenger/tasks/qa_data_collection/run.py b/parlai/messenger/tasks/qa_data_collection/run.py\n--- a/parlai/messenger/tasks/qa_data_collection/run.py\n+++ b/parlai/messenger/tasks/qa_data_collection/run.py\n@@ -27,7 +27,7 @@\n     class_name = 'DefaultTeacher'\n     my_module = importlib.import_module(module_name)\n     task_class = getattr(my_module, class_name)\n-    task_opt = {}\n+    task_opt = opt.copy()\n     task_opt['datatype'] = 'train'\n     task_opt['datapath'] = opt['datapath']\n", "issue": "Messenger - qa_data_collection task \nRunning the messenger qa_data_collection task, it gives me te following error:\r\nException in user code:\r\nTraceback (most recent call last):\r\n  File \"/home/micol/PycharmProjects/parlai_project/ParlAI/parlai/messenger/core/messenger_manager.py\", line 552, in _task_function\r\n    task_functions[world_type](self, opt, agents, conversation_id)\r\n  File \"run.py\", line 45, in run_conversation\r\n    task = task_class(task_opt)\r\n  File \"/home/micol/PycharmProjects/parlai_project/ParlAI/parlai/tasks/squad/agents.py\", line 114, in __init__\r\n    build(opt)\r\n  File \"/home/micol/PycharmProjects/parlai_project/ParlAI/parlai/tasks/squad/build.py\", line 35, in build\r\n    if 'fulldoc' in opt['task']:\r\nKeyError: 'task'\r\n\"Facebook response from message send: {'recipient_id': '2172740222785536', 'message_id': 'm_rDniDdXXKp9KY2DDR7nYxf46FEm_jG446gMYoyCBkXQ1qs8d7VUug8eG31SNJbRdWO5T8BAyL5R4_1-p3tHWVQ'}\"\r\nMessage data received: {'object': 'page', 'entry': [{'id': '336760520259323', 'time': 1546939725227, 'messaging': [{'sender': {'id': '336760520259323'}, 'recipient': {'id': '2172740222785536'}, 'timestamp': 1546939724784, 'message': {'is_echo': True, 'app_id': 322301978494112, 'mid': 'rDniDdXXKp9KY2DDR7nYxf46FEm_jG446gMYoyCBkXQ1qs8d7VUug8eG31SNJbRdWO5T8BAyL5R4_1-p3tHWVQ', 'seq': 32111, 'text': 'Sorry, this world closed. Returning to overworld.'}}]}]}\r\nMessage data received: {'object': 'page', 'entry': [{'id': '336760520259323', 'time': 1546939725478, 'messaging': [{'sender': {'id': '2172740222785536'}, 'recipient': {'id': '336760520259323'}, 'timestamp': 1546939725466, 'delivery': {'mids': ['rDniDdXXKp9KY2DDR7nYxf46FEm_jG446gMYoyCBkXQ1qs8d7VUug8eG31SNJbRdWO5T8BAyL5R4_1-p3tHWVQ'], 'watermark': 1546939724784, 'seq': 0}}]}]}\r\n \r\nWhat is the possible solution?\r\n\r\nThank you\n", "before_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright (c) 2017-present, Facebook, Inc.\n# All rights reserved.\n# This source code is licensed under the BSD-style license found in the\n# LICENSE file in the root directory of this source tree. An additional grant\n# of patent rights can be found in the PATENTS file in the same directory.\nfrom parlai.core.params import ParlaiParser\nfrom parlai.messenger.tasks.qa_data_collection.worlds import \\\n    QADataCollectionWorld\nfrom parlai.messenger.core.messenger_manager import MessengerManager\nfrom parlai.messenger.core.worlds import SimpleMessengerOverworld as \\\n    MessengerOverworld\nimport os\nimport importlib\n\n\ndef main():\n    argparser = ParlaiParser(False, False)\n    argparser.add_parlai_data_path()\n    argparser.add_messenger_args()\n    opt = argparser.parse_args()\n    opt['task'] = os.path.basename(os.path.dirname(os.path.abspath(__file__)))\n\n    # Initialize a SQuAD teacher agent, which we will get context from\n    module_name = 'parlai.tasks.squad.agents'\n    class_name = 'DefaultTeacher'\n    my_module = importlib.import_module(module_name)\n    task_class = getattr(my_module, class_name)\n    task_opt = {}\n    task_opt['datatype'] = 'train'\n    task_opt['datapath'] = opt['datapath']\n\n    messenger_manager = MessengerManager(opt=opt)\n    messenger_manager.setup_server()\n    messenger_manager.init_new_state()\n\n    def get_overworld(opt, agent):\n        return MessengerOverworld(opt, agent)\n\n    def assign_agent_role(agent):\n        agent[0].disp_id = 'Agent'\n\n    def run_conversation(manager, opt, agents, task_id):\n        task = task_class(task_opt)\n        agent = agents[0]\n        world = QADataCollectionWorld(\n            opt=opt,\n            task=task,\n            agent=agent\n        )\n        while not world.episode_done():\n            world.parley()\n        world.shutdown()\n\n    # World with no onboarding\n    messenger_manager.set_onboard_functions({'default': None})\n    task_functions = {'default': run_conversation}\n    assign_agent_roles = {'default': assign_agent_role}\n    messenger_manager.set_agents_required({'default': 1})\n\n    messenger_manager.set_overworld_func(get_overworld)\n    messenger_manager.setup_socket()\n    try:\n        messenger_manager.start_new_run()\n        messenger_manager.start_task(\n            assign_role_functions=assign_agent_roles,\n            task_functions=task_functions,\n        )\n    except BaseException:\n        raise\n    finally:\n        messenger_manager.shutdown()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "parlai/messenger/tasks/qa_data_collection/run.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright (c) 2017-present, Facebook, Inc.\n# All rights reserved.\n# This source code is licensed under the BSD-style license found in the\n# LICENSE file in the root directory of this source tree. An additional grant\n# of patent rights can be found in the PATENTS file in the same directory.\nfrom parlai.core.params import ParlaiParser\nfrom parlai.messenger.tasks.qa_data_collection.worlds import \\\n    QADataCollectionWorld\nfrom parlai.messenger.core.messenger_manager import MessengerManager\nfrom parlai.messenger.core.worlds import SimpleMessengerOverworld as \\\n    MessengerOverworld\nimport os\nimport importlib\n\n\ndef main():\n    argparser = ParlaiParser(False, False)\n    argparser.add_parlai_data_path()\n    argparser.add_messenger_args()\n    opt = argparser.parse_args()\n    opt['task'] = os.path.basename(os.path.dirname(os.path.abspath(__file__)))\n\n    # Initialize a SQuAD teacher agent, which we will get context from\n    module_name = 'parlai.tasks.squad.agents'\n    class_name = 'DefaultTeacher'\n    my_module = importlib.import_module(module_name)\n    task_class = getattr(my_module, class_name)\n    task_opt = opt.copy()\n    task_opt['datatype'] = 'train'\n    task_opt['datapath'] = opt['datapath']\n\n    messenger_manager = MessengerManager(opt=opt)\n    messenger_manager.setup_server()\n    messenger_manager.init_new_state()\n\n    def get_overworld(opt, agent):\n        return MessengerOverworld(opt, agent)\n\n    def assign_agent_role(agent):\n        agent[0].disp_id = 'Agent'\n\n    def run_conversation(manager, opt, agents, task_id):\n        task = task_class(task_opt)\n        agent = agents[0]\n        world = QADataCollectionWorld(\n            opt=opt,\n            task=task,\n            agent=agent\n        )\n        while not world.episode_done():\n            world.parley()\n        world.shutdown()\n\n    # World with no onboarding\n    messenger_manager.set_onboard_functions({'default': None})\n    task_functions = {'default': run_conversation}\n    assign_agent_roles = {'default': assign_agent_role}\n    messenger_manager.set_agents_required({'default': 1})\n\n    messenger_manager.set_overworld_func(get_overworld)\n    messenger_manager.setup_socket()\n    try:\n        messenger_manager.start_new_run()\n        messenger_manager.start_task(\n            assign_role_functions=assign_agent_roles,\n            task_functions=task_functions,\n        )\n    except BaseException:\n        raise\n    finally:\n        messenger_manager.shutdown()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "parlai/messenger/tasks/qa_data_collection/run.py"}]}