Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skills dialog sample fails with RuntimeError: Timeout context manager should be used inside a task #3933

Closed
Fuehnix opened this issue Dec 13, 2023 · 5 comments · Fixed by microsoft/botbuilder-python#2110
Assignees
Labels
Area: Skills The issue is related to skills bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. python Issues or PR's that update Python code

Comments

@Fuehnix
Copy link

Fuehnix commented Dec 13, 2023

Sample information

  1. Sample type: samples
  2. Sample language: python
  3. Sample name: 81.skills-skilldialog

Describe the bug

Bot encounters an error after sending a message about what action # to send.
"RuntimeError: Timeout context manager should be used inside a task"

To Reproduce

Steps to reproduce the behavior:

$ python -m venv venv
$ source venv/bin/activate
$ python --version
Python 3.10.11
$ pip install --upgrade pip
$ cd 81.skills-skilldialog/dialog-root-bot
$ pip install -r requirements.txt

In a separate terminal...

$ cd 81.skills-skilldialog/dialog-skills-bot
$ pip install -r requirements.txt

Then in each terminal,

$ python app.py

dialog-skill-bot will run with:

======== Running on http://localhost:39783 ========

dialog-root-bot will run with:

======== Running on http://localhost:3978 ========
(Press CTRL+C to quit)
LoggerMiddleware conversationUpdate None
LoggerMiddleware message None
LoggerMiddleware message What skill would you like to call?
LoggerMiddleware trace None

Loading into Bot Framework Emulator with http://localhost:3978/api/messages, it works.
But then you select DialogSkillBot and try to provide an action # and it will fail

Here is the stack trace:

======== Running on http://localhost:3978 ========
(Press CTRL+C to quit)
LoggerMiddleware conversationUpdate None
LoggerMiddleware message None
LoggerMiddleware message What skill would you like to call?
LoggerMiddleware trace None
LoggerMiddleware message DialogSkillBot
LoggerMiddleware message Select an action # to send to **DialogSkillBot** or just type in a message and it will be forwarded to the skill

   1. BookFlight
   2. BookFlight with input parameters
   3. GetWeather
LoggerMiddleware trace None
LoggerMiddleware message 1

 [on_turn_error] unhandled error: Timeout context manager should be used inside a task
