Asyncio - Task exception was never retrieved error RASA 2.1.0

I’ve been getting this error when calling a specific action at the end of the conversation:

ERROR    asyncio  - Task exception was never retrieved
future: <Task finished coro=<configure_app.<locals>.run_cmdline_io() done, defined at c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\rasa\core\run.py:132> exception=TimeoutError()>
Traceback (most recent call last):
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\rasa\core\run.py", line 138, in run_cmdline_io
    sender_id=conversation_id,
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\rasa\core\channels\console.py", line 182, in record_messages
    async for response in bot_responses:
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\rasa\core\channels\console.py", line 137, in send_message_receive_stream
    async for line in resp.content:
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\aiohttp\streams.py", line 39, in __anext__
    rv = await self.read_func()
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\aiohttp\streams.py", line 328, in readline
    await self._wait('readline')
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\aiohttp\streams.py", line 296, in _wait
    await waiter
  File "c:\users\fredd\appdata\local\programs\python\python37\lib\site-packages\aiohttp\helpers.py", line 596, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError
Transport closed @ ('127.0.0.1', 59644) and exception experienced during error handling

The action uses a custom machine learning model I have made in another file and am calling to classify as user’s response, where CodeTypeClassifier and TextPreprocessor are both custom classes I’ve written. All this does is run a slot value through a model which is loaded from file, so the action itself takes ~10s to run:

class ClassifyCodeType(Action):

    def name(self) -> Text:
        return "action_classify_code_type"

    def run(
            self,
            dispatcher,
            tracker: Tracker,
            domain: "DomainDict",
    ):
        """Takes the describe_dispute slot and runs it through a pretrained ML classifier to classify it as a Code Type
           Output and confidence is then saved to a slot each"""

        model_directory = xxxx
        vectorizer_directory = xxxx
        encoder_directory = xxxx

        # Instantiating class objects
        codeType_classifier = CodeTypeClassifier(RANDOM_STATE=54,
                                                 classifier=LogisticRegression)
        text_processor = TextPreprocessor(text_attribute=None, data_type='list')

        # Model is trained against the free-text slot so need to grab that
        user_input = tracker.get_slot("describe_dispute")
        print(type(user_input))

        # Perform the same cleaning to the user_input variable as was done during training
        _user_input = text_processor.transform([user_input])

        # Get the probability and classification from the ML model
        prediction_probability, prediction = codeType_classifier.predict_on_user_input(user_input=_user_input,
                                                                                       vectorizer_directory=vectorizer_directory,
                                                                                       model_directory=model_directory,
                                                                                       label_encoder_directory=encoder_directory)

        print(f"Predicted class: {''.join(prediction)}, with probability: {np.amax(prediction_probability)}")

        return [SlotSet("code_type", ''.join(prediction)), SlotSet("code_probability_score", np.amax(prediction_probability))]

I’m not totally convinced that the action itself is the problem as the print statement can be seen in the action server, and the action server doesn’t crash after the above message appears in the shell:

I have seen other topics similar to this that suggest a fresh rasa install which I have tried, to no success.

Versions:

RASA: 2.1.0

rasa_sdk: 2.2.0

1 Like

I’ve managed to solve this thanks to this comment.

As the action sometimes took > 10s to run I had to change the value of:

DEFAULT_STREAM_READING_TIMEOUT_IN_SECONDS = 10

to ~20s in ..\AppData\Local\Programs\Python\Python37\Lib\site-packages\rasa\core\channels which ended up working perfectly

1 Like

Thanks a lot. It worked. But I had to set it to 90, even 30 wasn’t working

where to find this sir??

@alijboor

track down from your error message that the appdata can be found in the hidden folders, for my case

C:\ProgramData\Anaconda3\envs\venv\Lib\site-packages\rasa\core\channels

then open console.py change the:

DEFAULT_STREAM_READING_TIMEOUT_IN_SECONDS = 10 —> 20 for my case it works