Skip to content

refactor: Extract SyncStateCoordinator from SyncEngine#19

Merged
jaybarden1 merged 5 commits intomainfrom
copilot/refactor-extract-syncstatecoordinator
Feb 11, 2026
Merged

refactor: Extract SyncStateCoordinator from SyncEngine#19
jaybarden1 merged 5 commits intomainfrom
copilot/refactor-extract-syncstatecoordinator

Conversation

Copy link
Contributor

Copilot AI commented Feb 11, 2026

SyncEngine mixed sync orchestration with state management, progress calculation, and session lifecycle logic. This made the class complex (1200+ lines) and state behavior difficult to test in isolation.

Changes

New Component: ISyncStateCoordinator

  • Encapsulates session lifecycle (initialize, complete, fail, cancel)
  • Handles progress calculation with transfer speed tracking (rolling 10-sample window)
  • Provides observable state updates via BehaviorSubject<SyncState>
  • Manages session logging via ISyncSessionLogRepository

SyncEngine Simplification

  • Removed 113 lines of state management code
  • Replaced internal _progressSubject, _transferHistory, _currentSessionId with coordinator delegation
  • Progress observable now proxied from coordinator: public IObservable<SyncState> Progress => _syncStateCoordinator.Progress
  • Deleted methods: ReportProgress(), InitializeSyncSessionAsync(), FinalizeSyncSessionAsync(), HandleSyncFailedAsync(), HandleSyncCancelledAsync(), ResetTrackingDetails()

Example Usage

// Before: SyncEngine managed state internally
await InitializeSyncSessionAsync(accountId, enableDetailedLogging, ct);
ReportProgress(accountId, SyncStatus.Running, totalFiles, completedFiles, ...);

// After: Delegated to coordinator
string? sessionId = await _syncStateCoordinator.InitializeSessionAsync(accountId, enableDetailedLogging, ct);
_syncStateCoordinator.UpdateProgress(accountId, SyncStatus.Running, totalFiles, completedFiles, ...);

Testing

  • 16 unit tests for SyncStateCoordinator covering progress calculation, speed/ETA, session state transitions
  • Updated SyncEngine tests to mock coordinator with reactive BehaviorSubject

Impact

  • No breaking changes to ISyncEngine interface
  • State logic now independently testable
  • SyncEngine constructor gains one dependency: ISyncStateCoordinator

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll d -n 10 (dns block)
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.1/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll cture/Services/ISyncStateCoordinator.cs ame rgo/bin/git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>refactor: Extract SyncStateCoordinator from SyncEngine</issue_title>
<issue_description>## Description
Extract sync state management and progress reporting from SyncEngine into a dedicated SyncStateCoordinator.

Current State

Sync state management is scattered throughout SyncEngine:

  • Progress calculations in multiple methods
  • State updates mixed with business logic
  • Session lifecycle management embedded in main sync flow

Proposed Changes

Create ISyncStateCoordinator interface and implementation with methods:

  • InitializeSessionAsync(accountId) - Create sync session
  • UpdateProgress(...) - Calculate and report progress
  • RecordCompletion(files, bytes, conflicts) - Record sync completion
  • RecordFailure(error) - Record sync failure
  • GetCurrentState() - Get current sync state

Benefits

  • ✅ Centralizes all state management logic
  • ✅ Makes progress calculation testable in isolation
  • ✅ Simplifies SyncEngine core sync logic
  • ✅ Enables better sync state observability

Dependencies

Dependencies would be:

  • ISyncSessionLogRepository - for session persistence
  • Progress reporter callback (Action<...>)

Technical Notes

  • Manage session lifecycle (start, update, complete/fail)
  • Calculate totals (files, bytes, conflicts)
  • Handle progress throttling if needed
  • Support pause/resume scenarios

Acceptance Criteria

  • ISyncStateCoordinator interface created
  • SyncStateCoordinator implementation with state management logic
  • SyncEngine updated to inject and use the service
  • Comprehensive unit tests (targeting 90%+ coverage)
  • All existing tests still passing

Related

Part of the SyncEngine architectural refactoring effort following PR #9.</issue_description>

<agent_instructions>Please implement and ensure you follow the .github/copilot-instructions.md styling / coding standards</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 11, 2026 13:18
Co-authored-by: jaybarden1 <137005981+jaybarden1@users.noreply.github.com>
Co-authored-by: jaybarden1 <137005981+jaybarden1@users.noreply.github.com>
Co-authored-by: jaybarden1 <137005981+jaybarden1@users.noreply.github.com>
…nd improve test clarity

Co-authored-by: jaybarden1 <137005981+jaybarden1@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor sync state management into SyncStateCoordinator refactor: Extract SyncStateCoordinator from SyncEngine Feb 11, 2026
Copilot AI requested a review from jaybarden1 February 11, 2026 13:32
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@jaybarden1 jaybarden1 marked this pull request as ready for review February 11, 2026 14:24
Copy link
Contributor

@jaybarden1 jaybarden1 left a comment

Choose a reason for hiding this comment

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

I will remove:
private async Task<List> GetAllLocalFiles(string accountId, IReadOnlyList selectedFolders, AccountInfo account)
and cleanup to follow the style guide

@jaybarden1 jaybarden1 merged commit 1f11a3e into main Feb 11, 2026
9 of 11 checks passed
@jaybarden1 jaybarden1 deleted the copilot/refactor-extract-syncstatecoordinator branch February 11, 2026 14:26
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.

refactor: Extract SyncStateCoordinator from SyncEngine

2 participants