question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IBotContext information lost upon thread switches

See original GitHub issue

Hi,

Last few days I’ve been trying out a few things with the new botbuilder SDK. I’m using Akka.NET to implement my dialog flow. I really like Akka.NET because I can easily implement an actor based on the finite state machine pattern to model different stages of the conversation that my bot is in.

I noticed however that when I pass the IBotContext as a message to my Akka actor information is lost and the call ReplyToActivity on IBotContext doesn’t result in a message to the user of my bot.

I’m curious what happens with the IBotContext object when I pass it to another thread. Could it be that information is lost when I do this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wmeintscommented, Mar 8, 2018

Here’s the code that I wrote: https://github.com/wmeints/bot-actors-sample

I think I have time to extend the sample further tomorrow. Probably going to add stuff around LUIS and QnaMaker so that it becomes a real example 😃

1reaction
drub0ycommented, Mar 7, 2018

DISCLAIMER: I’m familiar with a couple of actor systems and the actor model in general, but not steeped in Akka.NET specifically.

First, to make sure I’m understanding you correctly, you’re trying to pass the IBotContext through to your actor via a message, correct? If so, I’m relatively certain that’s not going to work. Actor messages are meant to essentially be POCOs that get serialized, sent to a mailbox (in Akka.NET’s case) and then delivered to an actor “in time”. While IBotContext is technically thread safe, it is not able to be serialized and “remoted” in this this way. Besides, it would be violating the rule of passing a mutable object to an actor which is frowned upon.

You also wouldn’t be able to inject it via Akka.NET “props” because the props are only resolved when an actor instance is created and if that actor “lives” throughout many activity messages from the bot framework perspective, it would need to be working with the proper IBotContext for each of those messages.

I do actually think actor systems are potentially a really good match for implementing bots, I just don’t think the current abstractions of the v4 SDK as it stands right now are going to “fit” that kind of system naturally due to the major architectural differences actor systems present from a traditional application architectures. It would not be a stretch to imagine a more native SDK for Akka.NET (or other actor systems) at some point in the future, but, full disclosure, I’m not on the product team so I’m not promising anything. 😄

Anyway, let’s think… how could you do this right now? 🤔 I assume right now you are using some sort of API gateway leveraging ASP.NET, resolving an ActorRef and that’s when you tried to send it over the IBotContext via a Tell based message… maybe? Spitballing here: what if, instead of sending over the IBotContext itself, you sent over only the Activity and maybe even your state, but you do so with an Ask and then your API gateway awaits that, takes the result of the Ask, which would be a respone message with maybe List<Activity> and your state again, and marshals those back onto the IBotContext???

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Thread Context Switching Issue
The problem with this threading, I believe, is that the context switching between the threads is causing enough time (a very small amount...
Read more >
Am I missing something obvious, or is there really no ...
A Thread mesh network based on mains-powered light switches would be awesome. Then again, I'm getting to have so many HomePod Minis in...
Read more >
Trouble With New Eve Light Switch (3rd Gen, Thread)
I installed the new Eve light switch today in a three-way set up. Physically using the switches results in normal, expected behavior.
Read more >
Eve Light Switch | evehome.com
Enjoy the convenience of connected lighting with Eve Light Switch without replacing a single bulb in your home. Turn your lights on or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found