microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
685 stars 280 forks source link

CloudAdapter: messages are not sorted correctly #4314

Closed mschuelein closed 2 years ago

mschuelein commented 2 years ago

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Versions

What package version of the SDK are you using: 4.16.0 What nodejs version are you using: 14.15.1 What browser version are you using: Google Chrome Version 104.0.5112.102 What os are you using: Windows 10 Pro (Version 10.0.19044)

Describe the bug

We recently started using CloudAdapter, because we've seen that BotFrameworkAdapter is deprecated. Since we use CloudAdapter, activities that get sent very shortly after each other dont get sorted correctly. They get shown in seemingly random order in the WebChat Frontend. This happens when sendActivities and sendActivity are used from the TurnContext. The reason the messages are not in the right order is, that the timestamp of the activities recieved in the WebChat Frontend are in different order then when the activities where sent from the Backend.

To Reproduce

Steps to reproduce the behavior:

  1. Migrate from BotFrameworkAdapter to CloudAdapter
  2. Send multiple activities directly after each other. This can either be done by using sendActivities, or multiple use of sendActivity, f.e. in a for loop.
  3. Do this multiple times, and the activities dont get shown in the correct order, and for multiple tries they get shown in different orders.

Expected behavior

The timestamps that are recieved by the Frontend are in the same order as they get sent out in the Backend.

Additional context

stevkan commented 2 years ago

@mschuelein - Are you able to post a copy of your code for both your bot as well as your Web Chat implementation? Or, a basic repro of both in case you can't share your project? It looks like you have customized your code a little bit (when compared to our samples). Having your code will be easier than trying to guess your precise setup.

I'm curious to see your setup as I also migrated a test bot several months ago from the BF adapter to the cloud adapter. However, I did not run into this issue when doing so nor has it come up since.

MatthiasGwiozda commented 2 years ago

@stevkan I't very easy to reproduce, even without much customization:

reproduction - steps

Note that this problem seems like a reace condition. Sometimes the order of the messages is wrong and sometimes it's correct. It's random: image

Example - Code

Here the example, which Ive generated just today. You have to use npm install. before starting the bot: message_order_bug_reproduction.zip

Context

stevkan commented 2 years ago

@mschuelein - Thank you for the code sample. I am able to repro the issue and am diving deeper into it. I have a suspicion as to what the cause may be. I need to speak with a colleague about it. When I know more, I will respond.

dmvtech commented 2 years ago

@JuanAr This was reproduced by Steve and myself. Please let us know if you have any questions regarding the behavior/repro.