How does the chat thread-tutor affinity work?

The tutoring system attempts to keep chat threads with the same tutors where possible. It also has the ability to (optionally) round robin auto-assign online tutors to new incoming chat threads so that the online tutors aren't competing against each other to claim the new thread first.

The affinity between a chat thread and a tutor is illustrated by the following state machine:

When a new chat thread comes in, it is in the  UNASSIGNED state. Any tutor can manually claim an UNASSIGNED thread, and doing so will cause the thread to be ASSIGNED to them.

Tutors who are subscribed to a course for live tutoring can enable auto-assign mode for that course. In this live tutoring mode, any  UNACCEPTED chat threads will be auto-assign offered to this auto-assign tutor pool. The threads will be offered in a round robin fashion until a tutor accepts the offer, or until all tutors reject the offer. An offer on a thread will only last for 2 minutes — if it is not actioned within this time, it is auto-rejected and the round robin auto-assign allocation process continues.

A thread is  ASSIGNED to the tutor who either accepted an offer or manually claimed it (tutor a in the picture above). From here, the tutor and student can interact with one another. Tutors are unable to send a message to the student within a chat thread unless they are ASSIGNED to it. If the student responds within 8 minutes of the tutors last message, the chat thread will be automatically re-assigned to said tutor. If the student responds outside of this time window, said tutor gets offered the thread (state UNDER OFFER).

Only one tutor can be assigned to a chat thread at any particular point in time. If a tutor is assigned to a thread and they no longer want to be, they can  manually release the thread. This causes the thread to return to the UNASSIGNED state where it may re-enter the round robin auto-assign allocation process. If the tutor goes offline while they have threads assigned to them, the tutoring system will identify that they have gone offline and offline release them on behalf of the now-offline tutor.

If another tutor ( tutor b) wants to claim the thread but it is claimed by another tutor (tutor a), they can hijack the thread. The result of hijacking is that the thread will then be assigned to the hijacking tutor (tutor b).