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:
1 parent
353024fc71
commit
ed7452e739
4 files changed
+102
-9
No files matched your search
@@ -75,7 +75,27 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
}
|
||||
}
|
||||
|
||||
public void Publish(ServerEvent e) => _events.Writer.TryWrite(e);
|
||||
/// <summary>
|
||||
/// Sends an event to the stream open now. With <see cref="DropWhileClosed"/>, one sent while no stream is open is lost,
|
||||
/// as a real server's is.
|
||||
/// </summary>
|
||||
public void Publish(ServerEvent e)
|
||||
{
|
||||
if (DropWhileClosed && !Subscribed) return;
|
||||
_events.Writer.TryWrite(e);
|
||||
}
|
||||
|
||||
/// <summary>Events sent while no stream is open are lost (<see cref="Publish"/>).</summary>
|
||||
public bool DropWhileClosed { get; set; }
|
||||
|
||||
/// <summary>How long a stream takes to open after a lost one (a reconnection).</summary>
|
||||
public TimeSpan ReconnectDelay { get; set; }
|
||||
|
||||
/// <summary>Whether an event stream is open now.</summary>
|
||||
public bool Subscribed => Volatile.Read(ref _subscribed) > 0;
|
||||
|
||||
private int _subscribed;
|
||||
private int _opened;
|
||||
|
||||
public Task<IReadOnlyList<SequenceDto>> ListSequencesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -252,8 +272,11 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
public IAsyncEnumerable<ServerEvent> EventsAsync(CancellationToken cancellationToken) => EventsAsync(() => { }, cancellationToken);
|
||||
|
||||
public async IAsyncEnumerable<ServerEvent> EventsAsync(Action connected, [EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
if (Interlocked.Increment(ref _opened) > 1 && ReconnectDelay > TimeSpan.Zero) await Task.Delay(ReconnectDelay, cancellationToken);
|
||||
lock (_gate)
|
||||
{
|
||||
if (FailingEvents > 0)
|
||||
@@ -262,9 +285,18 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
throw new HttpRequestException("socket closed");
|
||||
}
|
||||
}
|
||||
while (await _events.Reader.WaitToReadAsync(cancellationToken))
|
||||
Interlocked.Increment(ref _subscribed);
|
||||
try
|
||||
{
|
||||
while (_events.Reader.TryRead(out var e)) yield return e;
|
||||
connected();
|
||||
while (await _events.Reader.WaitToReadAsync(cancellationToken))
|
||||
{
|
||||
while (_events.Reader.TryRead(out var e)) yield return e;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref _subscribed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user