feat(ui): add reconcile tick to self-heal lost worker broadcasts
TasksIslandViewModel now runs a periodic tick that diffs the flat Items collection against SQLite and patches properties in place (capped at 500 rows, sharing the Phase 1 delta sequence guard so it never overtakes a fresher broadcast). Never rebuilds rows or triggers Regroup/LoadForList, so it stays decoupled from the parallel Phase 2b virtualization work. The same cadence now refreshes the long-lived Worktrees Overview, Log Visualizer, and Merge Helper selection overlays; short-lived modals are untouched.
This commit is contained in:
@@ -41,8 +41,16 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
_worker = worker;
|
||||
_copyToClipboard = copyToClipboard;
|
||||
Rows.CollectionChanged += (_, _) => CopyLastCommand.NotifyCanExecuteChanged();
|
||||
// Phase 3 reconcile tick: this overlay is long-lived (stays open while the user reads
|
||||
// through the log), so refresh it on the same cadence as TasksIslandViewModel's tick
|
||||
// instead of leaving it frozen at the moment it was opened.
|
||||
_reconcileTimer.Elapsed += (_, _) =>
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() => _ = RefreshAsync());
|
||||
_reconcileTimer.Start();
|
||||
}
|
||||
|
||||
private readonly System.Timers.Timer _reconcileTimer = new(4_000);
|
||||
|
||||
[RelayCommand]
|
||||
public async Task RefreshAsync()
|
||||
{
|
||||
@@ -65,7 +73,13 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
: Loc.T("modals.logVisualizer.count", Rows.Count);
|
||||
}
|
||||
|
||||
[RelayCommand] private void Close() => CloseAction?.Invoke();
|
||||
[RelayCommand]
|
||||
private void Close()
|
||||
{
|
||||
_reconcileTimer.Stop();
|
||||
_reconcileTimer.Dispose();
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
|
||||
private bool CanCopyLast() => Rows.Count > 0;
|
||||
|
||||
|
||||
@@ -51,8 +51,18 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
public TaskCompletionSource<IReadOnlyList<string>?> Result { get; } = new();
|
||||
public Action? CloseAction { get; set; }
|
||||
|
||||
private readonly System.Timers.Timer _reconcileTimer = new(4_000);
|
||||
|
||||
public MergeHelperSelectionModalViewModel(IDbContextFactory<ClaudeDoDbContext> dbFactory)
|
||||
=> _dbFactory = dbFactory;
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
// Phase 3 reconcile tick: this overlay is long-lived (stays open while the user ticks
|
||||
// through candidates), so refresh it on the same cadence as TasksIslandViewModel's tick
|
||||
// instead of leaving it frozen at the moment it was opened.
|
||||
_reconcileTimer.Elapsed += (_, _) =>
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() => _ = ReconcileTickAsync());
|
||||
_reconcileTimer.Start();
|
||||
}
|
||||
|
||||
public void Configure(string listId, string listName)
|
||||
{
|
||||
@@ -60,6 +70,19 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
ScopeLabel = Loc.T("modals.mergeHelper.scopeList", listName);
|
||||
}
|
||||
|
||||
// LoadAsync rebuilds every row from scratch, which would wipe the user's ticks out from
|
||||
// under them on every tick — capture and restore selection by id around the reload.
|
||||
internal async Task ReconcileTickAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_listId)) return;
|
||||
var selected = Tasks.Where(t => t.IsSelected).Select(t => t.Id).ToHashSet();
|
||||
await LoadAsync();
|
||||
foreach (var t in Tasks)
|
||||
if (selected.Contains(t.Id))
|
||||
t.IsSelected = true;
|
||||
OnPropertyChanged(nameof(CanConfirm));
|
||||
}
|
||||
|
||||
public async Task LoadAsync(CancellationToken ct = default)
|
||||
{
|
||||
foreach (var row in Tasks) row.PropertyChanged -= OnRowChanged;
|
||||
@@ -163,6 +186,7 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private void Confirm()
|
||||
{
|
||||
StopReconcileTick();
|
||||
Result.TrySetResult(Tasks.Where(t => t.IsSelected).Select(t => t.Id).ToList());
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
@@ -170,7 +194,17 @@ public sealed partial class MergeHelperSelectionModalViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
StopReconcileTick();
|
||||
Result.TrySetResult(null);
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
|
||||
// Also called from the dialog's native-close fallback (WindowDialogService), which resolves
|
||||
// Result without going through Confirm/Cancel. Idempotent — Timer.Stop()/Dispose() tolerate
|
||||
// repeated calls.
|
||||
internal void StopReconcileTick()
|
||||
{
|
||||
_reconcileTimer.Stop();
|
||||
_reconcileTimer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +100,20 @@ public sealed partial class WorktreesOverviewModalViewModel : ViewModelBase
|
||||
_worker = worker;
|
||||
_diffVmFactory = diffVmFactory;
|
||||
_merge = merge;
|
||||
// Phase 3 reconcile tick: this overlay is long-lived (stays open while the user reviews
|
||||
// worktrees), so refresh it on the same cadence as TasksIslandViewModel's tick instead of
|
||||
// leaving it frozen at the moment it was opened. Skipped while a load or batch merge is
|
||||
// already in flight — reloading mid-merge would replace the row instances the merge loop
|
||||
// is still updating.
|
||||
_reconcileTimer.Elapsed += (_, _) =>
|
||||
Avalonia.Threading.Dispatcher.UIThread.Post(() => _ = ReconcileTickAsync());
|
||||
_reconcileTimer.Start();
|
||||
}
|
||||
|
||||
private readonly System.Timers.Timer _reconcileTimer = new(4_000);
|
||||
|
||||
internal Task ReconcileTickAsync() => IsBusy || IsMerging ? Task.CompletedTask : LoadAsync();
|
||||
|
||||
public void SelectRow(WorktreeOverviewRowViewModel row)
|
||||
{
|
||||
if (SelectedRow is not null) SelectedRow.IsSelected = false;
|
||||
@@ -179,7 +191,12 @@ public sealed partial class WorktreesOverviewModalViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Close() => CloseAction?.Invoke();
|
||||
private void Close()
|
||||
{
|
||||
_reconcileTimer.Stop();
|
||||
_reconcileTimer.Dispose();
|
||||
CloseAction?.Invoke();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowDiff(WorktreeOverviewRowViewModel? row)
|
||||
|
||||
Reference in New Issue
Block a user