Skip to content

fix: [SDK-5373] keep login waiters when a request gets no response (3/3) - #1579

Open
fadi-george wants to merge 2 commits into
fadi/sdk-5373-single-attempt-httpfrom
fadi/sdk-5373-login-waits-for-retry
Open

fadi-george wants to merge 2 commits into
fadi/sdk-5373-single-attempt-httpfrom
fadi/sdk-5373-login-waits-for-retry

Conversation

@fadi-george

@fadi-george fadi-george commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1577. Merge #1576 and #1577 first; this PR's diff is only OperationRepo's handling of a request that gets no response.

Description

1 Line Summary

Keep login() and other _enqueueAndWait waiters attached for the first few retries when a request gets no response, so await OneSignal.login() resolves when a retry succeeds after a blip, and still rejects if the API stays unreachable.

Details

Motivation

On main, when a request got no response while the browser was online, OperationRepo rejected the waiters but kept the ops queued (0c8fdaac4). await login() rejected after base.ts's ~2 min of retries, even when a later retry logged the user in. #1577 removes those internal retries, so this rejection would come right away on any blip. A 5xx or 429 (FailRetry) already keeps the waiter, so a missing response should behave the same way.

Scope

  • OperationRepo catch block: on RetryLimitError, requeue the ops with their resolvers and back off. This replaces the separate offline and online branches. Offline handling is unchanged, because _getNextOps holds the queue while navigator.onLine is false.
  • Once an op reaches OP_REPO_MAX_WAITER_RETRIES (5, about 2.5 min of backoff), its waiter rejects with FailNoretry and the op stays queued, like main's ~2 min rejection.
  • await login() now rejects on a final 4xx, FailPauseOpRepo, unauthorized, or after 5 tries with no response.
  • Left out: making login(sameId) return the earlier switch's promise. That branch is also the JWT refresh path after a 401, and returning a rejected promise there would fail login(sameId, newToken) even though the retry uses the new token.

Tradeoff

This reverses the intent of 0c8fdaac4. Internal code waits on _switchingUsersPromise, which settles with the login op, so these paths now wait through the login's retries too: SessionManager's handlers and the push grant (updatePushSubscriptionModelWithRawSubscription).

  • Brief network blip: they wait seconds, until the next retry succeeds.
  • API blocked (an ad blocker, CSP, or firewall): they wait about 2.5 min, then the waiters reject, close to main's ~2 min. The ops keep retrying in the background.

The cap covers only a missing response. A server that keeps returning 5xx still holds waiters, as it does on main. The ops stay queued and persisted either way.

  • Left out: keeping the waiter on a 401. The push grant has to go ahead while a login waits for a new JWT (covered by the SubscriptionManager IV tests), so a 401 still rejects login(). That rejection also tells the app its token was bad. A follow-up could split the promise: internal code waits on the first outcome, and login() on the final one.

Size (gzip -9 bytes, against #1577)

  • page.es6: 46781 → 46777
  • sw: unchanged

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

  • OperationRepo: on an online no-response failure, the ops and their waiter stay queued, and the waiter resolves after the retry. The login batch test checks that the waiter is not settled.
  • OperationRepo: after OP_REPO_MAX_WAITER_RETRIES failures with no response, the waiter rejects and the op stays queued.
  • LoginManagerQueue: addEmail during the backoff after a failed login still sends one user create with the email, and login() resolves.

vp check, full vp test (1113), and build:prod (size limits) pass.

Not tested in a browser.

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed (no UI)

Related Tickets


🤖 Generated with Claude Code

@abdulraqeeb33 abdulraqeeb33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review is of the commits on top of #1577.

A missing response now keeps the waiter and retries, the same way a 5xx already does. The batch goes back on the queue with its waiter, the retry count increments, and the repo waits. Offline still does not send until navigator.onLine is true, because _getNextOps returns null. A later success resolves login(). A final 4xx, a pause, or an unhandled unauthorized result still rejects it. Any other throw still deletes the batch. The tests cover the waiter staying through the failure and resolving on the retry, including addEmail during the backoff.

An online no-response used to log "Op execute error" before the requeue. The return now happens first, so that path only logs the delay. Offline was already silent. FailRetry still logs the retry.

@sherwinski sherwinski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createSubscribedUser awaits _enqueueAndWait, and init() awaits it on auto-resubscribe. With this change init() and SDK_INITIALIZED wait until a retry gets a response. Consider using _enqueue there instead.

@fadi-george
fadi-george force-pushed the fadi/sdk-5373-login-waits-for-retry branch 3 times, most recently from 460fc7c to 7cdec35 Compare November 14, 2026 00:59
A request that gets no response now keeps its operations and their
waiters in the queue and retries with backoff, as FailRetry already
does. login() resolves when a retry succeeds instead of rejecting on
a network blip while the login completes in the background.
Offline handling is unchanged: _getNextOps holds the queue.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fadi-george
fadi-george force-pushed the fadi/sdk-5373-login-waits-for-retry branch from 7cdec35 to 48769ff Compare November 14, 2026 01:00
@fadi-george

Copy link
Copy Markdown
Contributor Author

_enqueue would make requestPermission() resolve true when the backend rejects the subscription (covered by "should expose errors"), so I'd rather keep the wait there. Init only waits here when the subscription was never created, and main already holds init on a 5xx or offline in the same spot. This makes a no-response behave like a 5xx. If we want init to not block on it, I'd do that as a follow-up by not awaiting the backend part of auto-resubscribe, separate from the waiter change.

@fadi-george

Copy link
Copy Markdown
Contributor Author

Follow-up: added a cap (af8c438). After 5 tries with no response (~2.5 min of backoff) the waiter rejects and the op stays queued, so a blocked API no longer holds login() or init() forever, close to main's ~2 min. A 5xx still holds waiters like on main.

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.

3 participants