I've been re-watching Season 5 of Buffy the Vampire Slayer recently, and I was curious about some behind-the-scenes events that affected how the plot turned out. Specifically, at the end of "The Gift", the finale for that season,
Buffy dies.
This makes it seem like the episode was intended as a series finale, and indeed the show ended its run on the WB as this point, migrating to UPN for its remaining two seasons (and, in the process, undoing the major event described in the spoiler tag above.)
My question is: At what point in the production of Season 5 did Joss Whedon et al. realize that the show was going to continue beyond the end of that season? Did they think that the show was going to end with "The Gift", and then they had to scramble to "reset" things at the beginning of Season 6? Or did they know well in advance that they had been picked up by UPN, and still chose to go ahead with the Season 5 story arc as planned?