If the roleplay is going well and you want to reach a conclusion you both enjoy, just discuss it beforehand. A beginning, a middle, and an end... or leave the ending open, in case you and your partner want to revisit that world in the future and just want to take a break for the time being. You can cut it shorter than you originally intended if the completionist in you is losing passion for the world.
If the roleplay isn't going well, be as close to honest about the reason why as you can. It's never a happy conversation to have with someone enjoying themselves, but if for whatever reason you're not in a place to continue any longer, a partner deserves to know that much, even if your reason isn't entirely true.
And I get that that can be scary. You don't want to hurt someone's confidence or be subject to unnecessary insults, but I think being brave and adult enough to make that known is reasonable. If the opposing party pops off, hey, pop off right back. Either way, it's over, it's just a matter of how you decided to end it, one writer to another.