Repository navigation
fix(replay): let native opt-out and opt-in own the replay stop and restart - #687
Merged
Merged
Conversation
This was referenced Oct 29, 2026
Contributor
posthog-flutter Compliance ReportDate: 2026-10-30 15:34:04 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
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 blocking from me. I traced the new optOut/optIn path against posthog-ios 3.92.3 and posthog-android 3.72.9 and the Dart change lines up with what native does at those floors. The Android linked-flag gap you call out is real and sits on posthog-android#915. The only thing I left inline is the stale version comment in the podspec.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o fix/opt-in-native-restarts-replay
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:
optOut()andoptIn()now leave the session replay stop and restart to the native SDKs. Flutter only turns its own capture loop off and back on. Before, Flutter's own stop/start calls made native forget that the app wanted replay, and in two cases replay came back on the session that was active while the user was opted out.What was wrong:
optOut()called nativestopSessionRecording()while still opted in. Since posthog-ios #959 and posthog-android #839, native treats that as the app stopping replay, so nativeoptIn()never restarted it.optIn()then restarted replay itself withstartSessionRecording(resumeCurrent: false). That start checks the linked flag before starting a new session, on both iOS and Android. So when the linked flag held replay off at opt-in, no new session started, and replay later resumed on the opted-out session once flags loaded.Change
optOut()no longer calls nativestopSessionRecording(). Native opt-out stops replay itself.optIn()no longer calls nativestartSessionRecording(resumeCurrent: false). Native opt-in restarts the replay the app wanted, in a new session. Flutter forces a replay session reset, so the next frame is a full snapshot, and turns its capture loop back on.Android in the linked-flag case: this relies on native Android starting a new session even when the flag holds replay off, which is PostHog/posthog-android#915. Until that ships and Flutter's Android minimum is raised in a follow-up, Flutter on Android behaves as before in that one case. That's no regression.
Known issues, not changed here
sessionReplay = true) on the next remote-config re-evaluation. Flutter sends nothing in that state, because its capture loop stays off, butisSessionReplayActive()reportstrue. This is described in posthog-android#915 and will be a separate fix there.sendFullSnapshotencodes on a background queue before callingcapture. It happens on any session change, andmaindoes it too.💚 How did you test it?
flutter test test/opt_out_session_replay_test.dartpasses. The updated test asserts that no native stop/start is sent and that opt-in forces a replay session reset. Removing that reset fails the test.dart formatandflutter analyzeare 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