OAuth refresh recovery after a lost rotation response can miss the provider's replay window
Problem
MCPProxy can lose a rotating OAuth grant when the authorization server completes a refresh but the client does not adopt the response. A later attempt still sends the previous refresh token. If that attempt arrives after the server's bounded replay window, the server rejects it and a new sign-in is required.
Observed with MCPProxy personal 0.72.0 on macOS arm64 and a FastMCP 4.0.10 authorization server using a local, 45-second idempotent replay extension. The extension returns the same previously issued access/refresh pair for a matching retry; it never creates another rotation from the consumed token.
The refresh serialization from #1498 is already present. This report concerns recovery after a completed server-side rotation whose response was not adopted, rather than concurrent refresh requests initiating multiple rotations.
Observed evidence and limits
- The server recorded a successful rotation.
- Later requests from the same client presented the previous token 69 and 75 seconds after that rotation and were rejected. An earlier occurrence showed the same pattern at approximately 47 seconds.
- The client retained the previous access-token generation and eventually required authorization again.
- We could not establish whether the first real response was lost in transport, timed out, or failed to be persisted. The central client log for that moment was no longer available. Nearby transport failures are context, not proof of the initial cause.
No provider credentials, private endpoints or production token values are needed to reproduce the failure class.
Synthetic reproduction
An isolated local test uses a rotating authorization-server fixture, temporary BBolt storage and the real OAuth client path:
- Seed a synthetic grant with refresh token R0.
- Accept R0, rotate once to R1, and truncate the first token response before the client can save it.
- Keep an idempotent replay record for R0 for 45 seconds.
- Retry R0 after that window. The fixture rejects it; the client has no R1 and cannot recover the grant.
- As a control, retry inside the window. The fixture returns the exact same pair, with one rotation in total.
Separate virtual-clock provider tests confirm recovery at 0 and 44 seconds and rejection at 46, 47, 69 and 75 seconds. A locally tested, provider-specific client prototype uses one immediate retry for typed transport failures inside the existing 30-second coordinator budget. It recovers the truncated-response fixture for both reactive and proactive paths, preserving generation/revision checks. That prototype is not an upstream-ready generic patch and is not installed in our normal runtime.
Proposed discussion
Would a per-upstream, explicitly enabled recovery policy be appropriate for authorization servers known to support idempotent refresh replay?
A possible scope is one bounded retry after an ambiguous transport failure, plus sanitized attempt timing and outcome diagnostics. Preserve serialization, grant revision checks, retirement barriers and all terminal OAuth errors. Do not retry invalid_grant, change scopes, clear credentials or overwrite a newer grant as a recovery shortcut.
This should not silently become the default for every provider: repeating a consumed refresh token can trigger reuse detection and revoke the grant when the authorization server has no replay support. Client retry alone also cannot guarantee recovery across server crashes or longer outages.
Related work
- #1498: refresh serialization, classification and backoff; this report is a follow-up about an ambiguous completed rotation.
- #295: earlier stored-DCR token synchronization, a different failure path.
- #1722: pending login retirement, also a different path.
- https://github.com/PrefectHQ/fastmcp/issues/4901: server-side client-refresh rotation without grace.
- https://github.com/PrefectHQ/fastmcp/pull/5037: proposed server-side replay window, currently closed without merge.
We can adapt the synthetic reproduction to current main and prepare a small PR after agreeing on the recovery contract. The immediate operational workaround is a bounded server-side replay window while continuing to use the official MCPProxy binary.
Thanks for the detailed report and the synthetic reproduction. I read the refresh path on main before replying.
Today a lost refresh response is classified as a network failure, which is transient. The coordinator puts a cooldown on that grant (10s, doubling, capped at 5 min) and the proactive refresher reschedules with the same backoff. Both resend the same refresh token. So the first retry already goes out about 10s later and the next about 30s after the first failure. With a 45 second replay window those two attempts should fall inside it. The rejections you saw at 47, 69 and 75 seconds look like the third and fourth attempts, which means the earlier ones failed too or did not fire. If the cause was a sleeping laptop or a network outage, an immediate replay does not help either, because the flight is capped at 30s.
Could you share the sanitized refresh log lines for one occurrence (attempt times, outcome class, trigger)? That tells us whether the first retry is too late or the retries fail for another reason.
On the contract: I agree it must be opt-in. Replaying a consumed refresh token trips reuse detection on providers without a replay window, so it can never be inferred from a network error. I reviewed #1828 with that in mind and left notes there. I am keeping this issue open until we know the flag fixes the case you observed.
Thanks for checking the retry path and for the fixes in #1828. I rechecked the retained logs and need to qualify the original report: the +47/+69/+75 second values are provider-side rejection times, not proven times of the first client retry. Your explanation of the earlier retries is consistent with additional client-side markers I found.
The incident client reported MCPProxy v0.72.0, revision 766655d6a7c70a211beb4442cc5db25e624d0a15, on macOS arm64. The provider used FastMCP 4.0.10 with a custom 45-second idempotent replay window. That window was our provider extension, not a claim about stock FastMCP behavior.
For the November 5 occurrence, these are the retained client log excerpts. All timestamps are UTC-03:00. Identifying fields, endpoints and extra parameters are omitted:
2026-11-05T05:06:39.837-03:00 | DEBUG | oauth | Injected extra params into token request body
2026-11-05T05:09:31.223-03:00 | INFO | core/connection_oauth.go:476 | MCP initialization completed successfully
2026-11-05T05:09:31.242-03:00 | INFO | managed/client.go:623 | Successfully connected and initialized
2026-11-05T05:09:39.848-03:00 | DEBUG | oauth | Injected extra params into token request body
2026-11-05T05:10:29.852-03:00 | DEBUG | oauth | Injected extra params into token request body
2026-11-05T05:11:19.240-03:00 | INFO | core/connection_lifecycle.go:293 | Disconnecting from server
2026-11-05T05:12:40.088-03:00 | ERROR | core/connection.go:345 | Connection failed
The final connection failure contains no valid token available. It is a connection-level result, not the outcome of a correlated refresh attempt.
The preserved provider extraction contains the following events for the same client. These are normalized records, not verbatim raw lines:
2026-11-05T05:09:30-03:00 New token pair issued
2026-11-05T05:10:39-03:00 Refresh token not found (+69s after issuance)
2026-11-05T05:10:45-03:00 Refresh token not found (+75s after issuance)
The marker at 05:09:39.848 is approximately 10 seconds after provider issuance. In the reported revision's transport wrapper, that message is emitted before the underlying RoundTrip. It confirms request preparation at the token endpoint, but does not record grant_type, delivery, response class, trigger or retry number. We therefore cannot assign it to a specific coordinator/proactive retry or pair it with either provider rejection. Provider timestamps have one-second precision, and cross-host clock skew was not measured.
The main limitation is retention: during the investigation, the central client log archive only covered the afternoon, starting at 14:59. The per-server log retained the lines above but not the full refresh attempt/outcome/trigger sequence you requested. The earlier extraction had also omitted these request-preparation markers. On November 3 there is a similar marker at 20:25:33.879, shortly after provider issuance at 20:25:28 and before the rejection at 20:26:15. That further limits the original timing interpretation.
There was provider-host restart and connection instability before the November 5 sequence, but no recorded provider restart between issuance and the two rejections. That context does not establish why the new token pair was not subsequently available to the client.
We later increased our provider replay window to 120 seconds and observed a normal scheduled renewal on the unchanged official client. We did not observe a lost-response recovery, and we have not deployed #1828. The synthetic reproduction demonstrates the recovery mechanism under its injected failure; it does not demonstrate that the new flag fixes this production occurrence.
I agree this should remain open. The retained evidence cannot distinguish an early attempt that failed from other scheduling, transport or persistence paths. Establishing that would require a correlated trace of attempt start, trigger, outcome and token persistence; that trace is not available for this occurrence.
Thanks for the careful recheck. It changes the picture, so here is what the code says about your excerpts.
What the three markers are. Injected extra params into token request body is written for any POST to the token endpoint that goes through the server's OAuth transport. That covers the refresh mcp-go sends and a sign-in code exchange. The line is written before the request is sent, and only when extra_params are set. It does not record the grant type. The fractional seconds of the three lines (.837, .848, .852) stay almost the same over 230 s. That points to one timer chain: each request started a whole number of 10 s steps after the previous one ended. The retry backoff and the reactive cooldown both work in 10 s steps (10 s, doubling, up to 5 min). So these are most likely repeat attempts after failures, not separate triggers. The logs cannot say which trigger fired them.
Could a request carry an already-rotated token? Yes. The coordinator only holds a request back when the stored refresh token differs from the one the caller read. If the pair issued at 05:09:30 was never stored on the client, every later refresh sends the consumed token, and that fits Refresh token not found. Both later markers (05:09:39, 05:10:29) come after the issuance. If either was a refresh, it carried a rotated token.
What does not fit. The two rejections are 6 s apart (05:10:39, 05:10:45) and the markers are 50 s apart. No single clock offset matches both rejections to markers, and the issuance at 05:09:30 has no marker either. So at least one request the provider saw left no marker. One known reason: a refresh that uses the stored client registration (from dynamic client registration) does not go through that transport and logged no request line at all. The connect at 05:09:31 does not show that the new pair arrived either. The old access token was probably still valid then.
Would the #1828 flag have helped? That is not shown. refresh_replay_enabled (v0.73.0 and later) retries once, immediately, only when the first request fails with a transport error such as a timeout or a cut response. It also needs an explicit token_endpoint. If the client got the response and then lost the pair, or a later request used the old token through another path, the flag does not help. v0.72.0 did not have the flag.
The logging gap is real, and worse than it looked. On v0.72.0 (and on main until now), the coordinator's OAuth refresh flight finished line went to the global logger. This binary never installs that logger, so the line was written nowhere, not in main.log and not in the server log. That is why your logs have no attempt or outcome lines. The marker was the only trace left. #2063 adds these INFO lines to the main log and to the server's own log file:
OAuth refresh flight started:trigger(proactive or reactive), aflightnumber, andprior_transient_failures. It is written before anything is sent.OAuth token request finished: one line per request to the token endpoint, on both refresh paths. It carriesgrant_type,flight,trigger, the provider'shttp_status, anoutcomeclass andduration.OAuth refresh flight finished: the sameflightwith its outcome.
None of these lines contain tokens, codes, URLs or error text. Since v0.74.0, failed refresh requests also appear in mcpproxy activity list.
What would close this. Please run a release that includes #2063 (the next one after it merges, or a build from main). On the next occurrence, send the lines above from the issuance to the rejection, together with the provider events. If they show a lost response, refresh_replay_enabled is the fix and we can close. If they show a request with the consumed token after a successful response, that is a persistence bug and we will fix it here. I am leaving the issue open until then.
Thanks for tracking down the logging gap. One detail about the changes on our side may help. On November 13 we upgraded the existing Workspace MCP server from 2.1.0 to 2.4.2, which also moved FastMCP from 4.0.10 to 4.1.4. That version distinguishes temporary upstream refresh failures from invalid_grant (PrefectHQ/fastmcp#5002). We couldn’t link that behavior to the original incident.
On November 15 we switched to a fresh Workspace MCP 2.5.0 installation, still using FastMCP 4.1.4, with fresh OAuth storage and refresh_replay_enabled disabled for this upstream. Since then, we haven’t observed the specific sequence reported here: a new pair issued by the provider, followed by rejection of the previous refresh token. The original cause remains open. If it recurs on a release that includes #2063, we’ll share the sanitized client and provider events for the same interval.
Thanks for the update on the FastMCP upgrade and the fresh storage. I went through the refresh path on main once more to see what is still missing from the trace.
What the code does after a lost refresh response. The provider rotated the pair, but the client got no usable answer. The failure is classed as network, which is transient. Nothing is stored, so the old refresh token is still the stored one, and every retry sends it again. Without refresh_replay_enabled the first retry goes out 10 s after the flight ends (reactive cooldown or proactive backoff, 10 s doubling up to 5 min). A flight can wait up to 30 s for an answer that never comes, so with a hung response the first retry can leave about 40 s after the original request. That is close to a 45 s replay window. With refresh_replay_enabled the first request gets 10 s and the retry goes out right away inside the same flight. A prompt retry with the same token stays opt-in. On a provider without a replay window it trips reuse detection and revokes the grant.
What was still missing. #2063 logs each flight and each token request. It did not log whether the new pair was stored. The token store wrote that through the global logger, which writes nowhere in this binary. So "the provider issued a pair, the client got a 200, and the pair was then dropped" left no line. That is the case your November 5 trace could not rule out.
What #2094 changes. Each attempt to store a token response now writes one INFO line, OAuth token save finished, to the main log and to the server's own log. Fields:
result:saved;superseded(the stored refresh token or client ID no longer matches the one the flight started with, or the record is gone, for example after a sign-in, another flight, a sign-out or connection recovery);instance_replaced(the server was removed or reconfigured meanwhile);cancelled(the request's deadline passed before the answer could be stored); orfailed(reading or writing the stored record failed).flightandtrigger: the same values as on the flight and token-request lines. A sign-in has0andnone.refresh_token_changed(onsaved): a non-empty refresh token different from the stored one was saved; on a refresh, the provider rotated it.
One case is worth naming. If the answer arrives at the very end of the flight's 30 s deadline, the token store drops it and the old token stays stored (on the usual path through the connection's OAuth handler). Until now that happened silently. It now shows as cancelled.
The quick-retry lines (OAuth refresh attempt finished, OAuth quick retry skipped) now carry flight and trigger too, and they also reach the server's own log. No line contains tokens, codes, URLs or error text.
If it happens again, send these lines for the server, from the provider's issuance to the rejection, together with the provider events for the same interval:
OAuth refresh flight startedOAuth token request finishedOAuth token save finishedOAuth refresh flight finishedOAuth refresh attempt finished/OAuth quick retry skipped, ifrefresh_replay_enabledis on
What they would tell us: whether the request that got the new pair came back with a 200 or failed in transport (outcome), and whether that flight then stored the pair (result). A lost response points to refresh_replay_enabled. A pair that was read but not saved, or a later flight that still sends the old token after a saved line, is something to fix on our side.
I am leaving the issue open until a trace like this shows which case it was.