fix(agent): make sure we finish thinking on error

Kujtim Hoxha created

Change summary

internal/agent/agent.go | 2 ++
1 file changed, 2 insertions(+)

Detailed changes

internal/agent/agent.go 🔗

@@ -351,6 +351,8 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
 		if currentAssistant == nil {
 			return result, err
 		}
+		// Ensure we finish thinking on error to close the reasoning state
+		currentAssistant.FinishThinking()
 		toolCalls := currentAssistant.ToolCalls()
 		// INFO: we use the parent context here because the genCtx has been cancelled
 		msgs, createErr := a.messages.List(ctx, currentAssistant.SessionID)