fix(ingest): file uploads into API-made sequences and repair damaged frames

A sequence created with POST /api/v1/sequences had no folder, and the ingest
looked for its sidecar at the archive root: every upload into it failed with
503 commit_failed, so the Uploader's "New sequence" target never worked. Its
first frame now claims a folder by the rules of a sequence created by an
upload (folder template with its title, unique variant, sidecar with the
row's id, title, tags, rating, notes and project), and the row takes the
folder in one transaction (DOCKER-1).

A frame flagged missing or corrupt, or whose file is gone or has another
size, no longer stands for an upload: the start short-circuit and crash
recovery match only intact frames still on disk, and the ingest repairs such
a frame with the verified copy (same id and position, flags cleared, a damaged
file kept beside it as name.damaged-<time>) instead of calling it a
duplicate. The Uploader deletes a source only after the server received and
verified its bytes in that upload, never on "already on the server" (SRV-1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 09:40:27 +00:00
1 parent 23308c77dd
commit 94b13cc064
12 files changed
+441 -41

No files matched your search

+5 -4
View File
@@ -40,7 +40,8 @@ public interface IUploadEngine : INotifyPropertyChanged
/// <summary>
/// Works through the <see cref="UploadQueue"/> with <see cref="Parallelism"/> concurrent files: hash, upload
/// (resumable chunks; the server verifies the SHA-256), then optionally delete the source the server confirmed.
/// (resumable chunks; the server verifies the SHA-256), then optionally delete the source whose bytes the server
/// received and verified. A file the server already held is kept: no copy of it was verified on this run.
/// Lives on the UI thread: state changes happen there while hashing and HTTP run on the thread pool.
/// </summary>
public sealed class UploadEngine : IUploadEngine, IDisposable
@@ -221,7 +222,7 @@ public sealed class UploadEngine : IUploadEngine, IDisposable
item.State = outcome == UploadOutcome.Verified ? UploadItemState.Verified : UploadItemState.Skipped;
_queue.OnChanged();
ItemConfirmed?.Invoke(this, item);
if (_deleteAfterUpload()) DeleteConfirmedSource(item);
if (outcome == UploadOutcome.Verified && _deleteAfterUpload()) DeleteConfirmedSource(item);
}
catch (OperationCanceledException) when (ct.IsCancellationRequested)
{
@@ -312,8 +313,8 @@ public sealed class UploadEngine : IUploadEngine, IDisposable
}
/// <summary>
/// BRIEF §0.2 rule 8: deletes only a file the server confirmed by hash, and only when it is still exactly the
/// bytes that were hashed (same size and write time).
/// BRIEF §0.2 rule 8: deletes only a file whose bytes the server received and verified by hash before committing
/// them, and only when it is still exactly the bytes that were hashed (same size and write time).
/// </summary>
private static void DeleteConfirmedSource(UploadItem item)
{