Treaties typically include information on how to withdraw. Also under Customary international law if one party is violating a treaty the other can put the violator on notice and then leave the treaty if behavior does not change. That is what the Trump Admin did with Iran.
The last enemy that followed the then current laws of war when fighting the US was the German army (not the SS, the army) in WWII.