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:
mika kuns
2026-08-10 15:56:05 +02:00
parent 514d6111fe
commit 1cad264967
7 changed files with 381 additions and 4 deletions
@@ -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();
}
}