Traceback (most recent call last):
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\bot_adapter.py", line 174, in run_pipeline
    return await self._middleware.receive_activity_with_status(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 69, in receive_activity_with_status
    return await self.receive_activity_internal(context, callback)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 91, in receive_activity_internal
    raise error
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 89, in receive_activity_internal
    return await next_middleware.on_turn(context, call_next_middleware)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\middleware\logger_middleware.py", line 35, in on_turn
    await logic()
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 84, in call_next_middleware
    return await self.receive_activity_internal(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 79, in receive_activity_internal
    return await callback(context)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\bots\root_bot.py", line 26, in on_turn
    await DialogExtensions.run_dialog(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_extensions.py", line 40, in run_dialog
    await DialogExtensions._internal_run(turn_context, dialog.id, dialog_context)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_extensions.py", line 65, in _internal_run
    dialog_turn_result = await DialogExtensions.__inner_run(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_extensions.py", line 117, in __inner_run
    result = await dialog_context.continue_dialog()
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 167, in continue_dialog
    return await dialog.continue_dialog(self)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\component_dialog.py", line 105, in continue_dialog
    turn_result = await self.on_continue_dialog(inner_dc)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\dialogs\main_dialog.py", line 127, in on_continue_dialog
    return await super().on_continue_dialog(inner_dc)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\component_dialog.py", line 230, in on_continue_dialog
    return await inner_dc.continue_dialog()
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 167, in continue_dialog
    return await dialog.continue_dialog(self)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\prompts\prompt.py", line 146, in continue_dialog
    return await dialog_context.end_dialog(recognized.value)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 202, in end_dialog
    return await dialog.resume_dialog(self, DialogReason.EndCalled, result)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\waterfall_dialog.py", line 96, in resume_dialog
    return await self.run_step(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\waterfall_dialog.py", line 154, in run_step
    return await self.on_step(step_context)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\waterfall_dialog.py", line 130, in on_step
    return await self._steps[step_context.index](step_context)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\dialogs\main_dialog.py", line 209, in _call_skill_action_step
    return await step_context.begin_dialog(selected_skill.id, skill_dialog_args)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 121, in begin_dialog
    return await dialog.begin_dialog(self, options)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\skills\skill_dialog.py", line 76, in begin_dialog
    eoc_activity = await self._send_to_skill(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\skills\skill_dialog.py", line 207, in _send_to_skill
    response = await self.dialog_options.skill_client.post_activity(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\bot_framework_http_client.py", line 105, in post_activity       
    status, content = await self._post_content(to_url, token, activity)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\bot_framework_http_client.py", line 130, in _post_content       
    resp = await self._session.post(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\aiohttp\client.py", line 467, in _request
    with timer:
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\aiohttp\helpers.py", line 701, in __enter__
    raise RuntimeError(
RuntimeError: Timeout context manager should be used inside a task
LoggerMiddleware message The bot encountered an error or bug.
LoggerMiddleware message To continue to run this bot, please fix the bot source code.
LoggerMiddleware trace None
Datetime with no tzinfo will be considered UTC.

 Exception caught on _end_skill_conversation : Timeout context manager should be used inside a task
Traceback (most recent call last):
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\bot_adapter.py", line 174, in run_pipeline
    return await self._middleware.receive_activity_with_status(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 69, in receive_activity_with_status
    return await self.receive_activity_internal(context, callback)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 91, in receive_activity_internal
    raise error
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 89, in receive_activity_internal
    return await next_middleware.on_turn(context, call_next_middleware)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\middleware\logger_middleware.py", line 35, in on_turn
    await logic()
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 84, in call_next_middleware
    return await self.receive_activity_internal(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\core\middleware_set.py", line 79, in receive_activity_internal
    return await callback(context)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\bots\root_bot.py", line 26, in on_turn
    await DialogExtensions.run_dialog(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_extensions.py", line 40, in run_dialog
    await DialogExtensions._internal_run(turn_context, dialog.id, dialog_context)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_extensions.py", line 65, in _internal_run
    dialog_turn_result = await DialogExtensions.__inner_run(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_extensions.py", line 117, in __inner_run
    result = await dialog_context.continue_dialog()
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 167, in continue_dialog
    return await dialog.continue_dialog(self)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\component_dialog.py", line 105, in continue_dialog
    turn_result = await self.on_continue_dialog(inner_dc)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\dialogs\main_dialog.py", line 127, in on_continue_dialog
    return await super().on_continue_dialog(inner_dc)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\component_dialog.py", line 230, in on_continue_dialog
    return await inner_dc.continue_dialog()
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 167, in continue_dialog
    return await dialog.continue_dialog(self)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\prompts\prompt.py", line 146, in continue_dialog
    return await dialog_context.end_dialog(recognized.value)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 202, in end_dialog
    return await dialog.resume_dialog(self, DialogReason.EndCalled, result)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\waterfall_dialog.py", line 96, in resume_dialog
    return await self.run_step(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\waterfall_dialog.py", line 154, in run_step
    return await self.on_step(step_context)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\waterfall_dialog.py", line 130, in on_step
    return await self._steps[step_context.index](step_context)
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\dialogs\main_dialog.py", line 209, in _call_skill_action_step
    return await step_context.begin_dialog(selected_skill.id, skill_dialog_args)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\dialog_context.py", line 121, in begin_dialog
    return await dialog.begin_dialog(self, options)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\skills\skill_dialog.py", line 76, in begin_dialog
    eoc_activity = await self._send_to_skill(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\dialogs\skills\skill_dialog.py", line 207, in _send_to_skill
    response = await self.dialog_options.skill_client.post_activity(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\bot_framework_http_client.py", line 105, in post_activity       
    status, content = await self._post_content(to_url, token, activity)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\bot_framework_http_client.py", line 130, in _post_content       
    resp = await self._session.post(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\aiohttp\client.py", line 467, in _request
    with timer:
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\aiohttp\helpers.py", line 701, in __enter__
    raise RuntimeError(
RuntimeError: Timeout context manager should be used inside a task

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "\BotBuilder-Samples-main\samples\python\81.skills-skilldialog\dialog-root-bot\adapter_with_error_handler.py", line 113, in _end_skill_conversation
    await self._skill_client.post_activity_to_skill(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\skills\skill_http_client.py", line 69, in post_activity_to_skill
    return await super().post_activity(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\bot_framework_http_client.py", line 105, in post_activity       
    status, content = await self._post_content(to_url, token, activity)
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\botbuilder\integration\aiohttp\bot_framework_http_client.py", line 130, in _post_content       
    resp = await self._session.post(
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\aiohttp\client.py", line 467, in _request
    with timer:
  File "\BotBuilder-Samples-main\samples\python\venv\lib\site-packages\aiohttp\helpers.py", line 701, in __enter__
    raise RuntimeError(
RuntimeError: Timeout context manager should be used inside a task

Expected behavior

The dialog should have continued, or at least returned a message saying it didn't recognize the action given.

Screenshots

image
@Fuehnix Fuehnix added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Dec 13, 2023
@jpiabrantes
Copy link

I'm also seeing this error on the sample 80.skills-simple-bot-to-bot.

@jpiabrantes
Copy link

It looks like the problem was on /botbuilder/integration/aiohttp/bot_framework_http_client.py, and that self._session was not initiated on an async coroutine.

Instead of calling self._session.post we can call session.post() like this:

        async with aiohttp.ClientSession() as session:
            resp = await session.post(to_url, data=json_content.encode("utf-8"), headers=headers_dict,)

Note: we need to make post async too.

But then I get another error on /botbuilder/core/skills/_skill_handler_impl.py

where we call self._adapter.continue_conversation with the wrong arguments.

        await self._adapter.continue_conversation(
            skill_conversation_reference.conversation_reference,
            callback,
            claims_identity=claims_identity,
            audience=skill_conversation_reference.oauth_scope,
        )

Note that continue_conversation has no "claims_identity" argument.

    async def continue_conversation(  # pylint: disable=arguments-differ
        self,
        reference: ConversationReference,
        callback: Callable,
        bot_app_id: str,
    ):

I gave up at this point, it seems that the library is not being tested or maintained ?

@tracyboehrer tracyboehrer self-assigned this Feb 1, 2024
@KirannBhavaraju
Copy link

KirannBhavaraju commented Feb 8, 2024

+1

is there any update regarding this? maybe a ccommit we can work off of?

@tracyboehrer tracyboehrer added Area: Skills The issue is related to skills python Issues or PR's that update Python code labels Apr 30, 2024
@javeria-geek
Copy link

I am facing same issue on the sample 80.skills-simple-bot-to-bot.
Is there any update ?

@tracyboehrer
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Skills The issue is related to skills bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. python Issues or PR's that update Python code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants