diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 6d07ef48..73850b88 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -245,6 +245,9 @@ match. A 1.1 server works as before, without Integrate; a 1.2 server adds the ph
details instead of overwriting them.
- A second version a merge's verify files is left out of Main also when the run stopped right after filing it (a
drive dropping out, project.json held, the app closing): the resumed merge leaves it out then.
+ - A merge whose verify stopped before filing a second version, and whose photo changed before the retry, files the
+ photo as it is now instead of failing on every retry; one that had filed it leaves it out of Main and asks for a
+ new comparison.
- *Upload all local* leaves out again a sequence answered *Keep here* after its server copy was deleted, and the
answer stays; only a *Keep apart* given before the deletion lets it send the sequence.
- An upload that joined a server sequence this PC already knew still compares its details when it is resumed or
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index e4241be0..fbde9c7f 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -1031,3 +1031,4 @@ One line per decision: date · decision · alternative · reason.
| 2026-11-18 | A merge's Verify stage journals a second version (`SecondVersions`, and in `VersionShas` the SHA-256 it is filed as) before it files it; a resumed verify that finds such a frame in the kept sequence leaves it out of Main again (a no-op when it already is), and one that reads other bytes for it stops with "changed" (#73) | Save the journal right after filing | The ingest commits the frame before any save can follow: a failed exclusion or a crash in between left the version in Main for good, since a resumed verify read it as the kept sequence's own |
| 2026-11-18 | Supersedes the 2026-11-18 unlinked-404 rows on Upload all local: a Kept apart pair whose server sequence reads deleted on the server holds nothing back only when it was answered before the first 404 (`AnsweredAt < RemoteGoneAt`); a Keep here (answered after the deletion was shown) still skips the local sequence (#73) | A separate Keep here state or marker | Both answers are stored as Kept apart with the gone mark; the answer time already tells them apart, and Keep here's tooltip and design §6.3 promise Upload all local leaves it out |
| 2026-11-18 | An upload's checkpoint names the server sequence its first original reached with `:joined` appended when that was one this PC already knew; a resumed or retried upload sends all its details only when the checkpoint names the target without that mark (a plain id from an older run still means made by this job) (#73) | Look the sequence up again in the known remotes on resume | After the first attempt the link to it exists, so a resume cannot tell a sequence it made from one it joined; only the attempt that sent the first original knows |
+| 2026-11-18 | Supersedes the 2026-11-18 `VersionShas` row where a resumed verify reads other bytes for a journalled second version: when the kept sequence does not hold the journalled SHA-256 (nothing was filed) the frame leaves `SecondVersions` and `VersionShas` and is verified as on a first visit, which files the bytes it reads now; when it holds them, they are left out of Main and the merge stops with "changed" and drops its journal, so the next run plans again (#73) | Treat the new bytes as another second version in the same run | A stop that kept the journal failed the same way on every retry once the file changed (an editor saving, a sync tool, an edit before a retry after a failed copy), and a cancel then left a filed version in Main; filing a third version unplanned goes further than the plan the user confirmed, while a new plan compares the new bytes and shows them |
diff --git a/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs b/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs
index 67d864ba..d89253fc 100644
--- a/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs
+++ b/src/Chronos.Data/Archiving/Jobs/MergeJobHandler.cs
@@ -55,6 +55,9 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
/// Called before a second version is left out of Main (tests: a failure between filing it and saving the journal).
internal Func? BeforeLeaveOutOfMain { get; set; }
+ /// Called before the verify files a second version, once the journal names it (tests: its file rewritten meanwhile).
+ internal Func? BeforeFileVersion { get; set; }
+
public async Task RunAsync(JobContext context)
{
var job = context.Job;
@@ -660,9 +663,27 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
if (frame.Sha256 is { Length: > 0 } recorded && !string.Equals(recorded, sha, StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName));
var version = journal.SecondVersions.Contains(frame.Id);
- if (version && !string.Equals(journal.VersionShas.GetValueOrDefault(frame.Id), sha, StringComparison.OrdinalIgnoreCase))
+ if (version && journal.VersionShas.GetValueOrDefault(frame.Id) is var filedAs
+ && !string.Equals(filedAs, sha, StringComparison.OrdinalIgnoreCase))
+ {
// A run that stopped while filing it as a second version read other bytes: changed since.
- throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName));
+ if (filedAs is null || !held.ContainsKey(filedAs))
+ {
+ // Nothing was filed (the copy failed or read other bytes): visited as for the first time.
+ journal.SecondVersions.Remove(frame.Id);
+ journal.VersionShas.Remove(frame.Id);
+ Save();
+ version = false;
+ }
+ else
+ {
+ // The old bytes were filed: left out of Main now (a new plan reads them as the kept sequence's
+ // own photo), then the merge stops and is planned again, which compares the new bytes.
+ await LeaveOutOfMainAsync(filedAs).ConfigureAwait(false);
+ ForgetJournal();
+ throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName));
+ }
+ }
if (held.TryGetValue(sha, out var keepFrame))
{
// Filed as a second version by a run that stopped before the journal said so: left out of Main again
@@ -686,6 +707,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
if (!version) journal.SecondVersions.Add(frame.Id);
journal.VersionShas[frame.Id] = sha.ToLowerInvariant();
Save();
+ if (owner.BeforeFileVersion is { } fileHook) await fileHook(frame.Id).ConfigureAwait(false);
var filed = await FileAsync(frame, sha, planned: false).ConfigureAwait(false);
await LeaveOutOfMainAsync(sha).ConfigureAwait(false);
journal.Verified[frame.Id] = new MergeVerified(sha, filed.FrameId);
diff --git a/src/Chronos.Data/Archiving/MergeJournal.cs b/src/Chronos.Data/Archiving/MergeJournal.cs
index dc927cf6..e7e714c8 100644
--- a/src/Chronos.Data/Archiving/MergeJournal.cs
+++ b/src/Chronos.Data/Archiving/MergeJournal.cs
@@ -107,7 +107,9 @@ internal sealed class MergeJournal
///
/// Drop frame of → the SHA-256 it is filed as, written before it is filed: a resumed verify
- /// that finds it in the kept sequence leaves it out of Main again, and one that reads other bytes stops.
+ /// that finds it in the kept sequence leaves it out of Main again. One that reads other bytes starts over for that frame
+ /// when the kept sequence does not hold the old ones (nothing was filed), else leaves them out of Main and stops, and the
+ /// merge is planned again.
///
public Dictionary VersionShas { get; set; } = [];
diff --git a/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs b/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs
index 0428f029..4cf73ab7 100644
--- a/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs
+++ b/tests/Chronos.Data.Tests/Archiving/SequenceMergerTests.cs
@@ -633,6 +633,82 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
AssertVersions(await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct), Sha(mine, 0), Sha(theirs, 0));
}
+ [Test]
+ public async Task AVersionWhoseFileChangedBeforeItWasFiledIsFiledAsItIsOnResume()
+ {
+ var fx = await FixtureAsync();
+ var (mine, theirs) = EqualSizeSeeds(0);
+ var edited = EqualSizeSeed(0, theirs, mine);
+ var keep = await SequenceAsync(fx, "keep", [(mine, 0, "IMG_0001.JPG")]);
+ var drop = await SequenceAsync(fx, "drop", [(theirs, 0, "IMG_0001.JPG")]);
+ await new DbAccess(fx.Db.Database).ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE sequence_id = $1 OR sequence_id = $2", [keep.Id, drop.Id], Ct);
+ var path = fx.Paths.FromRelative((await fx.Db.Frames.ListBySequenceAsync(drop.Id)).Single().RelativePath);
+ var copy = await PairAsync(fx, keep.Id, drop.Id);
+ var merger = Merger(fx);
+ var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
+ await engine.StartAsync(Ct);
+ // The file is rewritten (an editor saving a rotation) between its hash and its copy: the copy reads other bytes.
+ var rewritten = false;
+ handler.BeforeFileVersion = _ =>
+ {
+ if (rewritten) return Task.CompletedTask;
+ rewritten = true;
+ File.WriteAllBytes(path, Photos.Jpeg(Start, edited));
+ return Task.CompletedTask;
+ };
+ var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
+ var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
+ await fx.WaitForAsync(job.Id, JobState.Failed);
+ Assert.True((await HashesAsync(fx, keep.Id)).SetEquals([Sha(mine, 0)]), "nothing was filed");
+
+ await engine.ResumeAsync(job.Id, Ct);
+ await fx.WaitForAsync(job.Id, JobState.Done);
+
+ // Nothing was filed: the retry files the photo as it is now, as a second version left out of Main.
+ Assert.Null(await fx.Db.Sequences.GetAsync(drop.Id));
+ Assert.True((await HashesAsync(fx, keep.Id)).SetEquals([Sha(mine, 0), Sha(edited, 0)]));
+ AssertVersions(await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct), Sha(mine, 0), Sha(edited, 0));
+ }
+
+ [Test]
+ public async Task AVersionFiledBeforeItsFileChangedIsLeftOutOfMainAndTheMergePlannedAgain()
+ {
+ var fx = await FixtureAsync();
+ var (mine, theirs) = EqualSizeSeeds(0);
+ var edited = EqualSizeSeed(0, theirs, mine);
+ var keep = await SequenceAsync(fx, "keep", [(mine, 0, "IMG_0001.JPG")]);
+ var drop = await SequenceAsync(fx, "drop", [(theirs, 0, "IMG_0001.JPG")]);
+ await new DbAccess(fx.Db.Database).ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE sequence_id = $1 OR sequence_id = $2", [keep.Id, drop.Id], Ct);
+ var dropFrame = (await fx.Db.Frames.ListBySequenceAsync(drop.Id)).Single();
+ var path = fx.Paths.FromRelative(dropFrame.RelativePath);
+ var copy = await PairAsync(fx, keep.Id, drop.Id);
+ var merger = Merger(fx);
+ var (engine, handler) = Engine(fx, merger, new FakeProjects(), new FakeWorkspace());
+ await engine.StartAsync(Ct);
+ // Filed at the verify, then the exclusion fails; the file is rewritten before the retry.
+ var failedOnce = false;
+ handler.BeforeLeaveOutOfMain = _ =>
+ {
+ if (failedOnce) return Task.CompletedTask;
+ failedOnce = true;
+ File.WriteAllBytes(path, Photos.Jpeg(Start, edited));
+ throw new IOException("project.json is in use");
+ };
+ var plan = await merger.PlanAsync(copy.Id, keep.Id, drop.Id, await ChoicesAsync(fx, keep.Id, drop.Id, CopyPhotoPolicy.Union), NoContext, Ct);
+ var job = await merger.EnqueueAsync(engine, new FoundCopyStore(fx.Db), plan, keep.DisplayTitle, Ct);
+ await fx.WaitForAsync(job.Id, JobState.Failed);
+ Assert.True((await HashesAsync(fx, keep.Id)).SetEquals([Sha(mine, 0), Sha(theirs, 0)]));
+
+ await engine.ResumeAsync(job.Id, Ct);
+ var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
+
+ // The filed version is left out of Main, the other stays, and the journal goes: the next run plans again.
+ Assert.Equal(Chronos.Core.Localization.Loc.L("Errors.Copies.ChangedFile", dropFrame.FileName), failed.Error);
+ Assert.NotNull(await fx.Db.Sequences.GetAsync(drop.Id));
+ AssertVersions(await new CopySides(fx.Db).VersionsAsync(keep.Id, Ct), Sha(mine, 0), Sha(theirs, 0));
+ Assert.False(File.Exists(MergeJournal.PathFor(fx.Paths, job.Id)), "the next run plans again");
+ }
+
[Test]
public async Task ASecondVersionCopiedInByAMergeAbandonedBeforeItsDetailsStaysOutOfMain()
{
@@ -743,6 +819,14 @@ public abstract class SequenceMergerTests(TestContext context) : DatabaseTest(co
}
}
+ /// A seed other than and whose photo at has the same size as 's.
+ private static int EqualSizeSeed(int ms, int like, params int[] not)
+ {
+ var length = Photos.Jpeg(Start.AddMilliseconds(ms), like).Length;
+ for (var seed = 1; ; seed++)
+ if (seed != like && !not.Contains(seed) && Photos.Jpeg(Start.AddMilliseconds(ms), seed).Length == length) return seed;
+ }
+
[Test]
public async Task AnUnhashedPhotoOfTheKeptOneWithTheSameContentIsNoLastCopy()
{