Skip to content

feat: [SDK-5377] drain session requests on worker start and online (4/4) - #1574

Merged
fadi-george merged 2 commits into
fadi/sdk-5377-senderfrom
fadi/sdk-5377-drain
Nov 13, 2026
Merged

fadi-george merged 2 commits into
fadi/sdk-5377-senderfrom
fadi/sdk-5377-drain

Conversation

@fadi-george

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

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Drains the session request queue when the service worker starts, activates, and comes back online.

Details

  • Worker start: best-effort drain after listeners are set up. This also covers activation, without holding activate while requests retry offline.
  • online: drains when the network returns.

Bundle size

OneSignalSDK.sw.js limit 13.72 kB to 15.03 kB: the sessions client, queue and sender are first bundled here once the worker drains. Earlier PRs in the stack carry their own limit bumps.

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 send with retry
  4. feat: [SDK-5377] drain session requests on worker start and online (4/4) #1574 (this PR) drain on worker start and online

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

ServiceWorker.test.ts: drain on online. sender.replay.test.ts: a worker stopped mid-send replays the stored request with the same idempotency key on the next start (separate file since the first drain never settles).

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.

One suggestion. ServiceWorker.ts:937 puts the drain inside the activate waitUntil, so the worker stays in "activating" until the drain finishes, and push and notification click events wait for activation. Offline, executeFetch retries each request for about 2 minutes, so that wait can get long. run() already starts a drain on every worker start, so event.waitUntil(self.clients.claim()) plus void drainSessionRequests() covers it without holding activation.

@fadi-george
fadi-george force-pushed the fadi/sdk-5377-drain branch 2 times, most recently from 6e0da62 to c9b674e Compare November 12, 2026 23:11
@fadi-george
fadi-george force-pushed the fadi/sdk-5377-drain branch 2 times, most recently from 8970338 to 5cda268 Compare November 12, 2026 23:29
@fadi-george
fadi-george force-pushed the fadi/sdk-5377-drain branch 2 times, most recently from f25ac2b to dd8f435 Compare November 12, 2026 23:38
@fadi-george

Copy link
Copy Markdown
Contributor Author

Good call, done. Activate is back to event.waitUntil(self.clients.claim()), and the drain only runs on worker start in run() and on online.

@fadi-george
fadi-george merged commit 7f4df5d into new-session-events Nov 13, 2026
1 check passed
@fadi-george
fadi-george deleted the fadi/sdk-5377-drain 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