fix(copies): address the owner review 6 findings

The review of the found-copies work showed pairs that could stick, jobs that
could act on a pair the user had answered otherwise, and detection gaps:

- forgetting a link on an address-keyed server deletes the pair and Candidate
  rows of that remote and resets the probe, so the sequence is found again
  when it is back; a Linked/Integrated row with no link is asked again
- 404s count only on id-keyed servers, at most once per recheck interval
- probes store the server's newest update time (copy_probes.server_newest,
  migration 0012) instead of comparing with this PC's clock; the lookup
  sample carries hashed photos by size and capture time too, for servers
  that have not hashed their copy
- the older-server gate no longer re-compares unchanged manifests
- a failed Integrate keeps its job id so a retry resumes only an untouched
  pair; cancel and stale plans release the pair (ReleaseAsync)
- automatic photo transfers never create or retarget a sequence
- a first upload files photos the server holds elsewhere into the new
  sequence
- Unlink re-compares before keeping apart; Trash here names only true last
  copies; Drop... trashes one version on both sides after re-checking the
  other
- a merge keeping the pair's other sequence swaps the dialog's columns and
  re-keys Different choices; Upload all reads every pair

Each fix has a regression test where it makes sense.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 13:12:00 +01:00
1 parent 96b5b4078b
commit fe752a0a21
33 files changed
+957 -123

No files matched your search

@@ -97,10 +97,8 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
{
Log.Warning("archive", $"The journal of the cancelled merge {job.Id} was not removed", ex);
}
var store = new FoundCopyStore(db);
if (await store.GetAsync(parameters.CopyId, CancellationToken.None).ConfigureAwait(false) is { JobId: { } owner } copy && owner == job.Id
&& copy.State != CopyState.Integrating)
await store.SetStateAsync(copy.Id, copy.State, copy.State, null, CancellationToken.None).ConfigureAwait(false);
// By the stored row: the engine marked the job Cancelled first, so the row already reads as its state before.
await new FoundCopyStore(db).ReleaseAsync(parameters.CopyId, job.Id, null, keepJob: false, CancellationToken.None).ConfigureAwait(false);
}
/// <summary>The first run: plans again, refuses a plan that moved or is blocked, and journals it.</summary>
@@ -416,8 +414,9 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
}
if (failed.Count > 0)
{
// A photo held by another sequence of the index is not lost with the other; any other is.
var others = await new CopySides(_db).HeldElsewhereAsync(failed, [journal.DropId], _ct).ConfigureAwait(false);
// A photo held by another sequence of the index is not lost with the other; any other is. The kept
// sequence's index rows prove nothing: its files were hashed again above and did not hold it.
var others = await new CopySides(_db).HeldElsewhereAsync(failed, [journal.DropId, journal.KeepId], _ct).ConfigureAwait(false);
var lost = failed.Count(s => !others.Contains(s));
if (lost > 0) throw new InvalidOperationException(Loc.Plural("Errors.Copies.VerifyFailed", lost));
}