RasaHQ / rasa-sdk

SDK for the development of custom actions for Rasa
https://rasa.com/docs
Apache License 2.0
291 stars 233 forks source link

Update `rasa-sdk` dependencies to align with those of `rasa` #592

Closed ancalita closed 2 years ago

ancalita commented 2 years ago

Description of Problem:

Installing editable version of rasa-sdk after having installed editable version of rasa in the same venv causes the bot to crash when running rasa shell, full stack trace below:

Bot loaded. Type a message and press enter (use '/stop' to exit): 
2021-11-11 13:26:28 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished name='Task-6' coro=<SignalRouter._dispatch() done, defined at /Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/signals.py:102> exception=RuntimeError('this event loop is already running.') created at /Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/signals.py:165>
source_traceback: Object created at (most recent call last):
  File "/Users/ancalita/rasa-projects/rasa-oss-09/bin/rasa", line 5, in <module>
    main()
  File "/Users/ancalita/rasa-projects/rasa/rasa/__main__.py", line 121, in main
    cmdline_arguments.func(cmdline_arguments)
  File "/Users/ancalita/rasa-projects/rasa/rasa/cli/shell.py", line 125, in shell
    rasa.cli.run.run(args)
  File "/Users/ancalita/rasa-projects/rasa/rasa/cli/run.py", line 126, in run
    rasa.run(**vars(args))
  File "/Users/ancalita/rasa-projects/rasa/rasa/api.py", line 56, in run
    rasa.core.run.serve_application(
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/run.py", line 221, in serve_application
    app.run(
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/app.py", line 1051, in run
    serve_single(server_settings)
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/server/runners.py", line 199, in serve_single
    serve(**server_settings)
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/server/runners.py", line 146, in serve
    loop.run_until_complete(app._server_event("init", "after"))
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/app.py", line 1496, in _server_event
    await self.dispatch(
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/signals.py", line 163, in dispatch
    return await dispatch
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/signals.py", line 133, in _dispatch
    retval = await maybe_coroutine
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/app.py", line 1382, in _listener
    await maybe_coro
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/app.py", line 1368, in dispatch_delayed_tasks
    await app.dispatch(name, context={"app": app, "loop": loop})
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/signals.py", line 165, in dispatch
    task = asyncio.get_running_loop().create_task(dispatch)
Traceback (most recent call last):
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/signals.py", line 133, in _dispatch
    retval = await maybe_coroutine
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/sanic/app.py", line 1374, in run_delayed_task
    await prepped
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/run.py", line 134, in run_cmdline_io
    await console.record_messages(
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/channels/console.py", line 175, in record_messages
    text = _get_user_input(previous_response)
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/channels/console.py", line 108, in _get_user_input
    response = questionary.text(
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/questionary/question.py", line 50, in ask
    return self.unsafe_ask(patch_stdout)
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/questionary/question.py", line 64, in unsafe_ask
    return self.application.run()
  File "/Users/ancalita/rasa-projects/rasa-oss-09/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 890, in run
    return loop.run_until_complete(
  File "uvloop/loop.pyx", line 1450, in uvloop.loop.Loop.run_until_complete
  File "uvloop/loop.pyx", line 1443, in uvloop.loop.Loop.run_until_complete
  File "uvloop/loop.pyx", line 1351, in uvloop.loop.Loop.run_forever
  File "uvloop/loop.pyx", line 480, in uvloop.loop.Loop._run

This forum thread seems to pin the cause of this issue to the version of questionary which I noticed rasa-sdk downgrades from 1.10 to 1.8 when running make install.

Definition of Done:

carlad commented 2 years ago

I'm unable to replicate this issue after following the steps provided in the same virtualenv:

ancalita commented 2 years ago

@carlad So sorry, just saw your q on Python version, I was using python 3.8.6. Related to the dependencies' diff: are you comparing 3.0.x or 2.8.x?

carlad commented 2 years ago

@ancalita

Related to the dependencies' diff: are you comparing 3.0.x or 2.8.x?

I'm doing both, ~though it seems the dependencies are similar...~

ancalita commented 2 years ago

@carlad I'm seeing this issue again just now in a fresh venv with rasa and rasa-sdk installed via make install πŸ™ˆ questionary is version 1.10, and the project I'm using has a custom action defined and runs the actions server in a separate tab too. When you have some time, could you please check with a similar project to see if rasa shell crashes for you too?

(oss-0122) ➜  required_slots_formvalidationaction rasa shell
2022-01-24 16:19:36 INFO     root  - Connecting to channel 'cmdline' which was specified by the '--connector' argument. Any other channels will be ignored. To connect to all given channels, omit the '--connector' argument.
2022-01-24 16:19:36 INFO     root  - Starting Rasa server on http://0.0.0.0:5005
2022-01-24 16:19:37 INFO     rasa.core.processor  - Loading model models/20220124-161441-humid-duplet.tar.gz...
2022-01-24 16:19:50 WARNING  rasa.shared.utils.common  - The UnexpecTED Intent Policy is currently experimental and might change or be removed in the future πŸ”¬ Please share your feedback on it in the forum (https://forum.rasa.com) to help us make this feature ready for production.
2022-01-24 16:19:56 INFO     root  - Rasa server is up and running.
Bot loaded. Type a message and press enter (use '/stop' to exit): 
2022-01-24 16:19:57 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished name='Task-6' coro=<SignalRouter._dispatch() done, defined at /Users/ancalita/rasa-projects/oss-0122/lib/python3.8/site-packages/sanic/signals.py:102> exception=RuntimeError('this event loop is already running.')>
Traceback (most recent call last):
  File "/Users/ancalita/rasa-projects/oss-0122/lib/python3.8/site-packages/sanic/signals.py", line 133, in _dispatch
    retval = await maybe_coroutine
  File "/Users/ancalita/rasa-projects/oss-0122/lib/python3.8/site-packages/sanic/app.py", line 1374, in run_delayed_task
    await prepped
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/run.py", line 134, in run_cmdline_io
    await console.record_messages(
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/channels/console.py", line 175, in record_messages
    text = _get_user_input(previous_response)
  File "/Users/ancalita/rasa-projects/rasa/rasa/core/channels/console.py", line 108, in _get_user_input
    response = questionary.text(
  File "/Users/ancalita/rasa-projects/oss-0122/lib/python3.8/site-packages/questionary/question.py", line 70, in ask
    return self.unsafe_ask(patch_stdout)
  File "/Users/ancalita/rasa-projects/oss-0122/lib/python3.8/site-packages/questionary/question.py", line 92, in unsafe_ask
    return self.application.run()
  File "/Users/ancalita/rasa-projects/oss-0122/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 890, in run
    return loop.run_until_complete(
  File "uvloop/loop.pyx", line 1450, in uvloop.loop.Loop.run_until_complete
  File "uvloop/loop.pyx", line 1443, in uvloop.loop.Loop.run_until_complete
  File "uvloop/loop.pyx", line 1351, in uvloop.loop.Loop.run_forever
  File "uvloop/loop.pyx", line 480, in uvloop.loop.Loop._run
RuntimeError: this event loop is already running.
ancalita commented 2 years ago

Could it be related to this issue: https://github.com/RasaHQ/rasa/issues/10632?

carlad commented 2 years ago

So, without make installing anything, I wasn't able to replicate this working inside rasa-x-demo directory. I was able to run rasa shell with no issues on either a rasa 2.8.x or 3.0.x virtualenv.

Rasa Version      :         2.8.15
Minimum Compatible Version: 2.8.9
Rasa SDK Version  :         2.8.2
Rasa X Version    :         1.0.1
Python Version    :         3.7.12

With rasa 3.0.x I'm also able to execute rasa shell ok.

Rasa Version      :         3.0.0
Minimum Compatible Version: 3.0.0
Rasa SDK Version  :         3.0.3
Rasa X Version    :         1.0.1
Python Version    :         3.8.6

However

After I ran make install in the rasa-sdk directory (following Anca's flow). And then running rasa shell in rasa-x-demo I saw similar issues on 2.8.x and 3.0.x

At first I thought it was the questionary library version. There were several posts online from last year stating a rollback to v1.4.x fixed the issue. But after trying different questionary versions, settling finally on v1.8.1, I noticed that any time I ran make install in the rasa directory last, then ran rasa shell, it would launch fine. But anytime I ran make install in the rasa-sdk directory, then ran rasa shell, it would produce this error.

I've since updated questionary to v1.10.0 (i.e. using what is currently specified in the released projects) and the same behaviour happens.

So I'm thinking it's not about dependency conflicts, but about a loop process in the rasa-sdk make install task that doesn't end/close properly, but somehow gets reset when rasa is make installed .

carlad commented 2 years ago

So it turns out the issue was with the version of prompt-toolkit we were installing. Previously we had the version tied to '^2.0' in the .toml file, but I must have changed it to a range, which ended up installing the latest version (3.something). Rolling back to '^2.0' solves the problem.

carlad commented 2 years ago

The fix now released in rasa 3.0.6

https://github.com/RasaHQ/rasa/releases/tag/3.0.6

and rasa-sdk 3.0.4

https://github.com/RasaHQ/rasa-sdk/blob/3.0.4/CHANGELOG.mdx