on main help sign in
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.

commit23157b6a1dbbca77b4ce482f12ff98ea5e19d9e4 authorKieran Klukas <kieran@dunkirk.sh> dateThu 28 May 2026, 14:09 (5 months ago) parentd60a394
2 files changed+6−8
internal/agent/agent.go−8 internal/agent/coordinator.go+6
internal/agent/agent.go−8
@@ -641,14 +641,6 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (result *
641641 currentAssistant.AddFinish(message.FinishReasonCanceled, "User canceled request", "")
642642 } else if isHyper && errors.As(err, &providerErr) && providerErr.StatusCode == http.StatusUnauthorized {
643643 currentAssistant.AddFinish(message.FinishReasonError, "Unauthorized", `Please re-authenticate with Hyper. You can also run "crush auth" to re-authenticate.`)
644− if a.notify != nil {
645− a.notify.Publish(pubsub.CreatedEvent, notify.Notification{
646− SessionID: call.SessionID,
647− SessionTitle: currentSession.Title,
648− Type: notify.TypeReAuthenticate,
649− ProviderID: largeModel.ModelCfg.Provider,
650− })
651− }
652644 } else if isHyper && errors.As(err, &providerErr) && providerErr.StatusCode == http.StatusPaymentRequired {
653645 url := hyper.BaseURL()
654646 link := linkStyle.Hyperlink(url, "id=hyper").Render(url)
internal/agent/coordinator.go+6
@@ -266,6 +266,12 @@ func (c *coordinator) Run(ctx context.Context, sessionID string, prompt string,
266266 if err := c.retryAfterUnauthorized(ctx, providerCfg); err == nil {
267267 result, originalErr = run()
268268 }
269+ if c.notify != nil && model.ModelCfg.Provider == hyper.Name {
270+ c.notify.Publish(pubsub.CreatedEvent, notify.Notification{
271+ Type: notify.TypeReAuthenticate,
272+ ProviderID: model.ModelCfg.Provider,
273+ })
274+ }
269275 }
270276
271277 if hasLatest && c.runComplete != nil {