fix: preserve replay batch identity - #4
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Adds explicit delivery and recorder-lifecycle identities to ingest batches so retries are idempotent and replay order remains deterministic across reloads and recorder restarts.
Problem
Using
(session_id, seq)as a retry identity is unsafe becauseseqis a local counter. A full-page reload or stop/init cycle creates a new recorder lifecycle and restartsseqat zero, so the same session can legitimately contain multipleseq: 0batches. Treating those as duplicates would discard valid recordings; accepting all of them without a delivery identity allows retries to duplicate stored events and counters.Solution
batchIdis a stable delivery identity for one batch and is reused by transport retries.recordingInstanceIdidentifies a recorder lifecycle.recordingOrderexplicitly orders recorder lifecycles within a session.seqorders batches only within one recorder lifecycle and resets for a newly started lifecycle.(session_id, batch_id)conflicts; other database failures propagate.recording_order,seq,recording_instance_id, and row id for deterministic ties.ended_atis monotonic and records the latest observed activity time.Migration
eventswith non-nullbatch_id,recording_instance_id, andrecording_order, backfills historical rows with deterministic legacy identities, and adds the unique(session_id, batch_id)index.Testing
ended_at.Backward Compatibility
Legacy SDK payloads without all three new protocol fields are accepted. The server assigns a random delivery id,
legacy-<sessionId>recorder identity, and recording order0; therefore legacy batches replay before new SDK lifecycles, which begin at order1, in a shared session. Legacy clients do not gain retry deduplication because they cannot supply a stablebatchId. New-client semantics remain isolated by their explicit lifecycle ordering and stable delivery identity.Checklist