Skip to content

v3.3.7 β€” Auth-gated sync state machine; stop infinite retry on auth failure

Latest

Choose a tag to compare

@Suydev Suydev released this 08 Jun 02:49
· 88 commits to main since this release

[3.3.7] β€” 2026-06-08 β€” Fix: auth-gated sync state machine; stop infinite retry on auth failure

Fixed (sync state machine β€” complete rebuild)

  • Auth failure is now a STOP condition, not a retry condition β€” Previously any auth error (expired session, no session, 401) caused the sync to be written as failed and retried on the next timer tick, visibility change, or online event. The same 2009 KB payload would upload infinitely. Now any auth error immediately sets __isoSyncAuthBlocked = true and the entire sync pipeline halts.
  • New isAuthError / isPermissionError / isNetworkError classifiers β€” Errors are classified before deciding to stop vs. retry. Network errors still retry; auth and permission errors do not.
  • authedJson now throws tagged AuthError objects β€” When JWT is null or refresh fails, the thrown Error has __isAuthError = true. When the server returns 401/auth message, the thrown error is also tagged. All callers can now distinguish the error type.
  • 30-min timer stops on auth failure, restarts on recovery β€” __isoSyncAuthBlock() calls clearInterval(_autoSyncTimer). __isoSyncAuthUnblock() restarts it and schedules one sync attempt.
  • All sync triggers check auth-blocked state β€” __isoAutoSync, __isoStartupSync, the 30-min timer interval, the visibility-change handler, and the online-event handler all check window.__isoSyncAuthBlocked and return { reason: 'paused_auth' } without running any upload/download.
  • Token intercept unblocks sync on new valid session β€” When Supabase returns a new access_token (login, token refresh), the fetch interceptor calls window.__isoSyncAuthUnblock(), which clears the blocked flag, restarts the timer, and queues one sync attempt 2 s later.
  • Login (__isoLogin) unblocks sync on success β€” After a successful username/password login and profile sync, __isoSyncAuthUnblock() is called so sync resumes without waiting for the next Supabase token intercept.
  • Online event re-validates session before unblocking β€” When the network comes back and __isoSyncAuthBlocked is true, the handler calls getValidJwt() first; if a valid JWT exists, it unblocks and syncs. It does not blindly retry the upload.
  • Smart-sync catch re-throws auth errors β€” The try/catch around /__auth/backup/latest in __isoRunManualCloudSync previously swallowed all errors as "non-fatal". Now auth errors are rethrown so they propagate to the outer catch and trigger the block.
  • Permission errors get a distinct failed_permission status β€” These are written to sync metadata and history separately; they never trigger a retry.
  • All sync operations (snapshot, upload, download_import, manual_sync) handle auth errors uniformly β€” Each catch block calls __isoSyncAuthBlock() and writes paused_auth to sync history instead of failed.

Audit (v3.3.7 β€” 2026-06-08)

# Check Result
1 Auth failure stops all scheduled sync βœ… fixed
2 Same payload never uploads infinitely on auth error βœ… fixed
3 30-min timer cleared on auth failure βœ… fixed
4 Timer restarted on new valid session βœ… fixed
5 All sync triggers check __isoSyncAuthBlocked βœ… fixed
6 Token intercept calls __isoSyncAuthUnblock() βœ… fixed
7 Login success calls __isoSyncAuthUnblock() βœ… fixed
8 Auth vs network vs permission errors classified βœ… fixed
9 Smart-sync auth errors propagate instead of being swallowed βœ… fixed