Skip to content

refactor: [SDK-5373] send every API request once with exponential op backoff (2/3) - #1577

Open
fadi-george wants to merge 5 commits into
fadi/sdk-5373-sessions-single-attemptfrom
fadi/sdk-5373-single-attempt-http
Open

fadi-george wants to merge 5 commits into
fadi/sdk-5373-sessions-single-attemptfrom
fadi/sdk-5373-single-attempt-http

Conversation

@fadi-george

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

Copy link
Copy Markdown
Contributor

Stacked on #1576. Merge that first; this PR's diff is only the change to base.call and OperationRepo. Followed by #1579.

Description

1 Line Summary

Send every API request once, like Android's HttpClient, and give OperationRepo exponential backoff in place of the retry loop in base.ts.

Details

Motivation

#1576 gave session requests a single-attempt path (callOnce), separate from call(), which retried network errors 5 times over about 2 minutes and threw before returning the status on a non-JSON body. This PR applies the same behavior to every request. That removes the duplicate path, and the bundles get smaller. Android sends every request once and leaves retries to its OperationRepo, which uses exponential backoff.

Scope

  • base.ts: call() makes one attempt. With no response it rejects with RetryLimitError, so OperationRepo's offline and blocked branches keep working unchanged. Otherwise it returns ok, status and Retry-After even when the body is empty or not JSON (result is then undefined). executeFetch and callOnce are removed, and sessions goes back to post/patch.
  • OperationRepo._delayBeforeNextExecution, matching Android's ConfigModel: the backoff starts at 5s, doubles per failure up to 5 min, and is jittered by 0.5 to 1×. Retry-After is capped at 1h. Before this, the backoff was retries × 1s and Retry-After had no cap.
  • sendOutcome logs a non-2xx response. A non-JSON error used to show up only as a throw.
  • RETRY_MS is removed.

Behavior changes

  • With the browser online, a network failure now rejects login() and other waiters right away instead of after about 2 minutes. The ops stay queued and retry with the backoff above. Offline handling is unchanged.
  • The service worker's confirmed-delivery and opened puts are sent once. Android also sends these once.
  • A 2xx with a non-JSON body gives the executors result: undefined. Before, it threw. Both end in OperationRepo's "drop" branch.

Size (gzip -9 bytes, against #1576)

  • page.es6: 46820 → 46746
  • sw: 13643 → 13535
  • sw with the sessions client wired in (its future cost): 14092 → 13892

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

  • New _delayBeforeNextExecution tests: exponential growth, the max cap, jitter, Retry-After overriding the backoff, and the Retry-After cap.
  • nock now returns ok and headers like a real Response.
  • The outcome error test covers a non-JSON 400 and a network error.
  • The SW "pending restore after a failed retry" test holds the request open until the session is replaced. It used to rely on the old retry window to create that race.

vp check, full vp test (1085), 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

@fadi-george
fadi-george added this pull request to stack #1578 November 13, 2026 01:29
@fadi-george fadi-george changed the title refactor: [SDK-5373] send every API request once with exponential op backoff (2/2) refactor: [SDK-5373] send every API request once with exponential op backoff (2/3) Nov 13, 2026

@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.

Reviewed on top of unmerged parent branch fadi/sdk-5373-sessions-single-attempt (#1576).

call sends one request. A fetch rejection throws the RetryLimitError singleton, which OperationRepo already uses to keep the operation queued. A response still returns ok, status, and Retry-After when the body is empty or not JSON.

The backoff matches the description: 5 seconds, doubled per failure, capped at 5 minutes, then jittered. Retry-After is capped at 1 hour. sendOutcome logs a non-2xx status.

A 2xx with no JSON body was followed through the executors. Login, refresh, and create-subscription read result, throw before any model write, and the existing catch drops the operation. Update, transfer, delete, identity, and custom events only check ok, return success, and apply the operation's own payload. That is the right result for a 2xx.

No issues found.

@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.

Some general concerns about the affect on retries and wait times due to these changes:

  • 5xx and 429 waits aare now much longer. By the 7th retry the queue stops for 2.5 to 5 min, where before it stopped for about 7 s.
  • No response: the wait is now shorter for the first 5 or 6 retries. At the cap it is longer, up to about 2.5 times the old 120 s.

Curious if we need the waits to be this long or if we can rework it. Is this consistent with mobile retry behavior?

Similarly, the change to OneSignalApiBase.get makes it so that the ServiceWorker config download now makes 1 attempt on a network error. Beforehand, it would retry up to 5 times. Is this a change we're ok with making?

Comment thread src/shared/api/base.ts Outdated

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.

call() can return undefined now, so we'd need to update this type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, widened result to T | undefined (013b0ca). Executor reads are all behind ok so I asserted there, and downloadSWServerAppConfig now throws on an empty body like it did before.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Follow-up: switched to a union on ok so no assertions are needed (12be985). call() now only parses the body on a 2xx (throws if it isn't JSON), and downloadSWServerAppConfig throws on a non-ok status.

@fadi-george
fadi-george force-pushed the fadi/sdk-5373-single-attempt-http branch from 2f0e8fd to e20ca5d Compare November 14, 2026 00:31
fadi-george and others added 5 commits November 13, 2026 17:00
…backoff

base.call now makes a single attempt, like the Android HttpClient. It
rejects with RetryLimitError when there is no response and returns the
status and Retry-After even when the body is empty or not JSON. This
removes executeFetch's retry loop and the separate callOnce path.

OperationRepo owns retries: the backoff starts at 5s, doubles per
failure up to 5 min, and is jittered, and Retry-After is capped at 1h,
matching Android. sendOutcome now logs a non-2xx response.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…test

Requests now fail without waiting through retries, so the session could
still exist when the failure returned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fadi-george
fadi-george force-pushed the fadi/sdk-5373-single-attempt-http branch from 12be985 to 5a28cb3 Compare November 14, 2026 01:00
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