fix(workspace): a pull that succeeded never fails on the name it follows

The name follow after a pull caught only the home's own exceptions, so a 403
or any other error from the home's list (or a bundle in use) made a pull that
had already pulled and replayed report a failure. It is now logged as a
warning and the name is followed at the next pull; a cancellation still passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 13:35:47 +01:00
1 parent ab6cad51b2
commit 5ff9c086fd
3 files changed
+73 -6

No files matched your search

+15 -6
View File
@@ -388,21 +388,30 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
return await FollowNameLockedAsync(project, home, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <see cref="FollowNameAsync"/> under the project's lock. It runs after a pull that succeeded, so it never fails: whatever
/// the home or the copy answers (unreachable, a refusal such as a 403, a file in use) is logged and the name is followed
/// next time; only a cancellation is passed on.
/// </summary>
private static async Task<bool> FollowNameLockedAsync(WorkspaceProject project, IProjectHome home, CancellationToken cancellationToken)
{
SequenceProject? listed;
try
{
listed = (await home.ListAsync(cancellationToken).ConfigureAwait(false)).FirstOrDefault(p => p.Id == project.ProjectId);
var listed = (await home.ListAsync(cancellationToken).ConfigureAwait(false)).FirstOrDefault(p => p.Id == project.ProjectId);
var bundle = project.ReadBundle();
if (listed is null || bundle.Workspace is not { } workspace || (workspace.Name == listed.Name && workspace.IsMain == listed.IsMain)) return false;
project.WriteBundle(bundle with { Workspace = workspace with { Name = listed.Name, IsMain = listed.IsMain } });
return true;
}
catch (Exception ex) when (ex is HomeUnavailableException or ProjectException)
{
return false;
}
var bundle = project.ReadBundle();
if (listed is null || bundle.Workspace is not { } workspace || (workspace.Name == listed.Name && workspace.IsMain == listed.IsMain)) return false;
project.WriteBundle(bundle with { Workspace = workspace with { Name = listed.Name, IsMain = listed.IsMain } });
return true;
catch (Exception ex) when (ex is not OperationCanceledException || !cancellationToken.IsCancellationRequested)
{
Log.Warning("workspace", $"The name of project {project.ProjectId} could not be followed from its home; tried again at the next pull", ex);
return false;
}
}
/// <summary>
@@ -197,6 +197,41 @@ internal sealed class CountingHome(IProjectHome home) : IProjectHome
public Task<PushResult> PushAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken) => home.PushAsync(projectId, version, cancellationToken);
}
/// <summary>
/// A home whose list of projects fails with an error no other call gives (a server's 403 or 500 passed through as it is), the
/// rest passed through.
/// </summary>
internal sealed class FailingListHome(IProjectHome home) : IProjectHome
{
public int Lists { get; private set; }
public Task<IReadOnlyList<SequenceProject>> ListAsync(CancellationToken cancellationToken)
{
Lists++;
throw new InvalidOperationException("The server refused the list (403).");
}
public Task<HomeSequence> SequenceAsync(CancellationToken cancellationToken) => home.SequenceAsync(cancellationToken);
public Task<SequenceProject> CreateAsync(string name, Guid? fromVersionId, string? author, CancellationToken cancellationToken) =>
home.CreateAsync(name, fromVersionId, author, cancellationToken);
public Task<ProjectVersion> HeadAsync(Guid projectId, CancellationToken cancellationToken) => home.HeadAsync(projectId, cancellationToken);
public Task<ProjectVersion?> GetVersionAsync(Guid projectId, Guid versionId, CancellationToken cancellationToken) =>
home.GetVersionAsync(projectId, versionId, cancellationToken);
public Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken) =>
home.VersionsAfterAsync(projectId, afterNumber, limit, cancellationToken);
public Task<IReadOnlyList<ProjectVersion>> HistoryAsync(Guid projectId, int? beforeNumber, int limit, CancellationToken cancellationToken) =>
home.HistoryAsync(projectId, beforeNumber, limit, cancellationToken);
public Task<PushResult> PushAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken) => home.PushAsync(projectId, version, cancellationToken);
public Task<HomeFrames> FramesAsync(CancellationToken cancellationToken) => home.FramesAsync(cancellationToken);
}
/// <summary>A home that cannot be reached, standing for a server out of reach or an archive offline.</summary>
internal sealed class UnreachableHome(IProjectHome home) : IProjectHome
{
@@ -256,6 +256,29 @@ public abstract class WorkspaceTests(TestContext context) : DatabaseTest(context
Assert.SequenceEqual([0], working.ExcludedFrames);
}
[Test]
public async Task APullThatSucceededNeverFailsOnTheNameItFollows()
{
var fx = await FixtureAsync();
var (_, one) = fx.Workspace("one");
var (_, two) = fx.Workspace("two");
var id = (await fx.CheckoutAsync(one)).ProjectId;
await fx.CheckoutAsync(two, id);
await EditAsync(one, id, s => s with { Stack = new StackSettings { Mode = StackSetting.Median } }, fx.Ct);
await one.CommitAsync(id, cancellationToken: fx.Ct);
await one.PushAsync(id, fx.Home, fx.Ct);
// The home refuses its list (a server's 403) when the pull, done, follows the project's name: the pull stands.
var home = new FailingListHome(fx.Home);
var name = two.Store.Find(id)!.ReadBundle().Workspace!.Name;
var pulled = await two.PullAsync(id, home, fx.Ct);
Assert.Equal(1, home.Lists);
Assert.Equal((1, WorkspaceState.InSync), (pulled.Pulled.Count, pulled.Status.State));
Assert.Equal(StackSetting.Median, (await two.OpenAsync(id, fx.Ct)).Working.Stack.Mode);
Assert.Equal(name, two.Store.Find(id)!.ReadBundle().Workspace!.Name);
Assert.False(await two.FollowNameAsync(id, home, fx.Ct));
}
[Test]
public async Task SeveralLocalVersionsAreReplayedOnTopOfTheHomesWhenItMovedMeanwhile()
{