fix(server): a refused sequence delete names its reason

DELETE /api/v1/sequences/{id} answers 503 archive_offline for an offline
archive, 409 sequence_busy for a busy sequence or a stale plan, and 409
archive_root, contains_sequences, sidecar_mismatch, folder_missing or
folder_in_use otherwise; a sequence deleted meanwhile is a 404.

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-05 22:06:31 +00:00
1 parent 2b2d341497
commit 3f443eaacf
4 files changed
+79 -7

No files matched your search

+31 -5
View File
@@ -145,7 +145,9 @@ public static class SequenceEndpoints
/// <summary>
/// Moves a sequence's folder into the archive's trash and removes it from the index through the archive engine's
/// <see cref="SequenceTrash"/> (BRIEF §0.2 rule 8: nothing is erased, the trash keeps it restorable).
/// <c>?dryRun=true</c> only reports what would happen. Owners and admins only; a sequence a job is working on is refused (409).
/// <c>?dryRun=true</c> only reports what would happen. Owners and admins only. A sequence that cannot move is refused
/// with the reason as its code: 409 <c>sequence_busy</c> (a job works on it or its archive), <c>archive_root</c>,
/// <c>contains_sequences</c>, <c>sidecar_mismatch</c>, <c>folder_missing</c>; 503 <c>archive_offline</c>.
/// </summary>
private static async Task<IResult> DeleteAsync(HttpContext context, Caller caller, Guid id, bool? dryRun, TitanoDatabase db,
[FromServices] ArchiveService? archives, AuditLog audit, EventHub events)
@@ -157,13 +159,27 @@ public static class SequenceEndpoints
DeletePlan plan;
try
{
plan = await trash.PlanAsync([id], ct);
if (plan.Blocked is [{ } blocked]) return ApiErrors.Conflict(context, "sequence_busy", blocked.Reason.ToString());
plan = await trash.PlanAsync([id], null, ct);
if (plan.Blocked is [{ } blocked]) return Refused(context, blocked.Reason);
if (dryRun != true) await trash.DeleteAsync(plan, caller.User.Username, null, ct);
}
catch (StaleDeletePlanException)
catch (ArgumentException)
{
return ApiErrors.Conflict(context, "sequence_busy");
// Deleted by someone else between the lookup and the plan.
return ApiErrors.NotFound(context, "sequence");
}
catch (Titano.Core.Archiving.ArchiveOfflineException)
{
return Refused(context, DeleteBlock.Offline);
}
catch (Exception ex) when (ex is StaleDeletePlanException or Titano.Core.Archiving.LeaseUnavailableException)
{
return Refused(context, DeleteBlock.Busy);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
// A file of the folder is open elsewhere: nothing moved.
return ApiErrors.Conflict(context, "folder_in_use");
}
var step = plan.Steps[0];
var result = new SequenceDeletePlan(id, sequence.Folder, step.TrashFolder, sequence.FrameCount, sequence.TotalBytes, sequence.RenderedCount, dryRun == true);
@@ -174,6 +190,16 @@ public static class SequenceEndpoints
return Results.Json(result, ProtocolJson.Default.SequenceDeletePlan);
}
private static IResult Refused(HttpContext context, DeleteBlock reason) => reason switch
{
DeleteBlock.Offline => ApiErrors.Result(context, StatusCodes.Status503ServiceUnavailable, "archive_offline"),
DeleteBlock.Busy => ApiErrors.Conflict(context, "sequence_busy"),
DeleteBlock.ArchiveRoot => ApiErrors.Conflict(context, "archive_root"),
DeleteBlock.ContainsSequences => ApiErrors.Conflict(context, "contains_sequences"),
DeleteBlock.ForeignSidecar => ApiErrors.Conflict(context, "sidecar_mismatch"),
_ => ApiErrors.Conflict(context, "folder_missing"),
};
/// <summary>Everything a client needs to mirror a sequence and detect changes (BRIEF §14.5); ETag over the version counters.</summary>
private static async Task<IResult> ManifestAsync(HttpContext context, Guid id, TitanoDatabase db)
{