rasa icon indicating copy to clipboard operation
rasa copied to clipboard

Setting domain session_expiration_time has no effect

Open dgradwell-ams opened this issue 2 years ago • 29 comments

Rasa Open Source version

3.1.0

Rasa SDK version

No response

Rasa X version

No response

Python version

3.9

What operating system are you using?

Linux

What happened?

Since version 3.1.0, my preference for session_expiration_time (0) under session_config in the domain doesn't seem to be working anymore. The value is always being set to 60, the default.

I've confirmed that this is the actual value in three ways,

  1. Inspecting the result of the API call to get the domain of the running bot
  2. Extracting the trained model archive and inspecting the merged domain therein, and
  3. Every 60 minutes of actual inactivity on my session, action_session_start is invoked

This happens whether my domain is contained in a single file or split into multiple files in a directory. I've tried deleting the trained models and the .rasa cache directory and retraining the model to no avail.

Thing is, we have overridden the action_session_start in our project, and it has considerable side effects in our app that are only meant to be run once for each conversation. We cannot call it again -- we don't want sessions to expire.

Command / Request

No response

Relevant log output

No response

Reproduction repository

https://github.com/dgradwell-ams/rasa-issue-11061

dgradwell-ams avatar Apr 05 '22 18:04 dgradwell-ams

Thanks for raising this issue, @mvielkind will get back to you about it soon✨

Please also check out the docs and the forum in case your issue was raised there too 🤗

sara-tagger avatar Apr 06 '22 06:04 sara-tagger

Hi @dgradwell-ams, I can't duplicate this. Just tested session_expiration_time with a value of 3 and the session restarted when I was idle past the three minutes.

rgstephens avatar Apr 09 '22 05:04 rgstephens

@rgstephens Try setting it to zero.

dgradwell-ams avatar Apr 09 '22 06:04 dgradwell-ams

I tried zero and it worked for me. Started a session, waited more the 60 minutes, entered an utterance and session and slots were still set, no action_session_start.

I wonder if this could be channel specific. What channel are you using? I did my testing with rasa shell.

rgstephens avatar Apr 22 '22 16:04 rgstephens

@rgstephens Hey, you might be on to something. We are using custom connectors, but perhaps I missed something when updating.

dgradwell-ams avatar Apr 22 '22 20:04 dgradwell-ams

@rgstephens OK, so upon further investigation, we cannot see anything in our custom connector that would indicate how or why the domain session would not be properly setup. It's nearly identical to the example here: https://rasa.com/docs/rasa/connectors/custom-connectors

dgradwell-ams avatar Apr 22 '22 20:04 dgradwell-ams

I'll try to setup a reproduction repo.

dgradwell-ams avatar Apr 22 '22 20:04 dgradwell-ams

@rgstephens Here's a repo that reproduces the issue https://github.com/dgradwell-ams/rasa-issue-11061

I've set the expiration time to 1 minute in the configuration to demonstrate easily. See the README.

dgradwell-ams avatar Apr 23 '22 02:04 dgradwell-ams

I also have the issue. The entire session_config seems to be ignored. I doubt that it is related to the connector since it seems to get baked into the model at training time.

Here is my config:

image

And here is the metadata.json of the trained model:

image

benos avatar May 06 '22 08:05 benos

I'm wondering if this file has anything to do with it:

https://github.com/RasaHQ/rasa/blob/e9e99c31fabaa04e9f93942cec93abc33bde5218/rasa/graph_components/providers/domain_for_core_training_provider.py

image

benos avatar May 06 '22 09:05 benos

Note that if I hack the metadata.json in the trained model then things behave as expected.

benos avatar May 06 '22 10:05 benos

The way that I worked around it was to patch the defaults in the core constants in my docker image to the values I need. This confirms that the defaults are being used.

dgradwell-ams avatar May 06 '22 13:05 dgradwell-ams

Thanks @dgradwell-ams That indeed sounds better than changing the metadata each time ...

Is this something you can do via the Dockerfile / docker-compose or do you have to modify constants.py and build your own image?

(and if the former, would you be able to share how you did it?)

benos avatar May 06 '22 16:05 benos

I'm building my own image in a complicated process that makes it cross-platform between linux/amd64 and linux/arm64 so that it can be loaded on Apple Silicon for local development.....

In the image, I create a miniconda environment and install everything... then I just patch the constants.py using sed to change the one thing I need to change (session_expiration_time) to zero...

Relevant portion of Dockerfile for after rasa is installed:

# Patch the DEFAULT_SESSION_EXPIRATION_TIME_IN_MINUTES in rasa's constants
# to workaround an bug in the domain merging code.
# Related github issue: https://github.com/RasaHQ/rasa/issues/11061
RUN sed -ie 's/DEFAULT_SESSION_EXPIRATION_TIME_IN_MINUTES = 60/DEFAULT_SESSION_EXPIRATION_TIME_IN_MINUTES = 0/g' "${CONDA_ENV}/lib/python${PYTHON_VERSION}/site-packages/rasa/shared/constants.py"

