Just before the 8 year warranty expires for the battery pack. If you get a replacement battery pack what would the warranty be for the new pack?
If it is replaced under warranty you get the rest of the warranty period, like any other warranty repair. If the warranty replacement happens VERY close to the end of the warranty I would expect you would get a very short (90 day?) type warranty to guard against a dud. If you pay for replacement, whatever warranty Tesla ends up offering on a replacement pack.