Skip to content

Commit 9042b86

Browse files
AlexChambersclaude
andcommitted
LR-IMP-FORMATS: Build Smart Previews never converts a proxy from a newer build (storytold#1328 review)
Review of 0accb271: a format mismatch bypassed the forward-version guard. smart_run ORed Ages::stale with "stored format differs from the one to build", so an ordinary Build Smart Previews (no format asked for) rebuilt a Lossless proxy under the default Compact preference, or a Compact one under a Lossless preference, with this build's older look or decode and stamped its versions: (look + 1, 0), (look - 1, source + 1) and (look + 1, source + 1) all became (5, 1) in the other format. The opening refresh kept them already. A usable proxy is now classified first: one from a newer build (smart::from_newer_build: its look or source version, or a Compact proxy's encode version from storytold#850, above this build's) is kept as it is, in its stored format, whatever format is preferred or asked for, and counted as newerKept in the result; only a current or older one is considered for a format conversion. A deliberate downgrade is not offered (Discard removes the proxy). Ages::stale uses the same check. source_version stays a field the writer owns. Rebased onto storytold#1400 at cf1c803, which brings main b3d392b (batch 33 and storytold#850): LOOK_VERSION is 5 there (storytold#1340), so this build writes look 5 / source 1 (and Compact enc 2), which a build from main at look 5 takes as current; RENDER_CACHE_VERSION goes to 65 (main is at 62). Test: proxies at those three version pairs (and a Compact proxy from a newer encoding) survive the opening refresh and Build Smart Previews for both stored formats under both preferences, and are reported as newerKept (6 of the 12 version-pair cases were rewritten before; the encoding case is rewritten without its check). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c4e9e8e commit 9042b86

6 files changed

Lines changed: 79 additions & 13 deletions

File tree

‎crates/engine/src/cmd/previews.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ struct SmartCounts {
230230
/// Of those kept as they were: out of date, but the original can't be read now (offline), so
231231
/// the stored look stays and the next run with the original online rebuilds them.
232232
stale_kept: usize,
233+
/// Of those kept as they were: written by a newer build (a look or raw decode version above this build's), so
234+
/// neither refreshed nor converted to another format here.
235+
newer_kept: usize,
233236
removed: usize,
234237
/// `[[id, why]]`
235238
failed: Vec<Value>,
@@ -299,9 +302,15 @@ fn smart_run(
299302
let previous = crate::smart::header(&path);
300303
let storage = format.or_else(|| previous.as_ref().map(|(f, _)| *f)).unwrap_or_default();
301304
let usable = crate::smart::is_usable(&path);
302-
let stale = usable && (ages.stale(&path) || previous.as_ref().is_some_and(|(f, _)| *f != storage));
305+
// A usable proxy from a newer build stays as it is, in its format too: rewritten here, it would take this
306+
// build's older look or decode and versions (a deliberate downgrade is not offered; Discard is).
307+
let newer = usable && crate::smart::from_newer_build(&path);
308+
let stale = usable && !newer && (ages.stale(&path) || previous.as_ref().is_some_and(|(f, _)| *f != storage));
303309
if usable && !stale {
304310
n.built += 1;
311+
if newer {
312+
n.newer_kept += 1;
313+
}
305314
} else {
306315
let change = if stale { crate::media::Change::Replace } else { crate::media::Change::Write };
307316
// a stale proxy is rebuilt from the original only: never from itself (the file
@@ -431,7 +440,7 @@ fn smart(s: &mut Session, p: &Value) -> Result<Value> {
431440
let task = task_for(s, &state);
432441
let r = smart_run(&dir, custom, discard, jobs, Some((&state, &task)), Some(format), &cache).map_err(|e| bad(C, e))?;
433442
Ok(
434-
json!({"built": r.built, "repaired": r.repaired, "refreshed": r.refreshed, "staleKept": r.stale_kept, "removed": r.removed, "failed": r.failed}),
443+
json!({"built": r.built, "repaired": r.repaired, "refreshed": r.refreshed, "staleKept": r.stale_kept, "newerKept": r.newer_kept, "removed": r.removed, "failed": r.failed}),
435444
)
436445
}
437446

‎crates/engine/src/smart.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ pub fn versions(path: &Path) -> Option<(u64, u64)> {
420420
}
421421

422422
/// Whether the complete proxy at `path` was written by a newer build: its camera-look fit or raw decode version, or a
423-
/// Compact proxy's encode version, is above this build's. Such a proxy is never rewritten here: this build would put
424-
/// its own older look, decode or encoding in it and take that version back.
423+
/// Compact proxy's encode version, is above this build's. Such a proxy is never rewritten here, for staleness or for a
424+
/// format change: this build would put its own older look, decode or encoding in it and take that version back.
425425
pub fn from_newer_build(path: &Path) -> bool {
426426
complete_header(path).is_some_and(|(storage, h)| {
427427
header_version(&h, LOOK_FIELD) > u64::from(crate::camera_preview::LOOK_VERSION)

‎crates/engine/src/tests_import.rs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,3 +2233,60 @@ fn lossless_smart_previews_record_the_raw_decode_version_and_refresh_as_lossless
22332233
assert_eq!(crate::smart::header(&file).unwrap().0, crate::smart::Format::Lossless, "rebuilt in its format");
22342234
assert_eq!((head["source_version"].as_u64(), head["future_field"].as_u64()), (Some(u64::from(crate::smart::SOURCE_VERSION)), Some(7)), "{head}");
22352235
}
2236+
2237+
/// Round 4 review of #1328: a proxy from a newer build (either version above this build's) survives Build Smart
2238+
/// Previews whatever format is stored or preferred. A format mismatch was a reason to rebuild of its own, so a Lossless
2239+
/// proxy under the default Compact preference (or a Compact one under a Lossless preference) was rewritten by this
2240+
/// build's older decode or look and stamped with its versions: (look + 1, 0), (look - 1, source + 1) and
2241+
/// (look + 1, source + 1) all became (look, source) in the other format. The opening refresh kept them already. A
2242+
/// Compact proxy from a newer encoding (#850's `enc`) is kept the same way.
2243+
#[test]
2244+
fn proxies_from_a_newer_build_survive_build_smart_previews_in_either_format() {
2245+
use crate::smart::Format;
2246+
let (look, source) = (u64::from(crate::camera_preview::LOOK_VERSION), u64::from(crate::smart::SOURCE_VERSION));
2247+
let (mut rewritten, mut unreported) = (Vec::new(), Vec::new());
2248+
for stored in [Format::Compact, Format::Lossless] {
2249+
for preferred in [Format::Compact, Format::Lossless] {
2250+
// (look, source, a Compact proxy's encode version: #850's, format-local in a Lossless header)
2251+
let enc = crate::smart::ENCODE_VERSION;
2252+
let mut cases = vec![(look + 1, 0, None), (look - 1, source + 1, None), (look + 1, source + 1, None)];
2253+
if stored == Format::Compact {
2254+
cases.push((look, source, Some(enc + 1)));
2255+
}
2256+
for (l, s, e) in cases {
2257+
let mut f = SmartFixture::new("smartnewerformat");
2258+
if stored == Format::Lossless {
2259+
f.s.execute("library.smartPreviews", &json!({"format": "lossless"})).unwrap();
2260+
}
2261+
let name = if preferred == Format::Lossless { "lossless" } else { "compact" };
2262+
f.s.execute("library.smartPreviewsFormat", &json!({"format": name})).unwrap();
2263+
let file = f.files[0].clone();
2264+
assert_eq!(crate::smart::header(&file).unwrap().0, stored);
2265+
edit_smart_header(&file, |h| {
2266+
h["look_version"] = json!(l);
2267+
h["source_version"] = json!(s);
2268+
if let Some(e) = e {
2269+
h["enc"] = json!(e);
2270+
}
2271+
});
2272+
let before = std::fs::read(&file).unwrap();
2273+
std::fs::write(f.dir.join("source-version"), b"0\n").unwrap();
2274+
std::fs::write(f.dir.join("look-version"), b"0 0\n").unwrap();
2275+
crate::cmd::previews::refresh_stale_smart_previews(&mut f.s).unwrap().join().unwrap();
2276+
let opening = std::fs::read(&file).unwrap() == before;
2277+
let r = f.s.execute("library.smartPreviews", &json!({"ids": [f.ids[0].0]})).unwrap();
2278+
let build = std::fs::read(&file).unwrap() == before;
2279+
if !(opening && build) {
2280+
rewritten.push(format!(
2281+
"{stored:?} under {preferred:?} at ({l}, {s}, enc {e:?}): opening kept {opening}, build kept {build}, now {:?} {r}",
2282+
crate::smart::versions(&file)
2283+
));
2284+
} else if (r["refreshed"].as_u64(), r["newerKept"].as_u64()) != (Some(0), Some(1)) {
2285+
unreported.push(format!("{stored:?} under {preferred:?} at ({l}, {s}, enc {e:?}): {r}"));
2286+
}
2287+
}
2288+
}
2289+
}
2290+
assert!(rewritten.is_empty(), "{rewritten:#?}");
2291+
assert!(unreported.is_empty(), "kept, but not counted as from a newer build: {unreported:#?}");
2292+
}

‎docs/parity-checklist.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
442442
| Id | Feature | Tier | Status | Evidence | Missing / notes |
443443
|---|---|---|---|---|---|
444444
| LR-CLOUD-SYNC | Cloud sync | OOS | 🚫 | | |
445-
| LR-CLOUD-SMARTPREVIEW | Editable proxies | P2 | ✅ | `cmd:library.smartPreviews`, `cmd:library.smartPreviewsLocation`, `cmd:library.smartPreviewsFormat`, `cmd:photo.smartPreview`, `crates/engine/src/smart.rs`, `crates/ui-egui/src/panels/settings.rs` | File ▸ Previews ▸ Build / Discard Smart Previews (on a worker thread, progress and Stop like Build Previews): Compact JPEG remains the default; an opt-in per-library lossless float TIFF format preserves decoded source precision (about 40 to 50 MB in two public Sony samples). The build menu can override the format. Before Lossless builds, the app shows the estimated total size (about 39.5 MB per A7CR proxy) and destination free space, with a warning when the estimate exceeds it. Rebuilds convert from available originals and retain offline proxies; mixed-format size accounting and old JPEG decoding are supported (`docs/smart-previews.md`); with the original offline the photo renders, edits and exports (at proxy size) from its proxy; Info shows the status; the proxy folder is chosen per library (Settings → Performance → Smart previews, saved in the library): the effective path, count and size are shown, changing it needs a choice for the proxies already built (move / leave / delete), and an unavailable or unwritable folder is an error, never a fallback to the library drive; proxies are written atomically and a damaged one (cut short by a crash or a full drive) doesn't count as built, is rebuilt (`repaired`) and is never moved over a good one (issue #106). Each proxy records the version of the camera-look fit that wrote it (`look_version`, `LOOK_VERSION` in `crates/engine/src/camera_preview.rs`, bumped whenever the fit changes), and a Compact proxy its JPEG encode version (`enc`, PR #850; Lossless keeps its own format version); only raws with the per-file camera look go stale (JPEG / PNG / DNG proxies are never rebuilt for it); one from an older fit is rebuilt from its original by a background scan the first time the library is opened at a new version (a `look-version` marker in the proxy folder keeps it to once per version) and by Build Smart Previews, and kept as it is while the original is offline (`docs/camera-preview-colour.md`). Raws' proxies also record the version of the raw decode that made their source (`source_version`, `smart::SOURCE_VERSION`, bumped when the decode gives different pixels at preview size, as #1328's demosaic does for previews `files::bin_factor` can't bin); every raw developed from its sensor data goes stale for it, with or without the per-file look, and is refreshed the same way (`source-version` marker). Such a refresh, like a look refresh, develops the original read afresh, never the proxy or a source decoded from it, and replaces the proxy in its own format; the thumbnail and decoded-source invalidation that follows is the one every proxy replacement takes (below). A proxy with either version newer than this build's is never replaced automatically, and the folder markers only move up (protection that holds for builds with this check; a build that knows only the look version still rewrites a newer source version). The thumbnail cache stays in the library. Background folder migration keeps the old folder on cancellation; a thumbnail namespace saved atomically with the folder prevents stale thumbnails after a process exit at preference saving, including cleanup spawn failure. A build, discard or look refresh that ends before its thumbnail clear (a quit or crash) leaves a marker in the thumbnail folder, and the next opening uses a new namespace; on a full library drive the run clears the thumbnail cache first and after each proxy it replaces, and a discard is never refused. A run's thumbnail clear moves the cache generation on at once and removes the files without holding the generation lock (until they are gone none is read from disk), so drawing never waits for the removal. A folder move leaves a proxy that does not decode (cut short, say) in the old folder and names it. Storage-dialog text, its buttons, the format command and count plurals are translated in all nine locales. Older versions cannot read Lossless proxies and drop the format and namespace preferences (`docs/smart-previews.md`). |
445+
| LR-CLOUD-SMARTPREVIEW | Editable proxies | P2 | ✅ | `cmd:library.smartPreviews`, `cmd:library.smartPreviewsLocation`, `cmd:library.smartPreviewsFormat`, `cmd:photo.smartPreview`, `crates/engine/src/smart.rs`, `crates/ui-egui/src/panels/settings.rs` | File ▸ Previews ▸ Build / Discard Smart Previews (on a worker thread, progress and Stop like Build Previews): Compact JPEG remains the default; an opt-in per-library lossless float TIFF format preserves decoded source precision (about 40 to 50 MB in two public Sony samples). The build menu can override the format. Before Lossless builds, the app shows the estimated total size (about 39.5 MB per A7CR proxy) and destination free space, with a warning when the estimate exceeds it. Rebuilds convert from available originals and retain offline proxies; mixed-format size accounting and old JPEG decoding are supported (`docs/smart-previews.md`); with the original offline the photo renders, edits and exports (at proxy size) from its proxy; Info shows the status; the proxy folder is chosen per library (Settings → Performance → Smart previews, saved in the library): the effective path, count and size are shown, changing it needs a choice for the proxies already built (move / leave / delete), and an unavailable or unwritable folder is an error, never a fallback to the library drive; proxies are written atomically and a damaged one (cut short by a crash or a full drive) doesn't count as built, is rebuilt (`repaired`) and is never moved over a good one (issue #106). Each proxy records the version of the camera-look fit that wrote it (`look_version`, `LOOK_VERSION` in `crates/engine/src/camera_preview.rs`, bumped whenever the fit changes), and a Compact proxy its JPEG encode version (`enc`, PR #850; Lossless keeps its own format version); only raws with the per-file camera look go stale (JPEG / PNG / DNG proxies are never rebuilt for it); one from an older fit is rebuilt from its original by a background scan the first time the library is opened at a new version (a `look-version` marker in the proxy folder keeps it to once per version) and by Build Smart Previews, and kept as it is while the original is offline (`docs/camera-preview-colour.md`). Raws' proxies also record the version of the raw decode that made their source (`source_version`, `smart::SOURCE_VERSION`, bumped when the decode gives different pixels at preview size, as #1328's demosaic does for previews `files::bin_factor` can't bin); every raw developed from its sensor data goes stale for it, with or without the per-file look, and is refreshed the same way (`source-version` marker). Such a refresh, like a look refresh, develops the original read afresh, never the proxy or a source decoded from it, and replaces the proxy in its own format; the thumbnail and decoded-source invalidation that follows is the one every proxy replacement takes (below). A proxy with any version newer than this build's (look, source, or a Compact proxy's encode version) is never replaced, by the opening refresh or by Build Smart Previews, which keeps it in its stored format whatever format is preferred or asked for (`newerKept`), and the folder markers only move up (protection that holds for builds with this check; a build that knows only a newer look version still rewrites a newer source version). The thumbnail cache stays in the library. Background folder migration keeps the old folder on cancellation; a thumbnail namespace saved atomically with the folder prevents stale thumbnails after a process exit at preference saving, including cleanup spawn failure. A build, discard or look refresh that ends before its thumbnail clear (a quit or crash) leaves a marker in the thumbnail folder, and the next opening uses a new namespace; on a full library drive the run clears the thumbnail cache first and after each proxy it replaces, and a discard is never refused. A run's thumbnail clear moves the cache generation on at once and removes the files without holding the generation lock (until they are gone none is read from disk), so drawing never waits for the removal. A folder move leaves a proxy that does not decode (cut short, say) in the old folder and names it. Storage-dialog text, its buttons, the format command and count plurals are translated in all nine locales. Older versions cannot read Lossless proxies and drop the format and namespace preferences (`docs/smart-previews.md`). |
446446
| LR-AI-UPDATE-INDICATOR | AI-settings update indicator | P2 | ⬜ | | |
447447
| LR-AI-CREDITS | Generative credits | OOS | 🚫 | | |
448448

@@ -790,7 +790,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
790790

791791
| Date | Change | Summary |
792792
|---|---|---|
793-
| 2026-10-13 | patch | LR-CLOUD-SMARTPREVIEW: raws' proxies record the raw decode version in both formats and are refreshed for it (#1328); a newer proxy is never rewritten and the markers only move up; status and counts unchanged |
793+
| 2026-10-13 | patch | LR-CLOUD-SMARTPREVIEW: raws' proxies record the raw decode version in both formats and are refreshed for it (#1328); a newer proxy is never rewritten, nor converted to another format by Build Smart Previews, and the markers only move up; status and counts unchanged |
794794
| 2026-10-13 | minor | LR-IMP-FORMATS: full-size developments demosaic the mosaic white balanced as shot and tell highlight reconstruction which channels were interpolated from clipped samples (issue #1328: no yellow, green, cyan or magenta outlines on neutral edges and around clipped highlights; measured channels kept, so dark detail against a clipped sky stays); LR-EDIT-LIGHT-HIGHLIGHTS notes the full-size clip mask; LR-CLOUD-SMARTPREVIEW: raws' proxies record and refresh on the raw decode's version; statuses unchanged |
795795
| 2026-10-13 | patch | LR-CLOUD-SMARTPREVIEW: with PR #850 merged, Compact proxies are stored at JPEG quality 97 and rebuilt for an older encode version; a Lossless proxy's own `enc` is not read as that version; status and counts unchanged |
796796
| 2026-10-13 | patch | LR-CLOUD-SMARTPREVIEW: a thumbnail clear moves the generation on under a short lock and removes the files after it, reading none from disk meanwhile (100,000 files held drawing for 6.7 s); status and counts unchanged |

0 commit comments

Comments
 (0)