Skip to content

[Feature] Post-trigger Replay Capture (aka. Leading Replay)#1341

Merged
matux merged 4 commits into
masterfrom
matux/leading-replay
Oct 2, 2025
Merged

[Feature] Post-trigger Replay Capture (aka. Leading Replay)#1341
matux merged 4 commits into
masterfrom
matux/leading-replay

Conversation

@matux

@matux matux commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Description of the change

Implements post-trigger replay capture, enabling recording of user actions after a trigger event, such as an occurrence. Complements existing pre-trigger (trailing) replay with configurable postDuration.

Sub-PRs (All Approved)

  1. Capture leading replay #1334 - Capture leading replayInitial implementation with event count boundary
  2. Renamed ReplayManager.add to ReplayManager.capture #1337 - Renamed ReplayManager.add to ReplayManager.captureAPI clarity improvement
  3. Move send replay from Queue to ReplayManager #1338 - Move send replay from Queue to ReplayManagerArchitectural refactor for leading replay coordination
  4. Capture events post replay triggering and send them as spans #1339 - Replace count-based boundary with buffer cursorStable {slot, offset} cursor eliminates rotation bugs

Implementation Highlights

Architecture

  • Two-phase capture: trailing (immediate) + leading (delayed by postDuration).
  • Trailing prioritized for high success rate; leading sent only if trailing succeeds.
  • Coordinated via TrailingStatus state machine (PENDINGSENT/FAILED).

Buffer Cursor System

  • Replaced fragile event count with {slot: 0|1, offset: number} cursor.
  • Survives single checkout rotation; best-effort with multiple checkouts.
  • 2-slot ring buffer with XOR-based _previousSlot getter.

Key Features

  • Configure via recorder.postDuration (seconds)
  • Automatic coordination between trailing/leading sends
  • Complete state cleanup on success/failure/discard
  • 29 new tests; 124 total replay tests passing

Changes

  • Core: Recorder, ReplayManager
  • Tests: Unit, integration, e2e coverage

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

@matux matux requested review from Copilot and waltjones October 2, 2025 14:59
@matux matux self-assigned this Oct 2, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Implements post-trigger replay capture (leading replay) to enable recording user actions after a trigger event occurs. This complements the existing pre-trigger (trailing) replay functionality with a configurable postDuration setting.

  • Adds two-phase capture system: trailing (immediate) + leading (delayed by postDuration)
  • Implements buffer cursor system to replace fragile event count-based boundaries
  • Adds coordination between trailing and leading sends via state machine

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/replay/util/recorder.js New test utility for accessing recorder's ring buffer internals
test/replay/unit/replayManager.test.js Updates method calls from add to capture and adds comprehensive tests for sendOrDiscardReplay
test/replay/unit/recorder.collectEvents.test.js New unit tests for buffer cursor-based event collection methods
test/replay/unit/queue.replayManager.test.js Refactors tests to use sendOrDiscardReplay instead of direct send/discard calls
test/replay/integration/sessionRecording.test.js Updates method calls and spy names from add to capture
test/replay/integration/replayManager.test.js Updates method calls and adds integration tests for sendOrDiscardReplay
test/replay/integration/replayManager.bufferIndex.test.js New integration tests for buffer cursor system and leading replay functionality
test/replay/integration/replayManager.bufferIndex.checkoutResilience.test.js New tests for buffer cursor resilience across checkout operations
test/replay/integration/queue.replayManager.test.js Updates integration tests to use new sendOrDiscardReplay API
test/replay/integration/e2e.test.js Updates method calls and adds E2E test for trailing/leading replay flow
test/browser.replay.recorder.test.js Updates test expectations and adds postDuration to configuration tests
src/queue.js Removes replay decision logic and delegates to ReplayManager.sendOrDiscardReplay
src/browser/replay/replayManager.js Major refactor: renames add to capture, adds leading replay coordination, and implements sendOrDiscardReplay
src/browser/replay/recorder.js Replaces event arrays with ring buffer system and implements cursor-based event collection
src/browser/replay/defaults.js Adds default postDuration configuration option

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@matux matux merged commit b3aeddc into master Oct 2, 2025
4 checks passed
@matux matux deleted the matux/leading-replay branch October 2, 2025 15:15
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.

3 participants