Skip to content

fix(session-replay-browser): reduce snapshot size and handle 413s#1685

Open
lewgordon-amplitude wants to merge 5 commits intomainfrom
fix-413s-sdk
Open

fix(session-replay-browser): reduce snapshot size and handle 413s#1685
lewgordon-amplitude wants to merge 5 commits intomainfrom
fix-413s-sdk

Conversation

@lewgordon-amplitude
Copy link
Copy Markdown
Collaborator

@lewgordon-amplitude lewgordon-amplitude commented Apr 17, 2026

Summary

Reduce snapshot payload size

  • Enable all rrweb slimDOMOptions by default: scripts, comments, favicons, head whitespace, and all head meta tags (description/keywords, social, robots, http-equiv, authorship, verification) are now stripped from snapshots. None of these affect replay fidelity.
  • Remove the omitElementTags config option (was only wiring up script and comment; now all slim-DOM stripping is unconditional)

WAF 413 bisect-retry

  • On a WAF 413 (response body contains "Payload exceeds"), split the event batch in half and retry each half independently; recurse until batches reach a single event, then stop and warn
  • App-layer 413s (no WAF signature) are not retried, preventing infinite loops

Capture-time drop for oversized single events

  • Add MAX_SINGLE_EVENT_SIZE constant (9 MB)
  • Guard in EventCompressor.addCompressedEventToManager drops any serialized event exceeding the limit before it's queued — avoids a wasted network round trip for snapshots that would fail the server's ~10 MB limit anyway

Tests

  • Unit tests for all new behaviors
  • New e2e spec (size-limits.spec.ts): oversized event not delivered, SDK recovers after drop, WAF 413 triggers bisect-retry, app-layer 413 doesn't loop
  • Move e2e test server to port 5174 to isolate worktree from main-branch dev server

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: Yes — omitElementTags removed from public config (was undocumented/unused in practice)

Note

Medium Risk
Medium risk because it changes replay payload shaping and delivery retry behavior (including dropping events and splitting batches on 413), which could affect data completeness and network/load patterns.

Overview
Improves session replay reliability/size limits by dropping oversized single rrweb events (new MAX_SINGLE_EVENT_SIZE guard) and filtering any previously-stored oversized events before send.

Adds 413 Payload Too Large handling: when a 413 matches the WAF signature ("Payload exceeds"), the SDK bisects the event batch and retries each half until it bottoms out at a single event (which is then dropped with a warning); this behavior works in both main-thread and worker send paths.

Reduces snapshot payload size by enabling rrweb slimDOMOptions defaults (scripts/comments + head/favicon/meta trimming) and removes the omitElementTags option.

Expands unit/e2e coverage for oversized-event dropping and 413 behaviors (including “no infinite loop” and post-413 recovery), adds a dedicated size-limits.spec.ts, and moves the Playwright e2e server to port 5174.

Reviewed by Cursor Bugbot for commit f4b94d0. Bugbot is set up for automated code reviews on this repo. Configure here.

…p oversized events at capture

- Add MAX_SINGLE_EVENT_SIZE guard in EventCompressor to silently drop
  events that exceed the server's size limit before sending
- Bisect-retry logic in track-destination: on a WAF 413 (body contains
  "Payload exceeds"), split the batch in half and retry each half
  independently; bottom out at single events to avoid infinite loops
- Add MAX_SINGLE_EVENT_SIZE constant (9 MB)
- Add e2e tests covering oversized capture-time drop and 413 retry
- Move e2e test server to port 5174 to isolate worktree from main-branch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 17, 2026

Session Replay Browser E2E Results

passed  78 passed

Details

stats  78 tests across 5 suites
duration  1 minute, 44 seconds
commit  71f8cb9

@lewgordon-amplitude lewgordon-amplitude changed the title fix(session-replay-browser): handle WAF 413 with bisect-retry and drop oversized events at capture fix(session-replay-browser): reduce snapshot size and handle 413s Apr 17, 2026
@lewgordon-amplitude
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread packages/session-replay-browser/src/worker/track-destination.ts
… 413 useRetry inconsistency

- Enable all rrweb slimDOMOptions by default (scripts, comments, all
  head meta/favicon/whitespace tags) — none affect replay fidelity
- Remove omitElementTags from public config; stripping is now unconditional
- Fix worker sendWithRetry: only bisect on 413 when useRetry=true,
  matching main-thread behavior for flush(false) calls

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lewgordon-amplitude
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f4b94d0. Configure here.

lewgordon-amplitude and others added 3 commits April 17, 2026 11:27
…limDOM is always enabled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…in oversized-event warnings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lewgordon-amplitude lewgordon-amplitude marked this pull request as ready for review April 17, 2026 15:58
@lewgordon-amplitude lewgordon-amplitude requested a review from a team as a code owner April 17, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant