Skip to content

Automation & Integrations

Designing Reliable OAuth Integrations: Lessons From a Failed Gmail Automation

How to diagnose authorization failures, communicate connection health, and retry safely

Owen Velasco · Applied AI & Software Engineer | AI Applications, Automation Platforms, APIs & Enterprise Integrations · Dec 4, 2026 · 4 min read

When I tested a Gmail send in Automation Hub, the editor returned “Bad Request” twice. That sent me looking at the obvious suspects: the recipient, the message, the attachments. The trace showed a different failure. The connector had reached Google’s token endpoint and stopped there. Gmail had never received a send request.

The failure was straightforward once I could see the sequence. The access token had expired, the connector tried to refresh it, and Google rejected the refresh grant. The confusing part was that our error handling preserved the provider’s generic description and dropped the OAuth code that explained what had happened. To someone using the workflow builder, a broken connection looked like an invalid email.

Authorization precedes the Gmail request. A rejected refresh grant stops execution and asks the operator to reconnect.

The stage where a connector stops determines both the operator’s next action and whether the action can safely be attempted again.

Give authorization and execution separate outcomes

An access token is what the connector presents to an API. A refresh token is a credential the connector can exchange for a new access token. When the current access token expires, a valid refresh token can let the connector continue without involving the user. When the refresh grant itself is rejected, the connection may need fresh authorization. In the Gmail case, editing the request would change nothing about that exchange. The OAuth specification describes the exchange and its error responses. OAuth 2.0, sections 5.2 and 6

I model a connector execution as a series of checkpoints. Load the saved connection, obtain a usable access token, make the provider request, and interpret the result. Each checkpoint should be able to fail on its own terms. A missing connection needs setup. A rejected refresh grant needs attention from someone who can reauthorize. An invalid message needs a change to the action. The HTTP status alone is too coarse to determine which situation occurred.

The Gmail repair preserved the underlying OAuth error code so a rejected grant could produce a reconnect instruction. A genuine Gmail validation error could then identify the service and surface a safe provider reason. The distinction is valuable above the connector layer too. A workflow runner needs to decide whether to pause, retry, or stop. If it receives only a string like “Bad Request,” it has to guess.

Show what a connection can do now

A saved connection establishes that someone completed setup at some point. For an integration platform, I would also record when the connection last passed a relevant check, whether it has the scopes the action requires, and whether a recent failure requires the account owner’s intervention. A generic connection check can establish that authorization works for the check it performed. The workflow action still has its own permissions, inputs, and provider behavior.

I would keep connection health separate from run history. If someone reconnects an account, the settings screen can reflect the new health state while an earlier run retains the reason it stopped. That distinction matters when several workflows share one connection. A person investigating an old failure should be able to see what happened at the time and whether there is anything left to repair today.

I want errors to answer a practical question in plain language. “Reconnect Gmail to continue. This attempt stopped before the send request” tells the operator what to do and what happened to the email. An internal record can carry the stage, a safe provider code, and a run correlation identifier. Credentials, raw outbound messages, and provider responses containing account data have no place in a general-purpose diagnostic stream.

Retry based on the side effect

The run trace established that the Gmail action never started. If authorization is restored, retrying that action can proceed without duplicating a send from the failed attempt. Retrying an entire workflow deserves a separate decision. Steps before Gmail might already have created a record or sent a notification.

A timeout after handing the request to Gmail is a different problem. The action may have completed while the response was lost. For connectors I design, I would use a stable operation identifier where the provider supports idempotency, or reconcile against a provider receipt where there is a trustworthy lookup. Both approaches depend on actual provider capabilities. When neither is available, the run should preserve the uncertainty so an operator can weigh the consequence of another attempt.

I would also test two workers reaching an expired connection at the same time. If a provider rotates refresh tokens, independent refreshes can race, and a stale worker can overwrite newer credentials. Coordinating refresh per connection and checking which credential version is being updated are useful design options. Those are platform recommendations, separate from the error-handling change in the Gmail case.

Test the next decision

For a connector like this, I would put four cases in the release check. An expired access token successfully refreshes and the action runs. A rejected refresh prevents the provider request and offers reauthorization. A provider validation error preserves the relevant reason. A lost response after a potentially successful action leaves a visible uncertain outcome. In each case I would verify the UI message, the persisted run state, and the actual calls made by the runner.

The Gmail test taught me to judge connector reliability by what the workflow can do with a failure. It should preserve enough evidence to resume at the right step, explain when a person must intervene, and avoid repeating a side effect whose outcome is still unknown.

OAuth · API integrations · workflow automation · retry safety

Related work

More of the systems behind this writing is on the Work and Contact pages.