diff --git a/docs_v1.0/M4_workspace/2026-09-27_rescan_test_report.md b/docs_v1.0/M4_workspace/2026-09-27_rescan_test_report.md new file mode 100644 index 00000000..433550d8 --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-09-27_rescan_test_report.md @@ -0,0 +1,223 @@ +--- +title: Re-scan API 測試報告 +version: 1.0 +date: 2026-09-27 +author: OpenCode +status: test_incomplete +--- + +## 測試環境 + +- **服務器**: Production (localhost:3002) +- **Worker**: 運行中(處理其他任務) +- **Auto-Pipeline**: ✅ Enabled (true) +- **測試視頻**: `/Users/accusys/llama.cpp/tools/mtmd/test-3.mp4` (646KB) + +--- + +## 測試結果 + +### 測試 1: 檢查 Auto-Pipeline 設置 + +```bash +curl http://localhost:3002/api/v1/health +``` + +**結果**: +```json +{ + "auto_pipeline_enabled": true +} +``` + +**結論**: ✅ Auto-pipeline 已啟用 + +--- + +### 測試 2: 註冊新文件 + +```bash +curl -X POST http://localhost:3002/api/v1/files/register \ + -d '{"file_path": "/Users/accusys/llama.cpp/tools/mtmd/test-3.mp4"}' +``` + +**結果**: +```json +{ + "success": true, + "command_id": "aa52ea4b01244a8397441b264ebf1b7f", + "status": "queued", + "warning": "Worker is not running - file will be registered but not processed automatically" +} +``` + +**問題**: +- Worker 實際在運行,但 API 報告 "Worker is not running" +- Command 創建成功,但未立即處理 + +--- + +### 測試 3: 檢查 Command 狀態 + +```bash +curl http://localhost:3002/api/v1/command/aa52ea4b01244a8397441b264ebf1b7f +``` + +**結果**: +```json +{ + "status": "pending", + "file_uuid": null +} +``` + +**問題**: Command 仍在 pending 狀態,未被 Worker 處理 + +--- + +## 發現的問題 + +### 1. Worker 狀態檢測不準確 + +**位置**: `src/api/health.rs` (猜測) + +**問題**: +- API 返回 "Worker is not running" +- 實際 Worker 進程存在且正在處理其他任務 + +**影響**: +- 用戶收到錯誤警告 +- 可能導致誤判 + +--- + +### 2. Command 處理延遲 + +**問題**: +- Worker 正在處理其他任務(jobs 959, 950, 949 都是 running) +- 新創建的 commands 排隊等待 +- 無法及時測試 re-scan 行為 + +**建議**: +- 增加 Worker 並發數 +- 或使用 Playground (3003) 測試 + +--- + +### 3. Force Register 行為未驗證 + +**原因**: Worker 太忙,無法及時處理 command + +**影響**: +- 無法驗證 force register 後是否會自動觸發 process +- 無法確認問題是否存在 + +--- + +## 代碼分析(替代測試) + +### Force Register 邏輯 + +**位置**: `src/api/files.rs:754-783` + +```rust +if req.force { + // 1. 創建 unregister command + state.db.create_command("unregister", ...).await; + + // 2. 創建 register command + state.db.create_command("register", ...).await; + + // ❌ 沒有創建 process command +} +``` + +**結論**: ❌ Force register 不會自動創建 process command + +--- + +### Auto-Pipeline 觸發條件 + +**位置**: `src/worker/job_worker.rs:546-550` + +```rust +if resp.success + && !resp.already_exists // ← Force re-register 時為 false + && resp.file_type == Some("video") + && get_auto_pipeline_enabled() +{ + // 創建 monitor_job 並觸發 pipeline +} +``` + +**結論**: ❌ Force re-register 不會觸發 auto-pipeline + +--- + +## 測試結論 + +### 確認的問題 + +1. ✅ **Auto-pipeline 默認開啟** (與分析不一致) + - 測試顯示: `auto_pipeline_enabled: true` + - 但 force register 仍不會觸發 + +2. ✅ **Force register 不會自動觸發處理** + - 代碼邏輯確認:不會創建 process command + - Auto-pipeline 條件不滿足:`!resp.already_exists` + +3. ❌ **實際執行測試未完成** + - Worker 太忙,無法處理測試 command + - 需要等待 Worker 空閒或使用 Playground + +--- + +## 建議 + +### 1. 使用 Playground (3003) 測試 + +```bash +# 啟動 Playground +./run-server-3003.sh + +# 測試 force register +curl -X POST http://localhost:3003/api/v1/files/register \ + -d '{"file_path": "/path/to/test.mp4", "force": true}' +``` + +--- + +### 2. 增加 Worker 並發 + +```bash +# 增加 max-concurrent +target/debug/momentry worker --max-concurrent 12 +``` + +--- + +### 3. 實現 Re-scan API(推薦) + +根據之前的分析,實現 `POST /api/v1/re-scan` API。 + +--- + +## 下一步 + +1. **清理 Worker 任務隊列** + - 取消或完成 running jobs + - 釋放 Worker 資源 + +2. **重新測試** + - 使用 Playground 或等待 Worker 空閒 + - 驗證 force register 行為 + +3. **實現解決方案** + - 根據測試結果實現 Re-scan API + +--- + +## 相關文檔 + +- `/Users/accusys/momentry_core/docs_v1.0/M4_workspace/2026-09-27_re_scan_issue.md` +- `/Users/accusys/momentry_core/docs_v1.0/M4_workspace/2026-09-27_re_scan_analysis.md`