Skip to content

fix(replay): discard snapshots crossing recording boundaries - #771

Merged
dustinbyrne merged 1 commit into
mainfrom
fix/replay-session-boundaries
Sep 10, 2026
Merged

fix(replay): discard snapshots crossing recording boundaries#771
dustinbyrne merged 1 commit into
mainfrom
fix/replay-session-boundaries

Conversation

@dustinbyrne

Copy link
Copy Markdown
Contributor

💡 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?

  • Five deterministic regressions fail against unchanged 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, and git diff --check passed.
  • Packaged a local AAR and tested a separate Java consumer on an API 36 arm64 emulator with a local mock ingestion server. Both default screenshots and 0.5-scale/RGB_565 screenshots passed: 10 session rotations, 30 same-session stop/resume pairs, event-gate negatives, settled-stop negatives, complete initial keyframes, and matching session/window IDs. Decoded 16 actual screenshot payloads at 1080×2400 and 540×1200; 148 assertions passed.

The emulator test used synthetic data only. PostHog Cloud/player validation was not performed.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No public documentation changes needed.
  • No breaking change; Android patch changeset included.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi was used for reconciliation, an independent read-only SDK review, and validation, with the worker and reviewer agents, Gradle, and adb. The change was reconciled against the merged screenshot optimizations before review and runtime testing. Human review is still required.

@dustinbyrne
dustinbyrne requested a review from a team as a code owner September 9, 2026 16:14
@dustinbyrne dustinbyrne self-assigned this Sep 9, 2026
@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
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

@dustinbyrne
dustinbyrne merged commit 231caaf into main Sep 10, 2026
16 checks passed
@dustinbyrne
dustinbyrne deleted the fix/replay-session-boundaries branch September 10, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants