Skip to content

feat: [SDK-5814] split or move the session on a user switch (3/3) - #1820

Merged
fadi-george merged 2 commits into
fadi-SDK-5814-splitfrom
fadi-SDK-5814-wiring
Nov 23, 2026
Merged

fadi-george merged 2 commits into
fadi-SDK-5814-splitfrom
fadi-SDK-5814-wiring

Conversation

@fadi-george

Copy link
Copy Markdown
Contributor

Description

One Line Summary

On login or logout, move a held session to the new user, or split a logged-in user's session.

Details

Motivation

Part of SDK-5814, the iOS port of OneSignal/OneSignal-Android-SDK#2856. Wires 1/3 (hold) and 2/3 (split) to user switches, so time after a switch goes to the new user and requests never mix one user's onesignal_id with another user's push sub.

Scope

login() (only when the user actually changes) and _logout() call OSSessionService.onUserSwitched(). For a sessions API session:

Case Result
Create still held Session moves to the new user and keeps its start time. Its create goes out right away if that user is identified, including under Identity Verification.
Anonymous, create already sent No split. The session stays on the anonymous user and records the new external ID, so a later switch splits.
Logged-in user switches or logs out Split (2/3). In the background, S1 ends now and S2 starts on the next focus.
  • OSSessionRecord.identityModelId becomes settable for the move.
  • A switch is ignored while the record is about to be replaced: a record from an earlier launch, or a focus that will start a new session. Otherwise that old session's end would move to the switch time.
  • Removes splitSession(); the split is only reachable from a user switch.
  • _logout() also runs as 404 recovery, which now splits too.

Note: a session saved before this change has no externalId, so its first switch doesn't split. Fine since new-session-events hasn't shipped.

Stack

  1. feat: [SDK-5814] hold an anonymous session's create (1/3) #1818: hold the anonymous create
  2. feat: [SDK-5814] split a session at a user switch (2/3) #1819: split
  3. This PR: wiring

Testing

Unit testing

OSSessionSplitTests now go through onUserSwitched(). New: login while held moves and sends the create with attribution; Identity Verification login sends a create that couldn't be sent; switch to another anonymous user keeps holding; anonymous login after the create was sent keeps the session, then a later login splits; switch after a focus that will start a new session, or before a launch's first session, changes nothing. SessionRecordUserTests: login while held queues the create for the new user; login as B splits; logout splits and holds S2; login as the same user doesn't split.

Reduced test plan passes locally.

Manual testing

Not tested on device yet.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

🤖 Generated with Claude Code

On login or logout, move a held session to the new user and queue its create
if that user is identified, or split a logged-in user's session. An anonymous
user's login after the create was sent keeps the session and records the
external ID, so a later switch splits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
login() and logout() read the current user when they report the switch, so two
switches on different threads can both read the later user and split twice.
Each login gets a new identity model, so a switch reading the one the last
switch read is skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fadi-george
fadi-george merged commit 4e5c2c3 into new-session-events Nov 23, 2026
6 checks passed
@fadi-george
fadi-george deleted the fadi-SDK-5814-wiring branch November 23, 2026 23:54
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