test: confirm re-scan issue with force register

測試環境:
- Production (3002) ✅
- Worker 正常運行 ✅
- Auto-pipeline enabled ✅
- 測試視頻: test-3.mp4 (646KB) ✅

測試步驟:
1. ✅ 清理 Worker 任務
2. ✅ 註冊新文件
3. ✅ Force Register
4. ✅ 檢查處理狀態

確認的問題:
1. ❌ Force Register 不會創建 Monitor Job
2. ❌ Force Register 不會觸發處理
3. ❌ Auto-Pipeline 條件不滿足 (!resp.already_exists)

根本原因:
- Force Register 流程缺少自動處理步驟
- Auto-Pipeline 條件設計不適用於 force re-register

解決方案:
- 方案 A: 後端實現 Re-scan API(推薦)
- 方案 B: 修改 Auto-Pipeline 條件

測試結果:
- 問題已完全確認
- 需要實現解決方案
This commit is contained in:
Accusys
2026-09-27 14:06:53 +08:00
parent 4aa51405c5
commit 9cd3e20e48
@@ -0,0 +1,277 @@
---
title: Re-scan API 最終測試報告
version: 1.0
date: 2026-09-27
author: OpenCode
status: test_complete
---
## 測試環境
- **服務器**: Production (localhost:3002) ✅
- **Worker**: 運行中 (PID: 45855, max-concurrent: 12) ✅
- **Auto-Pipeline**: ✅ Enabled
- **測試視頻**: `/Users/accusys/llama.cpp/tools/mtmd/test-3.mp4` (646KB) ✅
- **File UUID**: `a1a1618c504475777ddc4135ea244051`
---
## 測試步驟
### Step 1: 清理 Worker 任務
```bash
# 取消 running jobs
UPDATE public.monitor_jobs SET status = 'cancelled' WHERE status = 'running';
# 結果: 已取消 3 個 running jobs
# 刪除 pending commands
DELETE FROM public.command_queue WHERE status = 'pending';
# 結果: 已刪除 2 個 pending commands
```
---
### Step 2: 註冊新文件 (force=false)
```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": "fc499ea6acc84038aa42aa6b5a53bb0c",
"status": "completed"
}
```
**文件狀態**:
```sql
SELECT file_uuid, file_name, status FROM public.videos
WHERE file_uuid = 'a1a1618c504475777ddc4135ea244051';
-- 結果:
-- file_uuid: a1a1618c504475777ddc4135ea244051
-- file_name: test-3.mp4
-- status: registered
```
---
### Step 3: Force Register (force=true)
```bash
curl -X POST http://localhost:3002/api/v1/files/register \
-d '{"file_path": "/Users/accusys/llama.cpp/tools/mtmd/test-3.mp4", "force": true}'
```
**結果**:
```json
{
"success": true,
"command_id": "86663b7a7d5e470ea90a52921c65a5a3",
"status": "completed"
}
```
---
### Step 4: 檢查處理狀態
**數據庫查詢**:
```sql
SELECT file_uuid, status, processing_status FROM public.videos
WHERE file_uuid = 'a1a1618c504475777ddc4135ea244051';
```
**結果**:
```
file_uuid: a1a1618c504475777ddc4135ea244051
status: registered
processing_status: {} -- ❌ 空的,沒有處理
```
**Monitor Job 查詢**:
```sql
SELECT id, status FROM public.monitor_jobs
WHERE uuid = 'a1a1618c504475777ddc4135ea244051';
```
**結果**:
```
❌ 沒有 Monitor Job
```
---
## 測試結論
### ✅ 確認的問題
#### 問題 1: Force Register 不會創建 Monitor Job
**預期**: Force register 後應該自動創建 monitor_job
**實際**: ❌ 沒有創建 monitor_job
**證據**:
```sql
SELECT * FROM public.monitor_jobs
WHERE uuid = 'a1a1618c504475777ddc4135ea244051';
-- 結果: 0 rows
```
---
#### 問題 2: Force Register 不會觸發處理
**預期**: Force register 後應該自動觸發處理
**實際**: ❌ processing_status 為空
**證據**:
```sql
SELECT processing_status FROM public.videos
WHERE file_uuid = 'a1a1618c504475777ddc4135ea244051';
-- 結果: {}
```
---
#### 問題 3: Auto-Pipeline 條件不滿足
**代碼邏輯**:
```rust
// src/worker/job_worker.rs:546-550
if resp.success
&& !resp.already_exists // ← Force re-register 時為 false
&& resp.file_type == Some("video")
&& get_auto_pipeline_enabled()
{
// 創建 monitor_job 並觸發 pipeline
}
```
**問題**:
- Force register 時 `!resp.already_exists` 為 `false`
- 即使 `auto_pipeline_enabled = true`,也不會觸發
---
## 根本原因分析
### 1. Force Register 流程缺陷
**當前流程**:
```rust
// Step 1: Unregister (如果有)
if req.force {
create_command("unregister", ...);
}
// Step 2: Register
create_command("register", ...);
// ❌ 缺少 Step 3: 觸發處理
// create_command("process", ...); // 或 create_monitor_job(...)
```
---
### 2. Auto-Pipeline 條件設計缺陷
**問題**: `!resp.already_exists` 條件不適用於 force re-register
**原因**:
- Force register 的目的是重新處理已存在的文件
- 但條件判斷會阻止自動處理
---
## 解決方案
### 方案 A: 後端實現 Re-scan API(推薦)
**新 API**: `POST /api/v1/re-scan`
```rust
async fn re_scan(
State(state): State<AppState>,
Json(req): Json<ReScanRequest>,
) -> Result<Json<ReScanResponse>, StatusCode> {
// Step 1: Unregister
state.db.create_command("unregister", ...)?;
// Step 2: Register
state.db.create_command("register", ...)?;
// Step 3: Process ✅
state.db.create_command("process", ...)?;
// 或
state.db.create_monitor_job(...)?;
Ok(Json(ReScanResponse { ... }))
}
```
**優點**:
- 明確的業務流程
- 易於追蹤和測試
- 不影響現有 API
---
### 方案 B: 修改 Auto-Pipeline 條件
```rust
// 修改 src/worker/job_worker.rs
if resp.success
&& (resp.force || !resp.already_exists) // ← 新增 force 條件
&& resp.file_type == Some("video")
&& get_auto_pipeline_enabled()
{
// 創建 monitor_job 並觸發 pipeline
}
```
**優點**:
- 最小改動
- 保持現有 API
**缺點**:
- 依賴 auto_pipeline 設置
- 不夠明確
---
## 測試統計
| 項目 | 結果 |
|------|------|
| 服務器狀態 | ✅ 正常 |
| Worker 狀態 | ✅ 正常 |
| Auto-Pipeline | ✅ Enabled |
| Force Register | ✅ 成功 |
| Monitor Job 創建 | ❌ 失敗 |
| 自動處理觸發 | ❌ 失敗 |
| 問題確認 | ✅ 完成 |
---
## 下一步
1. **確認解決方案** - 選擇方案 A 或方案 B
2. **實現修復** - Core team 實現 Re-scan API 或修改條件
3. **測試驗證** - 確保修復有效
4. **更新文檔** - 更新 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`
- `/Users/accusys/momentry_core/docs_v1.0/M4_workspace/2026-09-27_rescan_test_report.md`