Repository navigation
refactor: [SDK-5373] send every API request once with exponential op backoff (2/3) - #1577
fadi-george wants to merge 5 commits into
Conversation
abdulraqeeb33
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
call() can return undefined now, so we'd need to update this type
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
2f0e8fd to
e20ca5d
Compare
…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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
12be985 to
5a28cb3
Compare
Description
1 Line Summary
Send every API request once, like Android's
HttpClient, and give OperationRepo exponential backoff in place of the retry loop inbase.ts.Details
Motivation
#1576 gave session requests a single-attempt path (
callOnce), separate fromcall(), 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 withRetryLimitError, so OperationRepo's offline and blocked branches keep working unchanged. Otherwise it returnsok,statusandRetry-Aftereven when the body is empty or not JSON (resultis thenundefined).executeFetchandcallOnceare removed, and sessions goes back topost/patch.OperationRepo._delayBeforeNextExecution, matching Android'sConfigModel: the backoff starts at 5s, doubles per failure up to 5 min, and is jittered by 0.5 to 1×.Retry-Afteris capped at 1h. Before this, the backoff wasretries × 1sandRetry-Afterhad no cap.sendOutcomelogs a non-2xx response. A non-JSON error used to show up only as a throw.RETRY_MSis removed.Behavior changes
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.puts are sent once. Android also sends these once.result: undefined. Before, it threw. Both end in OperationRepo's "drop" branch.Size (gzip -9 bytes, against #1576)
Systems Affected
Validation
Tests
Info
_delayBeforeNextExecutiontests: exponential growth, the max cap, jitter,Retry-Afteroverriding the backoff, and theRetry-Aftercap.nocknow returnsokandheaderslike a realResponse.vp check, fullvp test(1085), andbuild:prod(size limits) pass.Not tested in a browser.
Checklist
Programming Checklist
Interfaces:
Functions:
Typescript:
Other:
elem of arraysyntax. PreferforEachor usemapcontextif possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.contextScreenshots
Checklist
Related Tickets
🤖 Generated with Claude Code