Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Reuse VAE fingerprint checks between generations

Bitti2cb12d65613f
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index cd63d88..686644f 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -16,6 +16,8 @@ This alpha update adds Prompt video scenes, agent image drafts, Sol attention an
## Fixes and improvements
+- Generation effects reuse VAE fingerprints between jobs, removing repeated full-file calibration checks for unchanged VAEs. Changed or replaced VAEs are verified again; saved calibrations remain reusable after restarting.
+
- Renamed image roots on the still image creation page now retain their names when switching images and reopening projects.
- Image edits keep the original as the parent with its saved prompt and settings. Child results open as normal images ready for further edits; selecting images does not create editing copies.
- Whole-image edits disable feathering at the native generation boundary, including requests with missing or previously saved feather settings.
diff --git a/docs/slopfab-compatibility.md b/docs/slopfab-compatibility.md
index 9973617..1d13ed7 100644
--- a/docs/slopfab-compatibility.md
+++ b/docs/slopfab-compatibility.md
@@ -20,7 +20,13 @@ The first active request calibrates its VAE automatically using 64 colors at
256 pixels. Calibration runs on the generation worker, reports progress and
honors cancellation. Completed archives are cached under `lcs` beside the
host's diagnostic log, keyed by full VAE SHA-256, calibration format and
-parameters. Corrupt archives are regenerated. Planning never calibrates or
+parameters. Full-file fingerprints are cached in both Slopus and SlopFab for
+the app/worker session. Each reuse checks file identity, size, modification and
+filesystem change times, so edits and replacements trigger fresh verification.
+The first use after a restart verifies the VAE again but reuses its saved
+calibration. Cached checks do not show calibration progress. Slopus retains the
+LCS library cache between isolated jobs while still releasing idle GPU model
+buffers. Corrupt archives are regenerated. Planning never calibrates or
runs inference. The generation request snapshots the archive before sampling;
region masks use fractional coverage of the resolved latent patch grid.
@@ -29,7 +35,7 @@ workers from silently dropping them. Each worker calibrates and caches its
own VAE. Update workers alongside the desktop app. A runtime missing the LCS
exports reports an explicit upgrade error.
-Both bundled libraries are built from SlopFab commit `e3eb8c4` (API 1.31.0)
+Both bundled libraries are built from SlopFab commit `274ce2e` (API 1.31.0)
with FFmpeg disabled. Windows and Linux C API and embedded-tokenizer checks
pass, including the previously failing malformed LCS settings checks. Slopus
checks cover UI authoring, project persistence, request snapshots, worker
diff --git a/lib/slopfab/libslopfab.so b/lib/slopfab/libslopfab.so
index 74aa52e..ffc7055 100644
--- a/lib/slopfab/libslopfab.so
+++ b/lib/slopfab/libslopfab.so
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:2dafe3687c2d9711acc7c24449a82aa6fda0abaef286f693454cc4c2a405f545
-size 21328208
+oid sha256:93d602150b7967b3e299e53aa40136c3d915e5a5ebf93455562a80f52cc77879
+size 21338136
diff --git a/lib/slopfab/slopfab.dll b/lib/slopfab/slopfab.dll
index 5e9b321..303ad97 100644
--- a/lib/slopfab/slopfab.dll
+++ b/lib/slopfab/slopfab.dll
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:1d8761ce4c7cf59472b8bbbe531ceeedcc46d450d2e9dfed5684a18547ad71ca
-size 18535424
+oid sha256:78eefe128a8a3e9b9655f8fbeb999d7b3df459df779fd464f0f4934287c67afa
+size 18542080
diff --git a/src-tauri/core/src/slopfab/lcs.rs b/src-tauri/core/src/slopfab/lcs.rs
index a819c6a..b5c4461 100644
--- a/src-tauri/core/src/slopfab/lcs.rs
+++ b/src-tauri/core/src/slopfab/lcs.rs
@@ -1,23 +1,33 @@
use super::{events::NativeEvent, ffi::{Api, RequestHandle}, platform::ComputePlatform, runtime::QueueItem, types::ProgressEvent};
use sha2::{Digest, Sha256};
-use std::{fs::File, io::Read, path::{Path, PathBuf}, sync::atomic::{AtomicBool, Ordering}, time::Instant};
+use std::{io::Read, path::{Path, PathBuf}, sync::atomic::{AtomicBool, Ordering}, time::Instant};
-fn calibration_path(directory: &Path, vae: &Path, cancel: &AtomicBool) -> Result<PathBuf, String> {
- let mut source = File::open(vae).map_err(|e| format!("Cannot read the VAE for generation effects: {e}"))?;
- let mut hash = Sha256::new();
- let mut buffer = vec![0; 1024 * 1024];
- loop {
- if cancel.load(Ordering::Acquire) { return Err("Generation effects preparation cancelled.".into()); }
- let count = source.read(&mut buffer).map_err(|e| e.to_string())?;
- if count == 0 { break; }
- hash.update(&buffer[..count]);
- }
- Ok(directory.join(format!("h3-v1-64-256-{:x}.safetensors", hash.finalize())))
+fn calibration_path(directory: &Path, vae: &Path, cancel: &AtomicBool, mut checking: impl FnMut()) -> Result<PathBuf, String> {
+ use super::lcs_fingerprint::{check_cancel, Fingerprints};
+ static FINGERPRINTS: std::sync::OnceLock<std::sync::Mutex<Fingerprints>> = std::sync::OnceLock::new();
+ let digest = FINGERPRINTS.get_or_init(Default::default).lock().map_err(|_| "VAE fingerprint cache lock failed.")?
+ .get(vae, cancel, |source| {
+ checking();
+ let mut hash = Sha256::new();
+ let mut buffer = vec![0; 1024 * 1024];
+ loop {
+ check_cancel(cancel)?;
+ let count = source.read(&mut buffer).map_err(|e| e.to_string())?;
+ if count == 0 { break; }
+ hash.update(&buffer[..count]);
+ }
+ Ok(format!("{:x}", hash.finalize()))
+ })?;
+ Ok(directory.join(format!("h3-v1-64-256-{digest}.safetensors")))
}
pub(super) fn prepare(api: &Api, request: &RequestHandle, item: &QueueItem, platform: ComputePlatform) -> Result<bool, String> {
let Some(settings) = item.request.generation_effects.as_ref().map(|e| e.native_settings()).transpose()?.flatten() else { return Ok(false); };
api.require_lcs()?;
+ // Retain the library's small fingerprint cache across isolated jobs, including
+ // Vulkan hosts. The queue still releases reused model/GPU buffers when idle.
+ static RUNTIME: std::sync::Mutex<Option<Api>> = std::sync::Mutex::new(None);
+ *RUNTIME.lock().map_err(|_| "LCS runtime cache lock failed.")? = Some(api.clone());
let started = Instant::now();
let report = |completed, total| {
(item.events)(NativeEvent::Progress(ProgressEvent {
@@ -28,12 +38,12 @@ pub(super) fn prepare(api: &Api, request: &RequestHandle, item: &QueueItem, plat
}));
!item.cancel.load(Ordering::Acquire)
};
- if !report(0, 0) { return Err("Generation effects preparation cancelled.".into()); }
+ super::lcs_fingerprint::check_cancel(&item.cancel)?;
let vae = item.configuration.models.iter().find(|(id, _, _)| *id == 3).and_then(|(_, _, path)| path.as_deref()).ok_or("Generation effects require a video VAE.")?;
let log_path = PathBuf::from(crate::diagnostics::log_info()?.path);
let directory = log_path.parent().ok_or("Cannot locate the generation effects cache.")?.join("lcs");
std::fs::create_dir_all(&directory).map_err(|e| format!("Cannot create the generation effects cache: {e}"))?;
- let path = calibration_path(&directory, vae, &item.cancel)?;
+ let path = calibration_path(&directory, vae, &item.cancel, || { report(0, 0); })?;
let settings = settings.to_string();
// set_lcs snapshots the archive, so a valid cache needs no GPU calibration.
if path.is_file() && api.set_lcs(request, &path, &settings).is_ok() { return Ok(true); }
@@ -55,11 +65,11 @@ mod tests {
let vae = directory.path().join("vae");
let cancel = AtomicBool::new(false);
std::fs::write(&vae, b"first").unwrap();
- let first = calibration_path(directory.path(), &vae, &cancel).unwrap();
- assert_eq!(first, calibration_path(directory.path(), &vae, &cancel).unwrap());
+ let first = calibration_path(directory.path(), &vae, &cancel, || {}).unwrap();
+ assert_eq!(first, calibration_path(directory.path(), &vae, &cancel, || panic!("cached VAE must not report another calibration check")).unwrap());
std::fs::write(&vae, b"other").unwrap();
- assert_ne!(first, calibration_path(directory.path(), &vae, &cancel).unwrap());
+ assert_ne!(first, calibration_path(directory.path(), &vae, &cancel, || {}).unwrap());
cancel.store(true, Ordering::Release);
- assert!(calibration_path(directory.path(), &vae, &cancel).unwrap_err().contains("cancelled"));
+ assert!(calibration_path(directory.path(), &vae, &cancel, || {}).unwrap_err().contains("cancelled"));
}
}
diff --git a/src-tauri/core/src/slopfab/lcs_fingerprint.rs b/src-tauri/core/src/slopfab/lcs_fingerprint.rs
new file mode 100644
index 0000000..4faaa3e
--- /dev/null
+++ b/src-tauri/core/src/slopfab/lcs_fingerprint.rs
@@ -0,0 +1,103 @@
+//! Avoid rereading multi-GB VAEs while their identity and change stamps match.
+use std::{collections::BTreeMap, fs::File, path::{Path, PathBuf}, sync::atomic::{AtomicBool, Ordering}, time::SystemTime};
+
+#[derive(PartialEq, Eq)]
+struct FileStamp {
+ bytes: u64,
+ modified: SystemTime,
+ identity: [u64; 4],
+}
+
+impl FileStamp {
+ fn read(file: &File) -> Result<Self, String> {
+ let metadata = file.metadata().map_err(|e| e.to_string())?;
+ #[cfg(unix)]
+ let identity = {
+ use std::os::unix::fs::MetadataExt;
+ [metadata.dev(), metadata.ino(), metadata.ctime() as u64, metadata.ctime_nsec() as u64]
+ };
+ #[cfg(windows)]
+ let identity = {
+ use std::os::windows::io::AsRawHandle;
+ use windows_sys::Win32::Storage::FileSystem::{GetFileInformationByHandle, GetFileInformationByHandleEx, BY_HANDLE_FILE_INFORMATION, FILE_BASIC_INFO, FileBasicInfo};
+ let mut info: BY_HANDLE_FILE_INFORMATION = unsafe { std::mem::zeroed() };
+ let mut basic: FILE_BASIC_INFO = unsafe { std::mem::zeroed() };
+ let handle = file.as_raw_handle();
+ // ChangeTime also detects same-size edits whose mtime was restored.
+ if unsafe { GetFileInformationByHandle(handle, &mut info) } == 0 || unsafe {
+ GetFileInformationByHandleEx(handle, FileBasicInfo, (&mut basic as *mut FILE_BASIC_INFO).cast(), std::mem::size_of::<FILE_BASIC_INFO>() as u32)
+ } == 0 { return Err(std::io::Error::last_os_error().to_string()); }
+ [u64::from(info.dwVolumeSerialNumber), u64::from(info.nFileIndexHigh), u64::from(info.nFileIndexLow), basic.ChangeTime as u64]
+ };
+ Ok(Self { bytes: metadata.len(), modified: metadata.modified().map_err(|e| e.to_string())?, identity })
+ }
+}
+
+#[derive(Default)]
+pub(super) struct Fingerprints(BTreeMap<PathBuf, (FileStamp, String)>);
+
+pub(super) fn check_cancel(cancel: &AtomicBool) -> Result<(), String> {
+ if cancel.load(Ordering::Acquire) { Err("Generation effects preparation cancelled.".into()) } else { Ok(()) }
+}
+
+impl Fingerprints {
+ pub(super) fn get(&mut self, vae: &Path, cancel: &AtomicBool, hash: impl FnOnce(&mut File) -> Result<String, String>) -> Result<String, String> {
+ check_cancel(cancel)?;
+ let path = vae.canonicalize().map_err(|e| format!("Cannot locate the VAE for generation effects: {e}"))?;
+ let mut file = File::open(&path).map_err(|e| format!("Cannot read the VAE for generation effects: {e}"))?;
+ let stamp = FileStamp::read(&file)?;
+ if let Some((cached_stamp, digest)) = self.0.get(&path) {
+ if cached_stamp == &stamp { return Ok(digest.clone()); }
+ }
+ // Remove obsolete entries even if hashing is subsequently cancelled.
+ self.0.remove(&path);
+ let digest = hash(&mut file)?;
+ check_cancel(cancel)?;
+ if FileStamp::read(&file)? != stamp || FileStamp::read(&File::open(&path).map_err(|e| e.to_string())?)? != stamp {
+ return Err("The VAE changed while checking generation effects. Retry generation.".into());
+ }
+ if self.0.len() >= 32 { self.0.clear(); }
+ self.0.insert(path, (stamp, digest.clone()));
+ Ok(digest)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::{fs, io::Read};
+ fn hash(file: &mut File) -> Result<String, String> {
+ let mut value = String::new(); file.read_to_string(&mut value).map_err(|e| e.to_string())?; Ok(value)
+ }
+ #[test]
+ fn unchanged_vae_is_not_read_and_replacements_and_edits_invalidate() {
+ let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("vae");
+ fs::write(&path, "first").unwrap();
+ let cancel = AtomicBool::new(false); let mut cache = Fingerprints::default();
+ assert_eq!(cache.get(&path, &cancel, hash).unwrap(), "first");
+ assert_eq!(cache.get(&path, &cancel, |_| panic!("unchanged VAE must not be read")).unwrap(), "first");
+ let time = fs::metadata(&path).unwrap().modified().unwrap();
+ fs::write(&path, "other").unwrap();
+ File::options().write(true).open(&path).unwrap().set_modified(time).unwrap();
+ assert_eq!(cache.get(&path, &cancel, hash).unwrap(), "other");
+ let replacement = dir.path().join("replacement"); fs::write(&replacement, "third").unwrap();
+ File::options().write(true).open(&replacement).unwrap().set_modified(time).unwrap();
+ fs::remove_file(&path).unwrap(); fs::rename(replacement, &path).unwrap();
+ assert_eq!(cache.get(&path, &cancel, hash).unwrap(), "third");
+ fs::remove_file(&path).unwrap();
+ assert!(cache.get(&path, &cancel, hash).is_err());
+ }
+ #[test]
+ fn failed_cancelled_and_changed_reads_are_never_cached() {
+ let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("vae");
+ fs::write(&path, "first").unwrap();
+ let cancel = AtomicBool::new(false); let mut cache = Fingerprints::default();
+ assert!(cache.get(&path, &cancel, |_| Err("read error".into())).is_err());
+ assert!(cache.get(&path, &cancel, |_| { cancel.store(true, Ordering::Release); Ok("bad".into()) }).is_err());
+ cancel.store(false, Ordering::Release);
+ assert!(cache.get(&path, &cancel, |_| { fs::write(&path, "changed").unwrap(); Ok("bad".into()) }).is_err());
+ assert_eq!(cache.get(&path, &cancel, hash).unwrap(), "changed");
+ cancel.store(true, Ordering::Release);
+ assert!(cache.get(&path, &cancel, |_| panic!("cancel before cache lookup")).is_err());
+ }
+}
diff --git a/src-tauri/core/src/slopfab/mod.rs b/src-tauri/core/src/slopfab/mod.rs
index add9168..5426fc9 100644
--- a/src-tauri/core/src/slopfab/mod.rs
+++ b/src-tauri/core/src/slopfab/mod.rs
@@ -16,6 +16,7 @@ mod events;
mod ffi;
mod generation;
mod lcs;
+mod lcs_fingerprint;
mod h3;
mod icons;
mod planning;