Repository navigation
feat: [SDK-5813] hold an anonymous session's create (1/3) - #2853
Conversation
A session that starts on an anonymous user holds its sessions API create until the first unfocus, a heartbeat, or the session end. A kill sends it on the next launch. Under identity verification it stays held while anonymous, so the queue no longer drops it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A verify on enqueueNew passes once the call starts, so a test could read the queue before the last enqueue landed. It failed in the full suite under the extra load from main's new tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81cb316 to
51ef6d6
Compare
📊 Diff Coverage ReportDiff Coverage Report (Changed Lines Only)Gate: aggregate coverage on changed executable lines must be ≥ 80% (JaCoCo line data for lines touched in the diff). Changed Files Coverage
Overall (aggregate gate)73/74 touched executable lines covered (98.6% — requires ≥ 80%) |
abdulraqeeb33
left a comment
There was a problem hiding this comment.
sendableHeldCreate holds every anonymous create while identity verification is required (SessionService.kt:408), and endSession then drops it (:274). The queue only drops an anonymous create when the onesignal id or the subscription id is missing or local (OperationRepo.kt:415). An anonymous user created before identity verification was turned on still has backend ids. On the base that session is sent. On this head it is held and discarded. The test at SessionServiceTests.kt:820 uses onesignal-id and subscription-id, so it locks in that drop. Hold under identity verification only when the queue would drop the create, and point that test at local ids.
SessionService.kt:395 sets isCreateHeld false before enqueue has stored the create. Those are different saves, and this release runs on unfocus, which is when Android kills a backgrounded process. The next launch has no hold and no create, and the update is dropped. Clear the flag only after the queue has stored the create. The cold-start test covers a kill while the flag is still true.
SessionService.kt:412 builds the held create with the live app id. An app id change replaces the user and leaves SessionModel in place, so app A's session is created under app B. Pin the app id when the session starts, or drop the held session when the live app id differs.
The body says the wiring is 3/4. The title says 1/3.
…on app ID Under identity verification, an anonymous held create now waits for a login only while its user or subscription is local, since the queue would drop it. Sessions API operations use the app ID the session started with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Fixed 1, 3 and the body in 58a29c9.
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
03b1e21 to
d03c9d2
Compare
abdulraqeeb33
left a comment
There was a problem hiding this comment.
The local-id hold is in d03c9d2. Identity verification holds an anonymous create only while the user or subscription id is local (SessionService.kt:411). Backend ids send on the first unfocus. New sessions pin the app id they started with (SessionService.kt:344).
The saved-session app id fallback is not on this head. 03b1e21 filled a saved session that had no app id at bootstrap, and this tip replaced that commit with the rename. A saved session with no app id still drops its end and checkpoints.
SessionService.kt:396 still sets isCreateHeld false before enqueue has stored the create. enqueue only posts to the operation repo thread. A kill on unfocus leaves no hold and no create, so the update is dropped. A duplicate create is not the cost. The idempotency key is the local session id and it survives a restart. Clear the flag only after the store add returns.
The class KDoc (SessionService.kt:59) still says identity verification holds every anonymous create.
A held create's flag was cleared before the queue stored the create, so a kill in between lost it. The session now stays unconfirmed until the queue is known to have the create, and a cold start resends it otherwise. The create's idempotency key makes a repeat harmless. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks! Updates in f53a479.
|
… unknown Mid-session, an unknown requirement holds a local anonymous create like a required one, matching iOS. Otherwise a create released before remote params arrive is purged if they come back as required, and a later login can't move the session. At the end the create still goes out, since the queue waits for the requirement before sending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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-5813. 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 JWT, the queue drops an anonymous create whose user or subscription ID is still local, so that session is lost even if the user logs in. A held create never reaches the queue, so it isn't dropped.
Scope
isCreateHeld(and its notification-open attribution) onSessionModelinstead of enqueuing its create.releaseHeldCreateenqueues it right before the first update: the unfocus checkpoint, a heartbeat, or the end. The end coversbackgroundRunand a cold start after a kill while held.REQUIRED), an anonymous create waits for a login only while its user or subscription ID is local, since the queue would drop it. With backend IDs it is sent at the first background like any other anonymous create.SessionModelpins the app ID when the session starts, and every sessions API request uses it. An app ID change keeps the model, so a held create or a later update no longer goes out under the new app.Known tradeoffs:
Stack
Test fix
Also fixes a race in
SessionOperationQueueTests:enqueueAllverifiedenqueueNewhad started, not finished, so a test could read the queue early. It failed every time in the full suite after main was merged intonew-session-events.Testing
Unit testing
New
SessionServiceTests: holds on focus; first unfocus sends the create (with attribution) before the checkpoint and no second create later; heartbeat and background run send it first; cold start after a kill while held sends create then end; JWT anonymous with local IDs stays held and reports nothing; JWT anonymous with backend IDs sends on the first unfocus; requests keep the starting app ID after an app ID change; unknown JWT requirement holds a local anonymous create until the end, and sends one with backend IDs on the first unfocus; JWT identified sends on focus; held create waits for consent. Test mocks now default to an identified user so existing tests keep the send-on-focus behavior.Manual testing
Ran the full stack (#2856 head) in the demo app on an Android 16 emulator, with the sessions API flag on. All session requests got 202.
Not covered on the emulator: logout in the background and login before the first focus (both need app code to trigger), and a kill mid-write. Unit tests cover these.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code