Repository navigation
feat: [SDK-5391] send a session end when a sessions API session ends - #1772
Closed
fadi-george wants to merge 1 commit into
Closed
fadi-george wants to merge 1 commit into
fadi-george wants to merge 1 commit into
Conversation
fadi-george
added this pull request to stack #1771
October 9, 2026 22:55
fadi-george
force-pushed
the
fadi/SDK-5391-ios-session-end
branch
from
October 9, 2026 22:56
c9c96f9 to
63f846c
Compare
9 of 18 tasks
… starts OSSessionService.startNewSession enqueues the previous session's end through the session user provider, before the new session's create, with end_time from the new lastUnfocusTime (or the start time for a session killed in the foreground) and the final duration. A session whose user is no longer loaded is sent with its pinned onesignal_id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fadi-george
force-pushed
the
fadi/SDK-5391-ios-session-end
branch
from
October 10, 2026 00:49
63f846c to
5815b71
Compare
abdulraqeeb33
approved these changes
Oct 12, 2026
abdulraqeeb33
left a comment
Contributor
There was a problem hiding this comment.
Approving.
The previous session is ended before the new create, and a user who is no longer loaded is restored from the pinned onesignal id. That stand-in lives in the in-memory identity repo.
A kill while focused still ends at startTime with duration 0. The heartbeat that covers this is #1773, and that branch is not based on this one, so the gap stays until it is rebased.
| if let previous, previous.usesSessionsApi { | ||
| // A session killed before its first unfocus ends at its start. Its foreground time was | ||
| // never added to the duration either. | ||
| userProvider.enqueueSessionUpdate(previous, endTime: previous.lastUnfocusTime ?? previous.startTime) |
Contributor
There was a problem hiding this comment.
A kill while focused has no lastUnfocusTime, so this ends at startTime with duration 0. #1773 is the fix, and it is not based on this branch. Rebase that onto this before the gap is closed.
Collaborator
Author
9 of 18 tasks
Collaborator
Author
|
Replaced by #1782, rebased on the new session executor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
When the sessions API flag is on, enqueue a session end with
end_timeand the final duration when the next session starts.Details
Motivation
Part of the iOS SDK Sessions stack (SDK-5391). Ended sessions need a
PATCH /apps/{app_id}/sessions/{session_id}withend_timeand the final cumulativeduration_seconds. Based on #1770. Android counterpart: OneSignal/OneSignal-Android-SDK#2781.Scope
OSSessionService.startNewSessiontakes the previous record under the same lock that replaces it, then enqueues its end before the new session's create.end_timeis the last time the app left the foreground, saved in a new optionalOSSessionRecord.lastUnfocusTime(records stored by earlier versions still decode). A session killed before its first unfocus ends at its start time.activeDuration.OSSessionOperationExecutor. No executor changes.onesignal_id.usesSessionsApiis true are ended this way. Flag off: nothing new is sent, and the legacy focus-time processors are unchanged.Things to note
end_timeandstart_timeare both wall clock, so a clock moved back mid-session could produceend_timebeforestart_time.Testing
Unit testing
Added
OSSessionServiceTestscases: the end's time and final duration, ordering before the next session's create, ending a session left by an earlier process before its user was created with its IDs, end time after a kill while focused, and no end for a legacy session.OSSessionOperationExecutorTestscovers a session whose user is no longer loaded; end replacing and blocking updates is covered there from #1768.OSSessionServiceTestscheckslastUnfocusTimeis recorded, survives decoding of old records, and is not set by an unfocus in a new process.The full
UnitTestAppscheme passes locally, apart from theUserConcurrencyTests.testSubscriptionExecutorConcurrencyflake. SwiftLint reports no new violation types.Manual testing
Not tested on device yet; end-to-end verification is planned in the iOS rollout and QA ticket.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code