Repository navigation
fix(replay): start a new session on opt-in whenever replay was wanted - #915
Merged
turnipdabeets merged 3 commits intoOct 30, 2026
Merged
Conversation
Contributor
posthog-android Compliance ReportDate: 2026-10-29 22:00:31 UTC ✅ All Tests Passed!46/46 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
marandaneto
approved these changes
Oct 30, 2026
marandaneto
left a comment
Member
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
ioannisj
approved these changes
Oct 30, 2026
ioannisj
left a comment
Contributor
There was a problem hiding this comment.
🤖 An AI agent wrote this on behalf of @ioannisj.
Nothing to flag. I checked the rotation in optIn() against the three startSessionReplayInternal callers and the recorder's uninstall() reset, and the new session lands before any restart path can resume the old one. Matches what iOS and RN do, so I'm happy with it.
turnipdabeets
deleted the
fix/opt-in-rotate-session-when-replay-wanted
branch
October 30, 2026 14:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
In short:
optIn()now starts a new session whenever the app wanted session replay at opt-out, even if the linked flag or remote config isn't ready to start replay yet. Before, Android only rotated the session once replay actually started, so a start after flags loaded resumed the session that was active while the user was opted out.How it failed before (reproduced on an emulator, see below):
startSessionReplayInternal(resumeCurrent = false)rotates.internalOnFeatureFlagsLoadedresumes replay on the current session, so post-consent frames go to the session from before opt-out.posthog-ios (#959) and React Native (posthog-js#5363) already rotate whenever replay was wanted. This makes Android match, and matches the opt-in spec in sdk-specs#138.
Change
optIn()rotates the session (endSession()+startSession()) whensessionReplayWanted, before reinstalling integrations, under the samesetupLock.startSessionReplayInternaltakesrotateSession. The opt-in restart passesfalse, so it still takes the fresh-start recorder path (forced state reset and redraw, so the new session starts with meta + full snapshot) without rotating twice.Behavior change: apps reading
getSessionId()acrossoptOut()/optIn()now see a new id whenever replay was wanted, including when the linked flag holds replay off.Known issue, not changed here
If the app calls
stopSessionReplay()whilesessionReplay = true, Android restarts replay on the next remote-config re-evaluation.optIn()triggers one, and so does any flags reload, so this also happens without an opt-out. It reproduces onmainand is unchanged by this PR. Fixing it changes what a stop means in general, so it belongs in its own PR.💚 How did you test it?
make testpasses, andmake formatis clean./flagsand records every request:mainsessionReplay = false→ opt-out → opt-inNo events or snapshots were sent while opted out in any run.
📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
🤖 Generated with Claude Code