fix: P5 VLM trigger after Face Dedup + sync label to on-disk JSON
- Move P5 VLM trigger from TKG block to Face Dedup block
(trace_profiles DB is written by update_face_track_labels, not TKG)
- Update on-disk trace_profile.json label when Face Dedup updates names
- Add output_dir and redis_clone to Face Dedup spawn scope
Pipeline flow:
Face → P2 Tracing → P3 Cluster → update_face_track_labels
→ DB trace_profiles + on-disk JSON updated
→ P5 VLM triggered with verified trace count
This commit is contained in:
+43
-66
@@ -2645,7 +2645,9 @@ impl JobWorker {
|
||||
>(cluster_data.clone())
|
||||
{
|
||||
let db_clone = self.db.clone();
|
||||
let redis_clone = self.redis.clone();
|
||||
let uuid_clone = uuid.to_string();
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.clone();
|
||||
tokio::spawn(async move {
|
||||
match Self::update_face_track_labels(
|
||||
&db_clone,
|
||||
@@ -2663,6 +2665,32 @@ impl JobWorker {
|
||||
uuid_clone, e
|
||||
),
|
||||
}
|
||||
|
||||
// P5: VLM Summary — after face dedup writes trace_profiles
|
||||
let face_count = Self::verify_traces_ready(&db_clone.pool(), &uuid_clone).await;
|
||||
if face_count > 0 {
|
||||
info!("[VLM] Starting for {}: {} traces verified", uuid_clone, face_count);
|
||||
let db_p5 = db_clone.clone();
|
||||
let redis_p5 = redis_clone.clone();
|
||||
let uuid_p5 = uuid_clone.clone();
|
||||
let output_dir_p5 = output_dir.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(300),
|
||||
crate::core::processor::vlm_summary::generate_vlm_summaries(
|
||||
&db_p5, &uuid_p5, &output_dir_p5, Some(redis_p5),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
match result {
|
||||
Ok(stats) => info!(
|
||||
"[VLM] Completed for {}: {}/{} summarized, {} embedded",
|
||||
uuid_p5, stats.summarized, stats.total, stats.embedded
|
||||
),
|
||||
Err(_) => error!("[VLM] Timed out after 5 min for {}", uuid_p5),
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
warn!("Failed to parse face_cluster.json for {}", uuid);
|
||||
@@ -2963,39 +2991,6 @@ impl JobWorker {
|
||||
error!("❌ TKG build failed for {}: {}", uuid_clone, e)
|
||||
}
|
||||
}
|
||||
|
||||
// 🚀 P5 Trigger: VLM Summary
|
||||
// Runs AFTER build_tkg().await completes — DB is already committed.
|
||||
// verify_traces_ready confirms data visibility before spawning VLM.
|
||||
let face_count = Self::verify_traces_ready(db_clone.pool(), &uuid_clone).await;
|
||||
if face_count > 0 {
|
||||
info!("[VLM] Starting for {}: {} traces verified", uuid_clone, face_count);
|
||||
let db_p5 = db_clone.clone();
|
||||
let redis_p5 = redis_clone.clone();
|
||||
let uuid_p5 = uuid_clone.clone();
|
||||
let output_dir_p5 = output_dir_clone.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(300),
|
||||
vlm_summary::generate_vlm_summaries(
|
||||
&db_p5,
|
||||
&uuid_p5,
|
||||
&output_dir_p5,
|
||||
Some(redis_p5),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
match result {
|
||||
Ok(stats) => info!(
|
||||
"[VLM] Completed for {}: {}/{} summarized, {} embedded",
|
||||
uuid_p5, stats.summarized, stats.total, stats.embedded
|
||||
),
|
||||
Err(_) => error!("[VLM] Timed out after 5 min for {}", uuid_p5),
|
||||
}
|
||||
});
|
||||
} else {
|
||||
info!("[VLM] Skipping for {} (no verified face traces)", uuid_clone);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -3078,37 +3073,6 @@ impl JobWorker {
|
||||
}
|
||||
Err(e) => error!("❌ TKG build failed for {}: {}", uuid_clone, e),
|
||||
}
|
||||
|
||||
// 🚀 P5 Trigger: VLM Summary (no-face TKG path)
|
||||
let face_count = Self::verify_traces_ready(db_clone.pool(), &uuid_clone).await;
|
||||
if face_count > 0 {
|
||||
info!("[VLM] Starting for {}: {} traces verified", uuid_clone, face_count);
|
||||
let db_p5 = db_clone.clone();
|
||||
let redis_p5 = redis_clone.clone();
|
||||
let uuid_p5 = uuid_clone.clone();
|
||||
let output_dir_p5 = output_dir_clone.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(300),
|
||||
vlm_summary::generate_vlm_summaries(
|
||||
&db_p5,
|
||||
&uuid_p5,
|
||||
&output_dir_p5,
|
||||
Some(redis_p5),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
match result {
|
||||
Ok(stats) => info!(
|
||||
"[VLM] Completed for {}: {}/{} summarized, {} embedded",
|
||||
uuid_p5, stats.summarized, stats.total, stats.embedded
|
||||
),
|
||||
Err(_) => error!("[VLM] Timed out after 5 min for {}", uuid_p5),
|
||||
}
|
||||
});
|
||||
} else {
|
||||
info!("[VLM] Skipping for {} (no verified face traces)", uuid_clone);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3419,7 +3383,6 @@ impl JobWorker {
|
||||
async fn verify_traces_ready(pool: &PgPool, uuid: &str) -> i64 {
|
||||
let tp_table = crate::core::db::schema::table_name("trace_profiles");
|
||||
let tkg_table = crate::core::db::schema::table_name("tkg_nodes");
|
||||
// JOIN ensures trace_profiles has matching tkg_nodes face_track entries
|
||||
let count: i64 = sqlx::query_scalar(&format!(
|
||||
"SELECT COUNT(*) FROM {tp_table} tp \
|
||||
INNER JOIN {tkg_table} tn \
|
||||
@@ -3514,9 +3477,23 @@ impl JobWorker {
|
||||
.context("Failed to insert tkg_nodes")?;
|
||||
}
|
||||
|
||||
// Sync name to trace_profiles
|
||||
// Sync name to trace_profiles DB + on-disk JSON
|
||||
let _ =
|
||||
schema::upsert_trace_profile(db.pool(), uuid, *trace_id as i32, &label, None).await;
|
||||
|
||||
// Update on-disk trace_profile.json
|
||||
let output_dir = crate::core::config::OUTPUT_DIR.as_str();
|
||||
let profile_path = crate::core::file_profile::FaceTraceProfile::profile_path(
|
||||
output_dir, uuid, *trace_id,
|
||||
);
|
||||
if profile_path.exists() {
|
||||
if let Ok(content) = std::fs::read_to_string(&profile_path) {
|
||||
if let Ok(mut profile) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
profile["label"] = serde_json::json!(label);
|
||||
let _ = std::fs::write(&profile_path, serde_json::to_string_pretty(&profile).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also update traces that are NOT in any cluster (keep default Person_N name)
|
||||
|
||||
Reference in New Issue
Block a user