Repository navigation
feat: [SDK-5814] hold an anonymous session's create (1/3) - #1818
Conversation
An anonymous user's sessions API session holds its create until the first background, a heartbeat, or the session end, so a login before then can move the session to that user. Under Identity Verification it stays held while its user is not created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ad3cc8c to
3e618fe
Compare
abdulraqeeb33
left a comment
There was a problem hiding this comment.
Request changes. CI is green on 3e618fe. The hold itself reads right. Two things are still open.
sessionRequiresIdentityVerification is ivBehaviorActive, which is false while the requirement is unknown (OneSignalUserManagerImpl+Session.swift:82). On a first install, a background or a heartbeat before params clears createHeld and queues the anonymous create. An IV-on hydration then drops it. #1820 only moves a session while createHeld is still true, so a later login cannot recover it. The repo already sends nothing while the requirement is unknown. Hold at background and heartbeat while it is unknown. Leave the end path as it is. Cover unknown to on, and unknown to off.
The first background checkpoint is queued in the same flush as the create. The executor sends one request per session per pass and does not run again after the create succeeds. The update waits out the 3 second post-create delay, and the background task ends with the create response. For a visit that backgrounds before the first heartbeat, that checkpoint is the only duration report if the user never comes back. Run the queue again under a background task after a background create succeeds, or say so in the description.
The consent check is still a static reach-in. Inject it next to the clock closures.
…ground create's updates - Keep an anonymous create held at background and heartbeat until the requirement is known - After a background create succeeds, rerun the queue past the post-create delay under a background task - Inject the privacy consent check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… 1s predicate wait Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, all three addressed in 6b9c942 and e8212bf:
2/3 and 3/3 are rebased on top. |
Description
One Line Summary
Hold an anonymous session's sessions API create until the first background, a heartbeat, or the session end.
Details
Motivation
Part of SDK-5814, the iOS port of the Android stack (OneSignal/OneSignal-Android-SDK#2853). The backend sets a session's owner from its create and drops updates with a different onesignal_id. Holding an anonymous create keeps the owner open, so a login before the first background can move the session to that user (wired in 3/3). Under Identity Verification the session executor drops an anonymous create whose user is never created, so that session is lost even if the user logs in. A held create never reaches the executor, so it isn't dropped.
Scope
OSSessionRecordgetsexternalId,createHeldanddirectAttributionId. A sessions API session for an anonymous user starts with its create held, keeping its attribution.startNewSession, which also covers a relaunch after a kill while held).sessionFirstFocusedbecomessessionCreate(_:), plussessionRequiresIdentityVerificationandOSSessionUser.externalId.Tradeoff: anonymous sessions show up on the server later, after the first background.
Stack
Testing
Unit testing
OSSessionServiceTests: anonymous holds with attribution; identified doesn't hold; background-started anonymous keeps holding after focus; first background releases once; end and cold start after a kill release before the end; Identity Verification with no backend IDs stays held and isn't reported; with backend IDs releases on background; consent.OSSessionHeartbeatTests: heartbeat releases first; heartbeat of a create that must stay held sends nothing.SessionRecordUserTests: existing create tests log in first; held create queued on the first background and before the end on the next launch.Reduced test plan passes locally.
Manual testing
Not tested on device yet.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code