feat: add TraceArtifacts phase + VLM waits for all key_frame.jpg

- Add TraceArtifacts phase to TkgPhase enum (phase 18)
- Report progress as key_frame.jpg/key_face.jpg are created
- VLM trigger now polls until ALL key_frame.jpg files exist
  (was: started after TKG build, before artifacts were ready)
- Add iron rule to AGENTS.md: ask before removing data

Tested: Gamma 8 (27 traces) → 27/27 VLM summaries completed
This commit is contained in:
Accusys
2026-08-24 19:13:11 +08:00
parent d29b4804af
commit 9f12e835b8
43 changed files with 3993 additions and 491 deletions
+54 -26
View File
@@ -2665,32 +2665,6 @@ 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);
@@ -2938,6 +2912,60 @@ impl JobWorker {
)
.await;
// P5: VLM Summary — wait for ALL key_frame.jpg files to be ready
let face_count = r.face_track_nodes;
if face_count > 0 {
let output_dir_wait = output_dir_clone.clone();
let uuid_wait = uuid_clone.clone();
let db_wait = db_clone.clone();
let redis_wait = redis_clone.clone();
tokio::spawn(async move {
// Poll until ALL key_frame.jpg files exist (max 10 min)
let max_attempts = 600; // 10 min / 1s
let mut ready_count = 0i64;
for attempt in 0..max_attempts {
// Count traces with key_frame.jpg on disk
let output_dir = output_dir_wait.as_str();
let trace_dir = std::path::PathBuf::from(output_dir)
.join(&uuid_wait);
ready_count = if trace_dir.exists() {
std::fs::read_dir(&trace_dir)
.ok()
.map(|entries| {
entries.filter_map(|e| e.ok()).filter(|e| {
e.path().join("key_frame.jpg").exists()
}).count() as i64
})
.unwrap_or(0)
} else {
0
};
if ready_count >= face_count as i64 && ready_count > 0 {
info!("[VLM-wait] All {}/{} key_frame.jpg ready for {}", ready_count, face_count, uuid_wait);
break;
}
if attempt % 30 == 0 {
info!("[VLM-wait] {}/{} key_frame.jpg ready for {} (waiting...)", ready_count, face_count, uuid_wait);
}
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
if ready_count >= face_count as i64 {
info!("[VLM] Starting for {}: {} traces verified", uuid_wait, ready_count);
let db_p5 = db_wait.clone();
let redis_p5 = redis_wait.clone();
let uuid_p5 = uuid_wait.clone();
let output_dir_p5 = output_dir_wait.clone();
crate::core::processor::vlm_summary::generate_vlm_summaries(
&db_p5, &uuid_p5, &output_dir_p5, Some(redis_p5),
).await;
} else {
warn!("[VLM] Skipping for {} (only {}/{} key_frame.jpg ready)", uuid_wait, ready_count, face_count);
}
});
}
// Trigger Rule 2 ingestion after TKG complete
if total_edges > 0 {
// Mark rule2_ingestion as running