Extract leading capture logic from replay manager#1360
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the ReplayManager by extracting leading capture functionality into a dedicated LeadingCapture component to improve code organization and maintainability. The change addresses growing complexity in ReplayManager by separating concerns through a focused delegation pattern.
- Extracts 158 lines of leading capture logic into a new LeadingCapture class
- Reduces ReplayManager from 438 to 330 lines using composition pattern
- Updates integration tests to access the new
_leadingCapture._pendingstructure
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/browser/replay/leadingCapture.js | New class managing delayed post-trigger replay captures with timer scheduling and buffer coordination |
| src/browser/replay/replayManager.js | Refactored to use LeadingCapture composition with delegate methods for coordination |
| test/replay/integration/replayManager.bufferIndex.test.js | Updated test assertions to access pending state through _leadingCapture |
| test/replay/integration/replayManager.bufferIndex.checkoutResilience.test.js | Updated test assertions to access pending state through _leadingCapture |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
258b23b to
0888b47
Compare
waltjones
approved these changes
Oct 10, 2025
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.
Description of the change
Refactors ReplayManager by extracting leading (post-trigger) replay coordination logic into a dedicated LeadingCapture component.
Motivation
ReplayManagerhas grown to 438 lines with multiple responsibilities. The leading capture logic (scheduling, export, coordination) is ~150 lines of complex async state management that deserves its own focused class.Plus, we're adding more complex logic around scheduling, exporting and sending post-trigger replay events in chunks to prevent loss of data.
On top of that, we're adding more complex logic surrounding replay triggers.
Changes
src/browser/replay/leadingCapture.js(158 lines)src/browser/replay/replayManager.js(438 → 330 lines, -25%)_leadingCaptureinstance_shouldSendLeading(),_onLeadingComplete()_leadingCapture._pendingdirectlyArchitecture
LeadingCapture uses delegate pattern for coordination:
shouldSend(replayId)- Checks if coordination allows sendingonComplete(replayId)- Notifies when capture completesThis inverts dependencies:
LeadingCapturedoesn't know aboutTrailingStatusor trailing replays, avoiding circular imports.Testing
Type of change