Repository navigation
fix(router): abort router-transform on proactive invalid_grant instead of retrying (INT-6779) - #7175
Merged
shekhar-rudder merged 1 commit intoAug 28, 2026
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7175 +/- ##
==========================================
+ Coverage 80.01% 80.31% +0.29%
==========================================
Files 595 600 +5
Lines 66133 67034 +901
==========================================
+ Hits 52915 53836 +921
+ Misses 10071 10036 -35
- Partials 3147 3162 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
saikumarrs
approved these changes
Jul 21, 2026
…d of retrying (INT-6779) When an OAuth destination's refresh token is revoked/expired, rudder-auth returns ref_token_invalid_grant. During router transformation, a proactive FetchToken that fails this way was returned by the OAuth transport's preRoundTrip as a raw-text HTTP 400 body. The router-transform response handler collapses any non-200 (non-404) response to a hardcoded 500 (retryable), so the real 400 was discarded - the job retried for the full retry window (~3h) and was ultimately drained at 410 instead of aborting. This makes ref_token_invalid_grant abort at 400 in the router-transform flow: - services/oauth/v2/http/transport.go: preRoundTrip now reports a failed FetchToken through the TransportResponse/InterceptorResponse envelope, carrying the real status code and a clean message. OriginalResponse keeps the raw error text, so every caller that falls back to it is unaffected. - services/oauth/v2/types.go: OAuthInterceptorResponse gains an ErrorType field, so callers act on the specific failure instead of inferring terminality from the status code. - router/transformer/transformer.go: the non-200 else-branch aborts with a 400 only when the interceptor reports ref_token_invalid_grant. The error type alone decides; the status the interceptor attached is not consulted, since a revoked refresh token is terminal however it arrives. Every other interceptor outcome keeps the existing retryable path and its original message. invalid_grant still counts toward the per-account OAuth circuit breaker (kept as-is to preserve control-plane protection); a multi-account breaker-trip alert to distinguish a control-plane-wide issue from isolated token revocations is tracked as a follow-up. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
shekhar-rudder
force-pushed
the
feature/int-6779-circuit-breaker-triggered-by-invalid-refresh-tokens
branch
from
August 4, 2026 12:28
5da4e14 to
705229a
Compare
saikumarrs
approved these changes
Aug 4, 2026
Contributor
|
This PR is considered to be stale. It has been open 20 days with no further activity thus it is going to be closed in 7 days. To avoid such a case please consider removing the stale label manually or add a comment to the PR. |
ItsSudip
approved these changes
Aug 28, 2026
shekhar-rudder
deleted the
feature/int-6779-circuit-breaker-triggered-by-invalid-refresh-tokens
branch
August 28, 2026 05:46
This was referenced Aug 31, 2026
Merged
itsmihir
pushed a commit
that referenced
this pull request
Aug 31, 2026
🤖 I have created a release *beep* *boop* --- ## [1.85.0-rc.1](v1.84.0...v1.85.0-rc.1) (2026-08-31) ### Features * backend config v2 resolver with stub mapper ([#7275](#7275)) ([267b973](267b973)) * **warehouse:** clickhouse v2 connection and schema ([#7301](#7301)) ([2eb1fa6](2eb1fa6)) * **warehouse:** clickhouse v2 ddl operations ([#7302](#7302)) ([f2887c5](f2887c5)) * **warehouse:** clickhouse v2 loading ([#7303](#7303)) ([3e48618](3e48618)) * **warehouse:** enable the clickhouse v2 driver behind a flag ([#7311](#7311)) ([3ce1da5](3ce1da5)) ### Bug Fixes * race conditions while counting initial pending events can cause wrong counting ([#7292](#7292)) ([3efa718](3efa718)) * replay destinations not using the config corresponding to their connected source type ([#7307](#7307)) ([ee7aa93](ee7aa93)) * **router:** abort router-transform on proactive invalid_grant instead of retrying (INT-6779) ([#7175](#7175)) ([4d7348d](4d7348d)) * tracking plan merged config is cached without its event type ([#7314](#7314)) ([624dd5c](624dd5c)) ### Miscellaneous * setattr/delattr hardening ([#7291](#7291)) ([2855af4](2855af4)) * sync release v1.84.0 to main branch ([#7306](#7306)) ([fa102b7](fa102b7)) * webhook reasons ([#7294](#7294)) ([c298d59](c298d59)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir
pushed a commit
that referenced
this pull request
Sep 1, 2026
🤖 I have created a release *beep* *boop* --- ## [1.85.0](v1.84.0...v1.85.0) (2026-08-31) ### Features * backend config v2 resolver with stub mapper ([#7275](#7275)) ([267b973](267b973)) * **warehouse:** clickhouse v2 connection and schema ([#7301](#7301)) ([2eb1fa6](2eb1fa6)) * **warehouse:** clickhouse v2 ddl operations ([#7302](#7302)) ([f2887c5](f2887c5)) * **warehouse:** clickhouse v2 loading ([#7303](#7303)) ([3e48618](3e48618)) * **warehouse:** enable the clickhouse v2 driver behind a flag ([#7311](#7311)) ([3ce1da5](3ce1da5)) ### Bug Fixes * race conditions while counting initial pending events can cause wrong counting ([#7292](#7292)) ([3efa718](3efa718)) * replay destinations not using the config corresponding to their connected source type ([#7307](#7307)) ([ee7aa93](ee7aa93)) * **router:** abort router-transform on proactive invalid_grant instead of retrying (INT-6779) ([#7175](#7175)) ([4d7348d](4d7348d)) * tracking plan merged config is cached without its event type ([#7314](#7314)) ([624dd5c](624dd5c)) ### Miscellaneous * setattr/delattr hardening ([#7291](#7291)) ([2855af4](2855af4)) * sync release v1.84.0 to main branch ([#7306](#7306)) ([fa102b7](fa102b7)) * webhook reasons ([#7294](#7294)) ([c298d59](c298d59)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Related to INT-6779.
When an OAuth destination's refresh token is revoked/expired, rudder-auth returns
ref_token_invalid_grant. During router transformation, a proactiveFetchTokenthat fails this way was returned by the OAuth transport'spreRoundTripas a raw-text HTTP 400 body. The router-transform response handler collapses any non-200 (non-404) response to a hardcoded500(retryable), so the real400was discarded — the job retried for the full retry window (~3h) and was ultimately drained at410instead of aborting.This PR makes
ref_token_invalid_grantabort at 400 in the router-transform flow.services/oauth/v2/http/transport.go—preRoundTripnow reports a failedFetchTokenthrough theTransportResponse/InterceptorResponseenvelope, carrying the real status code and a clean message.OriginalResponsekeeps the raw error text, so every caller that falls back to it is unaffected.services/oauth/v2/types.go—OAuthInterceptorResponsegains anErrorTypefield, so callers act on the specific failure instead of inferring terminality from the status code.router/transformer/transformer.go— the non-200 else-branch aborts with a400only when the interceptor reportsref_token_invalid_grant. The error type alone decides; the status the interceptor attached is not consulted, since a revoked refresh token is terminal however it arrives. Every other interceptor outcome keeps the existing retryable path and its original message.Why there is no explicit
invalid_grantcheckAn earlier revision gated the envelope on
errors.Is(err, common.ErrInvalidGrant). That check was redundant and has been removed:FetchTokencan only ever return400or500, and400is produced exclusively byref_token_invalid_grant—getRefreshTokenFromResponseinitialisesstatusCodeto500and only thecommon.RefTokenInvalidGrantcase sets400; every other failure path isNewStatusCodeError(http.StatusInternalServerError, ...). The status code already carries the signal the check was re-deriving.What actually fixes the bug is the response body, not the gate: router transformation ignores the raw HTTP status, so the real status has to travel inside the interceptor envelope for the handler to see it.
An earlier revision of this PR gated the abort on the interceptor status being
< 500. That was broader than intended:postRoundTripalso reportsAUTH_STATUS_INACTIVEas a terminal400, so a non-200 transform response carrying that category would have aborted where it previously retried. The gate is now keyed onErrorType == common.RefTokenInvalidGrantalone.Keying on the type rather than the status also closes a reachable gap:
getRefreshTokenFromResponsehas an early branch on a top-levelerrorTypekey that hardcodes a500, so a control plane reportingref_token_invalid_grantthat way produced a retryable500and burned the full retry window. It now aborts like any otherinvalid_grant.No change to the delivery/proxy flow — its reactive
RefreshToken→400abort already worked correctly.Scope note
An earlier revision of this PR also excluded
invalid_grantfrom the per-account OAuth circuit breaker. That has been reverted: we're keepinginvalid_grantcounting toward the breaker (it preserves control-plane protection). The circuit-breaker / alerting side of INT-6779 — detecting a control-plane bug that erroneously returnsinvalid_grant— will be handled separately via a multi-account breaker-trip alert (fire when the breaker trips across many distinct accounts, which distinguishes a CP-wide problem from isolated token revocations), tracked as a follow-up.Behavior change
For a revoked-token OAuth destination (e.g. LINKEDIN_ADS): jobs abort immediately with
400and a "please reauthorize" message — no 3-hour retry storm, no410drain. Transient/other failures (empty secret, network, non-invalid_granterrors →500) still retry, unchanged.Testing
TestRouterTransformationWithOAuthV2:invalid_grant→ jobs abort at400with the clean message;invalid_grantproactive failure (empty secret) stays500(retryable);TestRouterTransformationWithOAuthV2(new regression case):AUTH_STATUS_INACTIVE(a terminal400that is notinvalid_grant) stays500and is retried. This case fails under the old< 500gate;invalid_grantreported via the top-levelerrorTypekey (status500) still aborts at400. This case fails under the earlier status-honouring gate.services/oauth/v2/http(new, table-driven at the transport level):invalid_grant→400, taggedErrorType: ref_token_invalid_grant, clean message inInterceptorResponse.Response, raw text preserved inOriginalResponse;INVALID_REFRESH_RESPONSE→500, tagged with its own error type;500, emptyErrorType,OriginalResponseunchanged from the pre-envelope raw body.Also verified green (these consume the same transport and see the changed body):
regulation-worker/internal/delete/api,yandexmetrica,salesforce-bulk-upload,services/oauth/v2.Known review findings
Open, not addressed here — flagging for reviewer input:
invalid_grantstill counts toward the per-account error breaker, once it trips (5 consecutive failures)withErrBreakerreturns the cachedlastErrorfor 5 minutes without calling the control plane (services/oauth/v2/oauth_breaker.go:191). That stale error still carries the terminal400, so for that window every job on the account aborts on the strength of one old CP response. Given INT-6779's premise is that the CP can erroneously returninvalid_grant, it may be worth putting the abort behind a config var so it can be disabled without a rollback.🤖 Generated with Claude Code