Repository navigation
feat: [SDK-5813] split a session at a user switch (2/3) - #2854
Conversation
c51af9f to
95825f0
Compare
📊 Diff Coverage ReportDiff Coverage Report (Changed Lines Only)Gate: aggregate coverage on changed executable lines must be ≥ 80% (JaCoCo line data for lines touched in the diff). Changed Files Coverage
Overall (aggregate gate)74/74 touched executable lines covered (100.0% — requires ≥ 80%) |
abdulraqeeb33
left a comment
There was a problem hiding this comment.
The split keeps the app session going, and it skips onSessionStarted for that reason. startNextSession still writes session.startTime (SessionService.kt:364) on the focused split (:413) and on the focus that starts the next session after a background split (:343). IAM SESSION_TIME and the IAM list duration both read that field (DynamicTriggerController.kt:49, InAppMessagesManager.kt:359), so a logout or account switch zeros the clock in the same visit. Write startTime only when the app session is new. Pass the switch time into the create. Keep the focusTime and focusElapsedRealtime updates so the next session's active time starts at the switch.
The focus after a background split passes null (SessionService.kt:343) after onFocus already took pendingDirectAttributionId (:309). A warm return from a notification open drops directAttributionId. A cold start still forwards it. Pass directAttributionId on this branch. The focused split at :413 should stay null.
The body says 3/4 and 1/4. The title says 2/3.
95825f0 to
94ae696
Compare
|
Thanks! Fixed in c6a02e3.
The earlier test and build failures were a Maven Central 429. The new push reran CI. |
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Approve with nits. The three from 95825f0 are fixed in c6a02e3.
startNextSession writes sessionsApiStartTime and leaves startTime and sessionId alone, so the IAM clock stays on the app session. The focus after a background split passes directAttributionId. The focused split still passes null. The body matches the title.
The focused split starts the heartbeat even when startSessionsApi just turned this session legacy (SessionService.kt:416). A kill switch after S1 started ends S1 on the sessions API and then ticks updates for a session that was never created. Start the heartbeat only when usesSessionsApi is still true.
The splitSession KDoc (SessionService.kt:384) says no legacy callbacks fire. The focus after a background split fires onSessionActive. Say no onSessionStarted or onSessionEnded.
isSplitPending (SessionModel.kt:170) says the background switch sent the end. It is also set when no end was queued.
|
Thanks! All three addressed in 733716f.
|
733716f to
6b322aa
Compare
6b322aa to
1873710
Compare
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Heartbeat and the splitSession KDoc are fixed in faeea93.
The focused split starts the heartbeat only when usesSessionsApi is still true (SessionService.kt:422). splitSession now says onSessionStarted and onSessionEnded don't fire (:390).
isSplitPending still says a background switch ended the session (SessionModel.kt:170). It is also set while consent is paused in the foreground, and when the held create can't go out so nothing is queued (SessionService.kt:408, :424). Say the next session starts on the next focus, whether or not an end was queued.
The lock between a split and a session end looks right. CI test hit a Maven Central 429 and needs a rerun.
|
Thanks! Updated the isSplitPending doc in 9c3d31a: it's set after a switch while the session wasn't counting time (background or waiting for consent), and the next session starts on the next focus whether or not an end was queued. The push reran CI. |
9c3d31a to
59471f1
Compare
SessionService.splitSession ends the current sessions API session at the switch and starts the next one for the new user, without legacy session callbacks. In the background, it sends the end now and starts the next session on the next focus. Not wired to user switches yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he next session A split no longer resets the session start time and ID, which in-app messages read, so the sessions API start time is kept in its own field. A notification open on the focus after a background split now attributes the next session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also corrects the splitSession and isSplitPending docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A background split and the session timeout could both end the session, and the split could read durations the end had already reset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sion Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59471f1 to
ec5d83c
Compare
Description
One Line Summary
Add
SessionService.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-5813. 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
end_time= switch time, then starts S2 now: new local session ID, IDs pinned to the current user, S2's start time = switch time. S2's create goes out now, or is held if the new user is anonymous (1/3). The heartbeat restarts from S2's start.isSplitPending. The next focus starts S2, attributed to a notification open if that focus came from one. A timeout or cold start in between sends no second end.onSessionStarted/onSessionEndedcallbacks fire, since the app session goes on (IAM, outcomes and influence would treat them as a new app session). The focus that starts S2 after a background split firesonSessionActive.startTimeandsessionIdstay the same, since IAM readsstartTimefor session time. S2's start time goes in a newsessionsApiStartTimefield, which the create uses.handleOnFocusmoved tostartNextSession, shared with the split. Added a serial-laneisFocused.Stack
Testing
Unit testing
New
SessionServiceTests: focused split (end, create, IDs, no legacy callbacks, next checkpoint on S2); split to an anonymous user holds S2's create; heartbeat restarts; background split ends now and starts S2 on the next focus; the app session's start time and ID stay the same; a notification open after a background split attributes S2; timeout and cold start after a background split send no second end; legacy no-op.Manual testing
Ran the full stack (#2856 head) in the demo app on an Android 16 emulator, with the sessions API flag on. All session requests got 202.
end_timeat the switch, then S2's create started at the switch.Not covered on the emulator: logout in the background and login before the first focus (both need app code to trigger), and a kill mid-write. Unit tests cover these.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code