fix: TKG build waits for face_traced.json to ensure face_track nodes are built

- Add check for face_traced.json existence before spawning TKG build
- Prevents race condition where TKG reads Qdrant before trace_id is written
- Logs clearly when waiting and when proceeding
This commit is contained in:
Accusys
2026-07-20 22:20:33 +08:00
parent 70e6915246
commit 5ec18ed520
+24 -6
View File
@@ -2102,12 +2102,29 @@ impl JobWorker {
if tkg_done {
info!("✅ TKG already built for {}, skipping spawn", uuid);
} else {
info!("📝 Prerequisites met for TKG Build. Starting graph construction...");
let db_clone = self.db.clone();
let redis_clone = self.redis.clone();
let uuid_clone = uuid.to_string();
let output_dir_clone = crate::core::config::OUTPUT_DIR.clone();
tokio::spawn(async move {
// Check if face_traced.json exists (store_traced_faces.py completed)
let traced_path = format!(
"{}{}.face_traced.json",
crate::core::config::OUTPUT_DIR.as_str().trim_end_matches('/'),
uuid
);
if !std::path::Path::new(&traced_path).exists() {
info!(
"⏳ TKG build waiting for face_traced.json: {} (file_uuid={})",
traced_path, uuid
);
// Don't spawn TKG yet, wait for next poll
} else {
info!(
"📝 Prerequisites met for TKG Build (face_traced.json exists): {}",
uuid
);
let db_clone = self.db.clone();
let redis_clone = self.redis.clone();
let uuid_clone = uuid.to_string();
let output_dir_clone = crate::core::config::OUTPUT_DIR.clone();
tokio::spawn(async move {
match crate::core::processor::tkg::build_tkg(
&db_clone,
&uuid_clone,
@@ -2191,6 +2208,7 @@ impl JobWorker {
Err(e) => error!("❌ TKG build failed for {}: {}", uuid_clone, e),
}
});
}
}
}