Skip to content

feat(rokt): add MPRokt clearSession passthrough - #818

Merged
nickolas-dimitrakas merged 5 commits into
mainfrom
rokt/add-clear-session
Aug 21, 2026
Merged

feat(rokt): add MPRokt clearSession passthrough#818
nickolas-dimitrakas merged 5 commits into
mainfrom
rokt/add-clear-session

Conversation

@nickolas-dimitrakas

@nickolas-dimitrakas nickolas-dimitrakas commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds clearSession to MPRokt, forwarding to the Rokt kit so a host app can end the current Rokt session and have the next selectPlacements call start a new one.

Why

This is for self-service terminals — kiosks, counter tablets, shared point-of-sale hardware — where a queue of unrelated customers uses a single device.

The Rokt SDK carries session identity in a token it persists and replays on every request, and its gateway continues the existing session for as long as a live token is presented. On a device that is busy, that token never lapses, so consecutive customers were all recorded against one session. There was no way for a host app to say "this transaction is over, the next person is someone else."

The companion Rokt SDK change adds a public clearSession() that does the work; this passthrough exposes it to apps integrating through mParticle. The Rokt kit will also call it automatically on MPID change, so most integrations will not need this method — it is the manual escape hatch.

Implementation notes

Follows the existing close pattern: no parameters, forwarded via forwardSDKCall: with MPMessageTypeEvent, and no MPKitProtocol change needed since the selector resolves at runtime (setSessionId: forwards the same way today).

One deliberate difference from close: this dispatches on [MParticle messageQueue] rather than the main queue, to match selectPlacements. Both forwards ultimately hop to main inside attemptToLogEventToKit, so dispatching from two different queues would leave their relative order down to which queue drains first. A caller doing clearSession immediately followed by selectPlacements would then sometimes send the departing session's credentials. Sharing the serial message queue makes that ordering deterministic.

Compatibility

Purely additive — no existing behaviour changes. Kits that do not implement clearSession simply do not receive the forward.

Testing

The method is a forwarding shim with no branching logic. I have not run the full mParticle test suite locally; CI coverage on this PR is the check that matters.

Verification status

The underlying SDK behaviour this forwards to (ROKT/rokt-sdk-ios#298) has been verified end to end on simulators against the production gateway: a before/after matrix on two devices confirmed that consecutive "customers" separated by Rokt.clearSession() receive distinct session ids, that placements with no reset keep sharing one session (no premature severing), and that sessions still survive a full app kill and relaunch. Details in that PR's description.

This PR's own forwarding path was not part of that E2E — it exercised Rokt.clearSession() directly, which is the same single funnel this code calls. Kit-level unit coverage for the trigger conditions is a known follow-up.

🤖 Generated with Claude Code

@nickolas-dimitrakas
nickolas-dimitrakas requested a review from a team as a code owner August 19, 2026 15:52
@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Additive public API and kit forward with no protocol or existing-behavior changes. Kits that do not implement clearSession simply ignore the selector.

Overview
Adds clearSession on MPRokt so a host app can drop the current Rokt session (kiosks / shared POS) and have the next selectPlacements start a new one.

The method logs ROKT_CLEAR_SESSION then fire-and-forgets forwardSDKCall:@selector(clearSession) on [MParticle messageQueue] (same serial queue as selectPlacements, unlike close on main) so a clear immediately followed by a placement cannot race and reuse the departing session token. No MPKitProtocol change; unimplemented kits skip the forward.

Tests cover the diagnostic and the kit forward, plus a drainMessageQueue helper so the async block cannot hit torn-down OCMocks.

Reviewed by Cursor Bugbot for commit 6884be2. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

📦 SDK Size Impact Report

Measures how much the SDK adds to an app's size (with-SDK minus without-SDK).

Metric Target Branch This PR Change
App Bundle Impact 1.79 MB 1.79 MB +N/A
Executable Impact 848 bytes 848 bytes +N/A
XCFramework Size 6.49 MB 6.49 MB +N/A

➡️ SDK size impact change is minimal.

Raw measurements

Target branch (main):

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1920,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":1836,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6648}

This PR:

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1920,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":1836,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6648}

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e01ca56. Configure here.

Comment thread mParticle-Apple-SDK/MPRokt.m
Comment thread mParticle-Apple-SDK/MPRokt.m
thomson-t
thomson-t previously approved these changes Aug 20, 2026
nickolas-dimitrakas and others added 5 commits August 21, 2026 15:38
Adds a clearSession method to MPRokt that forwards to the Rokt kit, ending the
current Rokt session so the next selectPlacements call starts a new one.

This exists for self-service terminals — kiosks, counter tablets, shared
point-of-sale hardware — where a queue of unrelated customers uses a single
device. The Rokt SDK otherwise reuses its stored session while it stays alive,
so successive customers are recorded as one person.

Dispatched on the message queue rather than the main queue, matching
selectPlacements. Both forwards ultimately hop to main inside the kit
container, so dispatching from two different queues would leave the ordering to
whichever drains first, and a caller doing clearSession followed immediately by
selectPlacements could otherwise still send the departing session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Bugbot caught that moving clearSession onto the message queue left setSessionId
on the main queue, so the two are no longer mutually ordered. A host that clears
the session and immediately re-establishes a WebView hand-off could have
setSessionId apply first and then be wiped by the clear.

Puts setSessionId on the message queue as well, so all three Rokt session APIs —
setSessionId, clearSession and selectPlacements — share one serial queue and run
in the order the caller wrote them. The kit invocation itself still lands on main
inside attemptToLogEventToKit, so only the scheduling queue changes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Moving setSessionId to the message queue destabilised
MPRoktTests.testSetSessionIdForwardsToKitContainer, which fulfils its
expectation from the kit-container forward under a 0.2s timeout. Off the main
queue that margin is too thin, and the test began failing intermittently on
reruns of the same commit.

The ordering concern that prompted the move is real but pre-existing and wider
than this PR: setSessionId (main) and selectPlacements (message queue) were
already unordered relative to each other before any change here, so this API
surface does not currently guarantee cross-call ordering. Changing the dispatch
semantics of a shipped API to close that is a call for mParticle to make, not
something to slip into a feature PR.

clearSession stays on the message queue, which preserves the ordering that
matters for the case this PR exists for: a clearSession immediately followed by
selectPlacements must not send the departing session.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clearSession was the only public MPRokt API not reporting its usage
through the diagnostics path added in #813, so a partner calling it via
mParticle was invisible to Rokt diagnostics while every neighbouring API
was not. Adds ROKT_CLEAR_SESSION alongside ROKT_SET_SESSION_ID and
ROKT_GET_SESSION_ID.

Also adds the first tests for clearSession: one asserting the diagnostic
and one asserting the kit-container forward.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… test

testClearSessionLogsApiDiagnostic asserts only the synchronous half of
clearSession and returned with the dispatched kit-container forward still
in flight. That block then ran after tearDown had stopped its mocks, so
OCMock raised on [MParticle messageQueue] -- where XCTest has no handler
-- and aborted the whole test process, taking unrelated suites with it at
a point that moved with timing.

Full-suite runs failed roughly one in three, reporting partial totals
(282/333 of 945) after "Restarting after unexpected exit". Clean main was
unaffected, which is what pinned it to this test.

Drains from the test rather than tearDown so the other ~60 tests here,
which never touch that queue, do not gain sentinel traffic.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@nickolas-dimitrakas
nickolas-dimitrakas merged commit 6382c64 into main Aug 21, 2026
148 of 154 checks passed
@nickolas-dimitrakas
nickolas-dimitrakas deleted the rokt/add-clear-session branch August 21, 2026 20:29
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