Is there language I can insert that carves out an exception for patches I make to the open-source dependencies
Of course, but you've missed out the second requirement: that it be acceptable to the people who are paying for the work. We can't say whether any given proposal will be acceptable.
My standard terms say that "Copyright in all original code, configuration files, documentation and copy is and remains the property of the Company, and these are provided to the Client under the terms of the GNU General Public License, version 3 (or, at the Client's discretion, any later version).". If you can get them to sign that, your problems are over. If they balk, consider restraining that language to refer only to the work you do on the listed open-source dependencies (eg, change "all original code, configuration files, documentation and copy" to "all work on libfoo, barsnake, and gobaz").
If they won't go for that, you might try reversing the rider so that it obliges them to make all the work you do on those libraries available to you under the terms of whatever free licence will best enable you to contribute the work upstream. That way you won't have the copyright, but you will still have the code, and the right to contribute your changes in it to the projects.
Or you might try adding a similarly-constrained rider that commits them to contributing the work upstream in a fixed timeframe after payment. I wouldn't hold out too much hope in that option, because you don't want to end up suing your client for specific performance.