fix(sync): tell missed project changes only once the event stream is open again

The agent told "changes may have been missed" as soon as the stream dropped,
so a workspace re-read before the server's events could reach it again and
missed changes made in between. The signal now waits for the reconnected
stream and the refresh that follows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 12:31:51 +01:00
1 parent 353024fc71
commit ed7452e739
4 files changed
+102 -9

No files matched your search

@@ -80,6 +80,32 @@ public sealed class SyncAgentTests(TestContext context)
Assert.Equal(1, agent.Snapshot!.ServerSequences);
}
[Test]
public async Task MissedChangesAreToldOnlyOnceTheStreamIsOpenAgain()
{
// A change said between "changes may have been missed" and the stream's return would be lost for good: the signal
// comes from a comparison that started once the stream was open again, so every later change reaches the workspace.
await using var f = await SyncFixture.CreateAsync(context);
f.Remote.Add("Harbour", f.NewPhotos(1));
(f.Remote.FailingEvents, f.Remote.DropWhileClosed, f.Remote.ReconnectDelay) = (1, true, TimeSpan.FromMilliseconds(800));
var subscribedWhenMissed = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var changed = new TaskCompletionSource<ProjectChangedEvent>(TaskCreationOptions.RunContinuationsAsynchronously);
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(), null, EventsOnly);
agent.ProjectChanged += e =>
{
if (e is null) subscribedWhenMissed.TrySetResult(f.Remote.Subscribed);
else changed.TrySetResult(e);
};
agent.Start();
await SignalAsync(subscribedWhenMissed.Task, "the missed changes told");
Assert.True(await subscribedWhenMissed.Task, "the stream was open again when the missed changes were told");
var change = new ProjectChangedEvent(Guid.CreateVersion7(), Guid.CreateVersion7(), ProjectChanges.Pushed, 2, Guid.CreateVersion7());
f.Remote.Publish(change);
await SignalAsync(changed.Task, "the change said after the signal told");
Assert.Equal(change, await changed.Task);
}
[Test]
public async Task FailedComparisonsAreRetriedWithBackoff()
{