From 7f94bf4aed2294fc064b6d2a58153aa6b82af813 Mon Sep 17 00:00:00 2001 From: mika kuns Date: Fri, 21 Aug 2026 17:47:49 +0200 Subject: [PATCH] fix(ui): UsagePillViewModel loads snapshot on connection restore The ctor-time LoadAsync races WorkerClient.StartAsync, so the SignalR call fails silently and the pill only fills on the next worker poll (up to 900s). Subscribe to ConnectionRestoredEvent, which also fires on the first successful connect, to retry the cached snapshot. --- src/ClaudeDo.Ui/ViewModels/UsagePillViewModel.cs | 3 +++ .../ViewModels/UsagePillViewModelTests.cs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ClaudeDo.Ui/ViewModels/UsagePillViewModel.cs b/src/ClaudeDo.Ui/ViewModels/UsagePillViewModel.cs index 7e1d800d..787b06ae 100644 --- a/src/ClaudeDo.Ui/ViewModels/UsagePillViewModel.cs +++ b/src/ClaudeDo.Ui/ViewModels/UsagePillViewModel.cs @@ -22,6 +22,7 @@ public sealed partial class UsagePillViewModel : ViewModelBase { _worker = worker; _worker.UsageUpdatedEvent += OnUsageUpdated; + _worker.ConnectionRestoredEvent += OnConnectionRestored; _ = LoadAsync(); } @@ -34,6 +35,8 @@ public sealed partial class UsagePillViewModel : ViewModelBase private void OnUsageUpdated(UsageSnapshotDto snapshot) => Snapshot = snapshot; + private void OnConnectionRestored() => _ = LoadAsync(); + partial void OnSnapshotChanged(UsageSnapshotDto? value) { OnPropertyChanged(nameof(Text)); diff --git a/tests/ClaudeDo.Ui.Tests/ViewModels/UsagePillViewModelTests.cs b/tests/ClaudeDo.Ui.Tests/ViewModels/UsagePillViewModelTests.cs index 8e098ebb..fbba8668 100644 --- a/tests/ClaudeDo.Ui.Tests/ViewModels/UsagePillViewModelTests.cs +++ b/tests/ClaudeDo.Ui.Tests/ViewModels/UsagePillViewModelTests.cs @@ -144,4 +144,20 @@ public class UsagePillViewModelTests Assert.Contains("12", vm.Text); } + + // ── ConnectionRestored event ───────────────────────────────────────────── + + [Fact] + public void ConnectionRestored_Event_LoadsSnapshot() + { + var worker = new FakeWorker(); + var vm = new UsagePillViewModel(worker); + Assert.Null(vm.Snapshot); + + worker.InitialSnapshot = Snapshot(fiveHourPercent: 25); + worker.RaiseConnectionRestored(); + + Assert.NotNull(vm.Snapshot); + Assert.Contains("25", vm.Text); + } }