Repository navigation
feat: [SDK-5814] split a session at a user switch (2/3) - #1819
Conversation
ebd479a to
ab57b5e
Compare
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Request changes. This is the same split as ebd479a, and #1820 does not change onFocus.
onFocus reads the pending user before it takes the lock (OSSessionService.swift:335). A split on another thread can land in between. If nothing was pending, the focus continues the session that was just ended and arms its heartbeat (:344, :363). Those updates are dropped, and the visit counts for nobody. If a split was already pending, a second switch in that gap starts the next session for the user from before the switch. #1820 calls this from login on the caller thread and from _logout on the executor queues. Bump a counter under the lock at the top of splitSession, before the splitPending guard, and retry the read in onFocus when it moved. Bumping only after a committed split leaves the second case open.
splitPending and splitSession say "in the background". This runs on any unfocus. Say "while unfocused".
Removing focusedAt = now (:614) or openFocusTime = wallNow (:615) leaves the tests green. Without :615, the next session's end after its first heartbeat is 20 minutes early.
The only CI failure is OSRemoteLoggingControllerTests.testConstructsRemoteLoggerOnMainWhenConfiguredInBackground, a 2 second timeout this diff does not touch.
ab57b5e to
1619092
Compare
Add OSSessionService.splitSession(): end the current sessions API session at a user switch and start the next one for the new user. In the background, the end is sent now and the next session starts on the next focus. No legacy session start or end is sent, since the app session goes on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1619092 to
e85e78c
Compare
- A switch bumps a counter under the lock before it reads the new user. A focus that read the pending split's user outside the lock retries when the counter moved. - Say "while unfocused" for the split, since it runs on any unfocus - Cover the next session's focus and heartbeat times after a foreground split Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, all three addressed in a4ef80d:
#1820 is rebased on top. |
Description
One Line Summary
Add
OSSessionService.splitSession(): end the current sessions API session at a user switch and start the next one for the new user.Details
Motivation
Part of SDK-5814, the iOS port of OneSignal/OneSignal-Android-SDK#2854. When a logged-in user logs in as someone else or logs out, the session should split so time after the switch goes to the new user. This PR adds the split; 3/3 wires it to user switches.
Scope
splitPending. The next focus within the threshold starts S2, attributed to a notification open if that focus came from one. A timeout or cold start in between sends no second end.session_count, IAM, outcomes), since the app session goes on.sessionEnd(_:). The record build and hold rule are shared withstartNewSession.Stack
Testing
Unit testing
New
OSSessionSplitTests: focused split (end then create, IDs, start time); split to an anonymous user holds S2's create; heartbeat restarts from S2; anonymous S1 sends its held create before its end; background split ends now and starts S2 on the next focus with attribution; timeout and cold start after a background split send no second end; a second split while pending sends nothing; legacy no-op.Manual testing
Not wired yet; wired in 3/3.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code