docs: add Studio team handoff documents for worker deadlock fix

** Purpose:
- Provide clear deployment instructions for Studio team
- Document the fix and required actions
- Enable quick verification steps

** Files Added:
- docs_v1.0/STUDIO_TEAM/2026-09-18_worker_deadlock_fix_handoff.md
- docs_v1.0/STUDIO_TEAM/README.md

** Key Points:
- Code fix committed (0fe09af)
- Worker binary needs rebuild
- Studio team should rebuild and redeploy
- Verification steps included
This commit is contained in:
Accusys
2026-09-18 04:21:20 +08:00
parent 2c1618ef06
commit 51c86a22f4
2 changed files with 336 additions and 0 deletions
@@ -0,0 +1,279 @@
---
title: Worker Deadlock Fix - Studio Handoff
version: 1.0
date: 2026-09-18
author: Core Team
status: ready_for_deployment
---
# Worker Deadlock Fix - Studio Team Handoff
**Date**: 2026-09-18
**Priority**: High
**Impact**: UI "Deep Scan" 按鈕功能無法使用
---
## 執行摘要
UI "Deep Scan" 功能因 Worker deadlock 而無法正常運作。Core 團隊已完成代碼修復並提交,**需要 Studio 團隊重新 build 並部署**。
---
## 問題描述
### 用戶症狀
- UI 點擊 "Deep Scan" 按鈕後,處理器顯示為 "running" 但從未完成
- Worker 進入無限循環,持續等待處理器完成
- 用戶無法處理任何影片
### 根本原因
**文件**: `/Users/accusys/momentry_core/src/worker/job_worker.rs`
**Bug**: Worker 在設置處理器狀態為 "running" 後,才檢查並發限制
#### 錯誤流程(修復前)
```rust
// Line 590-600: 設置狀態為 'running'
for processor_type in &processors_to_run {
self.db.update_processor_progress(..., "running").await?;
// ... 檢查文件 ...
// Line 1434: 檢查並發限制(太晚了!)
if !self.processor_pool.can_start_for_job(job.id).await {
// 標記為 'skipped',但可能失敗
self.db.upsert_processor_result(..., "skipped").await?;
break;
}
}
```
**問題**:
1. Worker 設置 "running" 狀態
2. 發現並發限制已滿
3. 嘗試更新為 "skipped",但可能失敗或中斷
4. 狀態卡在 "running",Worker 下次跳過處理器
5. **Deadlock**
---
## 已完成的修復
### Core 團隊已完成
1. ✅ **定位問題**: Worker 並發檢查時機錯誤
2. ✅ **代碼修復**: 將並發檢查移到設置狀態之前
3. ✅ **提交代碼**: `git commit 0fe09af`
4. ✅ **文檔記錄**: `docs_v1.0/M4_workspace/2026-09-18_worker_running_deadlock_fix.md`
### 修復內容
**文件**: `src/worker/job_worker.rs`
**修改位置**: Lines 590-633
**修復後流程**:
```rust
for processor_type in &processors_to_run {
// 先檢查並發限制
if !self.processor_pool.can_start_for_job(job.id).await {
// 立即標記為 'skipped'
self.db.upsert_processor_result(..., "skipped").await?;
continue;
}
// 通過檢查後,才設置 'running'
self.db.update_processor_progress(..., "running").await?;
// 啟動處理器...
}
```
---
## ⚠️ Studio 團隊需要執行的動作
### 必要步驟
#### 1. 拉取最新代碼
```bash
cd /Users/accusys/momentry_core
git pull origin main
```
#### 2. 重新 Build Worker Binary
**方案 A:Release Binary(推薦用於生產環境)**
```bash
# 需要 5-10 分鐘
cargo build --release --bin momentry
# 驗證 build 時間
ls -la target/release/momentry
# 應該顯示 2026-09-18 20:xx:xx 或更晚
```
**方案 B:Debug Binary(更快,適合快速測試)**
```bash
# 需要 1-2 分鐘
cargo build --bin momentry
# 使用 debug binary
# 需要修改 run-worker-3002.sh 腳本,指向 target/debug/momentry
```
#### 3. 重啟 Worker
```bash
# 停止舊 Worker
pkill -f "target/release/momentry worker"
# 啟動新 Worker
./run-worker-3002.sh
```
#### 4. 驗證修復
**測試步驟**:
1. 在 UI 點擊 "🔍 Deep Scan" 按鈕
2. 觀察處理器狀態:
- ✅ **應該看到**: ASR, OCR, Pose 狀態變為 "pending" → "running" → "completed"
- ❌ **如果看到**: 處理器卡在 "running" 不動 → **未使用新 binary**
3. 檢查輸出文件:
```bash
ls -la /Users/accusys/momentry/output/1ad54677a8ad5a44c6c8cad1f4c21595.*.json
# 應該看到: .asr.json, .ocr.json, .pose.json
```
---
## 技術細節
### 相關 Commits
| Commit | 說明 |
|--------|------|
| `0fe09af` | fix: prevent 'running' status deadlock in worker |
| `31d1b405` | fix: correct face detection threshold defaults |
| `2c1618e` | docs: add worker running deadlock fix report |
### 相關文件
| 文件 | 說明 |
|------|------|
| `src/worker/job_worker.rs` | Worker 主邏輯,已修復 |
| `src/core/admin_config.rs` | Face detection 閾值,已修復 |
| `docs_v1.0/M4_workspace/2026-09-18_worker_running_deadlock_fix.md` | 詳細技術報告 |
### Worker 啟動腳本
**文件**: `/Users/accusys/momentry_core/run-worker-3002.sh`
**檢查 binary 路徑**:
```bash
# 確認腳本使用正確的 binary
grep "target/release/momentry worker" run-worker-3002.sh
# 或
grep "target/debug/momentry worker" run-worker-3002.sh
```
---
## 預期結果
### 修復前
```
UI 點擊 Deep Scan → Worker deadlock
處理器: ASR/OCR/Pose 顯示 "running" 但不執行
用戶: 無法處理影片
```
### 修復後
```
UI 點擊 Deep Scan → Worker 正常處理
處理器: ASR/OCR/Pose 顯示 "pending" → "running" → "completed"
用戶: 成功處理影片
```
---
## 故障排除
### 如果問題持續
1. **確認 binary 時間**:
```bash
ls -la target/release/momentry
# 時間應該在 2026-09-18 20:06 之後
```
2. **檢查 Worker 日誌**:
```bash
tail -f logs/worker_3002.log | grep -E "asr|ocr|pose|already running"
# 不應該看到 "already running, skipping"
```
3. **清理舊狀態**:
```python
# 使用 Python 清理
import psycopg2
conn = psycopg2.connect("postgres://accusys@localhost:5432/momentry")
cur = conn.cursor()
cur.execute("DELETE FROM processor_results WHERE status = 'running' AND started_at IS NULL")
conn.commit()
```
### 聯繫 Core 團隊
如果遇到問題,請在 `docs_v1.0/M4_workspace/` 創建問題報告,Core 團隊會通過 git commit 回覆。
---
## 附錄:完整的清理腳本
如果需要清理當前卡住的狀態,可以運行:
```bash
# 清理 processor_results 中的 running 狀態
python3 << 'EOF'
import psycopg2
conn = psycopg2.connect("postgres://accusys@localhost:5432/momentry")
cur = conn.cursor()
cur.execute("""
DELETE FROM processor_results
WHERE status = 'running'
AND started_at IS NULL
RETURNING job_id, processor
""")
rows = cur.fetchall()
conn.commit()
print(f"✓ 已清理 {len(rows)} 個過期的 'running' 記錄")
for row in rows:
print(f" Job: {row[0]}, Processor: {row[1]}")
conn.close()
EOF
```
---
## 歷史記錄
| 版本 | 日期 | 變更 |
|------|------|------|
| 1.0 | 2026-09-18 | 初始交付文件 |
+57
View File
@@ -0,0 +1,57 @@
# Worker Deadlock Fix - Quick Start Guide
**狀態**: ✅ 代碼已修復,等待部署
**優先級**: High
**影響**: UI "Deep Scan" 功能無法使用
---
## 立即執行(3 步驟)
### 1. 拉取最新代碼
```bash
cd /Users/accusys/momentry_core
git pull origin main
```
### 2. 重新 Build
```bash
# Release binary(推薦)
cargo build --release --bin momentry
# 驗證 build 時間(應該在 2026-09-18 20:06 之後)
ls -la target/release/momentry
```
### 3. 重啟 Worker
```bash
./run-worker-3002.sh
```
---
## 驗證修復
1. UI 點擊 "🔍 Deep Scan"
2. 觀察處理器狀態:
- ✅ 應該執行 ASR, OCR, Pose
- ❌ 如果卡在 "running" → binary 未更新
---
## 相關文件
- **詳細報告**: `docs_v1.0/STUDIO_TEAM/2026-09-18_worker_deadlock_fix_handoff.md`
- **技術細節**: `docs_v1.0/M4_workspace/2026-09-18_worker_running_deadlock_fix.md`
- **修復 commit**: `0fe09af`
---
## 如果問題持續
創建文件: `docs_v1.0/M4_workspace/YYYY-MM-DD_issue_report.md`
Core 團隊會通過 git commit 回覆。