Skip to content

fix(wp-native-auth): reuse grace window for refresh-token retries after a lost response - #132

Merged
chubes4 merged 1 commit into
mainfrom
fix/refresh-reuse-grace-window
Dec 2, 2026
Merged

chubes4 merged 1 commit into
mainfrom
fix/refresh-reuse-grace-window

Conversation

@chubes4

@chubes4 chubes4 commented Dec 2, 2026

Copy link
Copy Markdown
Member

Fixes #131.

Why

On 2026-12-02 an overloaded server rotated a refresh token, but the client (Roadie) timed out before it got the response and retried with the superseded token. Reuse detection revoked the whole family, and every refresh after that returned invalid_grant, which locked the person out of their MCP tools. Client side: Extra-Chill/roadie#496.

What

  • New filter wp_native_auth_refresh_reuse_grace_seconds (constant WP_NATIVE_AUTH_REFRESH_REUSE_GRACE_SECONDS = 60, 0 disables), plus wp_native_auth_refresh_reuse_in_grace().
  • Prev-hash branch: inside the window, the superseded token is rotated again from the row's current hash. The undelivered pair is discarded. prev_token_hash keeps the client-held token, and last_used_at stays at the original rotation time, so retries never extend the window. Outside the window, or for a revoked family, the family is still revoked as before.
  • 0-rows race branch: inside the window it returns a retryable refresh_in_progress (409; on the OAuth path temporarily_unavailable 503) and does not revoke. Outside the window it revokes as before.
  • Status check: /token returning 400 invalid_grant is correct per RFC 6749 §5.2. The native route keeps 401. Both are now pinned by a test.
  • SCHEMAS.md is updated.

Tests

  • test-refresh-reuse-detection.php: a retry inside the window gets a fresh pair, the family survives, and the new pair keeps working. Retries don't extend the window, and a late replay revokes. Filter 0 disables the window. A revoked family gets no grace. The existing reuse and concurrency tests now age the row or disable grace.
  • test-oauth-token.php: grace retry through the OAuth path; reuse returns invalid_grant with a 400 status.
  • test-push-tokens.php: the family-revocation test runs with grace disabled.
  • New standalone tests/reuse-grace-standalone-smoke.php (in the manifest) exercises the real wp_native_auth_refresh_reuse_in_grace(). It passes locally, and php -l is clean.

AI disclosure: written by Extra Chill Bot (Claude) via direct fallback outside Homeboy (homeboy-lab overloaded, Extra-Chill/homeboy#19733), authorized by @Chubes.

…er a lost response

A client whose refresh request timed out after the server rotated still
holds the superseded token. Its retry was treated as theft and revoked the
whole token family, forcing a re-login.

Within wp_native_auth_refresh_reuse_grace_seconds (default 60s, 0 disables)
of the rotation, re-presenting the superseded token now returns a freshly
rotated pair. The window is anchored to the original rotation and is not
extended by retries; outside it, or for a revoked family, replay still
revokes the family. A concurrent 0-rows race inside the window returns a
retryable refresh_in_progress (OAuth temporarily_unavailable 503) instead of
revoking. The OAuth invalid_grant 400 status is pinned by a test.

Fixes #131
@chubes4
chubes4 merged commit 30d21f8 into main Dec 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp-native-auth: refresh-token reuse grace window — lost response from slow server must not burn the token family

1 participant