From 8927ac97e220a5334683b22ed561e0ad339717d1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Oct 2026 22:08:36 +0000 Subject: [PATCH] fix(sync): record scan stamps after a pulled title only when the index held the folder ApplyLocallyAsync recorded the folder's scan stamps unconditionally after writing the server's title, tags, rating or notes into the sidecar. Photos another process (a desktop sharing this archive) had listed there since this index last synced the folder then stayed out of the index until the folder changed again, and the row's frames version stayed behind the sidecar's, so analyses here recorded nothing for the sequence meanwhile. It now asks ArchiveIndexer.InStepAsync before its sidecar write, as the other partial writers do, and records the stamps only when that held. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.Data/Sync/SyncService.cs | 5 +++- .../Sync/SyncServiceTests.cs | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Titano.Data/Sync/SyncService.cs b/src/Titano.Data/Sync/SyncService.cs index 35d9d0c7..e0efcfc5 100644 --- a/src/Titano.Data/Sync/SyncService.cs +++ b/src/Titano.Data/Sync/SyncService.cs @@ -767,6 +767,9 @@ public sealed class SyncService if (metadata) { var manifest = SequenceWriter.ReadLocked(folder, row.Id); + // Asked before the sidecar is written: frames or flags another process wrote there since this index last + // synced the folder keep it changed for the next scan (ArchiveIndexer.InStepAsync). + var inStep = await Archives.Indexer.InStepAsync(archive, folder, manifest, cancellationToken).ConfigureAwait(false); ManifestStore.WriteSequence(folder.ManifestPath, manifest with { Title = updated.Title, @@ -776,7 +779,7 @@ public sealed class SyncService Versions = manifest.Versions with { Settings = Math.Max(manifest.Versions.Settings, updated.SettingsVersion) }, UpdatedAt = DateTimeOffset.UtcNow, }); - await Archives.Indexer.RecordStampsAsync(archive, folder, row.Id, cancellationToken).ConfigureAwait(false); + if (inStep) await Archives.Indexer.RecordStampsAsync(archive, folder, row.Id, cancellationToken).ConfigureAwait(false); } return updated; } diff --git a/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs b/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs index 9d090650..1a348d07 100644 --- a/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs +++ b/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs @@ -1,6 +1,8 @@ using Titano.Core.Model; using Titano.Core.Project; +using Titano.Data.Archiving; using Titano.Data.Sync; +using Titano.Data.Tests.Archiving; using Titano.Protocol; using Titano.Protocol.Client; using Titano.Testing; @@ -289,6 +291,34 @@ public sealed class SyncServiceTests(TestContext context) Assert.SequenceEqual(["sunset"], (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Tags); } + [Test] + public async Task InfoTakenFromTheServerLeavesPhotosAnotherWriterAddedHereToTheNextScan() + { + await using var f = await SyncFixture.CreateAsync(context); + var photos = f.NewPhotos(2); + var local = await f.LocalAsync("Harbour", photos); + var remote = f.Remote.Add("Harbour", photos); + await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct); + await f.RefreshAsync(); + + // A desktop sharing this PC's archive imports a photo into the sequence: its own index follows the sidecar, this one not yet. + var (desktop, archive) = await f.Archive.OtherWriterAsync(); + var staged = f.Archive.Stage(ArchiveFixture.Start.AddMinutes(10), seed: 90); + await desktop.Ingest.CommitAsync(new IngestRequest(archive.Id, local.Id, null, null, staged.Path, "IMG_0009.JPG", staged.Size, staged.Sha256, null, null), + f.Ct); + + // The server's new title reaches this PC meanwhile, in its index and the sidecar. + await f.Remote.UpdateSequenceAsync(remote.Id, new UpdateSequenceRequest("Harbour at dusk", null, null, null, null, null), f.Ct); + await f.RefreshAsync(); + var taken = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!; + Assert.Equal(("Harbour at dusk", 2), (taken.Title, taken.FrameCount)); + + // The next scan still finds the folder changed, and indexes the photo. + Assert.Contains(local.Id, (await f.Archive.ScanAsync()).Sequences); + var row = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!; + Assert.Equal(("Harbour at dusk", 3), (row.Title, row.FrameCount)); + } + [Test] public async Task TheSameEditOnBothSidesIsAgreedWithoutAConflict() {