Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(teamhub): recreate job-less voice dispatches after the assignment timeout
muterC84222a48e842
diff --git a/apps/teamhub/internal/voicemedia/livekit_provider.go b/apps/teamhub/internal/voicemedia/livekit_provider.goindex a2dc048f..94175966 100644--- a/apps/teamhub/internal/voicemedia/livekit_provider.go+++ b/apps/teamhub/internal/voicemedia/livekit_provider.go@@ -306,18 +306,18 @@ func activeVoiceRuntimeDispatch(}state := dispatch.Stateif state == nil || len(state.Jobs) == 0 {- return dispatchAwaitingAssignment(state)+ return dispatchAwaitingAssignment(state, unassignedDispatchGrace)}for _, job := range state.Jobs {if job == nil || job.State == nil || job.State.Status == livekit.JobStatus_JS_PENDING {- if dispatchAwaitingAssignment(state) {+ if dispatchAwaitingAssignment(state, time.Minute) {return true}continue}if job.State.Status == livekit.JobStatus_JS_RUNNING {if job.State.ParticipantIdentity == "" {- if dispatchAwaitingAssignment(state) {+ if dispatchAwaitingAssignment(state, time.Minute) {return true}continue@@ -337,14 +337,22 @@ func activeVoiceRuntimeDispatch(return false}-func dispatchAwaitingAssignment(state *livekit.AgentDispatchState) bool {- // LiveKit can retain a dispatch with no assigned job after all workers were- // unavailable. Registration of a later worker does not replay that request.+// unassignedDispatchGrace bounds how long a dispatch may hold no job at all.+// LiveKit appends a job once a registered worker accepts it, which takes at+// most its 10 s assignment timeout. A job-less dispatch older than that was+// dropped because no worker was available, and a worker that registers later+// is not offered it, so the reconcile loop recreates it. Keeping this short+// lets a restarted worker get the job back within seconds of registering.+const unassignedDispatchGrace = 15 * time.Second++// dispatchAwaitingAssignment reports whether a dispatch without a joined job+// is still young enough to keep waiting for a worker.+func dispatchAwaitingAssignment(state *livekit.AgentDispatchState, grace time.Duration) bool {if state == nil || state.CreatedAt <= 0 {return false}age := time.Since(time.Unix(0, state.CreatedAt))- return age >= -5*time.Second && age < time.Minute+ return age >= -5*time.Second && age < grace}func staleVoiceRuntimeDispatches(diff --git a/apps/teamhub/internal/voicemedia/livekit_provider_test.go b/apps/teamhub/internal/voicemedia/livekit_provider_test.goindex dffaf177..18f771f1 100644--- a/apps/teamhub/internal/voicemedia/livekit_provider_test.go+++ b/apps/teamhub/internal/voicemedia/livekit_provider_test.go@@ -453,6 +453,23 @@ func TestUnassignedVoiceRuntimeDispatchExpiresAfterWorkerOutage(t *testing.T) {}}+func TestJobLessVoiceRuntimeDispatchIsReplacedSoonAfterAssignmentTimeout(t *testing.T) {+ metadata := voiceRuntimeDispatchMetadata(time.Now(), PurposeHardwareControl)+ dispatch := &livekit.AgentDispatch{Id: "dropped", AgentName: voiceRuntimeAgentName, Metadata: metadata,+ State: &livekit.AgentDispatchState{CreatedAt: time.Now().Add(-12 * time.Second).UnixNano()}}+ if !hasVoiceRuntimeDispatch(voiceRuntimeAgentName, []*livekit.AgentDispatch{dispatch}, metadata, nil, time.Time{}) {+ t.Fatal("a dispatch still within the worker assignment timeout was replaced")+ }+ dispatch.State.CreatedAt = time.Now().Add(-20 * time.Second).UnixNano()+ if got := staleVoiceRuntimeDispatches(voiceRuntimeAgentName, []*livekit.AgentDispatch{dispatch}, metadata, nil, time.Time{}); len(got) != 1 || got[0] != "dropped" {+ t.Fatalf("stale dispatches=%v want=[dropped]", got)+ }+ dispatch.State.Jobs = []*livekit.Job{{State: &livekit.JobState{Status: livekit.JobStatus_JS_PENDING}}}+ if !hasVoiceRuntimeDispatch(voiceRuntimeAgentName, []*livekit.AgentDispatch{dispatch}, metadata, nil, time.Time{}) {+ t.Fatal("a dispatch with a pending job lost its minute of assignment grace")+ }+}+func TestClosingVoiceSessionRemovesTheWholeProviderRoom(t *testing.T) {methods := make(chan string, 1)server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {