Repository navigation
fix: [SDK-5373] send session requests once and classify by status (1/3) - #1576
Open
fadi-george wants to merge 3 commits into
Open
fadi-george wants to merge 3 commits into
fadi-george wants to merge 3 commits into
Conversation
14 of 16 tasks
14 of 16 tasks
sherwinski
approved these changes
Nov 13, 2026
| if (!requestHasAppId(path, data)) throw AppIDMissingError; | ||
|
|
||
| const response = await fetch(...buildRequest(method, path, data, undefined)); | ||
| const retryAfter = parseInt(response.headers.get('Retry-After') ?? ''); |
Contributor
There was a problem hiding this comment.
nit: RangeError drop has no log, so a bad timestamp loses data with no message.
Contributor
Author
There was a problem hiding this comment.
Good catch, moved the log above the drop check so both cases log (d2c205b). Comment landed on base.ts but I think you meant sessions.ts:96.
abdulraqeeb33
approved these changes
Nov 13, 2026
abdulraqeeb33
left a comment
Contributor
There was a problem hiding this comment.
Baseline is the unmerged parent branch new-session-events (no open parent PR).
callOnce sends each session request once. Status and Retry-After still come back when the body is empty or not JSON, and an invalid time is dropped before fetch.
Session requests now go through base.callOnce: one attempt with no built-in retry or backoff, and the status and Retry-After are returned even when the body is empty or not JSON. A non-JSON 4xx now drops instead of retrying forever, and an empty 2xx on update succeeds. Invalid start or end times drop instead of throwing, and a negative Retry-After is ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
callOnce reads the body with response.json().catch() and validates Retry-After itself. sessions builds each body inside the request thunk, so an invalid time surfaces as a RangeError that send drops, replacing the separate validation and Retry-After helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fadi-george
force-pushed
the
fadi/sdk-5373-sessions-single-attempt
branch
from
November 14, 2026 01:00
d2c205b to
4e9f0e6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
1 Line Summary
Send session requests once with no built-in retry, and classify the result by status even when the body isn't JSON, matching Android.
Details
Motivation
Review of #1569 found that the sessions client could misclassify some responses and would retry inside
base.tsbefore the queue saw a result. I reproduced each case against the PR head:executeFetch's internal retries (5 attempts, 10/20/30/30/30s delays, ~2 min) before returningretry. The queue owns backoff, and a service worker can be killed during those waits.executeFetchparses JSON before returning the status. Any non-JSON response becameretry, so an HTML 400/404 from a CDN or WAF would retry forever. A 204 or a 202 with an empty body on update would also retry forever.startTime/endTimethrew aRangeErrorinstead of returning a result.Android (OneSignal/OneSignal-Android-SDK#2775) avoids all three: its
HttpClientmakes one attempt, returns status 0 on a network failure, and checks the status before parsing the payload.Scope
base.ts: new exportedcallOnce(method, path, data). It makes one fetch and returnsresult: undefinedwhen the body is empty or not JSON (response.json().catch()), sostatusandRetry-Afteralways come back. ARetry-Afterthat is negative or not a number is dropped. Request building is split out intobuildRequestand shared withcall. The deadmethod || 'NO_METHOD_SPECIFIED'fallback is removed. Existingget/post/patch/put/deletebehave the same.sessions.ts: usescallOnce. Each body is built inside the request thunk, so an invalid time throws aRangeErrorthere andsenddrops it without sending. A create 202 without a session id now passesRetry-Afterthrough.callOnceis a separate export, not a flag oncall(), so it is tree-shaken out of the page bundle. The base branch was already at the page.es6 size limit. Sizes (gzip -9 bytes): page.es6 46825 → 46820, sw 13649 → 13643. With the sessions client wired into the SW to measure its future cost, the SW is +71 B over the base branch's client, and most of that is the single-attempt path.base.tscallers still retry internally and still throw on non-JSON. Moving them over would change the user and subscription flows, so it is out of scope here.Systems Affected
Validation
Tests
Info
sessions.test.tsno longer mocksdelay, so a hidden retry would time out. New cases: one attempt on network failure, non-JSON 400/403/404 drop, non-JSON 502 retries with status andRetry-After, empty 204/202 on update succeeds, empty 202 on create retries,Retry-Afteron a 202 without a session id, negativeRetry-Afterignored, and NaN/Infinity/out-of-range times drop without sending.vp check, fullvp test(1076), andbuild:prod(size limits) pass.Not tested in a browser; the sessions client has no callers yet.
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
SessionsApiResultshape is unchanged.🤖 Generated with Claude Code