fix: session summarization dialog hanging indefinitely (#528)

Benjamin Oldenburg and Crush created

The summarization dialog was getting stuck in "Generating..." state due to two issues:
- Agent was formatting nil error values instead of actual response errors
- Dialog only handled summarize events but not error events, leaving it in loading state

💖 Generated with Crush

Co-authored-by: Crush <crush@charm.land>

Change summary

internal/llm/agent/agent.go                        |  2 +-
internal/tui/components/dialogs/compact/compact.go | 15 +++++++++++----
2 files changed, 12 insertions(+), 5 deletions(-)

Detailed changes

internal/llm/agent/agent.go 🔗

@@ -832,7 +832,7 @@ func (a *agent) Summarize(ctx context.Context, sessionID string) error {
 			if r.Error != nil {
 				event = AgentEvent{
 					Type:  AgentEventTypeError,
-					Error: fmt.Errorf("failed to summarize: %w", err),
+					Error: fmt.Errorf("failed to summarize: %w", r.Error),
 					Done:  true,
 				}
 				a.Publish(pubsub.CreatedEvent, event)

internal/tui/components/dialogs/compact/compact.go 🔗

@@ -104,17 +104,24 @@ func (c *compactDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		}
 
 	case agent.AgentEvent:
-		if msg.Type == agent.AgentEventTypeSummarize {
+		switch msg.Type {
+		case agent.AgentEventTypeSummarize:
 			if msg.Error != nil {
 				c.state = stateError
 				c.progress = "Error: " + msg.Error.Error()
 			} else if msg.Done {
-				return c, util.CmdHandler(
-					dialogs.CloseDialogMsg{},
-				)
+				return c, util.CmdHandler(dialogs.CloseDialogMsg{})
 			} else {
 				c.progress = msg.Progress
 			}
+		case agent.AgentEventTypeError:
+			// Handle errors that occur during summarization but are sent as separate error events.
+			c.state = stateError
+			if msg.Error != nil {
+				c.progress = "Error: " + msg.Error.Error()
+			} else {
+				c.progress = "An unknown error occurred"
+			}
 		}
 		return c, nil
 	}