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

When implementing proactive messaging how can i ensure bot state is synchronized so bot state remains correct.

Open Rich-biomni opened this issue 2 years ago • 1 comments

When implementing proactive messaging how can i ensure bot state is synchronized so bot state remains correct.

In c#

When a message is received the botcontroller fires

await _adapter.ProcessAsync(Request, Response, _bot);

Middleware saves the current bot state including the dialog stack.

When a proactive message is received a different controller fires

await _adapter.ContinueConversationAsync(_appId, conversationReference, BotCallback);

The conversation continues, middleware again saves bot the current bot state including the dialog stack.

There seems to be a potential race condition where the bot code can be running for the same conversation / user at the same time and thus the saved bot state dialog stack ends up being last saved wins..

_adapter.ProcessAsync(Request, Response, _bot); --- starts captures the the bot state ...

   a proactive message is revived

   ContinueConversationAsync ...			          --- starts captures the bot state
								                  --- asks a question
								                  --- end of turn - saves bot state dialog stack

_adapter.ProcessAsync(Request, Response, _bot); --- completes --- saves bot state - over writing the proactive state saved earlier

Ideally there's only one entry point where all bot messages are process in sequential queue.

Thanks

Rich-biomni avatar May 02 '23 08:05 Rich-biomni

Hi @Rich-biomni

Do you still need assistance with this?

dmvtech avatar Oct 08 '24 17:10 dmvtech