From 9892f9dae7019bd956d471be9efe3abdd01ec79d Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Thu, 6 Mar 2025 20:34:51 +0530 Subject: [PATCH] fix: shuffle users in team balancer to prevent ordering bias on app restart --- internal/autoassigner/autoassigner.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/autoassigner/autoassigner.go b/internal/autoassigner/autoassigner.go index 37114cea..427a234a 100644 --- a/internal/autoassigner/autoassigner.go +++ b/internal/autoassigner/autoassigner.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "math/rand" "strconv" "sync" "time" @@ -145,6 +146,12 @@ func (e *Engine) populateTeamBalancer() error { continue } + // Shuffle users to prevent ordering bias, as every app restart will pick the same first user. + r := rand.New(rand.NewSource(time.Now().UnixNano())) + r.Shuffle(len(users), func(i, j int) { + users[i], users[j] = users[j], users[i] + }) + for _, user := range users { // Team does not have a balancer pool, create one. if _, ok := e.roundRobinBalancer[team.ID]; !ok {