dgradwell-ams avatar May 06 '22 18:05 dgradwell-ams

Thanks so much for the details @dgradwell-ams. As it happens I'm also dealing with local dev on the M1, but have opted to do that outside of Docker. So I think I'll stick with hacking the models after training for now.

Hopefully the team at Rasa can fix the issue in the next release. It's quite a nasty bug.

benos avatar May 06 '22 21:05 benos

I would recommend using docker, I got better training times without Metal.

dgradwell-ams avatar May 10 '22 21:05 dgradwell-ams

You're probably right, but the overhead of figuring out how to create a Docker image that will work on the M1 is a bit much for me now. You can actually comment out tensorflow-metal in the requirements to solve the training times issues outside of Docker.

benos avatar May 11 '22 14:05 benos

@wochinge @erohmensing

Sorry to @ you in this way, but is the rasa team aware of this issue?

It is a nasty bug that will unexpectedly bite anyone relying on the session config. I also imagine it isn't a huge deal to fix

Thanks!

benos avatar May 31 '22 06:05 benos

@dgradwell-ams Thanks for submitting a repo for reproducing the issue! Confirming I managed to reproduce with Python 3.9 (albeit on a Mac machine with Intel chip) using your README instructions. I was expecting to see this debugging log message after 1 minute of waiting and retrying the curl command, however this is not the case.

Possibly worth investigating into whether Domain.session_config actually gets the configured values during merging of multiple domain files, or if it gets overwritten with the default values.

Do you experience the same issue when using a single domain file?

cc'ing our PM @chandrikas

ancalita avatar Jul 06 '22 14:07 ancalita

David is no longer working on the bot.

rgstephens avatar Jul 06 '22 16:07 rgstephens

Hi @ancalita

A bit late to the party, but I tested with a fresh rasa init (works fine) and then splitting a single response into a separate file (config gets ignored in the trained model), so I think you've nailed it. I've attached the repo of the latter in case it is of any use.

multiple_domain_file.tar.gz

Many thanks for looking into this!

Ben

benos avatar Jul 15 '22 08:07 benos

Hi @ancalita

From the changelog of 3.2.4 I understand the problem should be fixed with that release. However I find that not to be the case; if I train with a split domain file and then inspect the metadata.json of the model it still uses the default value.

Thanks,

Ben

benos avatar Aug 04 '22 19:08 benos

@benos I went back and tested the bugfix release with the provided repo here. On all counts, the bug was fixed:

  • I tested with rasa run --enable-api --debug and test_session.sh as laid out in the reproduction steps in the Readme. As expected, after >1 min, I could see this in the logs:
2022-08-08 12:10:42 DEBUG    rasa.core.processor  - The latest session for conversation ID '78e07430-1c30-415a-8e7c-f9d84a16faf7' has expired.
2022-08-08 12:10:42 DEBUG    rasa.core.processor  - Starting a new session for conversation ID '78e07430-1c30-415a-8e7c-f9d84a16faf7'.
  • I then inspected the components/domain_provider/domain.yml: the session_expiration_time was still set as 1. Screenshot 2022-08-08 at 12 18 00

  • I also inspected metadata.json, and the session_expiration_time was set as 1 there too. Screenshot 2022-08-08 at 12 17 44

Do you have a repo example that I can test your scenario with?

ancalita avatar Aug 08 '22 11:08 ancalita

Hi @ancalita ,

I've attached a demo of the issue, which is a minor modification of the "rasa init" output.

rasa_session_bug.tar.gz

  • If you inspect the model you can see that the metadata.json and the domain provider both use default values. You can also see that it was trained with 3.2.4
  • If you delete data/domain_copy.yml and retrain, then the model uses the correct value

Best,

Ben

benos avatar Aug 10 '22 07:08 benos

@benos What is the initial train command you use and how do you pass the two separate domain files to the training command? The expected way is to have all domain files in the same subdirectory. I would advise to create a separate folder for domain files rather than using data/

ancalita avatar Aug 10 '22 14:08 ancalita

HI @ancalita

  • rasa train
  • I don't do anything particular to pass the files. It just works

Note that the only thing that the domain file under 'data' contains are responses (so essentially a responses.yml).

To give some background, the way I've been working is to have the responses for a particular story contained within that story file, making it much easier to maintain.

From your response I assume that this is the wrong way and I should move them to one or more responses.yml files within the same directory as the domain. But I find that a real shame since it actually works great to combine the keys, except for the issue of the session config getting nixed.

Thanks!

Ben

benos avatar Aug 10 '22 14:08 benos

@ancalita To expand on that, if it is the case that one shouldn't mix the responses key with stories and rules then it probably shouldn't work and / or raise an error (though the way it is now is a feature not a bug IMO. Except for the session issue :-)

benos avatar Aug 10 '22 14:08 benos

@benos A fix for your reported issue was released in rasa 3.2.6.

ancalita avatar Aug 13 '22 09:08 ancalita

@ancalita That is awesome news. Many thanks!

benos avatar Aug 14 '22 15:08 benos