Skip to content

Extract leading capture logic from replay manager#1360

Merged
matux merged 1 commit into
masterfrom
matux/extract-capture
Oct 10, 2025
Merged

Extract leading capture logic from replay manager#1360
matux merged 1 commit into
masterfrom
matux/extract-capture

Conversation

@matux

@matux matux commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Description of the change

Refactors ReplayManager by extracting leading (post-trigger) replay coordination logic into a dedicated LeadingCapture component.

Motivation

ReplayManager has 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

  • Created src/browser/replay/leadingCapture.js (158 lines)
    • Manages delayed post-trigger replay captures
    • Handles timer scheduling and buffer cursor stability
    • Coordinates with trailing replay via delegate pattern
  • Refactored src/browser/replay/replayManager.js (438 → 330 lines, -25%)
    • Uses composition: _leadingCapture instance
    • Delegate methods: _shouldSendLeading(), _onLeadingComplete()
    • Clearer separation of concerns
  • Updated integration tests to access _leadingCapture._pending directly

Architecture

LeadingCapture uses delegate pattern for coordination:

  • shouldSend(replayId) - Checks if coordination allows sending
  • onComplete(replayId) - Notifies when capture completes

This inverts dependencies: LeadingCapture doesn't know about TrailingStatus or trailing replays, avoiding circular imports.

Testing

  • All tests pass with no logic changes, only some renaming, no API changes.

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

@matux matux requested a review from Copilot October 10, 2025 11:35
@matux matux self-assigned this Oct 10, 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

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._pending structure

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.

Comment thread src/browser/replay/leadingCapture.js
@matux matux force-pushed the matux/extract-capture branch from 258b23b to 0888b47 Compare October 10, 2025 11:37
@matux matux merged commit 965f0c8 into master Oct 10, 2025
6 checks passed
@matux matux deleted the matux/extract-capture branch October 10, 2025 13:10
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