Are there libraries to automatically implement the refresh logic?
For web-oidc (https://github.com/sergiodxa/web-oidc) I added a refresh method, that package comes with a OIDCStrategy for Remix Auth so if you're using Remix Auth with a OIDC compatible (not just OAuth) provider you can use that strategy, it will only hide how to do the refresh, you still need to update your session, btw doing this is just a fetch so it's not that hard anyway.
If a token is forcefully revoked on the backend, how do you "bubble up" an arbitrary 401 response to redirect the user back to login?
Usually you can know that by doing a fetch, the response should be a 401 and you can then destroy the user session and redirect it to the login, if you handle 401s by refreshing the token the backend would need to also invalidate the refresh token, this way the refreshing will also fail with a 401 and then you can do the destroy session + redirect to login.
How do people implementing refresh tokens (OAuth/JWT) typically handle race conditions: e.g. multiple requests/responses on a refresh can lead to the sessionCookie being set in competing requests... (this seems like an issue common to any frontend deployment).
This is a hard one, to solve the specific issue in Remix where multiple loaders run together and you want to refresh only once the simplest way is to do it on the HTTP server (e.g. Express) before Remix's request handler runs, this way it will always happen once.
The problem is that this solves the issue only on SSR where multiple loaders handle the same request, but if your app fetches more than one loader client-side then each loader will have a unique request meaning they won't run in the same request context, so each one will run the refresh "middleware".
I'm not 100% sure how to handle this, I would probably check how it's solved in Rails/Laravel/etc since they should have the same issue, one way could be store the tokens in a central place and batch the refreshes there.