Skip to content

feat: session replay minimum recording duration#548

Draft
ioannisj wants to merge 14 commits intomainfrom
feat/ios-minimum-recording-duration
Draft

feat: session replay minimum recording duration#548
ioannisj wants to merge 14 commits intomainfrom
feat/ios-minimum-recording-duration

Conversation

@ioannisj
Copy link
Copy Markdown
Contributor

@ioannisj ioannisj commented Apr 3, 2026

💡 Motivation and Context

Adds support for the minimumDurationMilliseconds remote config setting for session replay. When configured, session replay snapshots are buffered locally until the session reaches the minimum duration threshold, at which point they are migrated to the replay queue and sent to PostHog. Sessions that don't meet the minimum duration are discarded on next session start

This implementation is similar to Web SDK's strict mode but adapted for mobile:

  • Duration is measured from buffered recording data (first to last snapshot timestamp), not session age.
  • The buffer is not reset on navigation. On mobile apps, screen transitions are far more frequent than web page refreshes, so clearing the buffer on every navigation would make the feature impractical imho.

Implementation overview

  • Snapshots are written to a temporary disk-based buffer instead of the main replay queue
  • The buffer tracks duration using timestamps in UUID v7 filenames
  • A sliding window prunes snapshots older than the minimum duration threshold
  • Once the time span between oldest and newest buffered snapshot meets the threshold, all buffered snapshots are migrated to the replay queue for upload (moved)
  • Buffer is always cleared on new session start. So If the session ends before meeting the threshold, the buffer is discarded on next session
  • Once the minimum duration threshold is met for a session, subsequent snapshots go directly to the replay queue (no more buffering for that session).
  • When minimum duration is not configured or is zero, snapshots go directly to the replay queue (current behavior)
  • Flushing will be ignored while replay queue is writing to buffer

Performance considerations

  • There should be no additional memory footprint for this feature, since what really changes is where we write snapshots on disk. No memory buffer involved

💚 How did you test it?

  • Manual testing on sample projects mainly
  • Added a few tests to unit test queue changes

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the release label to the PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

posthog-ios Compliance Report

Date: 2026-04-03 11:14:36 UTC
Duration: 1665ms

✅ All Tests Passed!

0/0 tests passed


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant