botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Bot loses the context after a timeout

Open ycjuanesteban opened this issue 8 years ago • 18 comments

Bot Info

  • SDK Platform: .NET
  • SDK Version: 3.13.1
  • Active Channels: Skype For Business
  • Deployment Environment: Azure App Service

Issue Description

Actually I have a bot in test environment with S4B like Channel, but when the QA team start their test, one of them left the conversation (don't write for 10 or 15 minutes) and restart the conversation the bot don't response.

PD: The state service will no have support after 31th march so I changed this approach to this -> https://blog.botframework.com/2017/07/26/saving-state-sql-dotnet/

Reproduction Steps

  1. Start the conversation
  2. Interact with the bot
  3. Don't write for 10 or 15 minutes
  4. Restart to write
  5. The bot don't response

Expected Behavior

I suppose that the bot response the questions and continue with the context and dialog

Actual Results

This imagen show the error, I answer the bot question with Yes and the bot don't continue with the dialog. (The time elapsed between the answers was 10 minutes) erroractual

The next imagen show you the rigth way before the Yes answer continuaciondeldialogo

ycjuanesteban avatar Mar 14 '18 20:03 ycjuanesteban

I believe this is because SfB "randomly" starts new conversations. Some information about this can be found here: https://techcommunity.microsoft.com/t5/Skype-for-Business-IT-Pro/Multiple-chats-sessions-with-same-contact-in-S4B-window/td-p/40170 Since dialog state is keyed on conversation id, and the conversation id changes, then the state is not retrieved after the new conversation is started.

I will escalate this to someone on the Skype for Business Bots team.

EricDahlvang avatar Mar 14 '18 23:03 EricDahlvang

Hey @JuanEstebanYC

I spoke with one of the engineers who wrote the BotBuilder v3 .net sdk. He pointed out that you can override saving dialog state, so it is persisted in UserData instead. Currently, this line is what registers the data bag used for dialog state: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Builder.Autofac/Dialogs/DialogModule.cs#L296

If you override this with your own registration, you can change it to the .UserData bag instead:

Conversation.UpdateContainer(
            builder =>
            {
                builder.Register(c =>
                {
                    var cc = c.Resolve<IComponentContext>();
                    Func<IBotDataBag> make = () =>
                    {
                        return cc.Resolve<IBotData>().UserData;
                    };
                    return make;
                })
                .As<Func<IBotDataBag>>()
                .InstancePerLifetimeScope();
            });

Please try this, and let me know if it solves the problem.

EricDahlvang avatar Mar 15 '18 00:03 EricDahlvang

Hi Eric,

I'm actually having a similar issue in Web and Skype channel. Here's the error that occurs:

Event time ‎3‎/‎15‎/‎2018‎ ‎8‎:‎08‎:‎56‎ ‎AM
Message POST to FosterCareAssistant failed: POST to the bot's endpoint failed with HTTP status 500 POST to the bot's endpoint failed with HTTP status 500
Exception type System.Exception
Failed method Microsoft.Bot.ChannelConnector.BotAPI+d__29.MoveNext

{ "message": "An error has occurred.", "exceptionMessage": "Operation returned an invalid status code 'Unauthorized'", "exceptionType": "Microsoft.Bot.Connector.ErrorResponseException", "stackTrace": " at Microsoft.Bot.Connector.Conversations.d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Connector.ConversationsExtensions.d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at HHS.ChildWelfareBot.Web.MessagesController.d__0.MoveNext() in C:\code\Code\FosterCareDemo\ChildWelfareBot\Controllers\MessagesController.cs:line 32\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }

chixcancode avatar Mar 15 '18 12:03 chixcancode

@chixcancode Please open a new issue https://github.com/Microsoft/BotBuilder/issues/new

EricDahlvang avatar Mar 15 '18 15:03 EricDahlvang

@JuanEstebanYC Did the solution provided above work for you?

EricDahlvang avatar Mar 19 '18 16:03 EricDahlvang

Hi,

I downgraded to v 3.13.1 on Saturday night. Have not seen issue re-occur since.

chixcancode avatar Mar 19 '18 17:03 chixcancode

@chixcancode Thanks for the update, but this is a different issue.

EricDahlvang avatar Mar 19 '18 17:03 EricDahlvang

@EricDahlvang Thanks you for the answer, if you need to close that topic please do it, because the project are stoped and I don't have access to the code until the project restart.

ycjuanesteban avatar Mar 23 '18 16:03 ycjuanesteban

hi, Is this issue still open. Because I am also facing the same issue with skype for business channel.

subhamawasthi avatar Mar 27 '18 14:03 subhamawasthi

@subhamawasthi Have you tried the fix suggested:

Conversation.UpdateContainer(
            builder =>
            {
                builder.Register(c =>
                {
                    var cc = c.Resolve<IComponentContext>();
                    Func<IBotDataBag> make = () =>
                    {
                        return cc.Resolve<IBotData>().UserData;
                    };
                    return make;
                })
                .As<Func<IBotDataBag>>()
                .InstancePerLifetimeScope();
            });

Does that resolve the issue for you?

EricDahlvang avatar Mar 27 '18 16:03 EricDahlvang

@EricDahlvang I am having the same issue and the above fix did not work for me.

I am not entirely sure how this would work too. If the conversation Id is changed how it will resume with the same context and dialog stack?

waqas-zia-confiz avatar May 11 '18 10:05 waqas-zia-confiz

@waqas-zia-confiz as pointed out here: https://github.com/Microsoft/BotBuilder/issues/4315#issuecomment-373217490 <-- this change will store the dialog stack in the UserData bag instead of PrivateConversationData

Have you tried this method?

EricDahlvang avatar May 11 '18 18:05 EricDahlvang

@EricDahlvang

Yes, I have tried this method. On Skype for Business, the conversation still times out after 10 minutes.

waqas-zia-confiz avatar May 14 '18 11:05 waqas-zia-confiz

@waqas-zia-confiz Can you share your bot's code?

EricDahlvang avatar May 14 '18 17:05 EricDahlvang

@EricDahlvang

Conversation.UpdateContainer(
                builder =>
                {
                    account.CreateCloudTableClient().GetTableReference(tableName).CreateIfNotExists();
                    builder.RegisterModule(new Helpers.TableLoggerModule(account, tableName));
                    var store = new TableBotDataStore(connectionString);
                    builder.Register(c => store)
                        .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                        .AsSelf()
                        .SingleInstance();
                    builder.Register(c =>
                        {
                            var cc = c.Resolve<IComponentContext>();
                            Func<IBotDataBag> make = () =>
                            {
                                return cc.Resolve<IBotData>().UserData;
                            };
                            return make;
                        })
                        .As<Func<IBotDataBag>>()
                        .InstancePerLifetimeScope();
                });

Here is my code.

waqas-zia-confiz avatar May 15 '18 09:05 waqas-zia-confiz

@EricDahlvang Is there any update on this?

waqas-zia-confiz avatar May 18 '18 08:05 waqas-zia-confiz

@waqas-zia-confiz Sorry, no update at this time. I will look into this some more, and get back to you.

EricDahlvang avatar May 22 '18 07:05 EricDahlvang

I am also having the same situation. My bot is proactively pings the user on skype for business and the bot prompts one question with options but the user responded around 15 minutes later so the bot went off context and started the whole conversation. I checked the log there i can clearly see that the conversation id is different for first message and the user reply(After 15 minutes).

sdharshraj avatar Jun 20 '18 05:06 sdharshraj