fix(convert): the job converts exactly the photos its preview listed, once

A conversion job could still do something its confirmed dry run did not show,
or refuse what it should have converted:

- An upload landing between the confirmation and the sequence's turn made the
  sequence Changed at every retry. Each ConvertSequence now names the photos
  the plan converts (Photos, their frame ids); the job takes those from its
  re-plan, checks their content against the confirmed digest and leaves photos
  that came in since as they are. A photo the plan did not list is never
  converted, whatever changed on disk or in the index since the dry run.
- A file another program held during the dry run was planned as Missing and
  then converted or not depending on the re-plan. It is now its own reason
  (inaccessible, "held open or cannot be opened"); a truncated file reads as
  undecodable. At job time a confirmed photo that cannot be opened leaves the
  sequence Blocked for the retry; a held photo the job does not convert does
  not hide a real change.
- The same sequences could be converted twice (two dialogs or tabs, a lost
  answer, no dry run at all). MassConverter.QueueAsync checks the queued,
  running and paused conversions and queues under one lock, in the caller's
  context (the desktop's enqueue shows a toast on the UI thread); a job's own
  re-plan treats sequences of conversions queued before it as busy.
- The per-photo space check reserved a full batch of photos even when fewer
  were left, so a job whose preview had the space could stop at every retry.
  It now reserves the photo and those after it that may convert at once.
- New sequence now says in the dry run, the panel's totals and confirmation,
  and a new desktop confirmation, how many photos each new sequence lacks;
  only sequences that are copied use those words.
- On the server, a confirmation takes only the plan kept for the index as it
  is now (503 plan_dropped otherwise, never a plan made inside the request),
  and busy sequences and free space are as they are at every request. The
  panel's Apply asks the dry run again first, with Close still available,
  and confirms only the same fingerprint.
- Maintenance keeps another host's conversion staging as long as its journal
  and purges both together; the unstaged-copy failure and blocked sequences
  are logged in catalog sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fefd9c34ebfeed1f9e84161610ef286026d38355)
This commit is contained in:
Alby96 committed 2026-11-02 10:33:34 +01:00
1 parent 5b5acaf307
commit c669d0504d
25 files changed
+1307 -226

No files matched your search

@@ -62,11 +62,46 @@ public sealed record ConvertJobParameters(Guid ArchiveId, ConvertTarget Target,
string Fingerprint);
/// <summary>
/// A sequence of a <see cref="ConvertJobParameters"/>: the frames version it was planned at and the digest of the photos it
/// converts, each with its content (<see cref="ConvertSequencePlan.Digest"/>), which the job checks under the sequence's
/// lease before it converts anything; null in a job an earlier build queued, which checks the frames version only.
/// A sequence of a <see cref="ConvertJobParameters"/>: the frames version it was planned at, the digest of the photos it
/// converts, each with its content (<see cref="ConvertSequencePlan.Digest"/>), and which photos those are (<see cref="Photos"/>).
/// Under the sequence's lease, before it converts anything, the job takes those photos from its plan made again and goes
/// on only while they have the digest confirmed: photos that came in since (an upload while the job waited its turn) stay
/// as they are, and a photo the plan did not list (one another program held while it was made) is never converted. Null
/// in a job an earlier build queued, which checks the frames version only (no digest), or the whole plan's digest (no photos).
/// </summary>
public sealed record ConvertSequence(Guid Id, int FramesVersion, string? Frames = null);
/// <param name="Photos">The frame ids of the photos converted, in the plan's order, as <see cref="EncodePhotos"/> writes them.</param>
public sealed record ConvertSequence(Guid Id, int FramesVersion, string? Frames = null, string? Photos = null)
{
/// <summary>
/// Frame ids as a job's parameters hold them: their 16 bytes each, one after the other, in base64 (a whole-archive
/// conversion lists every photo it converts, so the job row stays about half the size of a list of ids).
/// </summary>
public static string EncodePhotos(IEnumerable<Guid> ids)
{
ArgumentNullException.ThrowIfNull(ids);
IReadOnlyCollection<Guid> frames = ids as IReadOnlyCollection<Guid> ?? [.. ids];
var bytes = new byte[frames.Count * 16];
var at = 0;
foreach (var frame in frames)
{
frame.TryWriteBytes(bytes.AsSpan(at, 16));
at += 16;
}
return Convert.ToBase64String(bytes);
}
/// <summary>The frame ids <see cref="Photos"/> holds, in order; null when it holds none (a job an earlier build queued).</summary>
/// <exception cref="FormatException">The text is not ids as <see cref="EncodePhotos"/> writes them.</exception>
public IReadOnlyList<Guid>? PhotoIds()
{
if (Photos is null) return null;
var bytes = Convert.FromBase64String(Photos);
if (bytes.Length % 16 != 0) throw new FormatException($"The photos of sequence {Id} are not frame ids.");
var ids = new Guid[bytes.Length / 16];
for (var i = 0; i < ids.Length; i++) ids[i] = new Guid(bytes.AsSpan(i * 16, 16));
return ids;
}
}
/// <summary>A job ready to enqueue.</summary>
public sealed record ArchiveJobRequest(JobKind Kind, IReadOnlyList<Guid> Targets, string? Label, string? ParametersJson, JobPriority Priority);