This has saved me a bunch of times, so might be useful to other people. When I change firewall rules on a remote machine, I always run the following command:
# service pf restart && sleep 30 && service pf stop
And then I hit control-C after a few seconds. If my ssh session is still working, this cancels the service pf stop command. If I've managed to break my ssh connection with the rule change, the firewall is disabled after 30 seconds and I can revert the changes and reenable it.