Reels pre-gen: make dedup cache-key-aware so key changes regenerate

exists_fresh only matched (span, library, render_version, age), so a
cache-key change that doesn't bump RENDER_VERSION (e.g. the max_segments
alignment, or any future selection-logic tweak) left last night's ledger
row looking 'fresh' — the nightly run would skip and the orphaned reel
would persist. Dedup now compares the stored cache_key to the freshly
computed key (and confirms the mp4 exists), so a changed key forces a
regen within the freshness window. exists_fresh stays as the HTTP
endpoint's fast gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cameron Cordes
2026-06-13 23:14:39 -04:00
parent 19fc1bbdf8
commit b52b1eb323
+20 -5
View File
@@ -1095,14 +1095,29 @@ async fn pregen_one(
}; };
let min_generated_at = now - (max_age_hours as i64 * 3600); let min_generated_at = now - (max_age_hours as i64 * 3600);
let is_fresh = { // Skip only when a fresh ledger row points at THIS exact cache key (same
// media, params, render version) and its file still exists. Comparing the
// stored cache_key — not just (span, library) — means a key change from
// selection-logic/params drift that doesn't bump RENDER_VERSION still forces
// a regen within the freshness window, instead of leaving a stale row that
// points at an orphaned reel.
let already_current = {
let mut dao = app_state.precomputed_reel_dao.lock().expect("lock"); let mut dao = app_state.precomputed_reel_dao.lock().expect("lock");
dao.exists_fresh(&ctx, span, library, RENDER_VERSION as i32, min_generated_at) matches!(
.unwrap_or(false) dao.latest_for(&ctx, span, library),
Ok(Some(row))
if row.cache_key == key
&& row.render_version == RENDER_VERSION as i32
&& row.generated_at >= min_generated_at
) && reel_mp4_path(app_state, &key).exists()
}; };
if is_fresh { if already_current {
log::info!("Fresh precomputed reel exists for span={}, skipping", span); log::info!(
"Fresh precomputed reel already current for span={} key={}, skipping",
span,
key
);
return Ok(()); return Ok(());
} }