fix(replay): discard snapshots crossing recording boundaries - #771
Merged
Conversation
Contributor
Prompt To Fix All With AI### Issue 1
posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt:805-808
**Stale frames reset warnings**
When recording stops while PixelCopy is in flight, screenshot processing can finish and reset the consecutive-discard warning state before this generation check rejects the stale frame. Because same-session stop and resume does not reset that counter, an undelivered screenshot is treated as successful and can delay or suppress warnings for later discarded frames. Preserve the previous discard state or count the generation-rejected screenshot as discarded.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "fix(replay): discard snapshots crossing ..." | Re-trigger Greptile |
marandaneto
approved these changes
Sep 9, 2026
7 tasks
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
A replay snapshot can finish after recording stops or its session changes. That stale frame could overwrite reset snapshot state, consume the next session's initial keyframe, or acquire the next session's identity during event enrichment.
Track the recording generation and session while producing a snapshot, then validate both before committing snapshot state. Stop, reset, and session changes invalidate pending work synchronously. Committed frames retain their captured session/window IDs; screenshot processing and SDK callbacks remain outside the state lock.
This preserves the existing screenshot optimizations and buffer lifecycle. Already-committed events can still finish sending with their original identity. No public API or default configuration changes; includes an Android patch changeset.
💚 How did you test it?
main(d4a3a038) and pass with this fix: stop, same-session resume, session rotation/keyframe preservation, rotation before listener delivery, and rotation before real core enrichment.make test: 527 Android tests passed, 3 existing benchmark skips; 9 Compose survey tests passed.make testJava: 945 core tests passed.make checkFormat,./gradlew apiCheck, andgit diff --checkpassed.The emulator test used synthetic data only. PostHog Cloud/player validation was not performed.
📝 Checklist
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Pi was used for reconciliation, an independent read-only SDK review, and validation, with the
workerandrevieweragents, Gradle, and adb. The change was reconciled against the merged screenshot optimizations before review and runtime testing. Human review is still required.