diff --git a/src/worker/job_worker.rs b/src/worker/job_worker.rs index b65b047..4e81e4c 100644 --- a/src/worker/job_worker.rs +++ b/src/worker/job_worker.rs @@ -1786,23 +1786,49 @@ impl JobWorker { }); } - // 🚀 P3 Trigger: Identity Agent (Face + ASRX) + // 🚀 P3 Trigger: Identity Agent (Face + ASRX + has seed identities) if has_face && has_asrx { - info!("📝 Prerequisites met for Identity Agent. Starting analysis..."); - let db_clone = self.db.clone(); - let redis_clone = self.redis.clone(); - let uuid_clone = uuid.to_string(); - tokio::spawn(async move { - match run_identity_agent(&db_clone, &uuid_clone, Some(redis_clone.clone())).await { - Ok(()) => { - info!("✅ Identity Agent completed for {}", uuid_clone); - let mut pp = PipelineProgress::new(&uuid_clone); - pp.update_stage("identity_agent", 1.0, "completed", None); - publish_pipeline_progress(redis_clone.as_ref(), &uuid_clone, &pp).await; + // Check if file has seed identity photos in Qdrant _seeds collection + let has_seeds = { + use crate::core::db::qdrant_db::QdrantDb; + let qdrant = QdrantDb::new(); + let schema = std::env::var("DATABASE_SCHEMA").unwrap_or_else(|_| "dev".to_string()); + let seeds_collection = if schema == "public" { + "momentry_public_seeds" + } else { + &format!("momentry_{}_seeds", schema) + }; + let filter = serde_json::json!({ + "must": [{"key": "file_uuid", "match": {"value": uuid}}] + }); + match qdrant.scroll_all_points("_seeds", filter, 1).await { + Ok(points) => !points.is_empty(), + Err(e) => { + warn!("Failed to check _seeds for {}: {}", uuid, e); + false } - Err(e) => error!("❌ Identity Agent failed for {}: {}", uuid_clone, e), } - }); + }; + + if has_seeds { + info!("📝 Prerequisites met for Identity Agent (has seeds). Starting analysis..."); + let db_clone = self.db.clone(); + let redis_clone = self.redis.clone(); + let uuid_clone = uuid.to_string(); + tokio::spawn(async move { + match run_identity_agent(&db_clone, &uuid_clone, Some(redis_clone.clone())).await { + Ok(()) => { + info!("✅ Identity Agent completed for {}", uuid_clone); + let mut pp = PipelineProgress::new(&uuid_clone); + pp.update_stage("identity_agent", 1.0, "completed", None); + publish_pipeline_progress(redis_clone.as_ref(), &uuid_clone, &pp).await; + } + Err(e) => error!("❌ Identity Agent failed for {}: {}", uuid_clone, e), + } + }); + } else { + info!("📝 Skipping Identity Agent for {} (no seed identities)", uuid); + } } // 🚀 P4 Trigger: TKG Build (Face + ASRX) → then Rule2 ingestion