Skip to content

feat: [SDK-5370] web session model and sessions v2 flag - #1568

Merged
fadi-george merged 2 commits into
new-session-eventsfrom
fadi/sdk-5370
Nov 12, 2026
Merged

fadi-george merged 2 commits into
new-session-eventsfrom
fadi/sdk-5370

Conversation

@fadi-george

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Capture the sdk_sessions_v2_api_cutover flag and pinned user/subscription IDs on the web session record at session start.

Details

First Web PR in the SDK Sessions stack. Later PRs need a persisted per-session record that knows which path the session is on and which user/subscription it belongs to. Mirrors Android (OneSignal/OneSignal-Android-SDK#2774) and iOS (OneSignal/OneSignal-iOS-SDK#1762).

  • Adds FeatureFlag._SessionsV2ApiCutover (sdk_sessions_v2_api_cutover).
  • Extends the IndexedDB Sessions record with sessionId (UUID), usesSessionsApi, onesignalId, subscriptionId, and serverSessionId.
  • When the worker starts a new session, it reads the flag once (via the IndexedDB mirror) and pins the IDs from the page payload. They stay fixed for the session, even after a login or a flag change.
  • New fields are optional: a session stored by an older SDK lacks them and stays on the legacy path until it ends.
  • accumulatedDuration already holds the cumulative duration.
  • No network calls. With the flag off, nothing reads the new fields, so behavior is unchanged.
  • Raises the SW size limit from 13.62 kB to 13.7 kB (about +80 B gzipped; the base had 10 B of headroom).

Differences from Android:

  • No monotonic clock. The worker's performance.now() resets when the worker restarts, so it can't be persisted. Duration stays on the wall clock.
  • No local-to-backend ID translation. Web sessions start only after _getOneSignalAndSubscriptionIds returns a OneSignal ID and a complete push subscription, so the IDs are pinned as the page sends them.

Open question from the ticket (sessions require a push subscription today) is not addressed here.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

New session model tests in ServiceWorker.test.ts: flag off/on capture, IDs pinned on start, flag and IDs fixed mid-session, new ID and fresh flag read after the session threshold, and an old record without the new fields staying on the legacy path. Each reads the record back from IndexedDB. Full suite (1037 tests), vp check, and build:prod pass.

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

Not tested in a browser. No user-facing behavior changes with the flag off.

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

Info

No UI changes.

Checklist

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

Related Tickets

SDK-5370


🤖 Generated with Claude Code

fadi-george and others added 2 commits November 12, 2026 11:08
Adds the sdk_sessions_v2_api_cutover flag and extends the Sessions record
with a session UUID, the flag value, pinned onesignal/subscription IDs, and
a slot for the server session ID. Captured once when the worker starts a
session. No network calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fadi-george fadi-george mentioned this pull request Nov 12, 2026
13 of 16 tasks
@fadi-george
fadi-george added this pull request to stack #1570 November 12, 2026 19:46
@fadi-george
fadi-george requested review from abdulraqeeb33 and sherwinski and removed request for sherwinski November 12, 2026 19:54

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

Approving. Nothing in the stack writes serverSessionId yet (src/shared/session/types.ts:37). Details on #1573.

@fadi-george
fadi-george merged commit 22f919c into new-session-events Nov 12, 2026
1 check passed
@fadi-george
fadi-george deleted the fadi/sdk-5370 branch November 12, 2026 23:09
await sendOnSessionCall(options, session);
}

async function startNewSession({

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.

Nit, for awareness: startNewSession could send a local ID. Would depend on how it gets called

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