Skip to content

fix(replay): Advance converted session segment ID from sent segment - #6804

Open
sahuadarsh0 wants to merge 1 commit into
getsentry:mainfrom
sahuadarsh0:fix/6740-replay-converted-segment-id
Open

sahuadarsh0 wants to merge 1 commit into
getsentry:mainfrom
sahuadarsh0:fix/6740-replay-converted-segment-id

Conversation

@sahuadarsh0

Copy link
Copy Markdown

📜 Description

Pass the segment ID that BufferCaptureStrategy.captureReplay actually sent into onSegmentSent(segmentId, timestamp) and set activeStrategy.currentSegment = sentSegmentId + 1 in ReplayIntegration.captureCurrentReplay instead of incrementing the snapshot copied during convert().

Also return the last captured buffered segment from bufferedSegments.capture() so onSegmentSent still advances currentSegment when buffered segments were uploaded and the trailing current segment failed to encode, initialize the converted SessionCaptureStrategy at segment 0 so nothing-sent flushes do not start past 0, and forward replayCacheProvider in BufferCaptureStrategy.convert().

💡 Motivation and Context

When an error triggers buffer-to-session conversion while a configuration_changed, pause, or add_frame rotation task is still queued on replayExecutor, convert() previously copied an out-of-date currentSegment into the new SessionCaptureStrategy. Once the queued task ran and mutated the buffer counter before capture_replay, incrementing that stale copy caused the next session segment to repeat an already-sent segment ID (or skip one after rotation).

💚 How did you test it?

Added deterministic queued-executor tests in ReplayIntegrationTest covering:

  • a queued configuration_changed before captureReplay (reproduced duplicate [0, 1, 1] before the fix; now [0, 1, 2]),
  • a queued add_frame rotating out an expired buffered segment before captureReplay (verifies [0, 1, 2] with no skipped ID),
  • a queued pause before captureReplay where the trailing current segment fails to encode after the buffered segment is sent (verifies [0, 1]),
    plus a BufferCaptureStrategyTest check for the buffered-only callback path.

Ran ./gradlew :sentry-android-replay:testReleaseUnitTest --tests "io.sentry.android.replay.ReplayIntegrationTest" --tests "io.sentry.android.replay.capture.*" --tests "io.sentry.android.replay.ReplaySmokeTest" :sentry-android-replay:spotlessCheck :sentry-android-replay:detekt --no-daemon.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

@sahuadarsh0
sahuadarsh0 requested review from a team and adinauer as code owners November 29, 2026 09:48
@sahuadarsh0
sahuadarsh0 requested review from 0xadam-brown and runningcode and removed request for a team November 29, 2026 09:48
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 5299581.

Main concerns: reach, data sent to Sentry, public contract.

This label is a hint for reviewers, not an approval.

This branch has not been deployed

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session Replay: session segment ID can repeat after an error converts buffer mode

1 participant