Compare commits

...
Author SHA1 Message Date
poli0981andClaude Opus 5.5 6dea3ac129 fix(app): the Games page shows its newest read of the library (beta.19 PR-6)
Reads of the library overlap - a session that ends, an import, a removal -
and each awaits its executable checks off the UI thread. The read that
started first could finish last, its checks waiting on a slow drive, and
its older list was shown over the newer one: after the Agent removed a
game, an overlapping older read put the removed game's card back until the
next read.

Found by running GamesViewModelTests in a loop while the release train was
gated: one local run in about 165 failed. The pre-existing
ACardSaysWhetherItsExecutableIsThereAndWhy starts its own two reads (the
constructor's and an explicit one), and the first could be applied last.

GamesViewModel.LoadAsync now numbers each read (Interlocked) and shows it
only if no newer read began meanwhile. The executable check is injectable
(Func<string, bool>, default GameLibrary.ExecutableExists) so a test can
hold one read's check.

Tests:
- GamesViewModelTests.AnOlderReadThatFinishesLastIsNotShownOverANewerOne
  holds the first read in its check (bounded waits, so a broken test
  fails rather than hangs), lets a newer read list two games, then lets
  the first finish. It goes red without the guard ("found 1").
- ACardSaysWhetherItsExecutableIsThereAndWhy awaits the page's first read
  before adding the games it lists.

Measured: 10 runs of the class green and the whole App suite 599/599.

Docs: 08_UI §Games; CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:39:19 +07:00
poli0981andClaude Opus 5.5 2639a655a0 fix(app): one check's removals are said once, after one read of the library (beta.19 PR-6)
The Agent removes an uninstalled, session-less entry by itself since this
train (D55), and says each removal in its own GameRemoved event. One check
that removes several sends them milliseconds apart, and the Games page on
screen showed a snackbar and started a full library read for each. WPF UI
4.3.0's SnackbarService keeps one snackbar and shows every message at once
in it (Show(true) -> SnackbarPresenter.ImmediatelyDisplay, read from the
4.3.0 assembly), so only the last name stayed on screen.

The page now waits GamesViewModel.RemovalSettle (one second, over an
injected TimeProvider) after the first removal for the rest of the check,
reads the library once and says them in one notice: the game's name as
before, or the count, five names and how many more
(Games_Removed_Many_Format, Games_Removed_More_Format; en/vi/ja, ja marked
review). A removal heard during the read starts the next notice. The game
page's own handling of its entry is unchanged.

Tests: GamesViewModelTests — the single removal waits, then says the one
name; three removals in one check make one wait, one notice naming all
three and the remaining card; six name five and "1 more". Both over a
clock whose timers fire when the test says so.

Docs: 08_UI §Games; CHANGELOG's D55 entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:06:31 +07:00
8 changed files with 254 additions and 12 deletions

No files matched your search

+4 -2
View File
@@ -43,8 +43,8 @@ numeric core and does not move; the heading is the full version — corrected 20
- **A game you uninstalled leaves the library by itself** when it has no sessions: the agent removes an entry whose `.exe`
has been gone for ten minutes, if its drive is connected and the folder it was installed in is still there — an
unplugged or re-lettered drive never counts — and never one where anti-cheat was found. A game with sessions stays, with
them, and reads *Not installed* as before. The Games page says so when it happens; **Settings ▸ Data ▸ Remove uninstalled
games** turns it off (`docs/02_SPEC.md` FR-1.8).
them, and reads *Not installed* as before. The Games page says so when it happens — once, naming them, for all the games
one check removes; **Settings ▸ Data ▸ Remove uninstalled games** turns it off (`docs/02_SPEC.md` FR-1.8).
### Changed
@@ -63,6 +63,8 @@ numeric core and does not move; the heading is the full version — corrected 20
that draws (`css\Game.exe` there; its launcher asks for administrator, so it is measured with *Run the agent as
administrator* on). The import also no longer offers a store's game again when the library has it at another
executable: an entry already there is re-pointed with *Change executable…* (`docs/05_DETECTION.md` §Library import).
- **The Games page shows its newest read of the library.** When two reads overlapped — a session ending while an import
added games — the one that started first could finish last and be shown, an older list until the next read.
## [0.1.0-beta.18] - 2026-10-07
+7 -1
View File
@@ -276,7 +276,13 @@ All screens are `Page`s registered with the navigation page provider and navigat
> *since beta.19 (D55) the Agent removes such an entry by itself after ten minutes when it has no session and no
> anti-cheat block or exception, and its drive is connected — Settings ▸ Data ▸ Remove uninstalled games, on by default; the
> page on screen hears `GameRemoved`, reloads and says so in the snackbar (`Games_Removed_Format`); one with sessions keeps
> its pill*). **The page reloads by itself** while it is on screen when a session ends (`SessionCompleted`) or an
> its pill. One check removes its games in one event each, milliseconds apart: the page waits `GamesViewModel.RemovalSettle`
> (one second) after the first, then reads the library once and says them all in one notice — the count, five names and
> how many more, `Games_Removed_Many_Format`. It said each and reloaded each, and WPF UI 4.3.0's `SnackbarService` shows every
> message at once in its one snackbar, so only the last name stayed on screen. And only the newest read of the library is
> shown: reads overlap — a session that ends, an import, a removal — and the one that started first could finish last,
> its executable checks waiting on a slow drive, and put back a removed game's card (`GamesViewModel.LoadAsync`,
> `GamesViewModelTests.AnOlderReadThatFinishesLastIsNotShownOverANewerOne`)*). **The page reloads by itself** while it is on screen when a session ends (`SessionCompleted`) or an
> import adds games (`LibraryChanges` — navigating to the page already on screen does nothing in WPF UI 4.3.0, so an
> import from the menu never showed until the page was left). **Import** (FR-1.2): the games already in the library — at
> this path or under another drive letter — are hidden by default (*Show the N games already in the library* brings them
+6
View File
@@ -520,6 +520,8 @@ public static class Strings
nameof(Games_Refresh),
nameof(Games_Refresh_ToolTip),
nameof(Games_Removed_Format),
nameof(Games_Removed_Many_Format),
nameof(Games_Removed_More_Format),
nameof(Games_Removed_Title),
nameof(Games_Search_Placeholder),
nameof(Games_Sort_Label),
@@ -2056,6 +2058,10 @@ public static class Strings
public static string Games_Removed_Format => ResourceManager.GetString(nameof(Games_Removed_Format), Culture) ?? nameof(Games_Removed_Format);
public static string Games_Removed_Many_Format => ResourceManager.GetString(nameof(Games_Removed_Many_Format), Culture) ?? nameof(Games_Removed_Many_Format);
public static string Games_Removed_More_Format => ResourceManager.GetString(nameof(Games_Removed_More_Format), Culture) ?? nameof(Games_Removed_More_Format);
public static string Games_Removed_Title => ResourceManager.GetString(nameof(Games_Removed_Title), Culture) ?? nameof(Games_Removed_Title);
public static string Games_Search_Placeholder => ResourceManager.GetString(nameof(Games_Search_Placeholder), Culture) ?? nameof(Games_Search_Placeholder);
+8
View File
@@ -2045,6 +2045,14 @@
<value>{0} はインストールされておらずセッションもないため、キャプチャエージェントが削除しました。「設定 ▸ データ」でオフにできます。</value>
<comment>review</comment>
</data>
<data name="Games_Removed_Many_Format" xml:space="preserve">
<value>{0} 本のゲームはインストールされておらずセッションもないため、キャプチャエージェントが削除しました: {1}。「設定 ▸ データ」でオフにできます。</value>
<comment>review</comment>
</data>
<data name="Games_Removed_More_Format" xml:space="preserve">
<value>{0} ほか {1} 本</value>
<comment>review</comment>
</data>
<data name="Settings_DeleteSessions_Label" xml:space="preserve">
<value>すべてのセッションを削除</value>
<comment>review</comment>
+6
View File
@@ -1539,6 +1539,12 @@
<data name="Games_Removed_Format" xml:space="preserve">
<value>{0} is no longer installed and had no sessions, so the capture agent removed it. Settings ▸ Data turns this off.</value>
</data>
<data name="Games_Removed_Many_Format" xml:space="preserve">
<value>{0} games are no longer installed and had no sessions, so the capture agent removed them: {1}. Settings ▸ Data turns this off.</value>
</data>
<data name="Games_Removed_More_Format" xml:space="preserve">
<value>{0} and {1} more</value>
</data>
<data name="Settings_DeleteSessions_Label" xml:space="preserve">
<value>Delete all sessions</value>
</data>
+6
View File
@@ -1534,6 +1534,12 @@
<data name="Games_Removed_Format" xml:space="preserve">
<value>{0} không còn được cài đặt và chưa có phiên nào, nên capture agent đã xoá nó. Tắt việc này trong Cài đặt ▸ Dữ liệu.</value>
</data>
<data name="Games_Removed_Many_Format" xml:space="preserve">
<value>{0} game không còn được cài đặt và chưa có phiên nào, nên capture agent đã xoá chúng: {1}. Tắt việc này trong Cài đặt ▸ Dữ liệu.</value>
</data>
<data name="Games_Removed_More_Format" xml:space="preserve">
<value>{0} và {1} game khác</value>
</data>
<data name="Settings_DeleteSessions_Label" xml:space="preserve">
<value>Xoá mọi phiên</value>
</data>
@@ -25,6 +25,9 @@ public sealed partial class GamesViewModel : ObservableObject
private const string _listValue = "list";
private const string _gridValue = "grid";
/// <summary>How many removed games one notice names; the rest are counted (<c>Games_Removed_More_Format</c>).</summary>
private const int _removedNamed = 5;
private readonly GameLibrary _library;
private readonly GameSelection _selection;
private readonly IPageNavigator _navigator;
@@ -34,8 +37,12 @@ public sealed partial class GamesViewModel : ObservableObject
private readonly IAgentLink? _agent;
private readonly LibraryChanges? _changes;
private readonly IMessageStrip? _strip;
private readonly TimeProvider _clock;
private readonly Func<string, bool> _exists;
private readonly UiThread _ui = new();
private readonly List<string> _removed = [];
private IReadOnlyList<GameCardViewModel> _all = [];
private int _reads;
private bool _viewRead;
private bool _attached;
@@ -59,9 +66,12 @@ public sealed partial class GamesViewModel : ObservableObject
private bool _listView;
public GamesViewModel(GameLibrary library, GameSelection selection, IPageNavigator navigator, AddGameFlow addGame, ImportLibraryFlow? import = null,
RegisteredSettings? settings = null, IAgentLink? agent = null, LibraryChanges? changes = null, IMessageStrip? strip = null)
RegisteredSettings? settings = null, IAgentLink? agent = null, LibraryChanges? changes = null, IMessageStrip? strip = null, TimeProvider? clock = null,
Func<string, bool>? executableExists = null)
{
_strip = strip;
_clock = clock ?? TimeProvider.System;
_exists = executableExists ?? GameLibrary.ExecutableExists;
_library = library ?? throw new ArgumentNullException(nameof(library));
_selection = selection ?? throw new ArgumentNullException(nameof(selection));
_navigator = navigator ?? throw new ArgumentNullException(nameof(navigator));
@@ -91,6 +101,12 @@ public sealed partial class GamesViewModel : ObservableObject
public static string ListText => Strings.Games_View_List;
/// <summary>
/// How long the page waits after the Agent says it removed a game (D55) for the rest of the same check before it reloads
/// and says what went (beta.19). One check removes its games a few milliseconds apart, each in its own event.
/// </summary>
public static TimeSpan RemovalSettle { get; } = TimeSpan.FromSeconds(1);
/// <summary>The sort orders, labelled in the language this page opened in (beta.15: a static list kept the first language).</summary>
public IReadOnlyList<Choice<GamesSort>> Sorts { get; } =
[
@@ -104,14 +120,26 @@ public sealed partial class GamesViewModel : ObservableObject
/// <summary>The load in flight, for a test to await.</summary>
public Task Pending { get; private set; }
/// <summary>
/// The library read and listed. Reads overlap — a session that ends, an import, a removal — and the one that started first
/// can finish last, its checks waiting on a drive that is slow to answer: only the newest read is shown (beta.19 — an
/// older one put back the card of a game the Agent had just removed, until the next read).
/// </summary>
public async Task LoadAsync(CancellationToken ct = default)
{
int read = Interlocked.Increment(ref _reads);
await ReadViewAsync(ct).ConfigureAwait(true);
IReadOnlyList<GameCard> cards = await _library.ListCardsAsync(ct).ConfigureAwait(true);
// Whether each executable is on disk is a file-system question per entry — a drive that is gone can take a moment
// to say so — so it is asked off the UI thread, the game page's own way (GameLibrary.ExecutableExists).
bool[] installed = await Task.Run(() => cards.Select(static c => GameLibrary.ExecutableExists(c.Row.Fingerprint.ExePath)).ToArray(), ct)
Func<string, bool> exists = _exists;
bool[] installed = await Task.Run(() => cards.Select(c => exists(c.Row.Fingerprint.ExePath)).ToArray(), ct)
.ConfigureAwait(true);
if (read != Volatile.Read(ref _reads))
{
return;
}
_all = [.. cards.Select((c, i) => new GameCardViewModel(c, installed[i]))];
HeaderText = string.Format(CultureInfo.CurrentCulture, Strings.Games_Header_Count_Format, _all.Count);
Apply();
@@ -251,11 +279,38 @@ public sealed partial class GamesViewModel : ObservableObject
&& IpcCodec.Payload<GameRemovedEvent>(e.Envelope) is { } removed)
{
// D55 (beta.19): the Agent removed an entry whose game is no longer installed; the card goes, and the page says why.
_strip?.Info(Strings.Games_Removed_Title, string.Format(CultureInfo.CurrentCulture, Strings.Games_Removed_Format, removed.GameName ?? removed.ExePath));
Pending = LoadAsync();
// A check that removes five says it in five events: the first waits for the rest, then one reload and one notice.
_removed.Add(removed.GameName ?? removed.ExePath);
if (_removed.Count == 1)
{
Pending = SayRemovedAsync();
}
}
});
/// <summary>
/// The games the Agent removed since the first of them, after <see cref="RemovalSettle"/>: the library read once, then one
/// notice — the game's name, or how many went and which. A removal heard during the read starts the next notice.
/// </summary>
private async Task SayRemovedAsync()
{
await Task.Delay(RemovalSettle, _clock).ConfigureAwait(true);
string[] names = [.. _removed];
_removed.Clear();
await LoadAsync().ConfigureAwait(true);
if (_strip is null)
{
return;
}
string listed = names.Length <= _removedNamed
? string.Join(", ", names)
: string.Format(CultureInfo.CurrentCulture, Strings.Games_Removed_More_Format, string.Join(", ", names.Take(_removedNamed)), names.Length - _removedNamed);
_strip.Info(Strings.Games_Removed_Title, names.Length == 1
? string.Format(CultureInfo.CurrentCulture, Strings.Games_Removed_Format, names[0])
: string.Format(CultureInfo.CurrentCulture, Strings.Games_Removed_Many_Format, names.Length, listed));
}
private void OnLibraryChanged(object? sender, EventArgs e) => _ui.Post(() => Pending = LoadAsync());
private void Apply()
@@ -103,9 +103,44 @@ public sealed class GamesViewModelTests
public void Warn(string title, string body) => Lines.Add(title + ": " + body);
}
/// <summary>A clock whose timers fire when the test says so (beta.19): the page's wait for the rest of a check, held.</summary>
private sealed class HeldTimers : TimeProvider
{
private readonly List<(TimerCallback Callback, object? State)> _due = [];
public int Waiting => _due.Count;
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
_due.Add((callback, state));
return new Held();
}
public void Fire()
{
(TimerCallback Callback, object? State)[] due = [.. _due];
_due.Clear();
foreach ((TimerCallback callback, object? state) in due)
{
callback(state);
}
}
private sealed class Held : ITimer
{
public bool Change(TimeSpan dueTime, TimeSpan period) => true;
public void Dispose()
{
}
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
}
/// <summary>
/// beta.19, D55: the Agent removed an entry whose game is no longer installed — the page on screen drops its card at once
/// and says why, in words that name the switch that turns it off.
/// beta.19, D55: the Agent removed an entry whose game is no longer installed — the page on screen drops its card and says
/// why, in words that name the switch that turns it off, once it has waited a moment for the rest of the same check.
/// </summary>
[Fact]
public async Task AnEntryTheAgentRemovedLeavesThePageOnScreenWithAWord()
@@ -121,7 +156,8 @@ public sealed class GamesViewModelTests
var nav = new NoNavigation();
var link = new FakeAgentLink();
var strip = new RecordingStrip();
var vm = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, new NoStrip()), agent: link, strip: strip);
var clock = new HeldTimers();
var vm = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, new NoStrip()), agent: link, strip: strip, clock: clock);
Task loaded = vm.Pending;
await loaded;
vm.Attach();
@@ -129,8 +165,10 @@ public sealed class GamesViewModelTests
// What the Agent did, then said.
await s.Db.WriteAsync((c, tx, ct) => Dapper.SqlMapper.ExecuteAsync(c, new Dapper.CommandDefinition("DELETE FROM games WHERE id = @id", new { id = gone.Id }, tx, cancellationToken: ct)), Ct);
link.Raise(IpcMessageType.GameRemoved, new GameRemovedEvent(gone.Id, "Gone", gone.Fingerprint.ExePath, GameRemovedEvent.Uninstalled));
Task reloaded = vm.Pending;
await reloaded;
Task said = vm.Pending;
strip.Lines.Should().BeEmpty("the page waits a moment for the rest of the same check");
clock.Fire();
await said;
vm.Games.Should().ContainSingle().Which.Name.Should().Be("Kept");
strip.Lines.Should().ContainSingle().Which.Should().StartWith("Removed from the library: Gone is no longer installed").And.Contain("Settings ▸ Data");
@@ -141,6 +179,70 @@ public sealed class GamesViewModelTests
}
}
/// <summary>
/// beta.19: a check that removes several entries says each in its own event, milliseconds apart. The page read the library
/// and spoke once per event, and the shell's one snackbar kept only the last name; it now waits once, reads the library
/// once and says them all in one notice — the count, and five names at most.
/// </summary>
[Fact]
public async Task OneCheckThatRemovesSeveralEntriesIsSaidOnceAfterOneRead()
{
CultureInfo? previous = Strings.Culture;
Strings.Culture = CultureInfo.GetCultureInfo("en");
try
{
await using ScratchLedger s = await ScratchLedger.OpenAsync();
GameRow[] gone = [await s.GameAsync("Alpha"), await s.GameAsync("Bravo"), await s.GameAsync("Charlie")];
_ = await s.GameAsync("Kept");
var selection = new GameSelection();
var nav = new NoNavigation();
var link = new FakeAgentLink();
var strip = new RecordingStrip();
var clock = new HeldTimers();
var vm = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, new NoStrip()), agent: link, strip: strip, clock: clock);
Task loaded = vm.Pending;
await loaded;
vm.Attach();
foreach (GameRow row in gone)
{
await s.Db.WriteAsync((c, tx, ct) => Dapper.SqlMapper.ExecuteAsync(c, new Dapper.CommandDefinition("DELETE FROM games WHERE id = @id", new { id = row.Id }, tx, cancellationToken: ct)), Ct);
}
foreach (GameRow row in gone)
{
link.Raise(IpcMessageType.GameRemoved, new GameRemovedEvent(row.Id, row.Name, row.Fingerprint.ExePath, GameRemovedEvent.Uninstalled));
}
Task said = vm.Pending;
clock.Waiting.Should().Be(1, "one wait for the whole check, not one per entry");
clock.Fire();
await said;
vm.Games.Should().ContainSingle().Which.Name.Should().Be("Kept");
strip.Lines.Should().ContainSingle().Which.Should().Be("Removed from the library: 3 games are no longer installed and had no sessions, so the capture "
+ "agent removed them: Alpha, Bravo, Charlie. Settings ▸ Data turns this off.");
// Six in one check: the count, five names and how many more.
for (int i = 1; i <= 6; i++)
{
link.Raise(IpcMessageType.GameRemoved, new GameRemovedEvent(1000 + i, "G" + i.ToString(CultureInfo.InvariantCulture), @"Q:\G\g.exe", GameRemovedEvent.Uninstalled));
}
Task again = vm.Pending;
clock.Waiting.Should().Be(1);
clock.Fire();
await again;
strip.Lines.Should().HaveCount(2);
strip.Lines[^1].Should().Contain("6 games").And.Contain(": G1, G2, G3, G4, G5 and 1 more. ").And.NotContain("G6");
}
finally
{
Strings.Culture = previous;
}
}
[Fact]
public async Task ACardSaysWhetherItsExecutableIsThereAndWhy()
{
@@ -156,6 +258,8 @@ public sealed class GamesViewModelTests
await using ScratchLedger s2 = await ScratchLedger.OpenAsync();
var listed = new GamesViewModel(s2.Library, new GameSelection(), new NoNavigation(),
new AddGameFlow(s2.Library, new NoPicker(), new GameSelection(), new NoNavigation(), new NoStrip()));
Task opened = listed.Pending;
await opened; // the page's own first read, of an empty library, before the games below are added
string here = typeof(GamesViewModelTests).Assembly.Location;
_ = await s2.GameAsync("Here", here);
_ = await s2.GameAsync("Gone", Path.Combine(AppContext.BaseDirectory, "no-such-game.exe"));
@@ -164,6 +268,55 @@ public sealed class GamesViewModelTests
listed.Games.Single(static g => string.Equals(g.Name, "Gone", StringComparison.Ordinal)).NotInstalled.Should().BeTrue();
}
/// <summary>
/// beta.19: reads of the library overlap, and the one that started first can finish last — its checks waiting on a drive
/// that is slow to answer. It used to be shown over the newer one: a game the Agent had just removed came back until the
/// next read. One local run in about 165 failed <see cref="ACardSaysWhetherItsExecutableIsThereAndWhy"/> that way, its
/// own two reads racing.
/// </summary>
[Fact]
public async Task AnOlderReadThatFinishesLastIsNotShownOverANewerOne()
{
await using ScratchLedger s = await ScratchLedger.OpenAsync();
_ = await s.GameAsync("Alpha");
var bound = TimeSpan.FromSeconds(30);
using var firstBegan = new ManualResetEventSlim();
using var firstMayEnd = new ManualResetEventSlim();
int checks = 0;
bool Exists(string path)
{
if (Interlocked.Increment(ref checks) == 1)
{
// The first read's check waits, as on a drive that is slow to answer.
firstBegan.Set();
_ = firstMayEnd.Wait(bound, Ct);
}
return true;
}
var selection = new GameSelection();
var nav = new NoNavigation();
var vm = new GamesViewModel(s.Library, selection, nav, new AddGameFlow(s.Library, new NoPicker(), selection, nav, new NoStrip()), executableExists: Exists);
Task first = vm.Pending;
try
{
// Only once the first read is held in its check does the second begin: its checks are then never the held one.
firstBegan.Wait(bound, Ct).Should().BeTrue("the page's first read checks its one game");
_ = await s.GameAsync("Bravo");
await vm.LoadAsync(Ct);
vm.Games.Should().HaveCount(2, "the newer read lists both");
}
finally
{
firstMayEnd.Set();
}
await first;
vm.Games.Should().HaveCount(2, "the older read, of one game, finished last and is not shown");
vm.HeaderText.Should().EndWith("2");
}
[Theory]
[InlineData(1200, 3)]
[InlineData(1248, 4)]