Skip to content

feat: [SDK-5814] hold an anonymous session's create (1/3) - #1818

Merged
fadi-george merged 3 commits into
new-session-eventsfrom
fadi-SDK-5814
Nov 23, 2026
Merged

fadi-george merged 3 commits into
new-session-eventsfrom
fadi-SDK-5814

Conversation

@fadi-george

@fadi-george fadi-george commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

  • OSSessionRecord gets externalId, createHeld and directAttributionId. A sessions API session for an anonymous user starts with its create held, keeping its attribution.
  • The held create is queued just before the first update: the background checkpoint, a heartbeat, or the end (startNewSession, which also covers a relaunch after a kill while held).
  • Extends the existing hold until first focus (SDK-5651): an identified session still releases on its first focus, an anonymous one keeps holding.
  • Under Identity Verification an anonymous create stays held while its user or subscription has no backend ID. If it ends that way, it isn't reported.
  • Stays held while privacy consent is missing.
  • Provider: sessionFirstFocused becomes sessionCreate(_:), plus sessionRequiresIdentityVerification and OSSessionUser.externalId.
  • Identified users and the legacy path are unchanged. Login/logout isn't wired yet (3/3).

Tradeoff: anonymous sessions show up on the server later, after the first background.

Stack

  1. This PR: hold the anonymous create
  2. feat: [SDK-5814] split a session at a user switch (2/3) #1819: split
  3. feat: [SDK-5814] split or move the session on a user switch (3/3) #1820: wiring

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

  • 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

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>

@abdulraqeeb33 abdulraqeeb33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

fadi-george and others added 2 commits November 23, 2026 13:58
…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>
@fadi-george

Copy link
Copy Markdown
Contributor Author

Thanks, all three addressed in 6b9c942 and e8212bf:

  • Unknown IV requirement: the provider now returns the full requirement. Background and heartbeat keep an anonymous create held while it's unknown. The end path (session start and the split in 2/3) only holds when it's on, so it's unchanged. Added tests for unknown then off, unknown then on, heartbeat while unknown, and an end while unknown.
  • Background checkpoint: after a create succeeds in the background, the executor begins a new background task, waits out the post-create delay (plus 200ms), and runs the queue again. It only does this when that session still has queued requests. Test: testBackgroundCreateSendsItsQueuedUpdateAfterThePostCreateDelay.
  • Consent: injected as requiresPrivacyConsent next to the clock closures. The consent test uses it now instead of UserDefaults.

2/3 and 3/3 are rebased on top.

@fadi-george
fadi-george merged commit 4705a8b into new-session-events Nov 23, 2026
9 of 10 checks passed
@fadi-george
fadi-george deleted the fadi-SDK-5814 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.

3 participants