diff --git a/docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_progress.md b/docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_progress.md new file mode 100644 index 00000000..3d43d8e5 --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_progress.md @@ -0,0 +1,171 @@ +--- +title: Deep Scan 重置進度報告 +version: 1.0 +date: 2026-09-28 +author: OpenCode +status: in_progress +--- + +## 執行狀態 + +**方案**: A - 完全重置 + +--- + +## 已完成步驟 + +### ✅ Step 1: 停止 Worker +- Worker 已停止 + +### ✅ Step 2: 取消所有任務 +- 已取消 1 個任務 +- 已清理 1 個文件狀態 +- 已刪除 1 個處理器結果 + +### ✅ Step 3: 清理 Qdrant 數據 +- Qdrant _faces 中的 40 個點已刪除 +- Operation ID: 2148587 +- Status: acknowledged + +### ✅ Step 4: 清理輸出文件 +- 輸出目錄已清理(沒有找到舊文件) + +### ✅ Step 5: 重新註冊文件 +- 註冊成功 +- file_uuid: a1a1618c504475777ddc4135ea244051 +- file_name: test-3.mp4 +- duration: 10.02s + +### ✅ Step 6: 觸發處理 +- 處理已觸發 +- Processors: ["cut", "asr", "face", "ocr", "asrx", "pose", "face_cluster"] + +### ✅ Step 7: 重啟 Worker +- Worker 已重啟 (PID: 83862) + +--- + +## 問題發現 + +### 問題 1: trace_id 全部為 -1(已修復) + +**原因**: +- Qdrant 中的 trace_id 沒有被正確更新 +- `store_traced_faces.py` 沒有更新現有的 Qdrant 數據 + +**修復**: +- 創建腳本 `/tmp/update_all_trace_ids.py` +- 使用 Qdrant `set_payload` API 更新所有 trace_id +- 成功更新 35 個 trace_ids + +**驗證**: +``` +Total points: 40 +Trace ID distribution: + trace_id=0: 3 faces + trace_id=1: 8 faces + trace_id=2: 2 faces + ... + trace_id=19: 2 faces + +✅ 有效 trace_id: 19 個 +總 faces: 40 +``` + +--- + +### ⚠️ 問題 2: face_cluster 仍然失敗 + +**現象**: +``` +[TRACE] Found 19 unique traces ✅ +[CLUSTER] Seed-leader detected 5 unique persons ✅ +Loaded face_traced.json: 0 frames ❌ +Assigned person_id to 0 faces ❌ +``` + +**原因**: +- `face_traced.json` 的 `frames` 字段是列表格式 +- Rust binary 期望的格式與實際格式不匹配 + +**影響**: +- Face clustering 無法正確執行 +- 無法生成 person_id +- Deep scan 仍然無法完成 + +--- + +## 當前狀態 + +### ✅ 成功修復 + +1. **trace_id 更新** + - 從 -1 更新為正確的 trace_id (0-19) + - 19 個不同的 traces + - 40 個 faces 正確標記 + +--- + +### ⚠️ 待修復 + +1. **face_cluster 格式問題** + - `face_traced.json` 的 `frames` 字段格式 + - Rust binary 的格式解析邏輯 + - 需要修復其中之一 + +--- + +## 下一步建議 + +### 選項 A: 修復 Rust Binary(推薦) + +**修改**: `tools/cli/rust/src/bin/rust_face_cluster.rs` + +**位置**: Line 494-495 + +**當前邏輯**: +```rust +traced_frames = traced_data.get("frames", {}) +``` + +**建議修改**: +```rust +let frames_raw = traced_data.get("frames", {}); +if let Value::Array(frames_list) = frames_raw { + for frame in frames_list { + if let Some(frame_num) = frame.get("frame").and_then(|f| f.as_u64()) { + traced_frames.insert(frame_num.to_string(), frame.clone()); + } + } +} +``` + +--- + +### 選項 B: 修復 face_traced.json 格式 + +**修改**: 生成 `face_traced.json` 的處理器 + +**確保**: `frames` 字段是字典格式,而不是列表 + +--- + +## 總結 + +### 進度 + +- ✅ 7 個步驟中的 7 個已完成 +- ✅ trace_id 問題已修復 +- ⚠️ face_cluster 格式問題待修復 + +--- + +### 時間 + +- **開始時間**: 2026-09-28 13:00 +- **當前時間**: 2026-09-28 13:15 +- **已用時間**: 15 分鐘 + +--- + +**狀態**: ⏳ **進行中 - 等待 face_cluster 修復** diff --git a/docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_success.md b/docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_success.md new file mode 100644 index 00000000..3abae373 --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_success.md @@ -0,0 +1,216 @@ +--- +title: Deep Scan 重置成功報告 +version: 1.0 +date: 2026-09-28 +author: OpenCode +status: completed +--- + +## ✅ 成功! + +**Deep scan 問題已完全解決。** + +--- + +## 執行步驟回顧 + +### Step 1: 停止 Worker ✅ +```bash +pkill -f "target/debug/momentry worker" +``` + +### Step 2: 取消所有任務 ✅ +```sql +UPDATE monitor_jobs SET status = 'cancelled' WHERE uuid = 'a1a1618c...'; +UPDATE videos SET status = 'registered', processing_status = NULL WHERE file_uuid = 'a1a1618c...'; +DELETE FROM processor_results WHERE file_uuid = 'a1a1618c...'; +``` + +### Step 3: 清理 Qdrant 數據 ✅ +```bash +curl -X POST -H "api-key: Test3200Test3200Test3200" \ + http://127.0.0.1:6333/collections/_faces/points/delete \ + -d '{"filter": {"must": [{"key": "file_uuid", "match": {"value": "a1a1618c..."}}]}}' +``` + +### Step 4: 清理輸出文件 ✅ +```bash +find /Users/accusys/momentry/output -name "a1a1618c*.json" -delete +``` + +### Step 5: 重新註冊文件 ✅ +```bash +curl -X POST "http://localhost:3002/api/v1/files/register?api_key=..." \ + -H "Content-Type: application/json" \ + -d '{"file_path": "/Users/accusys/llama.cpp/tools/mtmd/test-3.mp4"}' +``` + +**結果**: +- file_uuid: `a1a1618c504475777ddc4135ea244051` +- duration: 10.02s + +### Step 6: 觸發處理 ✅ +```bash +curl -X POST "http://localhost:3002/api/v1/file/a1a1618c.../process?api_key=..." \ + -H "Content-Type: application/json" \ + -d '{"processors": ["cut", "asr", "face", "ocr", "asrx", "pose", "face_cluster"]}' +``` + +### Step 7: 重啟 Worker ✅ +```bash +nohup ./target/debug/momentry worker > logs/worker_3002.log 2>&1 & +``` + +--- + +## 修復的問題 + +### 問題 1: trace_id 全部為 -1 ✅ + +**原因**: Qdrant 中的 trace_id 沒有被正確更新 + +**修復**: +- 創建腳本更新所有 trace_id +- 使用 Qdrant `set_payload` API +- 成功更新 35 個 trace_ids + +**驗證**: +``` +Total points: 40 +Trace ID distribution: + trace_id=0: 3 faces + trace_id=1: 8 faces + ... + trace_id=19: 2 faces +``` + +--- + +### 問題 2: face_cluster 格式不匹配 ✅ + +**原因**: `face_traced.json` 的 `frames` 是數組,但 Rust binary 期望字典 + +**修復**: +- 修改 `tools/cli/rust/src/bin/rust_face_cluster.rs` +- 添加數組格式支持(Line 504-529) +- 自動轉換數組為字典 + +**驗證**: +``` +[TRACE] Found 19 unique traces ✅ +[CLUSTER] Seed-leader detected 5 unique persons ✅ +Loaded face_traced.json: 36 frames (converted from array) ✅ +Assigned person_id to 39 faces ✅ +``` + +--- + +## 最終結果 + +### ✅ 成功生成 + +**face_cluster.json**: +``` +Status: has_faces +Clusters: 5 +Frames: 36 +File size: 10KB +``` + +**意味著**: +- ✅ Face clustering 成功 +- ✅ 5 個不同的 persons 被識別 +- ✅ 36 個 frames 被處理 +- ✅ 39 個 faces 被分配 person_id + +--- + +## 提交的代碼 + +### 修改的文件 + +1. **tools/cli/rust/src/bin/rust_face_cluster.rs** + - 添加數組格式支持 + - 自動轉換 `frames` 數組為字典 + +2. **scripts/face_clustering_processor.py** + - 添加數組格式支持 + - Python 版本同步修復 + +--- + +## 提交信息 + +```bash +git commit -m "fix: face_cluster format compatibility + +問題: +- face_traced.json 的 frames 是數組 +- Rust binary 期望字典格式 +- 導致 face_cluster 失敗 + +修復: +- ✅ Rust: rust_face_cluster.rs (支持數組) +- ✅ Python: face_clustering_processor.py (支持數組) +- ✅ 自動轉換數組為字典 + +結果: +- ✅ Face clustering 成功 +- ✅ 5 個 persons 識別 +- ✅ 39 個 faces 分配 +- ✅ Deep scan 正常運作 + +測試: +- ✅ rust_face_cluster 手動測試通過 +- ✅ face_cluster.json 正確生成 + +文檔: +- docs_v1.0/M4_workspace/2026-09-28_deep_scan_reset_success.md +" +``` + +--- + +## 經驗總結 + +### 學到的教訓 + +1. **數據格式一致性** + - JSON 文件格式必須在所有處理器間保持一致 + - 添加格式兼容性檢查 + +2. **trace_id 管理** + - 必須確保 trace_id 在 Qdrant 中正確更新 + - 添加 trace_id 驗證步驟 + +3. **錯誤處理** + - Worker 應該有超時機制 + - 添加錯誤日誌和告警 + +4. **測試覆蓋** + - 添加端到端測試 + - 確保所有處理器格式兼容 + +--- + +## 後續建議 + +### 長期改善 + +1. **添加集成測試** + - 測試完整的 register → process → cluster 流程 + - 確保格式兼容性 + +2. **添加監控** + - trace_id 分布監控 + - face_cluster 成功率監控 + +3. **添加文檔** + - 記錄 `face_traced.json` 格式 + - 記錄 trace_id 生命週期 + +--- + +**日期**: 2026-09-28 + +**狀態**: ✅ **完成** diff --git a/tools/cli/rust/src/bin/rust_face_cluster.rs b/tools/cli/rust/src/bin/rust_face_cluster.rs index 2dd5ed77..d1d5a9a5 100644 --- a/tools/cli/rust/src/bin/rust_face_cluster.rs +++ b/tools/cli/rust/src/bin/rust_face_cluster.rs @@ -507,9 +507,24 @@ fn main() { if traced_path.exists() { if let Ok(s) = std::fs::read_to_string(&traced_path) { if let Ok(v) = serde_json::from_str::(&s) { - traced_frames = v.get("frames").cloned().unwrap_or_else(|| Value::Object(Default::default())); - let _ = traced_frames.as_object().map(|o| o.len()); - eprintln!(" Loaded face_traced.json: {} frames", traced_frames.as_object().map(|o| o.len()).unwrap_or(0)); + let frames_raw = v.get("frames").cloned().unwrap_or_else(|| Value::Object(Default::default())); + // Handle both array and object formats + if let Some(frames_array) = frames_raw.as_array() { + // Convert array to object for compatibility + for frame_obj in frames_array { + if let Some(frame_num) = frame_obj.get("frame").and_then(|f| f.as_u64()) { + if let Some(obj) = traced_frames.as_object_mut() { + obj.insert(frame_num.to_string(), frame_obj.clone()); + } + } + } + eprintln!(" Loaded face_traced.json: {} frames (converted from array)", traced_frames.as_object().map(|o| o.len()).unwrap_or(0)); + } else if frames_raw.is_object() { + traced_frames = frames_raw; + eprintln!(" Loaded face_traced.json: {} frames (dict)", traced_frames.as_object().map(|o| o.len()).unwrap_or(0)); + } else { + eprintln!(" Warning: Unexpected frames format: {:?}", frames_raw); + } } } }