The Driver Transactions Specification says (paraphrasing):
The driver will automatically retry the commitTransaction once after a retryable error.
The driver MUST add the "UnknownTransactionCommitResult" error label when commitTransaction fails with a server selection error, network error, retryable writes error, or write concern failed / timeout. If an exception with this label is thrown, an application can safely call commitTransaction again.
See the spec for full details of which errors are retryable.
Let's make the shell's commitTransaction helper match this section of the drivers spec. DBAs may use transactions in the shell for critical tasks. For the sake of both reliability and consistency, the shell should provide them with the same retry logic drivers do.