fix(workspace): close the phase 5c review findings
Originals are now judged by their bytes, never by the media index: a removal or clean-up hashes every file under media/originals and deletes it only when the home holds that SHA-256; every other file, named or not, goes to the workspace trash. Trash entries are filled under a staging name that Empty never lists. A ledger can only name files inside exports/. Jobs follow the workspace: a copy, render or send resolves the folder that holds its project now (a moved workspace, a retry after a move) and waits while a move has not switched yet. A clean-up failure after the switch is a warning that keeps the journal for a later resume; entries that changed since they were copied are kept, and a same-volume rename refused across volumes falls back to copy and verify. Sends map a replayed version by content hash, or go with the project only, and note an old server that drops provenance. The media index (format 2) and project file (format 3) refuse older readers while they hold originals. Metered connections also hold sync downloads and server copies. The editor gains Send again, the Settings page can resume a stopped move, the disabled tooltips say why, and unused strings are pruned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09fcff4eb2
commit
2654683a12
125 files changed
+1618
-401
No files matched your search
@@ -18,7 +18,9 @@ namespace Chronos.Data.Workspaces;
|
||||
/// sent home with their project and version, per unsent ledger entry (<see cref="WorkspaceRenders"/>; the ids the job names,
|
||||
/// or every unsent one): the file hashed again (one missing or changed since it was rendered is refused, marked failed in the
|
||||
/// ledger and left where it is), the version it names pushed first when the home lacks it (a push that fails fails the job,
|
||||
/// the entry left as it was), then filed in this PC's archive (copied into the archive's staging folder, read back against
|
||||
/// the entry left as it was; a version the push replayed under a new id, after the home moved on, is found again by the
|
||||
/// content hash of what rendered, else the render goes with its project alone, and the entry says so from then on), then
|
||||
/// filed in this PC's archive (copied into the archive's staging folder, read back against
|
||||
/// its SHA-256, and filed under the sequence's lease as the sync files a server's exports,
|
||||
/// <see cref="SyncTransfers.FileRenderAsync"/>, after checking the project and version are the sequence's) or uploaded to its
|
||||
/// server (<see cref="RenderUploadRequest"/> with <c>ProjectId</c> and <c>ProjectVersionId</c>, which the server checks the
|
||||
@@ -27,7 +29,9 @@ namespace Chronos.Data.Workspaces;
|
||||
/// render id the home files under another sequence is refused. The ledger is read and written under the project's lease,
|
||||
/// each entry read again before it is written, so a render finished meanwhile is kept.
|
||||
/// A send to a server is held while <see cref="WorkspaceJobOptions.HoldTransfers"/> says so (a metered connection): it waits
|
||||
/// before each upload, and the desktop pauses it meanwhile. A send to this PC's archive is never held.
|
||||
/// before each upload, and the desktop pauses it meanwhile. A send to this PC's archive is never held. A server from before
|
||||
/// phase 5c files the render without its project and version: the job's log says so. A send queued before the workspace
|
||||
/// moved works where the workspace is now, and none runs while it is being moved (<see cref="WorkspaceJobRoots"/>).
|
||||
/// </summary>
|
||||
internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService archives, ISyncConnector? servers, WorkspaceJobOptions options) : IJobHandler
|
||||
{
|
||||
@@ -46,7 +50,10 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
if (context.Job.TargetIds is not [var sequenceId] || string.IsNullOrWhiteSpace(parameters.WorkspaceRoot))
|
||||
throw new InvalidDataException(Loc.L("Errors.Workspace.JobParameters"));
|
||||
var server = parameters.Server is { Length: > 0 } named ? named : null;
|
||||
var project = new WorkspaceStore(parameters.WorkspaceRoot).Find(parameters.ProjectId)
|
||||
// Where the project is now (a workspace moved since the job was queued), never while it is being moved; nothing is
|
||||
// made where it is not.
|
||||
var root = WorkspaceJobRoots.Resolve(parameters.WorkspaceRoot, parameters.ProjectId, options.CurrentRoot, "Errors.Workspace.NotCheckedOut");
|
||||
var project = new WorkspaceStore(root).Find(parameters.ProjectId)
|
||||
?? throw new InvalidOperationException(Loc.L("Errors.Workspace.NotCheckedOut"));
|
||||
var workspace = project.ReadBundle().Workspace ?? throw new InvalidOperationException(Loc.L("Errors.Workspace.NotCheckedOut"));
|
||||
var home = workspace.Home;
|
||||
@@ -77,7 +84,7 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
?? throw new InvalidOperationException(Loc.L("Errors.Sync.NotConnected"));
|
||||
await SendAsync(context, project, workspace, entries,
|
||||
() => servers!.ProjectHome(home) ?? throw new InvalidOperationException(Loc.L("Errors.Sync.NotConnected")), held: true,
|
||||
(entry, file, token) => UploadAsync(remote, sequenceId, entry, file, token)).ConfigureAwait(false);
|
||||
(entry, file, token) => UploadAsync(context, remote, sequenceId, entry, file, token)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,25 +108,35 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
{
|
||||
var ct = context.Cancellation;
|
||||
var (sent, there, refused) = (0, 0, 0);
|
||||
// The versions this run found at the home, or sent there first.
|
||||
var versions = new HashSet<Guid>();
|
||||
// The versions this run found at the home, or sent there first, with the id the home holds each by (a replay gives another).
|
||||
var versions = new Dictionary<Guid, Guid?>();
|
||||
for (var i = 0; i < entries.Count; i++)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
if (held) await WhileHeldAsync(context).ConfigureAwait(false);
|
||||
var entry = entries[i];
|
||||
var file = project.ExportFile(entry.File);
|
||||
var refusal = await CheckAsync(project, entry, file, folders: !held, ct).ConfigureAwait(false);
|
||||
var file = project.ContainedExportFile(entry.File);
|
||||
var refusal = file is null ? Loc.L("Errors.Workspace.SendMissing", Path.GetFileName(entry.File ?? string.Empty)) : await CheckAsync(entry, file, folders: !held, ct).ConfigureAwait(false);
|
||||
if (refusal is null)
|
||||
{
|
||||
if (entry.ProjectVersionId is { } versionId && !versions.Contains(versionId))
|
||||
if (entry.ProjectVersionId is { } versionId)
|
||||
{
|
||||
await EnsureVersionAsync(context, project, workspace, home(), entry.ProjectId, versionId, ct).ConfigureAwait(false);
|
||||
versions.Add(versionId);
|
||||
if (!versions.TryGetValue(versionId, out var atHome))
|
||||
{
|
||||
atHome = await EnsureVersionAsync(context, project, workspace, home(), entry, versionId, ct).ConfigureAwait(false);
|
||||
versions[versionId] = atHome;
|
||||
}
|
||||
if (atHome != versionId)
|
||||
{
|
||||
// The ledger says from now on what the home holds: later sends agree with this one.
|
||||
entry = entry with { ProjectVersionId = atHome };
|
||||
var mapped = atHome;
|
||||
await UpdateAsync(project, entry.RenderId, e => e with { ProjectVersionId = mapped }).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
if (await deliver(entry, file, ct).ConfigureAwait(false)) sent++;
|
||||
if (await deliver(entry, file!, ct).ConfigureAwait(false)) sent++;
|
||||
else there++;
|
||||
// The home holds it: recorded whatever stops the job now.
|
||||
await UpdateAsync(project, entry.RenderId, e => e.AsSent(DateTimeOffset.UtcNow)).ConfigureAwait(false);
|
||||
@@ -147,12 +164,10 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
/// when <paramref name="folders"/>: this PC's archive files folders as its own renders do) is checked by its total size
|
||||
/// and the hash of its listing, as the render recorded it (<see cref="WorkspaceRenderJobHandler.HashAsync"/>).
|
||||
/// </summary>
|
||||
private static async Task<string?> CheckAsync(WorkspaceProject project, WorkspaceRenderEntry entry, string file, bool folders, CancellationToken ct)
|
||||
/// <remarks>A ledger names files inside the exports only (<see cref="WorkspaceProject.ContainedExportFile"/>): one pointing elsewhere is never read.</remarks>
|
||||
private static async Task<string?> CheckAsync(WorkspaceRenderEntry entry, string file, bool folders, CancellationToken ct)
|
||||
{
|
||||
var name = Path.GetFileName(entry.File);
|
||||
var exports = Path.TrimEndingDirectorySeparator(Path.GetFullPath(project.ExportsDirectory)) + Path.DirectorySeparatorChar;
|
||||
// A ledger names files inside the exports only; one pointing elsewhere is never read.
|
||||
if (!Path.GetFullPath(file).StartsWith(exports, StringComparison.OrdinalIgnoreCase)) return Loc.L("Errors.Workspace.SendMissing", name);
|
||||
if (Directory.Exists(file))
|
||||
{
|
||||
if (!folders) return Loc.L("Errors.Workspace.SendSequence", name);
|
||||
@@ -168,14 +183,21 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>How many of the home's newest versions are read for one of the same content, when a replay gave a rendered version another id.</summary>
|
||||
private const int ReplayedLookBack = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Version <paramref name="versionId"/> of the project at the home: pushed there first (every local version, in order, as a
|
||||
/// sync pushes them) when the home lacks it. A push that does not bring it there fails the job.
|
||||
/// Version <paramref name="versionId"/> of the project at the home, as the id the home holds it by: pushed there first
|
||||
/// (every local version, in order, as a sync pushes them) when the home lacks it. A push that replays it on a home that
|
||||
/// moved on gives it another id (and one that changes nothing is not sent at all): the home's version of the content
|
||||
/// hash that rendered (<see cref="WorkspaceRenderEntry.SettingsHash"/>) stands for it, else none (null: the render goes
|
||||
/// with its project alone, as a render of a version the home never had). A push that fails fails the job.
|
||||
/// </summary>
|
||||
private static async Task EnsureVersionAsync(JobContext context, WorkspaceProject project, BundleWorkspace workspace, IProjectHome home, Guid projectId,
|
||||
Guid versionId, CancellationToken ct)
|
||||
private static async Task<Guid?> EnsureVersionAsync(JobContext context, WorkspaceProject project, BundleWorkspace workspace, IProjectHome home,
|
||||
WorkspaceRenderEntry entry, Guid versionId, CancellationToken ct)
|
||||
{
|
||||
if (await home.GetVersionAsync(projectId, versionId, ct).ConfigureAwait(false) is not null) return;
|
||||
var projectId = entry.ProjectId;
|
||||
if (await home.GetVersionAsync(projectId, versionId, ct).ConfigureAwait(false) is not null) return versionId;
|
||||
try
|
||||
{
|
||||
await new WorkspaceSync(project.Store, Environment.MachineName) { LockWait = LockWait }.PushAsync(projectId, home, ct).ConfigureAwait(false);
|
||||
@@ -186,9 +208,26 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
context.Log(ex.Message);
|
||||
throw new InvalidOperationException(Loc.L("Errors.Workspace.SendVersion"), ex);
|
||||
}
|
||||
var pushed = await home.GetVersionAsync(projectId, versionId, ct).ConfigureAwait(false)
|
||||
?? throw new InvalidOperationException(Loc.L("Errors.Workspace.SendVersion"));
|
||||
context.Log(Loc.L("Archive.Log.WorkspaceVersionPushed", workspace.Name, pushed.Number));
|
||||
if (await home.GetVersionAsync(projectId, versionId, ct).ConfigureAwait(false) is { } pushed)
|
||||
{
|
||||
context.Log(Loc.L("Archive.Log.WorkspaceVersionPushed", workspace.Name, pushed.Number));
|
||||
return versionId;
|
||||
}
|
||||
ProjectVersion? same = null;
|
||||
if (entry.SettingsHash is { Length: > 0 } hash)
|
||||
{
|
||||
var history = await home.HistoryAsync(projectId, null, ReplayedLookBack, ct).ConfigureAwait(false);
|
||||
same = history.FirstOrDefault(v => string.Equals(v.ContentHash, hash, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
if (same is not null)
|
||||
{
|
||||
Log.Info("workspace", $"Version {versionId} of project {projectId} reached the home as version {same.Id} (a replay): render {entry.RenderId} names that one");
|
||||
context.Log(Loc.L("Archive.Log.WorkspaceVersionReplayed", workspace.Name, same.Number));
|
||||
return same.Id;
|
||||
}
|
||||
Log.Info("workspace", $"Version {versionId} of project {projectId} is not at the home after the push, nor one of the same content: render {entry.RenderId} goes with its project alone");
|
||||
context.Log(Loc.L("Archive.Log.WorkspaceVersionNotHome", workspace.Name));
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -283,14 +322,21 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
/// project for another sequence's, the id for another sequence's render, the file for too large or not the one hashed):
|
||||
/// marked failed; anything else (the server out of reach, busy, the sign-in expired) fails the job, the entry left as it was.
|
||||
/// </summary>
|
||||
private async Task<bool> UploadAsync(ISyncRemote remote, Guid sequenceId, WorkspaceRenderEntry entry, string file, CancellationToken ct)
|
||||
private async Task<bool> UploadAsync(JobContext context, ISyncRemote remote, Guid sequenceId, WorkspaceRenderEntry entry, string file, CancellationToken ct)
|
||||
{
|
||||
var name = SyncTransfers.SafeFileName(Path.GetFileName(entry.File)) ?? entry.RenderId.ToString("N");
|
||||
var request = new RenderUploadRequest(entry.RenderId, name, entry.Size, entry.Sha256.ToLowerInvariant(), entry.PresetName, entry.Codec, entry.Width, entry.Height,
|
||||
entry.Fps, entry.DurationSeconds, options.Processing.ProducedBy, entry.ProjectId, entry.ProjectVersionId);
|
||||
try
|
||||
{
|
||||
return await remote.UploadRenderAsync(sequenceId, file, request, ct).ConfigureAwait(false) is not null;
|
||||
if (await remote.UploadRenderAsync(sequenceId, file, request, ct).ConfigureAwait(false) is not { } filed) return false;
|
||||
// A server from before phase 5c ignores the project and version: the render is there, without them.
|
||||
if (filed.ProjectId != entry.ProjectId || filed.ProjectVersionId != entry.ProjectVersionId)
|
||||
{
|
||||
Log.Warning("workspace", $"The server filed render {entry.RenderId} without its project {entry.ProjectId} and version {entry.ProjectVersionId} (a server before phase 5c)");
|
||||
context.Log(Loc.L("Archive.Log.WorkspaceSendNoProvenance", name));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status is HttpStatusCode.BadRequest or HttpStatusCode.Conflict or HttpStatusCode.RequestEntityTooLarge
|
||||
or HttpStatusCode.UnprocessableEntity)
|
||||
|
||||
Reference in new issue
Block a user