feat(rokt): add MPRokt clearSession passthrough - #818
Conversation
PR SummaryLow Risk Overview The method logs Tests cover the diagnostic and the kit forward, plus a Reviewed by Cursor Bugbot for commit 6884be2. Bugbot is set up for automated code reviews on this repo. Configure here. |
📦 SDK Size Impact ReportMeasures how much the SDK adds to an app's size (with-SDK minus without-SDK).
➡️ SDK size impact change is minimal. Raw measurementsTarget 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} |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
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>
318f220 to
6884be2
Compare

Summary
Adds
clearSessiontoMPRokt, forwarding to the Rokt kit so a host app can end the current Rokt session and have the nextselectPlacementscall 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
closepattern: no parameters, forwarded viaforwardSDKCall:withMPMessageTypeEvent, and noMPKitProtocolchange 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 matchselectPlacements. Both forwards ultimately hop to main insideattemptToLogEventToKit, so dispatching from two different queues would leave their relative order down to which queue drains first. A caller doingclearSessionimmediately followed byselectPlacementswould 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
clearSessionsimply 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