Skip to content

fix(auth): propagate transient refresh failures during sign out - #2071

Closed
ktsomani wants to merge 1 commit into
supabase:v2from
ktsomani:codex/fix-auth-signout-refresh-errors
Closed

ktsomani wants to merge 1 commit into
supabase:v2from
ktsomani:codex/fix-auth-signout-refresh-errors

Conversation

@ktsomani

@ktsomani ktsomani commented Nov 16, 2026 •

Copy link
Copy Markdown

Fixes #2070. Targets the stable v2 branch.

When an expired session must be refreshed before sign-out, a JSON HTTP 429 or 500 is classified as AuthApiError. The sign-out handler treated it as token rejection and silently cleared the session even though no logout request was sent. This left callers unable to retry global revocation.

Preserve the session and raise HTTP 429/5xx refresh errors for global/others scopes. Local scope still clears the local session and emits SIGNED_OUT, then raises the refresh error. Definite rejection handling and public error types are unchanged. This is a narrow v2 follow-up to #1823 / #1824; v3's policy is described in #2021.

Validation: four added async cases fail before the fix; after it, 76 selected sign-out cases pass across async and generated sync clients. Added cases cover JSON 429/500 across global/local/others. Ruff lint/format and mypy on both changed source files pass. Sync files were regenerated using the repository's unasync script and formatted. No live Auth integration suite was run.

Summary by CodeRabbit

  • Bug Fixes
    • Sign-out now handles rate-limit and server errors consistently: local sign-out clears the session, while other scopes retain it. The error is still reported in every case.
  • Tests
    • Added coverage for rate-limit and server errors across sign-out scopes.

@ktsomani
ktsomani requested a review from spydon as a code owner November 16, 2026 11:16
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Sign-out now re-raises refresh API errors with status 429 or 500+. For local scope, both clients clear the session and emit SIGNED_OUT before raising. For global and others scopes, they preserve the session. Tests cover both statuses across all scopes.

Changes: Sign-out refresh error handling

Layer / File(s) Summary
Scope-specific refresh error handling
src/auth/src/supabase_auth/_async/gotrue_client.py, src/auth/src/supabase_auth/_sync/gotrue_client.py, src/auth/tests/_async/test_gotrue.py, src/auth/tests/_sync/test_gotrue.py
Both clients separately handle AuthApiError statuses 429 and 500+. They re-raise the error for every scope; local scope clears the session and emits SIGNED_OUT. Tests cover both statuses for global, local, and others scopes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: irisfield, o-santi

Merge Risk: Minimal · up to 4463f

Sign-out now surfaces transient refresh failures such as rate limiting and server errors instead of treating them as token rejection. Sessions are preserved for global and others scopes, and local scope clears the session. No remaining merge-blocking risk was found.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #2070 requires, for JSON HTTP 429 and 500 refresh errors in sign_out: (1) global scope raises, keeps the session, and emits no SIGNED_OUT; (2) local scope clears the local session, emits SIGNED_… Provide readable blobs for the changed files at the reviewed head: src/auth/src/supabase_auth/_async/gotrue_client.py, src/auth/src/supabase_auth/_sync/gotrue_client.py, src/auth/tests/_async/test_gotrue.py, and src/auth/tests/_sync/test_go…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix (propagating transient refresh failures during sign out) and the scope (auth). The PR changes sign_out in the async and sync GoTrue clients so HTTP 429 and 5xx refresh errors a…
Out of Scope Changes check Passed The raw summary lists only small changes in the sign-out path of the async and sync GoTrue clients (+8/-1 each) and matching test additions (+6/-0 in each test file). It reports no changes to public o…
Full details: Title check

Explanation

The title names the fix (propagating transient refresh failures during sign out) and the scope (auth). The PR changes sign_out in the async and sync GoTrue clients so HTTP 429 and 5xx refresh errors are re-raised, with matching test coverage. The title matches the main change, so the check passes.

Full details: Out of Scope Changes check

Explanation

The raw summary lists only small changes in the sign-out path of the async and sync GoTrue clients (+8/-1 each) and matching test additions (+6/-0 in each test file). It reports no changes to public or exported declarations and no changes to error types or to the definite-rejection branch. Each change maps to issue #2070. The sync files are described as regenerated from the async source, which matches the stated unasync workflow. Changes outside these four files are not described in the PR evidence. The diff itself could not be read, so this verdict relies on the summary.

Full details: Linked Issues check

Explanation

Issue #2070 requires, for JSON HTTP 429 and 500 refresh errors in sign_out: (1) global scope raises, keeps the session, and emits no SIGNED_OUT; (2) local scope clears the local session, emits SIGNED_OUT, and raises; (3) others scope raises and keeps the session; (4) definite token-rejection handling is unchanged. The raw summary of the PR states that AsyncGoTrueClient.sign_out and SyncGoTrueClient.sign_out now follow this behavior, and that tests cover 429 and 500 across global, local, and others. The PR description reports four added async cases, while the issue and the summary describe six cases. The whole-PR diff for the source and test files could not be read: the changed blobs are missing from the checkout. The file read of _async/gotrue_client.py was truncated before sign_out, so the except-branch logic was not verified. Requirements (1) to (4) therefore rest on the AI-generated summary and the PR description, not on source evidence.

Resolution

Provide readable blobs for the changed files at the reviewed head: src/auth/src/supabase_auth/_async/gotrue_client.py, src/auth/src/supabase_auth/_sync/gotrue_client.py, src/auth/tests/_async/test_gotrue.py, and src/auth/tests/_sync/test_gotrue.py. Then confirm in the sign_out except-block that status 429 and status 500 and above route to the scope-dependent path, that the local branch clears the session and emits SIGNED_OUT before re-raising, and that the test set covers 429 and 500 for all three scopes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 416bffd and 4463fcd.

Files selected for processing: 4

  • src/auth/src/supabase_auth/_async/gotrue_client.py
  • src/auth/src/supabase_auth/_sync/gotrue_client.py
  • src/auth/tests/_async/test_gotrue.py
  • src/auth/tests/_sync/test_gotrue.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@spydon

spydon commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

We only accept critical bug or security fixes for v2, this is not critical: it's an edge case that needs a coincidental rate limit or outage at sign-out.

@spydon spydon closed this Nov 16, 2026
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.

2 participants