# M5 Fix Report — 2026-05-06

**Author**: M5 (OpenCode build mode)
**Based on**: M4 test reports (5 files in `M4_workspace/`)

---

## 已修復

### 1. Qdrant Voice/Face Collection Auto-Creation (🔴 Critical)
- `QdrantDb::ensure_collection()` — 檢查 + 自動建立 collection
- `_face` (512D) 和 `_voice` (192D) collection 在寫入前自動確保存在
- 根因：ASRX 完成後寫入不存在的 `momentry_dev_voice` → panic → pool leak → 所有 post-processing 跳過

### 2. Processor Task Panic Protection (🔴 Critical)
- `ProcessorCleanupGuard` — Drop guard 確保 task panic 時清理 pool counter

### 3. `/api/v1/file/:file_uuid/chunks` → 500
- 根因：SELECT 了 `identity_id`, `confidence` 兩個不存在於 DB 的欄位

### 4. `store_chunk_in_tx` ON CONFLICT 用錯欄位
- `ON CONFLICT (file_uuid, chunk_id)` → `(file_uuid, old_chunk_id)`，DB 實際 constraint 是後者

### 5. `rule3_ingest` 同樣 ON CONFLICT 問題 (INSERT 缺 `old_chunk_id`)

### 6. Qdrant face sync → `dev.dev.face_detections` (schema prefix 重複)

### 7. Job premature completion with pending processors
- `check_and_complete_job` 加入 `any_pending` 檢查，防止 job 在仍有 pending processor 時被標為 completed

### 8. Auto-vectorize after Rule 1 chunking (新功能)
- `JobWorker::vectorize_chunks()` 自動在 Rule 1 完成後對 sentence chunks 產生 embedding
- 寫入 PG `chunks.embedding` + Qdrant `momentry_dev_rule1`

## 受影響檔案

```
src/core/db/qdrant_db.rs         — ensure_collection(), fix sync_face_embeddings schema
src/worker/processor.rs           — ProcessorCleanupGuard, ensure_collection calls
src/worker/job_worker.rs          — any_pending check, vectorize_chunks()
src/api/server.rs                 — fix pre_chunks query columns
src/core/db/postgres_db.rs        — fix ON CONFLICT + old_chunk_id in INSERT
src/core/chunk/rule3_ingest.rs    — fix INSERT missing old_chunk_id
src/core/embedding/comic_embed.rs — dimension 768→1024
AGENTS.md                         — M4 read-only, M5_workspace
```

## 待驗證

- Charade 長片 pipeline 完成後，auto-vectorize 是否正確產生 embeddings
- Qdrant `momentry_dev_rule1` collection 是否自動建立

## 追加修復 (2026-05-07)

### cut_processor.py `--threshold 27` 參數錯誤
- **檔案**: `src/api/server.rs`
- **根因**: Registration 階段呼叫 `cut_processor.py --threshold 27`，但 script 已更新不支援此參數
- **修復**: 移除 `--threshold 27` 參數

### 下載模型就緒
- LLM: Gemma4 26B MoE, Qwen3 30B MoE, Mistral 24B (均 GGUF)
- Embedding (Ollama + GGUF): mxbai-embed-large, bge-m3, nomic-embed-text-v2-moe

### Charade Pipeline
- Job 252 running（新 binary, 含 all pending/skipped/panic fix）
