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

+7 -1
View File
@@ -26,14 +26,19 @@
<data name="Server.Disconnect" xml:space="preserve"><value>Disconnect</value></data>
<data name="Server.Empty" xml:space="preserve"><value>Not connected to a server</value></data>
<data name="Server.Error.AccountLocked" xml:space="preserve"><value>Too many failed sign-ins; the account is locked for a while.</value><comment>long</comment></data>
<data name="Server.Error.ArchiveOffline" xml:space="preserve"><value>The archive is offline or read-only; try again when it is back.</value><comment>long</comment></data>
<data name="Server.Error.ArchiveRoot" xml:space="preserve"><value>Its photos are the archive's root folder, which never moves to the trash.</value><comment>long</comment></data>
<data name="Server.Error.BadCredentials" xml:space="preserve"><value>Wrong user name or password.</value><comment>long</comment></data>
<data name="Server.Error.BadRequest" xml:space="preserve"><value>The request is not valid.</value><comment>long</comment></data>
<data name="Server.Error.CertificateChanged" xml:space="preserve"><value>The server certificate changed; confirm it and sign in again.</value><comment>long</comment></data>
<data name="Server.Error.ChunkOutOfRange" xml:space="preserve"><value>This upload has no such chunk.</value><comment>long</comment></data>
<data name="Server.Error.ChunkSize" xml:space="preserve"><value>The chunk has the wrong size.</value><comment>long</comment></data>
<data name="Server.Error.CommitFailed" xml:space="preserve"><value>The file could not be stored in the archive; try again.</value><comment>long</comment></data>
<data name="Server.Error.ContainsSequences" xml:space="preserve"><value>Its folder holds other sequences; move them elsewhere first.</value><comment>long</comment></data>
<data name="Server.Error.CsrfFailed" xml:space="preserve"><value>The security token is missing; reload the page.</value><comment>long</comment></data>
<data name="Server.Error.Failed" xml:space="preserve"><value>The connection failed; the log has the details.</value><comment>long</comment></data>
<data name="Server.Error.FolderInUse" xml:space="preserve"><value>A file of the sequence is open in another program; close it and try again.</value><comment>long</comment></data>
<data name="Server.Error.FolderMissing" xml:space="preserve"><value>Its folder is no longer on disk; nothing is left to move to the trash.</value><comment>long</comment></data>
<data name="Server.Error.Forbidden" xml:space="preserve"><value>Your account cannot do this.</value><comment>long</comment></data>
<data name="Server.Error.HashMismatch" xml:space="preserve"><value>The file arrived damaged; upload it again.</value><comment>long</comment></data>
<data name="Server.Error.HttpsRequired" xml:space="preserve"><value>Open the admin panel over HTTPS to sign in.</value><comment>long</comment></data>
@@ -66,10 +71,11 @@
<data name="Server.Error.RateLimited" xml:space="preserve"><value>Too many attempts; wait a minute and try again.</value><comment>long</comment></data>
<data name="Server.Error.SamePassword" xml:space="preserve"><value>Choose a password different from the current one.</value><comment>long</comment></data>
<data name="Server.Error.Self" xml:space="preserve"><value>You cannot do this to your own account.</value><comment>long</comment></data>
<data name="Server.Error.SequenceBusy" xml:space="preserve"><value>A job is working on this sequence, or it cannot move to the trash; try again when it is free.</value><comment>long</comment></data>
<data name="Server.Error.SequenceBusy" xml:space="preserve"><value>A job is working on this sequence or its archive; try again when it is free.</value><comment>long</comment></data>
<data name="Server.Error.SessionExpired" xml:space="preserve"><value>The session expired; sign in again.</value><comment>long</comment></data>
<data name="Server.Error.SettingLocked" xml:space="preserve"><value>An environment variable sets this; change it there.</value><comment>long</comment></data>
<data name="Server.Error.SettingsConflict" xml:space="preserve"><value>The sequence changed on the server; reload it and apply your edit again.</value><comment>long</comment></data>
<data name="Server.Error.SidecarMismatch" xml:space="preserve"><value>Its folder holds another sequence; scan the archive first.</value><comment>long</comment></data>
<data name="Server.Error.TooLarge" xml:space="preserve"><value>The request is larger than the server accepts.</value><comment>long</comment></data>
<data name="Server.Error.TooManyUploads" xml:space="preserve"><value>Too many uploads at once; retry shortly.</value><comment>long</comment></data>
<data name="Server.Error.Unauthorized" xml:space="preserve"><value>Sign in to continue.</value><comment>long</comment></data>
+7 -1
View File
@@ -24,14 +24,19 @@
<data name="Server.Disconnect" xml:space="preserve"><value>Disconnetti</value></data>
<data name="Server.Empty" xml:space="preserve"><value>Non connesso a un server</value></data>
<data name="Server.Error.AccountLocked" xml:space="preserve"><value>Troppi accessi falliti; l'account è bloccato per un po'.</value></data>
<data name="Server.Error.ArchiveOffline" xml:space="preserve"><value>L'archivio non è raggiungibile o è di sola lettura; riprova quando torna disponibile.</value></data>
<data name="Server.Error.ArchiveRoot" xml:space="preserve"><value>Le sue foto sono la cartella principale dell'archivio, che non va mai nel cestino.</value></data>
<data name="Server.Error.BadCredentials" xml:space="preserve"><value>Nome utente o password errati.</value></data>
<data name="Server.Error.BadRequest" xml:space="preserve"><value>La richiesta non è valida.</value></data>
<data name="Server.Error.CertificateChanged" xml:space="preserve"><value>Il certificato del server è cambiato; confermalo e accedi di nuovo.</value></data>
<data name="Server.Error.ChunkOutOfRange" xml:space="preserve"><value>Questo caricamento non ha quel blocco.</value></data>
<data name="Server.Error.ChunkSize" xml:space="preserve"><value>Il blocco ha la dimensione sbagliata.</value></data>
<data name="Server.Error.CommitFailed" xml:space="preserve"><value>Il file non è stato salvato nell'archivio; riprova.</value></data>
<data name="Server.Error.ContainsSequences" xml:space="preserve"><value>La sua cartella contiene altre sequenze; prima spostale altrove.</value></data>
<data name="Server.Error.CsrfFailed" xml:space="preserve"><value>Manca il token di sicurezza; ricarica la pagina.</value></data>
<data name="Server.Error.Failed" xml:space="preserve"><value>La connessione non è riuscita; i dettagli sono nel log.</value></data>
<data name="Server.Error.FolderInUse" xml:space="preserve"><value>Un file della sequenza è aperto in un altro programma; chiudilo e riprova.</value></data>
<data name="Server.Error.FolderMissing" xml:space="preserve"><value>La sua cartella non è più sul disco; non resta nulla da spostare nel cestino.</value></data>
<data name="Server.Error.Forbidden" xml:space="preserve"><value>Il tuo account non può farlo.</value></data>
<data name="Server.Error.HashMismatch" xml:space="preserve"><value>Il file è arrivato danneggiato; caricalo di nuovo.</value></data>
<data name="Server.Error.HttpsRequired" xml:space="preserve"><value>Apri il pannello di amministrazione in HTTPS per accedere.</value></data>
@@ -64,10 +69,11 @@
<data name="Server.Error.RateLimited" xml:space="preserve"><value>Troppi tentativi; attendi un minuto e riprova.</value></data>
<data name="Server.Error.SamePassword" xml:space="preserve"><value>Scegli una password diversa da quella attuale.</value></data>
<data name="Server.Error.Self" xml:space="preserve"><value>Non puoi farlo sul tuo account.</value></data>
<data name="Server.Error.SequenceBusy" xml:space="preserve"><value>Un'attività sta lavorando su questa sequenza, oppure non può andare nel cestino; riprova quando è libera.</value></data>
<data name="Server.Error.SequenceBusy" xml:space="preserve"><value>Un'attività sta lavorando su questa sequenza o sul suo archivio; riprova quando è libera.</value></data>
<data name="Server.Error.SessionExpired" xml:space="preserve"><value>La sessione è scaduta; accedi di nuovo.</value></data>
<data name="Server.Error.SettingLocked" xml:space="preserve"><value>È impostato da una variabile d'ambiente; modificala lì.</value></data>
<data name="Server.Error.SettingsConflict" xml:space="preserve"><value>La sequenza è cambiata sul server; ricaricala e riapplica la modifica.</value></data>
<data name="Server.Error.SidecarMismatch" xml:space="preserve"><value>La sua cartella contiene un'altra sequenza; prima esegui una scansione dell'archivio.</value></data>
<data name="Server.Error.TooLarge" xml:space="preserve"><value>La richiesta supera la dimensione accettata dal server.</value></data>
<data name="Server.Error.TooManyUploads" xml:space="preserve"><value>Troppi caricamenti insieme; riprova tra poco.</value></data>
<data name="Server.Error.Unauthorized" xml:space="preserve"><value>Accedi per continuare.</value></data>
+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)
{
@@ -173,6 +173,40 @@ public sealed class SequenceTests(TestContext context)
Assert.NotNull(await server.Database.Sequences.GetAsync(sequence.Id));
}
[Test]
public async Task ADeleteThatCannotMoveSaysWhy()
{
await using var server = await TestServer.StartAsync(context);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var a = (await server.Database.Sequences.GetAsync((await Uploads.UploadAsync(editor, Uploads.Photo(3000, 36), "a.jpg", sessionKey: "a")).SequenceId))!;
var b = (await server.Database.Sequences.GetAsync((await Uploads.UploadAsync(editor, Uploads.Photo(3000, 37), "b.jpg", sessionKey: "b")).SequenceId))!;
Assert.NotEqual(a.Folder, b.Folder);
var archive = new Titano.Core.Archiving.ArchivePaths(server.Options.ArchivePath);
// The folder of b now holds a sidecar naming another sequence (copied over by hand): the index is out of date.
var sidecar = archive.Sequence(b.Folder).ManifestPath;
Directory.CreateDirectory(Path.GetDirectoryName(sidecar)!);
File.WriteAllText(sidecar, $$"""{"schemaVersion":1,"id":"{{a.Id}}"}""");
await RefusedAsync(editor, b.Id, "sidecar_mismatch");
Directory.Delete(archive.Sequence(a.Folder).Folder, recursive: true);
await RefusedAsync(editor, a.Id, "folder_missing");
Assert.NotNull(await server.Database.Sequences.GetAsync(a.Id));
Assert.NotNull(await server.Database.Sequences.GetAsync(b.Id));
// A sequence still waiting for its first photo has no folder: only its row goes.
using var created = await editor.PostAsJsonAsync("/api/v1/sequences", new CreateSequenceRequest("Waiting", null), ProtocolJson.Default.CreateSequenceRequest);
var empty = await created.ReadAsync(ProtocolJson.Default.SequenceDto);
using (var deleted = await editor.DeleteAsync($"/api/v1/sequences/{empty.Id}")) Assert.Null((await deleted.ReadAsync(ProtocolJson.Default.SequenceDeletePlan)).TrashFolder);
Assert.Null(await server.Database.Sequences.GetAsync(empty.Id));
static async Task RefusedAsync(HttpClient client, Guid id, string code)
{
using var response = await client.DeleteAsync($"/api/v1/sequences/{id}");
var error = await response.ExpectErrorAsync(HttpStatusCode.Conflict, code);
Assert.NotEqual(code, error.Message, "the code has a sentence");
}
}
[Test]
public async Task FramesAndStatsArePaged()
{