on main help sign in
fix(agent): release activeRequests before publishing TypeAgentFinished
9d34668Sven Olsen
internal/agent/agent.go+14−11
@@ -581,16 +581,6 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
581 return nil, err
581 return nil, err
582 }
582 }
583
583
584− // Send notification that agent has finished its turn (skip for
585− // nested/non-interactive sessions).
586− if !call.NonInteractive && a.notify != nil {
587− a.notify.Publish(pubsub.CreatedEvent, notify.Notification{
588− SessionID: call.SessionID,
589− SessionTitle: currentSession.Title,
590− Type: notify.TypeAgentFinished,
591− })
592− }
593−
594 if shouldSummarize {
584 if shouldSummarize {
595 a.activeRequests.Del(call.SessionID)
585 a.activeRequests.Del(call.SessionID)
596 if summarizeErr := a.Summarize(genCtx, call.SessionID, call.ProviderOptions); summarizeErr != nil {
586 if summarizeErr := a.Summarize(genCtx, call.SessionID, call.ProviderOptions); summarizeErr != nil {
@@ -608,10 +598,23 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
608 }
598 }
609 }
599 }
610
600
611− // Release active request before processing queued messages.
601+ // Release active request before publishing the notification.
602+ // TUI handlers poll IsSessionBusy() and only re-evaluate when a
603+ // tea.Msg arrives, so the cleanup must precede the notify or
604+ // subscribers see stale busy state at the moment of receipt.
612 a.activeRequests.Del(call.SessionID)
605 a.activeRequests.Del(call.SessionID)
613 cancel()
606 cancel()
614
607
608+ // Send notification that agent has finished its turn (skip for
609+ // nested/non-interactive sessions).
610+ if !call.NonInteractive && a.notify != nil {
611+ a.notify.Publish(pubsub.CreatedEvent, notify.Notification{
612+ SessionID: call.SessionID,
613+ SessionTitle: currentSession.Title,
614+ Type: notify.TypeAgentFinished,
615+ })
616+ }
617+
615 queuedMessages, ok := a.messageQueue.Get(call.SessionID)
618 queuedMessages, ok := a.messageQueue.Get(call.SessionID)
616 if !ok || len(queuedMessages) == 0 {
619 if !ok || len(queuedMessages) == 0 {
617 return result, err
620 return result, err