fix(copies): close the seventh verification round of owner review 6

- A merge plan hashes the kept sequence's unhashed frames that match a hashed
  photo of the other by size and time: the same content is no longer a false
  last copy, and another content is copied in as a second version instead of
  going to the trash with the other sequence.
- The Replace stage trashes a losing version of the kept sequence only while
  another sequence still holds it or the plan listed it as a last copy;
  otherwise the journal goes and the job fails as a stale plan.
- A details conflict at the merge's or the Integrate's Details stage drops
  the journal, so a retry plans again instead of failing the same way.
- The Integrate's Projects stage keeps a project for good only for a
  permanent refusal; a server out of reach fails the job with the journal
  kept, and the retry finishes the same copy.
- A pair read as deleted on the server is cleared when the server lists it
  again or a link to that sequence is made.
- An upload of a sequence kept apart from a server sequence goes under a
  session key of the job, making a new server sequence; a link made over a
  kept-apart pair moves it to Linked.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 10:45:11 +01:00
1 parent c3273b7da5
commit 123ceba845
13 files changed
+418 -13

No files matched your search

+9 -2
View File
@@ -469,6 +469,8 @@ public sealed class SyncService
?? new SyncLink { Server = server, RemoteId = remoteId, Title = local.DisplayTitle, RemoteUpdatedAt = DateTimeOffset.UtcNow };
if (link.LocalId != local.Id) link = Unlinked(link) with { LocalId = local.Id };
await _links.UpsertAsync(link, cancellationToken).ConfigureAwait(false);
// Linked to that very server sequence, which answered for it: no pair of it reads "deleted on server" any more.
await Copies.ClearRemoteGoneAsync(server, remoteId, cancellationToken).ConfigureAwait(false);
await Copies.EnsureLinkedAsync(server, remoteId, local.Id, cancellationToken).ConfigureAwait(false);
return link;
}
@@ -498,6 +500,7 @@ public sealed class SyncService
{
var linked = Unlinked(Observe(link, remote.Server, dto)) with { LocalId = local.Id };
await ReconcileSafelyAsync(remote, linked, dto, local, locals, policy, cancellationToken).ConfigureAwait(false);
await Copies.ClearRemoteGoneAsync(remote.Server, dto.Id, cancellationToken).ConfigureAwait(false);
await Copies.EnsureLinkedAsync(remote.Server, dto.Id, local.Id, cancellationToken).ConfigureAwait(false);
}
catch
@@ -793,7 +796,8 @@ public sealed class SyncService
}
/// <summary>
/// Pairs one 404 marked (design §6.3): a remote listed again is cleared at once and asked about again; one still unlisted
/// Pairs a 404 marked (design §6.3): a remote listed again is cleared at once and asked about again, also one that read
/// "deleted on server" (restored there, or served again); one marked once and still unlisted
/// is asked for once more, no sooner than <see cref="GoneRecheck"/> after it was marked, and a second 404 there makes the
/// pair read "deleted on server". A refresh's first 404 forgot the link (the pair is asked about again); a job's 404
/// kept it (the pair stays Linked or Integrated).
@@ -804,12 +808,15 @@ public sealed class SyncService
var now = DateTimeOffset.UtcNow;
foreach (var pair in await Copies.ListByServerAsync(remote.Server, cancellationToken).ConfigureAwait(false))
{
if (pair is not { RemoteGoneHits: 1, RemoteId: { } remoteId }) continue;
if (pair is not { RemoteGoneHits: >= 1, RemoteId: { } remoteId }) continue;
if (listed.Contains(remoteId))
{
// Listed again (restored from the server's trash, or the server serves its archive again): whatever the
// count, the server answers for it, so the pair no longer reads "deleted on server".
await BackAsync(pair, remoteId).ConfigureAwait(false);
continue;
}
if (pair.RemoteGoneHits > 1) continue;
// A sweep of 404s (the server serves something else now) confirms no earlier hit either.
if (!confirm || (pair.RemoteGoneAt is { } at && now - at < GoneRecheck)) continue;
try
+17 -1
View File
@@ -80,9 +80,10 @@ internal sealed class SyncTransfers(SyncService sync)
// server has filed one, which creates the sequence (an original it already holds elsewhere creates nothing, and
// is filed into the new sequence once there is one).
var heldElsewhere = new List<Frame>();
var sessionKey = remoteId is null ? await SessionKeyAsync(context, remote, local).ConfigureAwait(false) : null;
while (remoteId is null && pending.TryDequeue(out var first))
{
var sent = await UploadFrameAsync(context, remote, null, SyncService.SessionKey(local.Id), paths.FromRelative(first.RelativePath), first, tombstones,
var sent = await UploadFrameAsync(context, remote, null, sessionKey, paths.FromRelative(first.RelativePath), first, tombstones,
hashes, ct).ConfigureAwait(false);
if (sent is null) skipped++;
else if (sent.SequenceId == Guid.Empty && sent.FrameId != Guid.Empty) heldElsewhere.Add(first);
@@ -962,6 +963,21 @@ internal sealed class SyncTransfers(SyncService sync)
return (null, true);
}
/// <summary>
/// The session key the first original of an upload without a target goes under: this sequence's own
/// (<see cref="SyncService.SessionKey"/>), unless the user kept it apart from (or unlinked it from) a sequence of this
/// server. The server files that key into the sequence an earlier upload made, which the user chose to keep separate;
/// such an upload makes a new sequence instead, under a key of this job (the same on a retry).
/// </summary>
private async Task<string> SessionKeyAsync(JobContext context, ISyncRemote remote, Sequence local)
{
var own = SyncService.SessionKey(local.Id);
var apart = (await sync.Copies.ListByLocalAsync(local.Id, context.Cancellation).ConfigureAwait(false))
.Any(c => c is { Kind: CopyKind.LocalServer, State: CopyState.KeptApart } && string.Equals(c.Server, remote.Server, StringComparison.Ordinal)
&& c.LocalId == local.Id);
return apart ? string.Create(CultureInfo.InvariantCulture, $"{own}:{context.Job.Id:N}") : own;
}
private static async Task<bool> ExistsAsync(ISyncRemote remote, Guid id, CancellationToken cancellationToken)
{
try