Skip to content

feat: [SDK-5377] send queued session requests with retry (3/4) - #1573

Merged
fadi-george merged 1 commit into
fadi/sdk-5377-enqueuefrom
fadi/sdk-5377-sender
Nov 13, 2026
Merged

fadi-george merged 1 commit into
fadi/sdk-5377-enqueuefrom
fadi/sdk-5377-sender

Conversation

@fadi-george

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

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Sends queued session requests one per session in order, with backoff, Retry-After, and the post-create 404 window.

Details

Mirrors Android #2794 and iOS #1768 where they apply.

  • Oldest first, only the first request of each session is sendable, so a session goes create, updates, end. A waiting session does not block others.
  • After a send, the request is re-read. If an enqueue replaced it or the cap dropped it meanwhile, the result is ignored.
  • A create with a local- onesignal or subscription ID is dropped with its updates, since queued records are never rewritten.
  • On a create success, the server session_id is saved in SessionRequestStates before the create record is deleted. Updates read it at send time and wait 5s after the create (post-create delay, like Android), so updates and ends enqueued later or after a restart still get it.
  • A state is deleted once its session's end leaves the queue, or after 30 days.
  • A request is deleted only on success or a non-retryable failure (from the feat: [SDK-5373] add sessions API client #1569 client classification). A dropped create drops its updates.
  • An update with no create queued and no stored state is dropped.
  • Retry: exponential backoff with jitter (5s doubling, capped at 5 min). Retry-After is a floor on the backoff, capped at 1 hour; a 429 without it waits at least 60s.
  • A create answered with a success but no session_id is dropped with its updates after 3 tries.
  • An update 404 within 60s of its create is retried (backend may not have processed the 202 create yet), then dropped.
  • No wake timer: a request that is not ready waits for the next drain (worker start, page message, online). The worker usually stops within seconds of going idle, so a timer would rarely fire. Drains run one after another under their own Web Lock.

Unlike Android there is no closed flag: session IDs are per-session UUIDs and the worker is the only producer, so nothing is enqueued for a session after its end.

Stack

Built on #1569 (SDK-5373 sessions API client).

  1. feat: [SDK-5377] add SessionRequests IndexedDB store (1/4) #1571 SessionRequests IndexedDB store
  2. feat: [SDK-5377] enqueue policy for session requests (2/4) #1572 enqueue policy
  3. feat: [SDK-5377] send queued session requests with retry (3/4) #1573 (this PR) send with retry
  4. feat: [SDK-5377] drain session requests on worker start and online (4/4) #1574 drain on worker start and online

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

sender.test.ts: create then update after the post-create delay, local-ID create dropped without blocking other sessions, Retry-After 0 still backing off, 429 default, Retry-After cap, missing session_id limit, orphan update drop, retry keeps record and key, Retry-After, backoff bounds, dropped create takes updates, 404 window, update replaced while being sent is not retried, update enqueued while its create is in flight gets the server ID, updates and ends enqueued after the create was sent, an end replacing an update waiting out the post-create delay, state removed after the end and past the age limit.

vp check clean (only existing warnings), full vp run test passes, each PR in the stack passes on its own. Not tested in a browser: nothing enqueues session requests until the lifecycle wiring (SDK-5381).

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. Uses for...of where IndexedDB writes must run in sequence.
  • Avoid using global OneSignal accessor for context if possible.

Screenshots

Info

No UI changes.

Checklist

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

Related Tickets

SDK-5377


🤖 Generated with Claude Code

@nan-li nan-li left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Main issue is inline. Smaller things, mostly where this differs from Android and iOS:

  • Line 146: Retry-After replaces the backoff. Native uses it as a minimum, caps it at 1 hour, and defaults to 60s for a 429 with no header. Here, Retry-After: 0 would resend in a tight loop. Math.max(backoff, retryAfter) fixes it.
  • A create that keeps coming back without a session_id retries for 30 days. Native drops it after 3.
  • Line 86 waits on local IDs, but nothing ever rewrites a queued record, so the wait never ends. The page already blocks local OneSignal IDs, but a local subscription ID can still get through. Android rewrites the IDs and iOS reads the current ones at send time. Do one of those or drop the record.
  • Backoff caps at 10 minutes, native at 5. Fine if that's on purpose.
  • Line 185 says online covers a lost wake timer, but a stopped worker doesn't start for online. Only the next worker start covers it.
  • isMissingInRetryWindow is a type guard that also returns false for updates, so TypeScript treats record as a create in the drop branch. A plain boolean return would be accurate.
  • The comment on backoffMs (line 179) restates the code.

Comment thread src/sw/sessionRequests/sender.ts Resolved
@fadi-george
fadi-george force-pushed the fadi/sdk-5377-sender branch 4 times, most recently from 1ae3737 to c23801b Compare November 12, 2026 23:15
@fadi-george

Copy link
Copy Markdown
Contributor Author

Thanks, addressed:

  • Retry-After is now a floor on the backoff, capped at 1 hour, and a 429 without it waits at least 60s. Retry-After: 0 backs off normally.
  • A create that comes back without a session_id is dropped with its updates after 3 tries.
  • A create with a local ID is now dropped with its updates instead of waiting.
  • Backoff cap is 5 min to match native.
  • Fixed the wake timer comment, only the next worker start covers it.
  • isMissingInRetryWindow returns a plain boolean now.
  • Removed the backoffMs comment.

@fadi-george
fadi-george requested a review from nan-li November 12, 2026 23:23
@fadi-george
fadi-george force-pushed the fadi/sdk-5377-sender branch 2 times, most recently from 8913f38 to 7d1661a Compare November 12, 2026 23:38

@nan-li nan-li left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, LGTM

Drains SessionRequests oldest first, one request per session at a time.
A create waits for real onesignal/subscription ids; updates wait for the
server session id plus a 5s post-create delay. Requests stay stored until
a success or a non-retryable failure. Retries back off exponentially with
jitter and honor Retry-After. An update 404 within 60s of its create is
retried as possible replication lag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fadi-george
fadi-george merged commit 3684e4e into new-session-events Nov 13, 2026
1 check passed
@fadi-george
fadi-george deleted the fadi/sdk-5377-sender branch November 13, 2026 02:19
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.

2 participants