[FormFlow, .NET SDK] FormFlow ends unexpectedly and without error with multiple users
Bot Info
- SDK Platform: .NET
- SDK Version: 3.15.2.2
- Active Channels: Skype, Directline
- Deployment Environment: Azure Bot Service
Issue Description
I am building a bot that performs a calculation. It requires four values that I populate using a formflow. I want the bot to be reachable through both chat and a Skype call. For the calling functionality, I have set up a directline client which is forwarded to the message controller. That way, I can use the same bot-logic and easily extend the bot with alexa. (If there is a better way to do this, please let me know in https://github.com/Microsoft/BotBuilder/issues/4702 )
Individually, both flows work. However, when I try them simultaneously, or when multiple users call the bot and try to fill the form, the bot starts acting up. The bot shows a prompt of the formflow, but when I try to enter the property, it turns out the form is no longer active.
Code Example
message controller
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
Trace.TraceInformation(DateTime.Now + " Message received: " + activity.Text + " from " + activity.ChannelId + " in conversation " + activity.Conversation.Id);
if (activity.Type == ActivityTypes.Message || activity.Type == ActivityTypes.ConversationUpdate)
{
var mainDialogBot = new MainDialogBot();
string responseMessage = await mainDialogBot.ProcessMessageFromBotProject(activity);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
In mainDialog, we resolve a LuisDialog:
public async Task<string> ProcessMessageFromBotProject(Activity activity)
{
if (activity != null)
{
switch (activity.GetActivityType())
{
case ActivityTypes.Message:
{
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
{
await Conversation.SendAsync(activity, () =>return scope.Resolve<RootLuisDialog>();});
}
}
}
}
}
and in RootLuisDialog, we start the formflow:
[LuisIntent("Calculation")]
public async Task CalculateInterest(IDialogContext context, LuisResult result)
{
Trace.TraceInformation(DateTime.Now + " Starting finance calculation for " + context.Activity.ChannelId + " for converstation " + context.Activity.Conversation.Id);
await _chat.PostAsync(context, "Let me get my calculator");
var calculationForm = new CalculationForm();
var calculationFormDialog = new FormDialog<CalculationForm>(calculationForm, CalculationForm.BuildForm, FormOptions.PromptInStart, result.Entities, CultureInfo.InvariantCulture);
}
The form contains a BuildForm method where some validation is done
public class Calculation_v2Form
{
[Prompt("What is the amount financed?")]
public string SalePrice { get; set; }
// Other fields
public static IForm<Calculation_v2Form> BuildForm()
{
return new FormBuilder<Calculation_v2Form>()
// Omitted some custom validation for all the fields
.Build();
}
}
Expected Behavior
I expected that I can fill multiple forms at the same time for different users / in different channels.
Actual Results
In the logging below, you can see that the buildform method is called between line 12-13 for the "skype" channel, and between 22-23 for the "directline" channel. In line 29, I want supply a value to fill the first property of the form by typing in the "skype" channel. However, the form is no longer active, and the message is going through the LuisDialog instead of the formflow.

My question is: How do you work with FormFlows when you have multiple users/channels filling the form at the same time?
Edit 1: We start directline for Skype calls when a call is received:
private async Task OnIncomingCallReceived(IncomingCallEvent incomingCallEvent)
{
var client = new DirectLineClient(directLineSecret);
var conversation = client.Conversations.StartConversation();
// Add actions and save the conversation into a dictionary
}
And we retrieve the conversation when the person calling has replied:
private async Task OnRecordCompleted(RecordOutcomeEvent recordOutcomeEvent)
{
if (recordOutcomeEvent.RecordOutcome.Outcome == Outcome.Success)
{
var text = await GetResultFromRecording(recordOutcomeEvent);
var client = new DirectLineClient(directLineSecret);
// Get conversation using recoderOutcomeEvent.Conversation.Id
// Send activity to directline
}
}
How did you setup DI for the RootLuisDialog, is it possibly using the same instance across users?
@ukphillips See Edit 1 in the original post.
After doing more research this issue also happens when talking with just Skype Chat Clients to the bot (only in this case the bot steps back into the formflow even though it was already out):

In the image you can see the calculation ending at 15:29 and the bot saying that it will 'crunch some numbers'. You should be out of the formflow now. So I say start to start a new calculation (enter the formflow again), but suddenly we're back at filling in the 'Payment Frequency'.
I then enter Annually, the bot crunches the numbers and we're now actually out.
I don't think we have enough code here to reproduce the problem. Are you able to make a small and concise repro project?
@EricDahlvang ,
I've created a repro repository: https://github.com/devedse/ReproFormFlowIssueBot
You have to fill in a few items/secrets/appId's in the web.config And also the AppId and Secret in the RootLuisDialog for your LUIS Model
(I've added a TODO comment near all these, so just search for that)
We did another deploy of exactly this version and the same issue occurs. So basically with 2 chat clients sometimes the bot asks for the last value of the Form, then finishes the form and performs the final calculation. When you then enter 'start' again to start a new calculation the bot drops back into the form and asks for the final value again.
Edit: Furthermore, the bot sometimes goes very slow. Even though there's no backend API's or anything being called.
(Sometimes messages are missed or duplicated when you spam the bot, but this could potentially be due to LUIS?):

@devedse Is this bot deployed to a single server, or is it scaled sideways to multiple machines?
Hi Eric, according to the latest release notes a bug has been fixed regarding this. After upgrading to this new nuget package we have not seen the bug reappearing. I still find it very peculiar that we seem to be the only ones running into this issue though.
Fixed regression around state getting reset in >3.14 packages by reverted Caching changes
Hi Devedse,
I don't think you're the only ones who were having issues like this. The 3.14 CachingBotDataStore changes caused all kinds of issues.
Thanks for confirming that the fix is working.