Repository navigation
Conversation
…ansient failures When every upload attempt for a batch failed with a transient error (send timeout, 5xx, 408, 429, 499), the SDK called onComplete as if the batch had been delivered, deleting its IndexedDB record. If that batch held the initial full snapshot, later batches uploaded normally but the replay played back blank. Keep the stored record instead, so sendStoredEvents re-sends it on the next page load. The worker now reports transient exhaustion as `retryExhausted` rather than a plain `complete`. Non-retryable failures still settle the record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦
|
Session Replay Browser E2E ResultsDetails
|
|
bugbot run |
|
If a batch exhausts reloads and is saved for next time, should it also store the device id to avoid using the newest device id once it tries again on next initialization? Or will the device id be correct on the next time? |
…w often it is kept - Persist the device id a batch was first sent with on its stored record and use it when the batch is re-sent on a later page load, so it keeps its original replay id if the device id changed in between. Records without one (older SDK versions, batches promoted from another tab) fall back to the current device id. - Count how many times a stored batch's retries ran out on transient failures (onRetryExhausted -> markRetryExhausted) and drop it after MAX_RETRY_EXHAUSTED_COUNT (3), so a batch the endpoint keeps rejecting is not stored and re-sent forever. Merged requests fan the callback out to every source batch. The in-memory store drops the batch right away, since nothing re-reads it on a later page load. - Bind each batch's store callbacks to the store its record is in, so a mid-page fallback to the in-memory store can't clean up an unrelated record with an overlapping id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Good catch, thanks — yes. Fixed in 5a234a2:
This gap was already there for batches left behind by a closed page. Keeping batches after retries run out just makes it more common. While I was in here I also capped how often a batch is kept. After its retries run out on 3 page loads it's dropped, so a batch the endpoint keeps rejecting doesn't pile up in IndexedDB. Details are in the PR description. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5a234a2. Configure here.
| logIdbError(this.loggerProvider, `${STORAGE_FAILURE}: ${e as string}`, e); | ||
| this.recordFailure(); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Missing transaction rejection handler
Low Severity
markRetryExhausted opens a manual readwrite transaction and only awaits tx.done after get/put/delete. The other manual transactions in this store attach tx.done.catch immediately so an aborted commit cannot become an unhandled rejection. If get or put rejects, control jumps to the outer catch and never awaits tx.done, so that rejection is unhandled.
Triggered by learned rule: IDB store tx.done.catch handlers must call recordFailure()
Reviewed by Cursor Bugbot for commit 5a234a2. Configure here.


Summary
Problem. When every upload attempt for a replay batch fails with a transient error, the SDK treats the batch as delivered and deletes its IndexedDB record. Transient errors here are a send timeout, 5xx, 408, 429 or 499. If the deleted batch held the initial full snapshot, the rest of the session still uploads, but the replay plays back blank: there is no snapshot to apply the later events to. The full snapshot batch is the largest one, so on a slow uplink it is also the one most likely to hit the 10s send timeout twice.
The deletion happens on two paths:
sendWithRetryposted{ type: 'complete' }after the last failed attempt. That is the same message a successful upload sends, so the main thread rancompleteRequest→onComplete→cleanUpSessionEventsStore.handleOtherResponsecalledcompleteRequestwhen the retry budget ran out.Fix. When the retry budget runs out on a transient failure, keep the stored record instead of completing it.
sendStoredEventsthen re-sends it on the next page load. Concretely:{ type: 'complete', retryExhausted: true }.keepForNextPageLoad, which logs a warning and does not callonComplete.Re-sending a batch that the server did receive is safe, because the server deduplicates. The drain on load already relies on this.
Kept batches keep their device id. A stored record now also saves the device id the batch was first sent with, and
sendStoredEventsre-sends with it. Without this, a batch re-sent after the device id changed (reset(), cleared cookies) would be attached to a different replay, since the replay id is session id + device id. Records without one fall back to the current device id, as before. Those are records from older SDK versions and batches promoted from another tab.A batch is kept at most 3 times. If the endpoint keeps failing with a retryable status, kept batches must not pile up in IndexedDB and be re-sent on every page load. Each time a stored batch's retries run out,
onRetryExhausted→markRetryExhaustedincrements a counter on its record, and on the 3rd time (MAX_RETRY_EXHAUSTED_COUNT) the record is deleted. Details:onCompletealready does.Related fix. Each batch's store callbacks are now bound to the store its record is in. Before, after a mid-page fallback from IndexedDB to the in-memory store, a batch sent earlier would clean up the in-memory record with the same sequence id. The two stores' ids overlap, so that record was unrelated.
Tests
retryExhausted;onRetryExhausted;e2e/retry-exhausted-keep.spec.ts, run for both the main-thread and worker send paths:main: 0 full snapshots are left in IndexedDB after retries run out. The device id assertion fails without the device id change. Both pass with this change.shadow-dom.spec.ts, which is flaky onmaintoo (2 of 20 runs failed there).Follow-ups, not in this PR
EventCompressorkeeps the device id it was created with, so aftersetSessionId(sessionId, newDeviceId)within one page, split-off batches still go out with the old device id while flushed ones use the new one. This was already the case before this PR.sendBeacon64KB prefix trim can send a Meta event without its full snapshot; its code comment assumes the snapshot was already sent eagerly.Checklist
🤖 Generated with Claude Code
Note
Medium Risk
Changes core upload settlement and IndexedDB lifecycle for failed batches; wrong branching could duplicate uploads or leave stale data, though server deduplication and a 3-attempt drop cap limit exposure.
Overview
Fixes session replay losing full snapshots (blank playback) when upload retries exhaust on transient errors: the SDK no longer treats those batches as delivered and deletes their IndexedDB rows.
On the send path, transient retry exhaustion now goes through
keepForNextPageLoadinstead ofonComplete/cleanUpSessionEventsStore— on both main-thread (handleOtherResponse) and web worker (retryExhausted: trueon workercomplete). Non-retryable failures still complete and remove the record as before.Persistence is extended so retries can survive reloads: batches store
deviceIdand are re-sent with the original id (replay id = session + device);markRetryExhaustedincrements a counter and drops afterMAX_RETRY_EXHAUSTED_COUNT(3) page loads of repeated failure.events-managerwiresonRetryExhausted, prefers storeddeviceIdinsendStoredEvents, and pins the source store for cleanup when IDB falls back to memory. Coalesced flushes fan outonRetryExhaustedto every merged source.Tests: new Playwright e2e
retry-exhausted-keep.spec.ts(main thread + worker, device id, eventual drop); unit tests updated across stores, manager, track destination, and worker.Reviewed by Cursor Bugbot for commit 5a234a2. Bugbot is set up for automated code reviews on this repo. Configure here.