SIGN IN SIGN UP

fix(replay): Preserve segment ID after buffer-to-session conversion (#5753)

* fix(replay): Preserve segment ID after buffer-to-session conversion

After a buffer-to-session conversion, the replay type stays BUFFER
but the segment counter reflects the real sequence. If the app
crashes and finalizePreviousReplay recovers the last segment,
fromDisk() was normalizing the segment ID to 0 for all BUFFER
replays, creating a duplicate segment 0 that overwrites the original.

Add a persisted isFlushed flag set when the buffer is successfully
flushed. fromDisk() now only normalizes to 0 when the buffer was
never flushed (no segments were ever sent to the server).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* changelog

* Apply suggestion from @romtsn

* Add comment explaining isFlushed flag purpose

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(replay): Use persisted timestamp for flushed buffer recovery

After buffer-to-session conversion, use the persisted segmentTimestamp
(which chains with previous segments) instead of the first frame
timestamp, avoiding gaps in the recovered segment timeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Revert timestamp normalization change

The gap from using first-frame timestamp vs persisted segmentTimestamp
is at most ~1s (1/frameRate) — negligible for crash recovery.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
R
Roman Zavarnitsyn committed
31c558ecbc0ceee6d01fe587848d7307f7c78de1
Parent: f232e4f
Committed by GitHub <noreply@github.com> on 7/13/2026, 7:53:48 PM