From 23157b6a1dbbca77b4ce482f12ff98ea5e19d9e4 Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Thu, 28 May 2026 14:09:31 -0400 Subject: [PATCH] fix(agent): move reauth notification from agent to coordinator The agent was publishing TypeReAuthenticate immediately on 401, before the coordinator had a chance to retry with a refreshed token. This caused premature reauth popups even when the retry would succeed. Move the notification to the coordinator so it only fires after retryAfterUnauthorized fails. --- internal/agent/agent.go | 8 -------- internal/agent/coordinator.go | 6 ++++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 53e63af3b95e8bb4fba6144675d97c3686e78546..5461ae7c5bd3ca055f286635199222ad02facfa5 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -641,14 +641,6 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (result * currentAssistant.AddFinish(message.FinishReasonCanceled, "User canceled request", "") } else if isHyper && errors.As(err, &providerErr) && providerErr.StatusCode == http.StatusUnauthorized { currentAssistant.AddFinish(message.FinishReasonError, "Unauthorized", `Please re-authenticate with Hyper. You can also run "crush auth" to re-authenticate.`) - if a.notify != nil { - a.notify.Publish(pubsub.CreatedEvent, notify.Notification{ - SessionID: call.SessionID, - SessionTitle: currentSession.Title, - Type: notify.TypeReAuthenticate, - ProviderID: largeModel.ModelCfg.Provider, - }) - } } else if isHyper && errors.As(err, &providerErr) && providerErr.StatusCode == http.StatusPaymentRequired { url := hyper.BaseURL() link := linkStyle.Hyperlink(url, "id=hyper").Render(url) diff --git a/internal/agent/coordinator.go b/internal/agent/coordinator.go index a26aa111eeb8e45a699a6aab90774f04a1aca4bb..860db8b36cb67c43667a0f4a0dfa0a8b1d2e3992 100644 --- a/internal/agent/coordinator.go +++ b/internal/agent/coordinator.go @@ -266,6 +266,12 @@ func (c *coordinator) Run(ctx context.Context, sessionID string, prompt string, if err := c.retryAfterUnauthorized(ctx, providerCfg); err == nil { result, originalErr = run() } + if c.notify != nil && model.ModelCfg.Provider == hyper.Name { + c.notify.Publish(pubsub.CreatedEvent, notify.Notification{ + Type: notify.TypeReAuthenticate, + ProviderID: model.ModelCfg.Provider, + }) + } } if hasLatest && c.runComplete != nil {